diff --git a/src/javascript/billing.js b/src/javascript/billing.js index f3f6573..88fb099 100644 --- a/src/javascript/billing.js +++ b/src/javascript/billing.js @@ -85,6 +85,13 @@ $(document).ready(function () { checkCart(); } + function resetTenderedAmountInput() { + $("#tenderedAmount").val(""); // Clear the input field + $("#proceedOrder").prop("disabled", true); // Disable the Proceed Order button + $("#changeDisplay").html(""); // Clear the change display + } + + // Run the checkCart function on page load checkCart(); @@ -191,6 +198,8 @@ $(document).ready(function () { }, }); + resetTenderedAmountInput(); + $("#orderConfirmationModal").modal("hide"); $("#receiptModal").modal("show"); @@ -205,6 +214,11 @@ $(document).ready(function () { checkCart(); }); + + $("#orderConfirmationModal").on("hidden.bs.modal", function () { + resetTenderedAmountInput(); + }); + function printOrderConfirmation(tenderedAmount) { const printableContent = generatePrintableContent(tenderedAmount); clearOrdersAndSubtotal(); @@ -222,69 +236,72 @@ $(document).ready(function () { function generatePrintableContent(tenderedAmount) { const processedBy = currentUser; const orderDetails = { - items: [], - subtotal: parseFloat($("#subtotalValue").text().replace(/,/g, "")), - discountPercentage: parseFloat($("#discountInput").val()) || 0, // Set to 0 if NaN - 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"); + const productName = cells.eq(1).text().trim(); + const quantity = cells.eq(0).text().trim().slice(1); + const price = parseFloat( + cells + .eq(2) + .text() + .trim() + .replace(/[^\d.]/g, "") + ); + + orderDetails.items.push({ + productName: productName, + quantity: quantity, + price: price, + }); }); return ` - -
-${new Date().toLocaleString()}
Product | +
---|
Product | Quantity | -Price | -Price | + + - ${orderDetails.items - .map( - (item) => ` -
---|---|---|
${capitalizeEachWord(item.productName)} | -${item.quantity} | -₱${item.price.toFixed(2)} | -
Subtotal: ₱${orderDetails.subtotal.toFixed(2)}
@@ -360,109 +377,111 @@ $(document).ready(function () {Thank you for your patronage. We’d love to see you again soon. You're always welcome here!