|
|
@@ -0,0 +1,311 @@ |
|
|
|
|
|
"use client"; |
|
|
|
|
|
|
|
|
|
|
|
import axiosInstance from "@/app/(main)/axios/axiosInstance"; |
|
|
|
|
|
import { NEXT_PUBLIC_API_URL } from "@/config/api"; |
|
|
|
|
|
|
|
|
|
|
|
export type StockLedgerFixDayStatus = { |
|
|
|
|
|
date: string; |
|
|
|
|
|
cnt: number; |
|
|
|
|
|
missLot: number; |
|
|
|
|
|
missUom: number; |
|
|
|
|
|
missInventoryId: number; |
|
|
|
|
|
missLotQty: number; |
|
|
|
|
|
dayTableLots: number; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export type StockLedgerFixCalendarResponse = { |
|
|
|
|
|
from: string; |
|
|
|
|
|
to: string; |
|
|
|
|
|
days: StockLedgerFixDayStatus[]; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export type StockLedgerFixCheckPart = { |
|
|
|
|
|
key: string; |
|
|
|
|
|
label: string; |
|
|
|
|
|
ok: number; |
|
|
|
|
|
miss: number; |
|
|
|
|
|
incorrect: number; |
|
|
|
|
|
group?: string; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export type StockLedgerFixDayDetail = { |
|
|
|
|
|
date: string; |
|
|
|
|
|
cnt: number; |
|
|
|
|
|
parts: StockLedgerFixCheckPart[]; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export type StockLedgerFixRunResponse = { |
|
|
|
|
|
date: string; |
|
|
|
|
|
filledLotLineId: number; |
|
|
|
|
|
filledUomId: number; |
|
|
|
|
|
filledInventoryId: number; |
|
|
|
|
|
filledLotQty: number; |
|
|
|
|
|
filledBalance: number; |
|
|
|
|
|
dayRowsWritten: number; |
|
|
|
|
|
stillMissLot: number; |
|
|
|
|
|
stillMissUom: number; |
|
|
|
|
|
stillMissInventoryId: number; |
|
|
|
|
|
stillMissLotQty: number; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export type StockLedgerFixInventoryPreview = { |
|
|
|
|
|
inventoryRows: number; |
|
|
|
|
|
lotUomPairs: number; |
|
|
|
|
|
missingUomPairs: number; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export type StockLedgerFixInventoryResponse = { |
|
|
|
|
|
inserted: number; |
|
|
|
|
|
updated: number; |
|
|
|
|
|
missingUomPairsAfter: number; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export type StockLedgerFixSearchInventoryHit = { |
|
|
|
|
|
inventoryId: number; |
|
|
|
|
|
itemId: number | null; |
|
|
|
|
|
itemCode: string | null; |
|
|
|
|
|
uomId: number | null; |
|
|
|
|
|
ledgerCnt: number; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export type StockLedgerFixSearchLotHit = { |
|
|
|
|
|
inventoryLotLineId: number; |
|
|
|
|
|
lotNo: string | null; |
|
|
|
|
|
itemCode: string | null; |
|
|
|
|
|
inventoryId: number | null; |
|
|
|
|
|
ledgerCnt: number; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export type StockLedgerFixScopeDetail = { |
|
|
|
|
|
kind: string; |
|
|
|
|
|
id: number; |
|
|
|
|
|
itemCode: string | null; |
|
|
|
|
|
lotNo: string | null; |
|
|
|
|
|
inventoryId: number | null; |
|
|
|
|
|
uomId: number | null; |
|
|
|
|
|
firstDate: string | null; |
|
|
|
|
|
lastDate: string | null; |
|
|
|
|
|
cnt: number; |
|
|
|
|
|
lastBalance: string | null; |
|
|
|
|
|
lastLotQtyAfter: string | null; |
|
|
|
|
|
parts: StockLedgerFixCheckPart[]; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export type StockLedgerFixAdjRow = { |
|
|
|
|
|
lotLineId: number; |
|
|
|
|
|
inventoryId: number | null; |
|
|
|
|
|
itemCode: string | null; |
|
|
|
|
|
lineIn: string; |
|
|
|
|
|
lineOut: string; |
|
|
|
|
|
ledgerIn: string; |
|
|
|
|
|
ledgerOut: string; |
|
|
|
|
|
missIn: string; |
|
|
|
|
|
missOut: string; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export type StockLedgerFixAdjPreview = { |
|
|
|
|
|
adjDate: string; |
|
|
|
|
|
lotCount: number; |
|
|
|
|
|
adjInCount: number; |
|
|
|
|
|
adjOutCount: number; |
|
|
|
|
|
skippedNegCount: number; |
|
|
|
|
|
sumMissIn: string; |
|
|
|
|
|
sumMissOut: string; |
|
|
|
|
|
skuNet: string; |
|
|
|
|
|
rows: StockLedgerFixAdjRow[]; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export type StockLedgerFixAdjResponse = { |
|
|
|
|
|
adjDate: string; |
|
|
|
|
|
insertedIn: number; |
|
|
|
|
|
insertedOut: number; |
|
|
|
|
|
filledLotQty: number; |
|
|
|
|
|
filledBalance: number; |
|
|
|
|
|
dayRowsWritten: number; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export async function fetchStockLedgerFixAdjPreview( |
|
|
|
|
|
adjDate?: string, |
|
|
|
|
|
): Promise<StockLedgerFixAdjPreview> { |
|
|
|
|
|
const response = await axiosInstance.get<StockLedgerFixAdjPreview>( |
|
|
|
|
|
`${NEXT_PUBLIC_API_URL}/stock-ledger-fix/adj`, |
|
|
|
|
|
{ |
|
|
|
|
|
params: { |
|
|
|
|
|
rowLimit: 20, |
|
|
|
|
|
...(adjDate ? { adjDate } : {}), |
|
|
|
|
|
}, |
|
|
|
|
|
timeout: 600000, |
|
|
|
|
|
}, |
|
|
|
|
|
); |
|
|
|
|
|
return response.data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function runStockLedgerFixAdj( |
|
|
|
|
|
adjDate?: string, |
|
|
|
|
|
): Promise<StockLedgerFixAdjResponse> { |
|
|
|
|
|
const response = await axiosInstance.post<StockLedgerFixAdjResponse>( |
|
|
|
|
|
`${NEXT_PUBLIC_API_URL}/stock-ledger-fix/adj`, |
|
|
|
|
|
adjDate ? { adjDate } : {}, |
|
|
|
|
|
{ timeout: 1200000 }, |
|
|
|
|
|
); |
|
|
|
|
|
return response.data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function fetchStockLedgerFixCalendar( |
|
|
|
|
|
from: string, |
|
|
|
|
|
to: string, |
|
|
|
|
|
): Promise<StockLedgerFixCalendarResponse> { |
|
|
|
|
|
const response = await axiosInstance.get<StockLedgerFixCalendarResponse>( |
|
|
|
|
|
`${NEXT_PUBLIC_API_URL}/stock-ledger-fix/calendar`, |
|
|
|
|
|
{ params: { from, to } }, |
|
|
|
|
|
); |
|
|
|
|
|
return response.data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function fetchStockLedgerFixDay( |
|
|
|
|
|
date: string, |
|
|
|
|
|
): Promise<StockLedgerFixDayDetail> { |
|
|
|
|
|
const response = await axiosInstance.get<StockLedgerFixDayDetail>( |
|
|
|
|
|
`${NEXT_PUBLIC_API_URL}/stock-ledger-fix/day`, |
|
|
|
|
|
{ params: { date } }, |
|
|
|
|
|
); |
|
|
|
|
|
return response.data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function runStockLedgerFixDay( |
|
|
|
|
|
date: string, |
|
|
|
|
|
steps?: string[], |
|
|
|
|
|
): Promise<StockLedgerFixRunResponse> { |
|
|
|
|
|
const response = await axiosInstance.post<StockLedgerFixRunResponse>( |
|
|
|
|
|
`${NEXT_PUBLIC_API_URL}/stock-ledger-fix/run`, |
|
|
|
|
|
{ date, ...(steps && steps.length > 0 ? { steps } : {}) }, |
|
|
|
|
|
); |
|
|
|
|
|
return response.data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function runStockLedgerFixRange( |
|
|
|
|
|
from: string, |
|
|
|
|
|
to: string, |
|
|
|
|
|
steps?: string[], |
|
|
|
|
|
): Promise<StockLedgerFixRunResponse> { |
|
|
|
|
|
const response = await axiosInstance.post<StockLedgerFixRunResponse>( |
|
|
|
|
|
`${NEXT_PUBLIC_API_URL}/stock-ledger-fix/run`, |
|
|
|
|
|
{ |
|
|
|
|
|
mode: "range", |
|
|
|
|
|
from, |
|
|
|
|
|
to, |
|
|
|
|
|
...(steps && steps.length > 0 ? { steps } : {}), |
|
|
|
|
|
}, |
|
|
|
|
|
{ timeout: 1200000 }, |
|
|
|
|
|
); |
|
|
|
|
|
return response.data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function fetchStockLedgerFixInventory(): Promise<StockLedgerFixInventoryPreview> { |
|
|
|
|
|
const response = await axiosInstance.get<StockLedgerFixInventoryPreview>( |
|
|
|
|
|
`${NEXT_PUBLIC_API_URL}/stock-ledger-fix/inventory`, |
|
|
|
|
|
); |
|
|
|
|
|
return response.data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function runStockLedgerFixInventory(): Promise<StockLedgerFixInventoryResponse> { |
|
|
|
|
|
const response = await axiosInstance.post<StockLedgerFixInventoryResponse>( |
|
|
|
|
|
`${NEXT_PUBLIC_API_URL}/stock-ledger-fix/inventory`, |
|
|
|
|
|
); |
|
|
|
|
|
return response.data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function searchStockLedgerFixInventory( |
|
|
|
|
|
q: string, |
|
|
|
|
|
): Promise<StockLedgerFixSearchInventoryHit[]> { |
|
|
|
|
|
const response = await axiosInstance.get<StockLedgerFixSearchInventoryHit[]>( |
|
|
|
|
|
`${NEXT_PUBLIC_API_URL}/stock-ledger-fix/lookup/inventory`, |
|
|
|
|
|
{ params: { q } }, |
|
|
|
|
|
); |
|
|
|
|
|
return response.data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function searchStockLedgerFixLot( |
|
|
|
|
|
q: string, |
|
|
|
|
|
): Promise<StockLedgerFixSearchLotHit[]> { |
|
|
|
|
|
const response = await axiosInstance.get<StockLedgerFixSearchLotHit[]>( |
|
|
|
|
|
`${NEXT_PUBLIC_API_URL}/stock-ledger-fix/lookup/lot`, |
|
|
|
|
|
{ params: { q } }, |
|
|
|
|
|
); |
|
|
|
|
|
return response.data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function fetchStockLedgerFixInventoryScope( |
|
|
|
|
|
id: number, |
|
|
|
|
|
): Promise<StockLedgerFixScopeDetail> { |
|
|
|
|
|
const response = await axiosInstance.get<StockLedgerFixScopeDetail>( |
|
|
|
|
|
`${NEXT_PUBLIC_API_URL}/stock-ledger-fix/scope/inventory`, |
|
|
|
|
|
{ params: { id } }, |
|
|
|
|
|
); |
|
|
|
|
|
return response.data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function fetchStockLedgerFixLotScope( |
|
|
|
|
|
id: number, |
|
|
|
|
|
): Promise<StockLedgerFixScopeDetail> { |
|
|
|
|
|
const response = await axiosInstance.get<StockLedgerFixScopeDetail>( |
|
|
|
|
|
`${NEXT_PUBLIC_API_URL}/stock-ledger-fix/scope/lot`, |
|
|
|
|
|
{ params: { id } }, |
|
|
|
|
|
); |
|
|
|
|
|
return response.data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function runStockLedgerFixInventoryScope( |
|
|
|
|
|
inventoryId: number, |
|
|
|
|
|
): Promise<StockLedgerFixRunResponse> { |
|
|
|
|
|
const response = await axiosInstance.post<StockLedgerFixRunResponse>( |
|
|
|
|
|
`${NEXT_PUBLIC_API_URL}/stock-ledger-fix/run`, |
|
|
|
|
|
{ mode: "inventory", inventoryId }, |
|
|
|
|
|
); |
|
|
|
|
|
return response.data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function runStockLedgerFixLotScope( |
|
|
|
|
|
lotLineId: number, |
|
|
|
|
|
): Promise<StockLedgerFixRunResponse> { |
|
|
|
|
|
const response = await axiosInstance.post<StockLedgerFixRunResponse>( |
|
|
|
|
|
`${NEXT_PUBLIC_API_URL}/stock-ledger-fix/run`, |
|
|
|
|
|
{ mode: "lot", lotLineId }, |
|
|
|
|
|
); |
|
|
|
|
|
return response.data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function downloadStockLedgerFixSql( |
|
|
|
|
|
from: string, |
|
|
|
|
|
to: string, |
|
|
|
|
|
parts?: string[], |
|
|
|
|
|
): Promise<void> { |
|
|
|
|
|
const response = await axiosInstance.get( |
|
|
|
|
|
`${NEXT_PUBLIC_API_URL}/stock-ledger-fix/export`, |
|
|
|
|
|
{ |
|
|
|
|
|
params: { |
|
|
|
|
|
from, |
|
|
|
|
|
to, |
|
|
|
|
|
...(parts && parts.length > 0 ? { parts } : {}), |
|
|
|
|
|
}, |
|
|
|
|
|
paramsSerializer: { |
|
|
|
|
|
indexes: null, |
|
|
|
|
|
}, |
|
|
|
|
|
responseType: "blob", |
|
|
|
|
|
timeout: 600000, |
|
|
|
|
|
}, |
|
|
|
|
|
); |
|
|
|
|
|
const blob = new Blob([response.data], { type: "application/sql;charset=utf-8" }); |
|
|
|
|
|
const url = URL.createObjectURL(blob); |
|
|
|
|
|
const a = document.createElement("a"); |
|
|
|
|
|
a.href = url; |
|
|
|
|
|
const partTag = |
|
|
|
|
|
parts && parts.length > 0 && parts.length < 5 |
|
|
|
|
|
? `_${parts.join("-").replaceAll(".", "")}` |
|
|
|
|
|
: ""; |
|
|
|
|
|
a.download = `stock_ledger_fix_${from.replaceAll("-", "")}_${to.replaceAll("-", "")}${partTag}.sql`; |
|
|
|
|
|
document.body.appendChild(a); |
|
|
|
|
|
a.click(); |
|
|
|
|
|
a.remove(); |
|
|
|
|
|
URL.revokeObjectURL(url); |
|
|
|
|
|
} |