diff --git a/server/src/services/inventoryBatchCostService.ts b/server/src/services/inventoryBatchCostService.ts index 0260aef..c0efead 100644 --- a/server/src/services/inventoryBatchCostService.ts +++ b/server/src/services/inventoryBatchCostService.ts @@ -361,9 +361,9 @@ export async function recalcCoverLedgerForBatchCostChange( SET amount = $3::numeric, allocated_amount = $3::numeric, cover_qty = ( SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) - FROM order_items WHERE order_code = $1 AND sku_code = $2 - )) - WHERE order_code = $1 AND sku_code = $2 AND cost_source = 'inventory_cover'`, + FROM order_items WHERE order_code = $1::text AND sku_code = $2::text + ) + WHERE order_code = $1::text AND sku_code = $2::text AND cost_source = 'inventory_cover'`, [row.order_code, row.sku_code, row.after_amount] ); if ((updated.rowCount || 0) === 0 && Number(row.after_amount) > 0) { @@ -377,8 +377,8 @@ export async function recalcCoverLedgerForBatchCostChange( `INSERT INTO cost_details ( cycle_code, order_code, cost_type, cost_subtype, amount, allocated_amount, status, branch_code, sku_code, cost_source, remark, cover_qty - ) VALUES ($1, $2, 'purchase', 'stock_cover', $3, $3, 20, $4, $5, 'inventory_cover', 'stock_cover', - (SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) FROM order_items WHERE order_code = $2 AND sku_code = $5))`, + ) VALUES ($1, $2::text, 'purchase', 'stock_cover', $3, $3, 20, $4, $5::text, 'inventory_cover', 'stock_cover', + (SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) FROM order_items WHERE order_code = $2::text AND sku_code = $5::text))`, [cycleCode, row.order_code, row.after_amount, branch, row.sku_code] ); } @@ -471,8 +471,8 @@ export async function repairMissingCoverLedger(input: { SET amount = $2::numeric, allocated_amount = $2::numeric, cover_qty = ( SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) - FROM order_items WHERE order_code = $3 AND sku_code = $4 - )) + FROM order_items WHERE order_code = $3::text AND sku_code = $4::text + ) WHERE id = $1`, [existing.rows[0].id, amount, code, sku] ); @@ -489,8 +489,8 @@ export async function repairMissingCoverLedger(input: { `INSERT INTO cost_details ( cycle_code, order_code, cost_type, cost_subtype, amount, allocated_amount, status, branch_code, sku_code, cost_source, remark, cover_qty - ) VALUES ($1, $2, 'purchase', 'stock_cover', $3, $3, 20, $4, $5, 'inventory_cover', 'stock_cover', - (SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) FROM order_items WHERE order_code = $2 AND sku_code = $5))`, + ) VALUES ($1, $2::text, 'purchase', 'stock_cover', $3, $3, 20, $4, $5::text, 'inventory_cover', 'stock_cover', + (SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) FROM order_items WHERE order_code = $2::text AND sku_code = $5::text))`, [ trim(meta.rows[0]?.cycle_code) || '0000', code,