check the code, because it returns blank
<?php
// IMPORTANT: session_start() MUST be the very first thing in the file,
// before any output (including whitespace outside of <?php tags).
// This is necessary if your login system relies on raw PHP sessions ($_SESSION).
// In a standard WordPress setup, you would typically rely on WP's authentication
// functions like wp_get_current_user() and is_user_logged_in().
// If wp_get_current_user() is not working, the issue might be how this file
// is included or executed within the WordPress lifecycle.
session_start();
?>
<?php
global $wpdb;
// Define your tables
$table_name_categories = 'categories';
$table_name_products = 'products';
$table_name_orders = 'orders';
$table_name_order_items = 'order_items';
$inventory_history_table_name = 'inventory_history';
$message = '';
function log_inventory_action($action_type, $item_type, $item_name, $description) {
global $wpdb;
$username = isset($_SESSION['username']) ? $_SESSION['username'] : '';
$result = $wpdb->insert(
'inventory_history',
array(
'username' => $username,
'action_type' => $action_type,
'item_type' => $item_type,
'item_name' => $item_name,
'description' => $description,
'timestamp' => current_time('mysql')
),
array('%s', '%s', '%s', '%s', '%s', '%s')
);
return $result;
}
// --- Fetch Categories ---
$categories = $wpdb->get_results("SELECT * FROM $table_name_categories ORDER BY name ASC", ARRAY_A);
// --- Handle Add Order Form Submission ---
if (isset($_POST['add_order']) && isset($_POST['_wpnonce_order_form']) && wp_verify_nonce($_POST['_wpnonce_order_form'], 'add_order_action')) {
$product_name = isset($_POST['product_name']) ? sanitize_text_field($_POST['product_name']) : '';
$quantity = isset($_POST['quantity']) ? absint($_POST['quantity']) : 0;
$unit_price = isset($_POST['unit_price']) ? floatval($_POST['unit_price']) : 0.00;
if (empty($product_name) || !$quantity || !$unit_price) {
$message = 'Invalid product name, quantity, or unit price!';
} else {
$product = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table_name_products WHERE name = %s", $product_name));
if ($product) {
if ($quantity <= $product->{'in_stock'}) {
$amount = $unit_price * $quantity;
// Insert into orders table
$wpdb->insert($table_name_orders, [
'customer_name' => 'Default Customer',
'total_amount' => $amount,
'status' => 'Pending',
'created_at' => current_time('mysql'),
'amount_tendered' => 0.00, // Set default for amount tendered
'amount_change' => 0.00 // Set default for change
]);
$order_id = $wpdb->insert_id;
// Insert the order item
$wpdb->insert($table_name_order_items, [
'order_id' => $order_id,
'product_id' => $product->id,
'quantity' => $quantity,
'unit_price' => $unit_price,
'amount' => $amount
]);
// Update product stock
$new_stock = $product->{'in_stock'} - $quantity;
$wpdb->update($table_name_products, ['in_stock' => $new_stock], ['id' => $product->id]);
// Log the sale in inventory history
// Get the current logged-in user's username
$username = wp_get_current_user()->user_login;
// Log the sale in inventory history
log_inventory_action(
'sell', // Action type
'product', // Item type
$product_name, // Item name
"Sold {$quantity} units of {$product_name}. New stock: {$new_stock}",
$username, // Pass the username
);
wp_redirect($_SERVER['REQUEST_URI']);
exit;
} else {
$message = 'Insufficient stock for the product!';
}
} else {
$message = 'Product not found!';
}
}
}
// --- Handle Payment
if (isset($_POST['pay_orders'])) {
// First calculate the total amount of all pending orders
$total_amount = 0;
$pending_orders = $wpdb->get_results("
SELECT o.*, oi.*, p.name AS product_name
FROM $table_name_orders o
INNER JOIN $table_name_order_items oi ON o.id = oi.order_id
INNER JOIN $table_name_products p ON oi.product_id = p.id
WHERE o.status = 'Pending'
", ARRAY_A);
foreach ($pending_orders as $order) {
$total_amount += $order['amount'];
}
// Get the amount tendered from form
$amount_tendered = isset($_POST['amount_tendered']) ? floatval($_POST['amount_tendered']) : 0.00;
// Validate amount tendered
if ($amount_tendered <= 0) {
$message = 'Please enter a valid amount tendered!';
} elseif ($amount_tendered < $total_amount) {
$message = 'Amount tendered is insufficient!';
} else {
// Calculate change
$change = $amount_tendered - $total_amount;
// Update all pending orders
foreach ($pending_orders as $order) {
$wpdb->update($table_name_orders, [
'status' => 'Paid',
'amount_tendered' => $amount_tendered,
'amount_change' => $change
], ['id' => $order['id']]);
}
// Log the payment action
log_inventory_action(
'update',
'order',
'Multiple Products',
"Marked all pending orders as paid. Amount tendered: {$amount_tendered}, Change: {$change}"
);
// Check if user wants to print receipt
if (isset($_POST['print_receipt']) && $_POST['print_receipt'] == 'yes') {
// Generate receipt HTML
$receipt_html = generateReceipt($pending_orders, $total_amount, $amount_tendered, $change);
// Store receipt in session for printing
$_SESSION['receipt_html'] = $receipt_html;
// Redirect to print page
wp_redirect('http://localhost/inventory/index.php/print-receipt/');
exit;
} else {
wp_redirect($_SERVER['REQUEST_URI']);
exit;
}
}
}
// Function to generate receipt HTML
function generateReceipt($orders, $total_amount, $amount_tendered, $change) {
$current_date = date('F j, Y h:i A');
$username = isset($_SESSION['username']) ? $_SESSION['username'] : 'System';
$receipt = '
<!DOCTYPE html>
<html>
<head>
<title>ArKi Inventory - Receipt</title>
<style>
body { font-family: Arial, sans-serif; margin: 0; padding: 20px; }
.receipt { width: 300px; margin: 0 auto; border: 1px solid #000; padding: 15px; }
.header { text-align: center; margin-bottom: 10px; }
.header h1 { margin: 0; font-size: 20px; }
.header h2 { margin: 5px 0; font-size: 16px; }
.date { text-align: center; margin-bottom: 15px; font-size: 14px; }
.items { width: 100%; border-collapse: collapse; margin-bottom: 15px; }
.items th { border-bottom: 1px dashed #000; text-align: left; padding: 5px 0; }
.items td { padding: 3px 0; }
.items .right { text-align: right; }
.total { margin-top: 15px; border-top: 1px dashed #000; padding-top: 10px; }
.footer { text-align: center; margin-top: 20px; font-size: 12px; }
@media print {
body { padding: 0; }
.no-print { display: none; }
button { display: none; }
}
</style>
</head>
<body>
<div class="receipt">
<div class="header">
<h1>ArKi Inventory</h1>
<h2>Receipt of Order/s</h2>
</div>
<div class="date">' . $current_date . '</div>
<table class="items">
<thead>
<tr>
<th>Item</th>
<th class="right">Qty</th>
<th class="right">Price</th>
<th class="right">Amount</th>
</tr>
</thead>
<tbody>';
foreach ($orders as $order) {
$receipt .= '
<tr>
<td>' . esc_html($order['product_name']) . '</td>
<td class="right">' . esc_html($order['quantity']) . '</td>
<td class="right">₱' . number_format($order['unit_price'], 2) . '</td>
<td class="right">₱' . number_format($order['amount'], 2) . '</td>
</tr>';
}
$receipt .= '
</tbody>
</table>
<div class="total">
<div><strong>Total Amount:</strong> ₱' . number_format($total_amount, 2) . '</div>
<div><strong>Amount Tendered:</strong> ₱' . number_format($amount_tendered, 2) . '</div>
<div><strong>Change:</strong> ₱' . number_format($change, 2) . '</div>
</div>
<div class="footer">
<p>Thank you for your purchase!</p>
<p>Served by: ' . esc_html($username) . '</p>
</div>
</div>
<div class="no-print" style="text-align: center; margin-top: 20px;">
<button onclick="window.print()">Print Receipt</button>
<button onclick="window.close()">Close</button>
</div>
<script>
window.onload = function() {
window.print();
};
</script>
</body>
</html>';
return $receipt;
}
wp_redirect($_SERVER['REQUEST_URI']);
exit;
}
if (isset($_POST['cancel_orders']) && isset($_POST['_wpnonce_cancel_orders']) && wp_verify_nonce($_POST['_wpnonce_cancel_orders'], 'cancel_orders_action')) {
// Get all pending orders with their items
$pending_orders = $wpdb->get_results("
SELECT oi.*, p.name AS product_name
FROM {$table_name_order_items} oi
JOIN {$table_name_orders} o ON oi.order_id = o.id
JOIN {$table_name_products} p ON oi.product_id = p.id
WHERE o.status = 'Pending'
", ARRAY_A);
if ($pending_orders) {
// Restock all products first
foreach ($pending_orders as $order) {
$wpdb->query($wpdb->prepare("
UPDATE {$table_name_products}
SET in_stock = in_stock + %d
WHERE id = %d
", $order['quantity'], $order['product_id']));
}
// Delete all order items for pending orders
$wpdb->query("
DELETE oi FROM {$table_name_order_items} oi
JOIN {$table_name_orders} o ON oi.order_id = o.id
WHERE o.status = 'Pending'
");
// Delete all pending orders
$wpdb->query("DELETE FROM {$table_name_orders} WHERE status = 'Pending'");
// Log the cancellation
$username = isset($_SESSION['username']) ? $_SESSION['username'] : '';
log_inventory_action(
$username,
'cancel',
'order',
'Multiple Products',
"Cancelled all pending orders and restocked items",
);
wp_redirect($_SERVER['REQUEST_URI']);
exit;
}
}
// --- Handle Individual Order Item Cancellation ---
if (isset($_GET['cancel_item']) && isset($_GET['id']) && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'cancel_item_' . $_GET['id'])) {
$item_id = absint($_GET['id']);
// Get the order item details
$order_item = $wpdb->get_row($wpdb->prepare("
SELECT oi.*, p.name AS product_name
FROM {$table_name_order_items} oi
JOIN {$table_name_products} p ON oi.product_id = p.id
WHERE oi.id = %d
", $item_id));
if ($order_item) {
// Restock the product
$wpdb->query($wpdb->prepare("
UPDATE {$table_name_products}
SET in_stock = in_stock + %d
WHERE id = %d
", $order_item->quantity, $order_item->product_id));
// Delete the order item
$wpdb->delete($table_name_order_items, ['id' => $item_id], ['%d']);
// Check if this was the last item in the order
$remaining_items = $wpdb->get_var($wpdb->prepare("
SELECT COUNT(*)
FROM {$table_name_order_items}
WHERE order_id = %d
", $order_item->order_id));
if ($remaining_items == 0) {
// Delete the order if no items left
$wpdb->delete($table_name_orders, ['id' => $order_item->order_id], ['%d']);
}
// Log the cancellation
$username = isset($_SESSION['username']) ? $_SESSION['username'] : '';
log_inventory_action(
$username,
'cancel',
'product',
$order_item->product_name,
"Cancelled order for {$order_item->quantity} units of {$order_item->product_name}",
);
wp_redirect(remove_query_arg(['cancel_item', 'id', '_wpnonce']));
exit;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Orders Management</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 0; padding: 0; }
.dashboard-container { display: flex; }
.sidebar { width: 240px; background-color: #D1B48C; color: #000000; height: 100vh; position: fixed; left: 0; top: 0; overflow-y: auto; box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1); z-index: 1000; }
.sidebar-header {
padding: 20px;
text-align: center;
}
.sidebar-header .inventory-name {
font-size: 17px;
font-weight: bold;
color: #000;
}
.sidebar-menu { padding: 20px 0; }
.sidebar-menu ul { list-style: none; padding: 0; margin: 0; }
.sidebar-menu li a { display: flex; align-items: center; padding: 12px 20px; text-decoration: none; color: #000000; transition: background-color 0.3s ease, color 0.3s ease; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 16px; }
.sidebar-menu li a i { margin-right: 12px; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar-menu li a:hover { background-color: #ffffff; color: #000000; }
.header {
position: fixed;
top: 0;
left: 240px;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #77693A;
padding: 10px 30px;
height: 60px; /* Fixed height */
z-index: 999;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.header h1 {
font-size: 20px;
font-weight: 500;
margin: 0;
color: #ffffff; /* Added to ensure visibility against header background */
}
.header-left .date-time {
font-size: 15px; /* Slightly smaller */
color: #fff; /* Darker color */
font-weight: 500; /* Slightly bolder */
}
.header-right {
display: flex;
align-items: center;
/* Removed gap here, gap is now on .user-info */
font-size: 16px; /* Slightly smaller */
color: #ffffff;
}
/* New style for user info container */
.header-right .user-info {
display: flex;
align-items: center; /* Center items horizontally */
gap: 1px; /* Small gap between icon and text */
}
.user-dropdown {
position: relative;
display: inline-block;
cursor: pointer;
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
}
.user-dropdown-header {
padding: 8px 12px;
background-color: ; #D1B48C
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 8px;
}
.user-dropdown-header i {
font-size: 20px;
color: #000000;
}
.user-dropdown-content.user-info {
display: flex;
align-items: right;
gap: 1px;
color: #000000;
}
.user-dropdown-content a {
display: flex;
padding: 8px 15px;
align-items: center;
color: #000000;
text-decoration: none;
font-size: 16px;
transition: all 0.2s;
}
.user-dropdown-content a i {
font-size: 16px; /* Adjust logout icon size separately */
margin-right: 8px; /* Space between icon and text */
}
.user-dropdown-content a:hover {
text-decoration: underline;
color: #000000;
}
.user-dropdown:hover .user-dropdown-content {
display: block;
}
.user-dropdown-content.user-info i {
font-size: 16px;
align-items: center;
}
.header-right i {
color: #ffffff; /* Icon color */
font-size:40px; /* Larger icon */
/* Remove margin-right when stacked */
}
.header-right span {
font-size: 15px; /* Smaller font for username */
color: #ffffff;
}
.main-content {
margin-left: 240px;
padding: 80px 20px 20px 20px;
flex-grow: 1;
}
/* New Add Order Container */
.add-order-container {
background-color: #fff;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 20px;
margin-bottom: 30px;
}
.add-order-container h2 {
font-size: 20px;
margin-top: 0;
margin-bottom: 20px;
color: #2f4050;
border-bottom: 1px solid #eee;
padding-bottom: 10px;
}
.order-row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
flex-wrap: nowrap; /* ensures it stays in one row */
}
.order-row input[type="text"],
.order-row input[type="number"] {
width: 20%; /* you can adjust to fit your layout */
padding: 10px;
}
.order-row button {
padding: 10px 20px;
white-space: nowrap;
}
.orders-container h2 {font-size: 20px;
margin-top: 0;
margin-bottom: 20px;
color: #2f4050;
border-bottom: 1px solid #eee;
padding-bottom: 10px;}
.form-container, .orders-container { background-color: #fff; padding: 15px; margin-bottom: 20px; }
input, select { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #000000;}
button { padding: 12px 24px; /* Increased size */font-size: 16px;padding: 10px;background-color: #ADD8E6; color: #000000; border: none; border-radius: 5px; cursor: pointer; text-align: middle; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px; border: 1px solid #000000; font-size: 16px; text-align: center; }
th { background-color: #f2f2f2; }
.align-right {text-align: right; }
/* New styles for enhanced form */
.form-select, .form-input {
padding: 12px;
border: 1px solid #000000;
border-radius: 4px;
font-size: 20px;
transition: all 0.3s;
}
.form-select {
width: 30%;
background-color: #f9f9f9;
font-size: 20px;
}
.form-input {
width: 15%;
text-align: center;
font-size: 20px;
}
.form-select:focus, .form-input:focus {
border-color: #D1B48C;
outline: none;
box-shadow: 0 0 0 2px rgba(209, 180, 140, 0.2);
}
.add-order-btn {
padding: 12px 24px;
background-color: #ADD8E6;
color: #000;
border: none;
border-radius: 4px;
font-weight: 500;
cursor: pointer;
transition: background-color 0.3s;
width: 20%;
}
.add-order-btn:hover {
background-color: #be9b7b;
}
.payment-section {
display: flex;
justify-content: flex-end;
margin-top: 20px;
}
.pay-btn {
padding: 14px 30px;
background-color: #98FB98;
color: white;
border: none;
border-radius: 4px;
font-size: 16px;
font-weight: 500;
cursor: pointer;
transition: background-color 0.3s;
}
.pay-btn:hover {
background-color: #3e8e41;
}
.order-table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
.cancel-btn {
background-color: #F08080;
color: black;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
text-align: middle;
}
.cancel-btn:hover {
background-color: #d32f2f;
}
.item-cancel-btn {
background-color: #F08080;
color: black;
border: none;
border-radius: 5px;
padding: 5px 5px;
cursor: pointer;
transition: background-color 0.3s;
font-size: 16px;
text-align: middle;
}
.item-cancel-btn:hover {
background-color: #d32f2f;
}
.button-group {
display: flex;
gap: 15px;
justify-content: space-between;
margin-top: 30px;
}
.button-group {
display: flex;
gap: 15px;
justify-content: flex-end;
margin-top: 30px;
}
.order-table th {
background-color: #f2f2f2;
padding: 12px;
text-align: left;
}
.order-table td {
padding: 12px;
border-bottom: 1px solid #eee;
}
.stock-info {
margin-top: 8px;
font-size: 14px;
color: #666;
}
</style>
</head>
<body <?php body_class(); ?>>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">ArKi Inventory</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="http://localhost/inventory/index.php/admin-page/"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<?php
$current_username = isset($_SESSION['username']) ? $_SESSION['username'] : '';
if ($current_username === 'admin'):
?>
<li><a href="http://localhost/inventory/index.php/usersmanagement/"><i class="fas fa-users-cog"></i> User Management</a></li>
<li><a href="http://localhost/inventory/index.php/category-page/"><i class="fas fa-list"></i> Categories</a></li>
<li><a href="http://localhost/inventory/index.php/products/"><i class="fas fa-boxes"></i> Products</a></li>
<li><a href="http://localhost/inventory/index.php/order/"><i class="fas fa-shopping-cart"></i> Orders</a></li>
<li><a href="http://localhost/inventory/index.php/view-order/"><i class="fas fa-eye"></i> View Orders</a></li>
<li><a href="http://localhost/inventory/index.php/sales/"><i class="fas fa-chart-line"></i> Sales & Report</a></li>
<li><a href="http://localhost/inventory/index.php/report/"><i class="fas fa-file-alt"></i> Inventory Report</a></li>
<li><a href="http://localhost/inventory/index.php/history/"><i class="fas fa-history"></i> Inventory History</a></li>
<?php else : ?>
<li><a href="http://localhost/inventory/index.php/category-page/"><i class="fas fa-list"></i> Categories</a></li>
<li><a href="http://localhost/inventory/index.php/products/"><i class="fas fa-boxes"></i> Products</a></li>
<li><a href="http://localhost/inventory/index.php/order/"><i class="fas fa-shopping-cart"></i> Orders</a></li>
<?php endif; ?>
</ul>
</div>
</aside>
<main class="main-content">
<header class="header">
<div class="header-left">
<span class="date-time" id="current-date-time"></span>
</div>
<div class="header-right">
<!-- Updated user info with dropdown -->
<div class="user-dropdown">
<div class="user-info">
<span id="current-username-header">
<?php echo esc_html($current_username); ?>
<i class="fas fa-user-circle"></i>
</span>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle"style="color:#000000;"></i>
<span style="color:#000000;"><?php echo esc_html($current_username); ?></span>
</div>
<a href="http://localhost/inventory/index.php/sign-in2/" onclick="return confirm('Are you sure you want to log out?');">
<i class="fas fa-sign-out-alt" style="font-size: 16px; color:#000000;"></i>Logout
</a>
</div>
</div>
</div>
</header>
<h1>Order Management</h1>
<hr/>
<?php if (!empty($message)): ?>
<div style="color: red;"><?= esc_html($message); ?></div>
<?php endif; ?>
<div class="add-order-container">
<h2>Add Order</h2>
<form method="post" action="">
<?php wp_nonce_field('add_order_action', '_wpnonce_order_form'); ?>
<div class="order-row">
<?php
// Fetch all active products for the dropdown
$products = $wpdb->get_results("SELECT id, name, selling_price, in_stock FROM $table_name_products WHERE in_stock > 0 ORDER BY name ASC", ARRAY_A);
?>
<select id="product_select" name="product_name" required class="form-select">
<option value="">Select Product</option>
<?php foreach ($products as $product): ?>
<option value="<?php echo esc_attr($product['name']); ?>"
data-price="<?php echo esc_attr($product['selling_price']); ?>"
data-stock="<?php echo esc_attr($product['in_stock']); ?>">
<?php echo esc_html($product['name']); ?>
(₱<?php echo number_format($product['selling_price'], 2); ?> | Stock: <?php echo $product['in_stock']; ?>)
</option>
<?php endforeach; ?>
</select>
<input type="number" id="quantity" name="quantity" min="1" max="in_stock" required placeholder="Qty" class="form-input">
<input type="number" id="unit_price" name="unit_price" step="0.01" required placeholder="Retail Price" readonly style="width: 20%;">
<button type="submit" name="add_order" class="add-order-btn">Add Order</button>
</div>
<div class="stock-info" id="stock_info"></div>
</form>
</div>
<script>
document.getElementById('product_select').addEventListener('change', function() {
var selectedOption = this.options[this.selectedIndex];
if (selectedOption.value) {
var sellingPrice = selectedOption.getAttribute('data-price');
document.getElementById('unit_price').value = sellingPrice;
// Auto-focus on quantity field for better UX
document.getElementById('quantity').focus();
} else {
document.getElementById('unit_price').value = '';
}
});
</script>
<div class="orders-container">
<h2>Order List</h2>
<table class="order-table">
<thead>
<tr>
<th>ID</th>
<th>Product</th>
<th>Quantity</th>
<th>Retail Price</th>
<th>Amount</th>
<th>Status</th>
<th>Action</th> <!-- Added new column for Cancel button -->
</tr>
</thead>
<tbody>
<?php
$orders = $wpdb->get_results("
SELECT o.*, oi.id as item_id, oi.*, p.name AS product_name
FROM $table_name_orders o
INNER JOIN $table_name_order_items oi ON o.id = oi.order_id
INNER JOIN $table_name_products p ON oi.product_id = p.id
WHERE o.status = 'Pending'
", ARRAY_A);
$total_amount = 0;
if ($orders) foreach ($orders as $order):
$amount = $order['quantity'] * $order['unit_price'];
$total_amount += $amount;
?>
<tr>
<td><?php echo esc_html($order['id']); ?></td>
<td><?php echo esc_html($order['product_name']); ?></td>
<td><?php echo esc_html($order['quantity']); ?></td>
<td>₱<?php echo esc_html($order['unit_price']); ?></td>
<td>₱<?php echo esc_html($amount); ?></td>
<td><?php echo esc_html($order['status']); ?></td>
<td>
<a href="<?php echo esc_url(wp_nonce_url(
add_query_arg(['cancel_item' => 1, 'id' => $order['item_id']]),
'cancel_item_' . $order['item_id']
)); ?>"
class="item-cancel-btn"
onclick="return confirm('Are you sure you want to cancel this order item? The quantity will be restocked.');">
Cancel
</a>
</td>
</tr>
<?php endforeach; ?>
<tr>
<td colspan="5" style="text-align: right;"><strong>Total (₱):</strong></td>
<td colspan="2">₱<?php echo esc_html($total_amount); ?></td>
</tr>
<tr>
<td colspan="5" style="text-align: right;"><strong>Amount Tendered (₱):</strong></td>
<td colspan="2">
<input type="number" id="amount_tendered" name="amount_tendered" placeholder="Enter Amount" step="0.01" value="" oninput="calculateChange()">
</td>
</tr>
<tr>
<td colspan="5" style="text-align: right;"><strong>Change (₱):</strong></td>
<td colspan="3" id="change_display">₱0.00</td>
</tr>
</tbody>
</table>
<div class="button-group">
<form method="post" action="">
<button type="submit" name="pay_orders" class="pay-btn"
style=" padding: 5px 20px; color: #000000; border: none; cursor: pointer; text-align: middle; font-size: 18px; line-weight: 600px; margin-left: auto; display: block; background-color: #98FB98; border-radius: 5px; margin-top: 20px;">
Pay Now
</button>
</form>
<div class="button-group">
<form method="post" action="">
<input type="hidden" name="print_receipt" id="print_receipt" value="no">
<button type="button" onclick="confirmPayment()" class="pay-btn"
style="padding: 5px 20px; color: #000000; border: none; cursor: pointer; text-align: middle; font-size: 18px; line-weight: 600px; margin-left: auto; display: block; background-color: #98FB98; border-radius: 5px; margin-top: 20px;">
Pay Now
</button>
</form>
<form method="post" action="">
<?php wp_nonce_field('cancel_orders_action', '_wpnonce_cancel_orders'); ?>
<button type="submit" name="cancel_orders" class="cancel-btn"
style="font-size: 18px; padding: 5px 20px; margin-left: auto; display: block;"
onclick="return confirm('Are you sure you want to cancel all pending orders? All items will be restocked.');">
Cancel All Orders
</button>
</form>
</div>
</div>
</main>
</div>
<script>
function confirmPayment() {
if (confirm('Do you want to print a receipt?')) {
document.getElementById('print_receipt').value = 'yes';
} else {
document.getElementById('print_receipt').value = 'no';
}
document.forms[1].submit(); // Submit the payment form
}
</script>
<script>
function calculateChange() {
const totalAmount = <?php echo json_encode($total_amount); ?>; // Get the total amount from PHP
const amountTendered = parseFloat(document.getElementById('amount_tendered').value) || 0; // Get the amount tendered
const change = amountTendered - totalAmount; // Calculate change
document.getElementById('change_display').textContent = '₱' + change.toFixed(2); // Update change display
}
</script>
<script>
function updateDateTime() {
const now = new Date();
const options = {
weekday: 'short', year: 'numeric', month: 'short',
day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit'
};
document.getElementById("current-date-time").textContent = now.toLocaleDateString('en-US', options);
}
setInterval(updateDateTime, 1000);
updateDateTime();
</script>
</body>
</html>