yyb
2026-05-12 38d723b6de39a6882a537a691159e40bd4c0e837
src/pages/inventoryManagement/scanOut/scanOut.logic.ts
@@ -13,16 +13,23 @@
}
export function parseRemainingQuantity(row: AnyRow): number | null {
  const remRaw =
    row?.remainingQuantity ??
    row?.remaining_quantity ??
    row?.remainQuantity ??
    row?.remain_quantity;
  const remRaw = row?.remainingQuantity;
  return parseOptionalNumber(remRaw);
}
export function defaultStockedQuantityFromRow(row: AnyRow): string {
  const rem = parseRemainingQuantity(row);
export function parseRemainingShippedQuantity(row: AnyRow): number | null {
  const remRaw = row?.remainingShippedQuantity;
  return parseOptionalNumber(remRaw);
}
export function defaultStockedQuantityFromRow(
  row: AnyRow,
  scene: "inbound" | "outbound" = "inbound"
): string {
  const rem =
    scene === "outbound"
      ? parseRemainingShippedQuantity(row) ?? parseRemainingQuantity(row)
      : parseRemainingQuantity(row) ?? parseRemainingShippedQuantity(row);
  if (rem !== null) return String(Math.max(0, rem));
  const avail = parseOptionalNumber(row?.availableQuality ?? row?.availableQuantity);
@@ -65,9 +72,35 @@
export function buildSalesLedgerProductList(recordList: AnyRow[]): AnyRow[] {
  return recordList.map((item: AnyRow) => {
    const n = parseOptionalNumber(item.stockedQuantity);
    const n = parseOptionalNumber(item.operateQuantity);
    const qty = n !== null && !Number.isNaN(n) ? Math.max(0, n) : 0;
    const { stockedQuantity: _sq, ...rest } = item;
    const { operateQuantity: _oq, ...rest } = item;
    return { ...rest, stockedQuantity: qty };
  });
}
/**
 * 扫码整单发货:每行待发数量由台账字段算出,与用户输入无关(与 defaultStockedQuantityFromRow 出库口径一致)。
 */
export function resolveScanShipLineQuantity(row: AnyRow): number {
  const rem =
    parseRemainingShippedQuantity(row) ?? parseRemainingQuantity(row);
  if (rem !== null) return Math.max(0, rem);
  const avail = parseOptionalNumber(row?.availableQuality ?? row?.availableQuantity);
  if (avail !== null) return Math.max(0, avail);
  const qty = parseOptionalNumber(row?.quantity);
  const shipped = parseOptionalNumber(row?.shippedQuantity) ?? 0;
  if (qty !== null) return Math.max(0, qty - shipped);
  return 0;
}
export function buildScanShipProductList(recordList: AnyRow[]): AnyRow[] {
  return recordList.map((item: AnyRow) => {
    const qty = resolveScanShipLineQuantity(item);
    const { operateQuantity: _oq, ...rest } = item;
    return { ...rest, stockedQuantity: qty };
  });
}