diff --git a/src/finish-order.php b/src/finish-order.php index c189768..52f18a2 100644 --- a/src/finish-order.php +++ b/src/finish-order.php @@ -4,42 +4,8 @@ require_once FileUtils::normalizeFilePath('includes/db-connector.php'); include_once FileUtils::normalizeFilePath('includes/default-timezone.php'); -if ($_SERVER['REQUEST_METHOD'] === 'POST') { - $conn = new mysqli($db_host, $db_user, $db_pass, $db_name); +header('Content-Type: application/json'); - if ($conn->connect_error) { - die(json_encode(['success' => false, 'message' => 'Connection failed: ' . $conn->connect_error])); - } - - $subtotal = (float) $_POST['subtotal']; - $discount = (float) $_POST['discount']; - $grand_total = (float) $_POST['grand_total']; - $change = (float) $_POST['change']; - $items = json_decode($_POST['items'], true); - $user_id = 54; - - // Insert transaction into `transaction` table - $stmt = $conn->prepare("INSERT INTO `transaction` (user_id, timestamp, total_amount, receipt) VALUES (?, NOW(), ?, ?)"); - $stmt->bind_param('idd', $user_id, $grand_total); - - if ($stmt->execute()) { - $transaction_id = $stmt->insert_id; - - // Insert items into `items_purchased` table - $stmt = $conn->prepare("INSERT INTO `items_purchased` (transaction_id, item_id, quantity, price_per_unit) VALUES (?, ?, ?, ?)"); - foreach ($items as $item) { - $stmt->bind_param('iiid', $transaction_id, $item['id'], $item['quantity'], $item['price']); - $stmt->execute(); - } - - $stmt->close(); - $conn->close(); - echo json_encode(['success' => true]); - } else { - echo json_encode(['success' => false, 'message' => 'Failed to insert transaction']); - } -} else { - echo json_encode(['success' => false, 'message' => 'Invalid request method']); -} - -?> \ No newline at end of file +if($_SERVER["REQUEST_METHOD"] === "POST") { + // SQL to insert to transaction and items purchased table +} \ No newline at end of file diff --git a/src/javascript/billing.js b/src/javascript/billing.js index c5ae54d..3a49e5d 100644 --- a/src/javascript/billing.js +++ b/src/javascript/billing.js @@ -103,16 +103,6 @@ $(document).ready(function () { const tenderedAmount = parseFloat($("#tenderedAmount").val()); const change = tenderedAmount - parseFloat($("#grandTotalValue").text()); - const items = []; - $("#orderCart tr").each(function () { - const itemData = $(this).find("td"); - items.push({ - id: itemData.data("item-id"), - quantity: parseInt(itemData.eq(0).find("p").text().trim().slice(1)), - price: parseFloat(itemData.eq(2).find(".text-carbon-grey").text().trim().replace(/[^\d.]/g, "")) - }); - }); - $("#orderConfirmationModal").modal("hide"); $("#receiptModal").modal("show"); @@ -122,65 +112,39 @@ $(document).ready(function () { $("#tenderedAmount").val(""); $("#changeDisplay").html(""); + // $.ajax({ + // url: "finish-order.php", + // type: "POST", + // dataType: "json", + // success: function (response) { + // // code here + // }, + // }); printOrderConfirmation(tenderedAmount); - checkCart(); - - $.ajax({ - type: "POST", - url: "clear_cart.php", - success: function (response) { - let data = JSON.parse(response); - if (data.status === "success") { - $("#subtotalValue").text("0.00"); - $("#orderCart") - .empty() - .append( - '