71 lines
2.7 KiB
JavaScript
71 lines
2.7 KiB
JavaScript
import { overseasRequest } from './overseas.js'
|
|
|
|
const BASE = '/pda/v1/last-leg'
|
|
const encoded = (value) => encodeURIComponent(String(value || '').trim())
|
|
|
|
function asList(value) {
|
|
if (Array.isArray(value)) return value
|
|
if (Array.isArray(value?.records)) return value.records
|
|
return []
|
|
}
|
|
|
|
function count(value) {
|
|
const result = Number(value || 0)
|
|
return Number.isFinite(result) ? Math.max(0, result) : 0
|
|
}
|
|
|
|
export function normalizeStocktake(value) {
|
|
const task = value?.task || value || {}
|
|
return {
|
|
...value,
|
|
task: { ...task, taskNo: String(task.taskNo || ''), scopeCode: String(task.scopeCode || ''), version: count(task.version) },
|
|
items: asList(value?.items).map((item) => ({
|
|
...item,
|
|
itemId: String(item.itemId || ''), balanceId: String(item.balanceId || ''), positionId: String(item.positionId || ''),
|
|
palletCode: String(item.palletCode || ''), locationCode: String(item.locationCode || ''),
|
|
bookPackages: count(item.bookPackages), actualPackages: item.actualPackages == null ? null : count(item.actualPackages),
|
|
differencePackages: item.differencePackages == null ? null : Number(item.differencePackages),
|
|
positionVersion: count(item.positionVersion), version: count(item.version)
|
|
}))
|
|
}
|
|
}
|
|
|
|
export async function listStocktakes(status = 'IN_PROGRESS') {
|
|
const suffix = `?page=1&size=100${status ? `&status=${encoded(status)}` : ''}`
|
|
return asList(await overseasRequest('GET', `${BASE}/stocktakes${suffix}`)).map((item) => ({
|
|
...item, taskNo: String(item.taskNo || ''), scopeCode: String(item.scopeCode || ''), version: count(item.version)
|
|
}))
|
|
}
|
|
|
|
export async function createStocktake(request) {
|
|
return normalizeStocktake(await overseasRequest('POST', `${BASE}/stocktakes`, request))
|
|
}
|
|
|
|
export async function getStocktake(taskNo) {
|
|
return normalizeStocktake(await overseasRequest('GET', `${BASE}/stocktakes/${encoded(taskNo)}`))
|
|
}
|
|
|
|
export function countStocktake(taskNo, request) {
|
|
return overseasRequest('POST', `${BASE}/stocktakes/${encoded(taskNo)}/counts`, request)
|
|
}
|
|
|
|
export async function submitStocktake(taskNo, request) {
|
|
return normalizeStocktake(await overseasRequest('POST', `${BASE}/stocktakes/${encoded(taskNo)}/submit`, request))
|
|
}
|
|
|
|
export function moveInventory(request) {
|
|
return overseasRequest('POST', `${BASE}/inventory-moves`, request)
|
|
}
|
|
|
|
export function resolveInventory(code) {
|
|
return overseasRequest('POST', `${BASE}/inventory/resolve`, { code: String(code || '').trim() })
|
|
}
|
|
|
|
export function resolveWarehouseLocation(code) {
|
|
return overseasRequest('POST', `${BASE}/locations/resolve`, { code: String(code || '').trim() })
|
|
}
|
|
|
|
export function resolveWarehousePallet(code) {
|
|
return overseasRequest('POST', `${BASE}/pallets/resolve`, { code: String(code || '').trim() })
|
|
}
|