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

main
Albert Goral 1 week ago
parent 9023b9a5ed
commit 7da3865110

@ -42,7 +42,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
$message = "<div class='alert alert-danger'>Nie udało się zapisać zamówienia.</div>";
}
} else {
$message = "<div class='alert alert-warning'>Wypełnij nazwę produktu i ilość.</div>";
$message = "<div class='alert alert-warning'>Wypełnij nazwę produktu i podaj ilość większą od zera.</div>";
}
}
?>

@ -22,6 +22,9 @@ try {
$price = (float)str_replace(',', '.', $data['price_per_unit'] ?? 0);
$qty = (int)($data['quantity'] ?? 1);
if ($qty < 1) {
die(json_encode(['success' => false, 'error' => 'Ilość musi być większa od zera.']));
}
$stmt->execute([
trim($data['product_name']),

@ -45,6 +45,13 @@ try {
$old_val = $stmt->fetchColumn();
if ((string)$old_val !== (string)$value) {
if ($field === 'quantity') {
$value = (int)$value;
if ($value < 1) {
die(json_encode(['success' => false, 'error' => 'Ilość musi być większa od zera.']));
}
}
if ($field === 'price_per_unit') {
$value = (float)str_replace(',', '.', $value);
}

@ -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 (!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]);
$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>";
$stmt->execute([$id]);
$order = $stmt->fetch();
} catch (PDOException $e) {
$pdo->rollBack();
$message = "<div class='alert alert-danger'>Błąd bazy: " . $e->getMessage() . "</div>";
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();
$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]);
$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>";
}
}
}
}

@ -501,7 +501,9 @@ function getStatusClass($status) {
</select>`;
} else if (fieldName === 'delivery_date') {
inputHTML = `<input type="date" class="inline-input" value="${currentText}">`;
} else if (fieldName === 'quantity' || fieldName === 'price_per_unit') {
} else if (fieldName === 'quantity') {
inputHTML = `<input type="number" min="1" step="1" class="inline-input" style="width: 70px;" value="${currentText}">`;
} else if (fieldName === 'price_per_unit') {
inputHTML = `<input type="number" step="0.01" class="inline-input" style="width: 70px;" value="${currentText}">`;
} else {
inputHTML = `<input type="text" class="inline-input" value="${currentText}">`;
@ -558,7 +560,7 @@ function getStatusClass($status) {
<td></td>
<td class="text-muted"><span class="badge bg-info text-dark">Nowe</span></td>
<td><input type="text" class="form-control form-control-sm border-primary" id="add-prod" placeholder="Nazwa produktu..."></td>
<td><input type="number" class="form-control form-control-sm border-primary" id="add-qty" value="1" style="width: 60px;"></td>
<td><input type="number" class="form-control form-control-sm border-primary" id="add-qty" value="1" min="1" step="1" style="width: 60px;"></td>
<td><input type="text" class="form-control form-control-sm border-primary" id="add-place" placeholder="Sklep..."></td>
<td><input type="text" class="form-control form-control-sm border-primary" id="add-price" placeholder="0.00" style="width: 80px;"></td>
<td class="text-muted small">Brak</td>
@ -581,6 +583,7 @@ function getStatusClass($status) {
const price = document.getElementById('add-price').value;
if(!prod) { alert("Nazwa produktu jest obowiązkowa!"); document.getElementById('add-prod').focus(); return; }
if(!qty || Number(qty) < 1) { alert("Ilość musi być większa od zera!"); document.getElementById('add-qty').focus(); return; }
try {
let response = await fetch('ajax_add_row.php', {

Loading…
Cancel
Save