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,6 +66,9 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && !isset($_POST['archive_action']) &&
$delivery_address = trim($_POST['delivery_address'] ?? '');
$company = trim($_POST['company'] ?? '');
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]";
@ -103,6 +106,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && !isset($_POST['archive_action']) &&
}
}
}
}
// POBIERANIE HISTORII
$hist_sql = "SELECT h.action, h.created_at, u.username

@ -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