document.
addEventListener("DOMContentLoaded", function() {
const addToCartButtons = [Link](".add-to-cart-button");
const receiptContent = [Link]("receipt-content");
const checkoutButton = [Link]("checkout-button");
const selectedProducts = [];
[Link](addToCartButton => {
addProductToCart(addToCartButton);
});
[Link]("click", function() {
printReceipt();
});
function addProductToCart(addToCartButton) {
[Link]("click", function() {
const productName = [Link]("data-product");
const productPrice = parseFloat([Link]("data-price"));
// Check if the product is already in the cart
const existingProduct = [Link](product => [Link]
=== productName);
if (existingProduct) {
[Link] += 1;
} else {
[Link]({ name: productName, price: productPrice,
quantity: 1 });
}
updateReceipt();
});
}
function updateReceipt() {
let total = 0;
[Link] = "";
[Link](product => {
total += [Link] * [Link];
// Display the quantity indicator if quantity is greater than 1
const quantityIndicator = [Link] > 1 ? `(x$
{[Link]})` : "";
[Link] += `
<div class="receipt-item">
<span class="product-info">${[Link]} $
{quantityIndicator}:</span>
<span class="product-info" style="text-align: right;">₱$
{([Link] * [Link]).toFixed(2)}</span>
<button class="cancel-button" data-product="$
{[Link]}">Cancel</button>
</div>
`;
});
[Link] += `
<div class="receipt-total">
<span class="total-label">Total:</span>
<span class="total-value" style="text-align: right;">₱$
{[Link](2)}</span>
</div>
`;
// Add event listeners for cancel buttons
const cancelButtons = [Link](".cancel-button");
[Link](cancelButton => {
[Link]("click", function() {
const productName = [Link]("data-product");
removeProductFromReceipt(productName);
});
});
}
function removeProductFromReceipt(productName) {
const index = [Link](product => [Link] ===
productName);
if (index !== -1) {
const product = selectedProducts[index];
if ([Link] > 1) {
[Link] -= 1;
} else {
[Link](index, 1);
}
updateReceipt();
}
}
function printReceipt() {
const receiptWindow = [Link]("", "_blank");
const receiptHTML = `
<html>
<head>
<title>Order Receipt</title>
<style>
/* Add your receipt styling here */
body {
font-family: Arial, sans-serif;
}
.receipt {
border: 2px solid #333;
padding: 20px;
max-width: 400px;
margin: 0 auto;
text-align: center;
background-color: #fff;
}
.receipt-header {
font-size: 24px;
text-align: center;
margin-bottom: 10px;
}
.receipt-subheader{
font-size: 24px:
text-align: center;
margin-bottom: 10px;
}
.receipt-item {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
}
.product-info {
flex: 2;
text-align: left;
}
.total-label {
flex: 2;
text-align: left;
font-weight: bold;
}
.total-value {
flex: 1;
text-align: right;
font-weight: bold;
}
.receipt-total {
display: flex;
justify-content: space-between;
margin-top: 10px;
font-weight: bold;
}
.receipt-footer {
font-size: 12px;
margin-top: 20px;
text-align: center;
}
/* Hide cancel buttons in the receipt */
.receipt-item .cancel-button {
display: none;
}
</style>
</head>
<body>
<div class="receipt">
<div class="receipt-header">
<h1>"Meat & Seafood Express"</h1>
</div>
<div class="receipt-subheader">
<h3>Order Receipt</h3>
</div>
<div class="receipt-items">
${[Link]}
</div>
<div class="receipt-footer">
Thank you for choosing Meat & Seafood Express!
</div>
</div>
</body>
</html>
`;
[Link]();
[Link](receiptHTML);
[Link]();
}
});