Lot, Serial, ExpiryDate
This commit is contained in:
@@ -54,41 +54,60 @@
|
||||
);
|
||||
}
|
||||
|
||||
// Defensive check — UI cascade should already prevent mismatches
|
||||
// Defensive checks — UI cascade should already prevent mismatches
|
||||
if ($source_stock['product_sku'] !== $data["product_sku"]) {
|
||||
throw new Exception(
|
||||
"Rack holds {$source_stock['product_sku']}, not {$data['product_sku']}."
|
||||
);
|
||||
}
|
||||
|
||||
// If user selected a specific lot, verify it matches the rack's stock
|
||||
if (!empty($data["lot_number"]) && $source_stock['lot_number'] !== $data["lot_number"]) {
|
||||
throw new Exception(
|
||||
"Rack holds lot '{$source_stock['lot_number']}', not '{$data['lot_number']}'."
|
||||
);
|
||||
}
|
||||
|
||||
// If user selected a specific serial, verify it matches the rack's stock
|
||||
if (!empty($data["serial_number"]) && $source_stock['serial_number'] !== $data["serial_number"]) {
|
||||
throw new Exception(
|
||||
"Rack holds serial '{$source_stock['serial_number']}', not '{$data['serial_number']}'."
|
||||
);
|
||||
}
|
||||
|
||||
// Quantity comes from the source stock_in row, NOT user input.
|
||||
// Under 1:1, taking from this rack = taking the full batch.
|
||||
$quantity = (int) $source_stock['in'];
|
||||
$ref_id = (int) $source_stock['id'];
|
||||
$quantity = (int) $source_stock['in'];
|
||||
$ref_id = (int) $source_stock['id'];
|
||||
$lot_number = $source_stock['lot_number'] ?? null;
|
||||
$serial_number = $source_stock['serial_number'] ?? null;
|
||||
|
||||
// INSERT new stock_out record.
|
||||
// lot_number and serial_number carried from source stock_in row.
|
||||
// ref_id links this stock_out row back to the stock_in batch it consumed.
|
||||
$sql = "INSERT INTO `$table`
|
||||
(uuid, company_id, `date`, product_sku, `out`, zone, aisle, rack,
|
||||
contact_id, `description`, `log`, `type`, ref_id)
|
||||
contact_id, `description`, `log`, `type`, ref_id, lot_number, serial_number)
|
||||
VALUES
|
||||
(:uuid, :company_id, :date, :product_sku, :quantity, :zone, :aisle, :rack,
|
||||
:contact_id, :description, :log, 'out', :ref_id)";
|
||||
:contact_id, :description, :log, 'out', :ref_id, :lot_number, :serial_number)";
|
||||
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([
|
||||
":uuid" => $uuid,
|
||||
":company_id" => $company_id,
|
||||
":date" => date('Y-m-d H:i:s'),
|
||||
":product_sku" => $data["product_sku"],
|
||||
":quantity" => $quantity,
|
||||
":zone" => $data["zone"],
|
||||
":aisle" => $data["aisle"],
|
||||
":rack" => $data["rack"],
|
||||
":contact_id" => (int)$data["contact_id"],
|
||||
":description" => $data["description"],
|
||||
":log" => json_encode($table_log),
|
||||
":ref_id" => $ref_id,
|
||||
":uuid" => $uuid,
|
||||
":company_id" => $company_id,
|
||||
":date" => date('Y-m-d H:i:s'),
|
||||
":product_sku" => $data["product_sku"],
|
||||
":quantity" => $quantity,
|
||||
":zone" => $data["zone"],
|
||||
":aisle" => $data["aisle"],
|
||||
":rack" => $data["rack"],
|
||||
":contact_id" => (int)$data["contact_id"],
|
||||
":description" => $data["description"],
|
||||
":log" => json_encode($table_log),
|
||||
":ref_id" => $ref_id,
|
||||
":lot_number" => $lot_number,
|
||||
":serial_number" => $serial_number,
|
||||
]);
|
||||
|
||||
// Release the rack — stock is now gone from this location.
|
||||
|
||||
Reference in New Issue
Block a user