|
|
|
@ -66,40 +66,44 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && !isset($_POST['archive_action']) &&
|
|
|
|
$delivery_address = trim($_POST['delivery_address'] ?? '');
|
|
|
|
$delivery_address = trim($_POST['delivery_address'] ?? '');
|
|
|
|
$company = trim($_POST['company'] ?? '');
|
|
|
|
$company = trim($_POST['company'] ?? '');
|
|
|
|
|
|
|
|
|
|
|
|
$changes = [];
|
|
|
|
if ($quantity < 1) {
|
|
|
|
if (($order['company'] ?? '') !== $company) $changes[] = "Firma: [{$order['company']}] ➔ [$company]";
|
|
|
|
$message = "<div class='alert alert-warning'>Ilość musi być większa od zera.</div>";
|
|
|
|
if (($order['product_name'] ?? '') !== $product_name) $changes[] = "Produkt: [{$order['product_name']}] ➔ [$product_name]";
|
|
|
|
} else {
|
|
|
|
if (($order['part_number'] ?? '') !== $part_number) $changes[] = "PN: [{$order['part_number']}] ➔ [$part_number]";
|
|
|
|
$changes = [];
|
|
|
|
if ((int)$order['quantity'] !== $quantity) $changes[] = "Ilość: [{$order['quantity']}] ➔ [$quantity]";
|
|
|
|
if (($order['company'] ?? '') !== $company) $changes[] = "Firma: [{$order['company']}] ➔ [$company]";
|
|
|
|
if (($order['purchase_place'] ?? '') !== $purchase_place) $changes[] = "Sklep: [{$order['purchase_place']}] ➔ [$purchase_place]";
|
|
|
|
if (($order['product_name'] ?? '') !== $product_name) $changes[] = "Produkt: [{$order['product_name']}] ➔ [$product_name]";
|
|
|
|
if (($order['status'] ?? '') !== $status) $changes[] = "Status: [{$order['status']}] ➔ [$status]";
|
|
|
|
if (($order['part_number'] ?? '') !== $part_number) $changes[] = "PN: [{$order['part_number']}] ➔ [$part_number]";
|
|
|
|
if ((float)$order['price_per_unit'] !== $price) $changes[] = "Cena: [{$order['price_per_unit']}] ➔ [$price]";
|
|
|
|
if ((int)$order['quantity'] !== $quantity) $changes[] = "Ilość: [{$order['quantity']}] ➔ [$quantity]";
|
|
|
|
if (($order['delivery_date'] ?? '') !== $delivery_date) $changes[] = "Dostawa: [{$order['delivery_date']}] ➔ [$delivery_date]";
|
|
|
|
if (($order['purchase_place'] ?? '') !== $purchase_place) $changes[] = "Sklep: [{$order['purchase_place']}] ➔ [$purchase_place]";
|
|
|
|
if (($order['recipient'] ?? '') !== $recipient) $changes[] = "Odbiorca: [{$order['recipient']}] ➔ [$recipient]";
|
|
|
|
if (($order['status'] ?? '') !== $status) $changes[] = "Status: [{$order['status']}] ➔ [$status]";
|
|
|
|
if (($order['delivery_address'] ?? '') !== $delivery_address) $changes[] = "Adres: [{$order['delivery_address']}] ➔ [$delivery_address]";
|
|
|
|
if ((float)$order['price_per_unit'] !== $price) $changes[] = "Cena: [{$order['price_per_unit']}] ➔ [$price]";
|
|
|
|
if (($order['notes'] ?? '') !== $notes) $changes[] = "Zaktualizowano notatki";
|
|
|
|
if (($order['delivery_date'] ?? '') !== $delivery_date) $changes[] = "Dostawa: [{$order['delivery_date']}] ➔ [$delivery_date]";
|
|
|
|
|
|
|
|
if (($order['recipient'] ?? '') !== $recipient) $changes[] = "Odbiorca: [{$order['recipient']}] ➔ [$recipient]";
|
|
|
|
if (!empty($changes)) {
|
|
|
|
if (($order['delivery_address'] ?? '') !== $delivery_address) $changes[] = "Adres: [{$order['delivery_address']}] ➔ [$delivery_address]";
|
|
|
|
try {
|
|
|
|
if (($order['notes'] ?? '') !== $notes) $changes[] = "Zaktualizowano notatki";
|
|
|
|
$pdo->beginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($changes)) {
|
|
|
|
$update = $pdo->prepare("UPDATE " . DB_PREFIX . "orders SET
|
|
|
|
try {
|
|
|
|
product_name=?, part_number=?, quantity=?, purchase_place=?, status=?, price_per_unit=?, delivery_date=?, notes=?, recipient=?, delivery_address=?, company=?
|
|
|
|
$pdo->beginTransaction();
|
|
|
|
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=?
|
|
|
|
$action_text = "Zmieniono: " . implode(', ', $changes);
|
|
|
|
WHERE id=?");
|
|
|
|
$hist = $pdo->prepare("INSERT INTO " . DB_PREFIX . "order_history (order_id, user_id, action) VALUES (?, ?, ?)");
|
|
|
|
$update->execute([$product_name, $part_number, $quantity, $purchase_place, $status, $price, $delivery_date, $notes, $recipient, $delivery_address, $company, $id]);
|
|
|
|
$hist->execute([$id, $_SESSION['user_id'], $action_text]);
|
|
|
|
|
|
|
|
|
|
|
|
$action_text = "Zmieniono: " . implode(', ', $changes);
|
|
|
|
$pdo->commit();
|
|
|
|
$hist = $pdo->prepare("INSERT INTO " . DB_PREFIX . "order_history (order_id, user_id, action) VALUES (?, ?, ?)");
|
|
|
|
$message = "<div class='alert alert-success'>Zmiany zostały zapisane!</div>";
|
|
|
|
$hist->execute([$id, $_SESSION['user_id'], $action_text]);
|
|
|
|
|
|
|
|
|
|
|
|
$stmt->execute([$id]);
|
|
|
|
$pdo->commit();
|
|
|
|
$order = $stmt->fetch();
|
|
|
|
$message = "<div class='alert alert-success'>Zmiany zostały zapisane!</div>";
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
|
|
|
|
$pdo->rollBack();
|
|
|
|
$stmt->execute([$id]);
|
|
|
|
$message = "<div class='alert alert-danger'>Błąd bazy: " . $e->getMessage() . "</div>";
|
|
|
|
$order = $stmt->fetch();
|
|
|
|
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
|
|
|
|
$pdo->rollBack();
|
|
|
|
|
|
|
|
$message = "<div class='alert alert-danger'>Błąd bazy: " . $e->getMessage() . "</div>";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|