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 ` - - - Receipt - - -
+ + + Receipt + + + +
+
- Sweet Avenue Logo
-

SWEET AVENUE

-
COFFEE • BAKESHOP
+

SWEET AVENUE

+
COFFEE • BAKESHOP

${new Date().toLocaleString()}


- +
- - - + + + @@ -278,15 +335,9 @@ $(document).ready(function () { .map( (item) => ` - - - + + + ` ) @@ -295,30 +346,29 @@ $(document).ready(function () {
ProductQuantityPriceProductQuantityPrice
${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!

- - - `; - } +
+ + + `; +} + +function capitalizeEachWord(str) { + return str.replace(/\b\w/g, char => char.toUpperCase()); +} // Calculate grand total function calculateGrandTotal() { diff --git a/src/product.php b/src/product.php index 8726bda..c2dea65 100644 --- a/src/product.php +++ b/src/product.php @@ -101,7 +101,7 @@ function getCategories($db, $table) { food_variation fv ON fi.id = fv.food_id"; $result = $db->query($query); while($row = $result->fetch_assoc()) { - echo ""; + echo ""; echo ""; echo "Product Image"; echo "".$row['Name'].""; @@ -157,7 +157,7 @@ function getCategories($db, $table) { drink_variation dv ON di.id = dv.drink_id"; $result = $db->query($query); while($row = $result->fetch_assoc()) { - echo ""; + echo ""; echo ""; echo "Product Image"; echo "".$row['Name'].""; @@ -228,8 +228,8 @@ function getCategories($db, $table) {
- - + +
@@ -251,7 +251,7 @@ function getCategories($db, $table) {
- +
@@ -476,7 +476,7 @@ function resetCategoryForm() { } }); - document.getElementById('saveChangesBtn').addEventListener('click', addNewProduct); + //document.getElementById('saveChangesBtn').addEventListener('click', addNewProduct); $('#addProductModal').on('hidden.bs.modal', function () { resetForm(); }); @@ -506,8 +506,14 @@ function addNewProduct() { var category = document.getElementById('category').value.trim(); var priceInput = document.getElementById('price'); var price = priceInput.value.trim(); + var imageInput = document.getElementById('image'); + var image = imageInput.value.trim(); // Validate form fields + if (!image) { + showError('Image is required.'); + return; + } if (!name) { showError('Name is required.'); return; @@ -553,6 +559,7 @@ function showError(message) { document.getElementById('errorMessage').innerText = message; document.getElementById('errorContainer').style.display = 'block'; } + function resetForm() { document.getElementById('addProductForm').reset(); document.getElementById('errorContainer').style.display = 'none'; @@ -569,13 +576,15 @@ function resetForm() { $('#drink').DataTable(); // Capture product data when a row is clicked - $('body').on('click', '.product-checkbox', function() { + $('body').on('click', '.product-checkbox', function() { var productId = $(this).closest('tr').data('id'); // Fetch the product ID from the data attribute of the closest element var variationId = $(this).closest('tr').data('variation-id'); // Fetch the variation ID from the data attribute of the closest element + var productType = $(this).closest('tr').data('product-type'); // Fetch the product type (drink or food) var row = $(this).closest('tr'); selectedProduct = { id: productId, variationId: variationId, + productType: productType, image: row.find('img').attr('src'), name: row.find('td:eq(2)').text().trim(), category: row.find('td:eq(3)').text().trim(), @@ -585,7 +594,6 @@ function resetForm() { }; }); - // Populate the edit modal with the selected product data $('#editProductModal').on('show.bs.modal', function () { if (!selectedProduct) { $('#noProductSelectedModal').modal('show'); @@ -600,16 +608,12 @@ function resetForm() { $('#editPrice').val(selectedProduct.price); $('#productId').val(selectedProduct.id); $('#variationId').val(selectedProduct.variationId); // Set variationId in the hidden input field + $('#productType').val(selectedProduct.productType); // Set productType in the hidden input field // Clear previous error messages $('#editErrorContainer').hide().text(''); $('#priceError').hide(); }); - - // Handle save changes for editing product - $('#saveChangesEditBtn').on('click', function() { - saveChangesEdit(); - }); }); function saveChangesEdit() { diff --git a/src/sales.php b/src/sales.php index a153593..c8e8e45 100644 --- a/src/sales.php +++ b/src/sales.php @@ -61,10 +61,11 @@
- + +
- +
@@ -356,6 +357,144 @@ function updateViewButton() { } }); }); + +