43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
include('include/headscript.php');
|
|
header('Content-Type: application/json');
|
|
|
|
$id = isset($_POST['id']) ? (int)$_POST['id'] : 0;
|
|
$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 ($id <= 0 || $idpackaging_item <= 0 || $idsupplier <= 0) {
|
|
echo json_encode(['success' => false, 'message' => 'Invalid input']);
|
|
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("UPDATE packaging_stock_lots
|
|
SET idsupplier=?, lot_code=?, expiry_date=?, qty=?
|
|
WHERE id=? AND idpackaging_item=?");
|
|
|
|
$stmt->execute([
|
|
$idsupplier,
|
|
($lot_code !== '' ? $lot_code : null),
|
|
$expiry_date,
|
|
$qty,
|
|
$id,
|
|
$idpackaging_item
|
|
]);
|
|
|
|
echo json_encode(['success' => true]);
|
|
} catch (PDOException $e) {
|
|
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
|
}
|