Ilości ujemne w zamówieniu (Ilość)

This commit is contained in:
2026-03-30 09:43:59 +02:00
parent 9023b9a5ed
commit 7da3865110
5 changed files with 49 additions and 32 deletions
+33 -29
View File
@@ -66,40 +66,44 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && !isset($_POST['archive_action']) &&
$delivery_address = trim($_POST['delivery_address'] ?? '');
$company = trim($_POST['company'] ?? '');
$changes = [];
if (($order['company'] ?? '') !== $company) $changes[] = "Firma: [{$order['company']}] ➔ [$company]";
if (($order['product_name'] ?? '') !== $product_name) $changes[] = "Produkt: [{$order['product_name']}] ➔ [$product_name]";
if (($order['part_number'] ?? '') !== $part_number) $changes[] = "PN: [{$order['part_number']}] ➔ [$part_number]";
if ((int)$order['quantity'] !== $quantity) $changes[] = "Ilość: [{$order['quantity']}] ➔ [$quantity]";
if (($order['purchase_place'] ?? '') !== $purchase_place) $changes[] = "Sklep: [{$order['purchase_place']}] ➔ [$purchase_place]";
if (($order['status'] ?? '') !== $status) $changes[] = "Status: [{$order['status']}] ➔ [$status]";
if ((float)$order['price_per_unit'] !== $price) $changes[] = "Cena: [{$order['price_per_unit']}] ➔ [$price]";
if (($order['delivery_date'] ?? '') !== $delivery_date) $changes[] = "Dostawa: [{$order['delivery_date']}] ➔ [$delivery_date]";
if (($order['recipient'] ?? '') !== $recipient) $changes[] = "Odbiorca: [{$order['recipient']}] ➔ [$recipient]";
if (($order['delivery_address'] ?? '') !== $delivery_address) $changes[] = "Adres: [{$order['delivery_address']}] ➔ [$delivery_address]";
if (($order['notes'] ?? '') !== $notes) $changes[] = "Zaktualizowano notatki";
if ($quantity < 1) {
$message = "<div class='alert alert-warning'>Ilość musi być większa od zera.</div>";
} else {
$changes = [];
if (($order['company'] ?? '') !== $company) $changes[] = "Firma: [{$order['company']}] ➔ [$company]";
if (($order['product_name'] ?? '') !== $product_name) $changes[] = "Produkt: [{$order['product_name']}] ➔ [$product_name]";
if (($order['part_number'] ?? '') !== $part_number) $changes[] = "PN: [{$order['part_number']}] ➔ [$part_number]";
if ((int)$order['quantity'] !== $quantity) $changes[] = "Ilość: [{$order['quantity']}] ➔ [$quantity]";
if (($order['purchase_place'] ?? '') !== $purchase_place) $changes[] = "Sklep: [{$order['purchase_place']}] ➔ [$purchase_place]";
if (($order['status'] ?? '') !== $status) $changes[] = "Status: [{$order['status']}] ➔ [$status]";
if ((float)$order['price_per_unit'] !== $price) $changes[] = "Cena: [{$order['price_per_unit']}] ➔ [$price]";
if (($order['delivery_date'] ?? '') !== $delivery_date) $changes[] = "Dostawa: [{$order['delivery_date']}] ➔ [$delivery_date]";
if (($order['recipient'] ?? '') !== $recipient) $changes[] = "Odbiorca: [{$order['recipient']}] ➔ [$recipient]";
if (($order['delivery_address'] ?? '') !== $delivery_address) $changes[] = "Adres: [{$order['delivery_address']}] ➔ [$delivery_address]";
if (($order['notes'] ?? '') !== $notes) $changes[] = "Zaktualizowano notatki";
if (!empty($changes)) {
try {
$pdo->beginTransaction();
if (!empty($changes)) {
try {
$pdo->beginTransaction();
$update = $pdo->prepare("UPDATE " . DB_PREFIX . "orders SET
product_name=?, part_number=?, quantity=?, purchase_place=?, status=?, price_per_unit=?, delivery_date=?, notes=?, recipient=?, delivery_address=?, company=?
WHERE id=?");
$update->execute([$product_name, $part_number, $quantity, $purchase_place, $status, $price, $delivery_date, $notes, $recipient, $delivery_address, $company, $id]);
$update = $pdo->prepare("UPDATE " . DB_PREFIX . "orders SET
product_name=?, part_number=?, quantity=?, purchase_place=?, status=?, price_per_unit=?, delivery_date=?, notes=?, recipient=?, delivery_address=?, company=?
WHERE id=?");
$update->execute([$product_name, $part_number, $quantity, $purchase_place, $status, $price, $delivery_date, $notes, $recipient, $delivery_address, $company, $id]);
$action_text = "Zmieniono: " . implode(', ', $changes);
$hist = $pdo->prepare("INSERT INTO " . DB_PREFIX . "order_history (order_id, user_id, action) VALUES (?, ?, ?)");
$hist->execute([$id, $_SESSION['user_id'], $action_text]);
$action_text = "Zmieniono: " . implode(', ', $changes);
$hist = $pdo->prepare("INSERT INTO " . DB_PREFIX . "order_history (order_id, user_id, action) VALUES (?, ?, ?)");
$hist->execute([$id, $_SESSION['user_id'], $action_text]);
$pdo->commit();
$message = "<div class='alert alert-success'>Zmiany zostały zapisane!</div>";
$pdo->commit();
$message = "<div class='alert alert-success'>Zmiany zostały zapisane!</div>";
$stmt->execute([$id]);
$order = $stmt->fetch();
} catch (PDOException $e) {
$pdo->rollBack();
$message = "<div class='alert alert-danger'>Błąd bazy: " . $e->getMessage() . "</div>";
$stmt->execute([$id]);
$order = $stmt->fetch();
} catch (PDOException $e) {
$pdo->rollBack();
$message = "<div class='alert alert-danger'>Błąd bazy: " . $e->getMessage() . "</div>";
}
}
}
}