diff --git a/src/add_product.php b/src/add_product.php index 608cfdf..bbee0f1 100644 --- a/src/add_product.php +++ b/src/add_product.php @@ -9,12 +9,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = $_POST['name'] ?? null; $category = $_POST['category'] ?? null; - $servingType = $_POST['servingType'] ?? null; - $flavorSize = $_POST['flavorSize'] ?? null; + $servingType = !empty($_POST['servingType']) ? $_POST['servingType'] : null; + $flavorSize = !empty($_POST['flavorSize']) ? $_POST['flavorSize'] : null; $price = $_POST['price'] ?? null; $image = $_FILES['image'] ?? null; - if ($name && $category && $price) { // Removed image check here, see below + if ($name && $category && $price) { // Determine the table based on the category type $categoryLower = strtolower($category); if (strpos($categoryLower, 'drink') !== false || in_array($categoryLower, ['froyo', 'coffee & blended'])) { @@ -23,14 +23,14 @@ $variationTable = 'drink_variation'; $servingField = 'type'; $flavorField = 'size'; - $idField = 'drink_id'; // Add this line for dynamic ID field + $idField = 'drink_id'; } else { $categoryTable = 'food_item'; $categoryField = 'food_category'; $variationTable = 'food_variation'; $servingField = 'serving'; $flavorField = 'flavor'; - $idField = 'food_id'; // Add this line for dynamic ID field + $idField = 'food_id'; } // Check if the product already exists @@ -89,23 +89,19 @@ } } - // Insert into variations table - if ($servingType || $flavorSize) { - $sql = "INSERT INTO $variationTable ($idField, $servingField, $flavorField, price) VALUES (?, ?, ?, ?)"; - $stmt = $db->prepare($sql); - if ($stmt) { - $stmt->bind_param("issd", $productId, $servingType, $flavorSize, $price); - if ($stmt->execute()) { - $response['success'] = true; - } else { - $response['message'] = 'Failed to insert product variations: ' . $stmt->error; - } - $stmt->close(); + // Always insert the price, even if servingType and flavorSize are not provided + $sql = "INSERT INTO $variationTable ($idField, $servingField, $flavorField, price) VALUES (?, ?, ?, ?)"; + $stmt = $db->prepare($sql); + if ($stmt) { + $stmt->bind_param("issd", $productId, $servingType, $flavorSize, $price); + if ($stmt->execute()) { + $response['success'] = true; } else { - $response['message'] = 'Failed to prepare variation insertion statement: ' . $db->error; + $response['message'] = 'Failed to insert product variations: ' . $stmt->error; } + $stmt->close(); } else { - $response['success'] = true; + $response['message'] = 'Failed to prepare variation insertion statement: ' . $db->error; } } else { $response['message'] = 'Name, category, and price are required'; diff --git a/src/javascript/billing.js b/src/javascript/billing.js index 30d4783..f3f6573 100644 --- a/src/javascript/billing.js +++ b/src/javascript/billing.js @@ -222,55 +222,112 @@ $(document).ready(function () { function generatePrintableContent(tenderedAmount) { const processedBy = currentUser; const orderDetails = { - items: [], - subtotal: parseFloat($("#subtotalValue").text().replace(/,/g, "")), - discount: parseFloat($("#discountInput").val()), - grandTotal: parseFloat($("#grandTotalValue").text()), - tenderedAmount: tenderedAmount, + items: [], + subtotal: parseFloat($("#subtotalValue").text().replace(/,/g, "")), + discountPercentage: parseFloat($("#discountInput").val()) || 0, // Set to 0 if NaN + grandTotal: parseFloat($("#grandTotalValue").text()), + tenderedAmount: tenderedAmount, }; const change = tenderedAmount - orderDetails.grandTotal; + const discountAmount = orderDetails.subtotal * (orderDetails.discountPercentage / 100); $("#orderCart tr").each(function () { - const cells = $(this).find("td"); - orderDetails.items.push({ - productName: cells.eq(1).find(".text-capitalize").text().trim(), - quantity: cells.eq(0).find("p").text().trim().slice(1), - price: parseFloat( - cells - .eq(2) - .find(".text-carbon-grey") - .text() - .trim() - .replace(/[^\d.]/g, "") - ), - }); + const cells = $(this).find("td"); + orderDetails.items.push({ + productName: cells.eq(1).find(".text-capitalize").text().trim(), + quantity: cells.eq(0).find("p").text().trim().slice(1), + price: parseFloat( + cells + .eq(2) + .find(".text-carbon-grey") + .text() + .trim() + .replace(/[^\d.]/g, "") + ), + }); }); return ` - -
-${new Date().toLocaleString()}
Product | -Quantity | -Price | +Product | +Quantity | +Price |
---|---|---|---|---|---|
${capitalizeEachWord( - item.productName - )} | -${ - item.quantity - } | -₱${item.price.toFixed( - 2 - )} | +${capitalizeEachWord(item.productName)} | +${item.quantity} | +₱${item.price.toFixed(2)} |
Subtotal: ₱${orderDetails.subtotal.toFixed( - 2 - )}
-Discount: ${orderDetails.discount.toFixed( - 2 - )} %
-Grand Total: ₱${orderDetails.grandTotal.toFixed( - 2 - )}
-Tendered Amount: ₱${orderDetails.tenderedAmount.toFixed( - 2 - )}
+Subtotal: ₱${orderDetails.subtotal.toFixed(2)}
+Discount Percentage: ${orderDetails.discountPercentage.toFixed(2)} %
+Discount Amount: - ₱${discountAmount.toFixed(2)}
+Grand Total: ₱${orderDetails.grandTotal.toFixed(2)}
+Tendered Amount: ₱${orderDetails.tenderedAmount.toFixed(2)}
Change: ₱${change.toFixed(2)}
Processed by: ${processedBy}
Processed by: ${processedBy}
+Wifi Password: Sweet_Avenue123
Thank you for your patronage. We’d love to see you again soon. You're always welcome here!