41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
include('include/headscript.php');
|
|
header('Content-Type: application/json');
|
|
|
|
$idpackaging_item = isset($_POST['idpackaging_item']) ? (int)$_POST['idpackaging_item'] : 0;
|
|
$idsupplier = isset($_POST['idsupplier']) ? (int)$_POST['idsupplier'] : 0;
|
|
$lot_code = trim($_POST['lot_code'] ?? '');
|
|
$expiry_date = trim($_POST['expiry_date'] ?? '');
|
|
$qty = isset($_POST['qty']) ? (float)$_POST['qty'] : 0;
|
|
|
|
if ($idpackaging_item <= 0 || $idsupplier <= 0) {
|
|
echo json_encode(['success' => false, 'message' => 'Missing required fields']);
|
|
exit;
|
|
}
|
|
if ($qty < 0) {
|
|
echo json_encode(['success' => false, 'message' => 'Quantity cannot be negative']);
|
|
exit;
|
|
}
|
|
if ($expiry_date === '') $expiry_date = null;
|
|
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
try {
|
|
$stmt = $pdo->prepare("INSERT INTO packaging_stock_lots
|
|
(idpackaging_item, idsupplier, lot_code, expiry_date, qty)
|
|
VALUES (?,?,?,?,?)");
|
|
|
|
$stmt->execute([
|
|
$idpackaging_item,
|
|
$idsupplier,
|
|
($lot_code !== '' ? $lot_code : null),
|
|
$expiry_date,
|
|
$qty
|
|
]);
|
|
|
|
echo json_encode(['success' => true]);
|
|
} catch (PDOException $e) {
|
|
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
|
}
|