'', 'payment_amount' => '', 'payment_status' => '', 'payer_email' => '', 'first_name' => '', 'last_name' => '', 'account_id' => '', 'payment_method' => '', 'discount_code' => '', 'address_street' => '', 'address_city' => '', 'address_state' => '', 'address_zip' => '', 'address_country' => '', 'shipping_method' => '', 'shipping_amount' => '', 'created' => date('Y-m-d\TH:i'), 'address_phone' => '' ]; // Retrieve the products from the database $stmt = $pdo->prepare('SELECT * FROM products ORDER BY id'); $stmt->execute(); $products = $stmt->fetchAll(PDO::FETCH_ASSOC); // Retrieve the accounts from the database $stmt = $pdo->prepare('SELECT * FROM accounts ORDER BY id'); $stmt->execute(); $accounts = $stmt->fetchAll(PDO::FETCH_ASSOC); // Add transactions items to the database function addOrderItems($pdo, $txn_id) { if (isset($_POST['item_id']) && is_array($_POST['item_id']) && count($_POST['item_id']) > 0) { // Iterate items $delete_list = []; for ($i = 0; $i < count($_POST['item_id']); $i++) { // If the item doesnt exist in the database if (!intval($_POST['item_id'][$i])) { // Insert new item $stmt = $pdo->prepare('INSERT INTO transactions_items (txn_id,item_id,item_price,item_quantity,item_options) VALUES (?,?,?,?,?)'); $stmt->execute([ $txn_id, $_POST['item_product'][$i], $_POST['item_price'][$i], $_POST['item_quantity'][$i], $_POST['item_options'][$i] ]); $delete_list[] = $pdo->lastInsertId(); } else { // Update existing item $stmt = $pdo->prepare('UPDATE transactions_items SET txn_id = ?, item_id = ?, item_price = ?, item_quantity = ?, item_options = ? WHERE id = ?'); $stmt->execute([ $txn_id, $_POST['item_product'][$i], $_POST['item_price'][$i], $_POST['item_quantity'][$i], $_POST['item_options'][$i], $_POST['item_id'][$i] ]); $delete_list[] = $_POST['item_id'][$i]; } } // Delete item $in = str_repeat('?,', count($delete_list) - 1) . '?'; $stmt = $pdo->prepare('DELETE FROM transactions_items WHERE txn_id = ? AND id NOT IN (' . $in . ')'); $stmt->execute(array_merge([ $txn_id ], $delete_list)); } else { // No item exists, delete all $stmt = $pdo->prepare('DELETE FROM transactions_items WHERE txn_id = ?'); $stmt->execute([ $txn_id ]); } } // Save captured data if (isset($_GET['id'])) { // Retrieve the transaction from the database $stmt = $pdo->prepare('SELECT * FROM transactions WHERE id = ?'); $stmt->execute([ $_GET['id'] ]); $transaction = $stmt->fetch(PDO::FETCH_ASSOC); // Retrieve the transaction items from the database $stmt = $pdo->prepare('SELECT * FROM transactions_items WHERE txn_id = ?'); $stmt->execute([ $transaction['txn_id'] ]); $transactions_items = $stmt->fetchAll(PDO::FETCH_ASSOC); // ID param exists, edit an existing transaction $page = 'Edit'; if (isset($_POST['submit'])) { // Update the transaction $stmt = $pdo->prepare('UPDATE transactions SET txn_id = ?, payment_amount = ?, payment_status = ?, created = ?, payer_email = ?, first_name = ?, last_name = ?, address_street = ?, address_city = ?, address_state = ?, address_zip = ?, address_country = ?, account_id = ?, payment_method = ?, discount_code = ?, shipping_method = ?, shipping_amount = ?, address_phone= ? WHERE id = ?'); $stmt->execute([ $_POST['txn_id'], $_POST['amount'], $_POST['status'], date('Y-m-d H:i:s', strtotime($_POST['created'])), $_POST['email'], $_POST['first_name'], $_POST['last_name'], $_POST['address_street'], $_POST['address_city'], $_POST['address_state'], $_POST['address_zip'], $_POST['address_country'], empty($_POST['account']) ? NULL : $_POST['account'], $_POST['method'], $_POST['discount_code'], $_POST['shipping_method'], $_POST['shipping_amount'], $_POST['address_phone'], $_GET['id'] ]); addOrderItems($pdo, $_POST['txn_id']); if ($_POST['status'] == 'Paid'){ createGiftCart($pdo, $_POST['txn_id']); include_once('./factuur.php'); } header('Location: index.php?page=orders&success_msg=2'); exit; } if (isset($_POST['delete'])) { // Delete the transaction $stmt = $pdo->prepare('DELETE t, ti FROM transactions t LEFT JOIN transactions_items ti ON ti.txn_id = t.txn_id WHERE t.id = ?'); $stmt->execute([ $_GET['id'] ]); // Deactive giftcards removeGiftCart($pdo, $_POST['txn_id']); header('Location: index.php?page=orders&success_msg=3'); exit; } } else { // Create a new transaction $page = 'Create'; if (isset($_POST['submit'])) { $stmt = $pdo->prepare('INSERT INTO transactions (txn_id,payment_amount,payment_status,created,payer_email,first_name,last_name,address_street,address_city,address_state,address_zip,address_country,account_id,payment_method,discount_code,shipping_method,shipping_amount, address_phone) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'); $stmt->execute([ $_POST['txn_id'], $_POST['amount'], $_POST['status'], date('Y-m-d H:i:s', strtotime($_POST['created'])), $_POST['email'], $_POST['first_name'], $_POST['last_name'], $_POST['address_street'], $_POST['address_city'], $_POST['address_state'], $_POST['address_zip'], $_POST['address_country'], empty($_POST['account']) ? NULL : $_POST['account'], $_POST['method'], $_POST['discount_code'], $_POST['shipping_method'], $_POST['shipping_amount'], $_POST['address_phone'] ]); addOrderItems($pdo, $_POST['txn_id']); header('Location: index.php?page=orders&success_msg=1'); exit; } } ?>

Order

Cancel
Details Address Items
Product Price Quantity Options
There are no order items
Add Item