35607-vm/receipt.php
Flatlogic Bot 9b5a06451f SInarKasih
2025-11-10 04:11:47 +00:00

135 lines
4.1 KiB
PHP

<?php
require_once 'includes/auth.php';
require_login();
require_once 'db/config.php';
if (!isset($_GET['sale_id']) || !is_numeric($_GET['sale_id'])) {
die('Invalid Sale ID.');
}
$sale_id = $_GET['sale_id'];
$pdo = db();
// Get sale details
$sale_stmt = $pdo->prepare("SELECT * FROM sales WHERE id = ?");
$sale_stmt->execute([$sale_id]);
$sale = $sale_stmt->fetch(PDO::FETCH_ASSOC);
if (!$sale) {
die('Sale not found.');
}
// Get sale items
$items_stmt = $pdo->prepare(
"SELECT si.*, p.name as product_name
FROM sale_items si
JOIN products p ON si.product_id = p.id
WHERE si.sale_id = ?"
);
$items_stmt->execute([$sale_id]);
$items = $items_stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Receipt - Sale #<?php echo htmlspecialchars($sale['id']); ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background-color: #f8f9fa;
font-family: 'Courier New', Courier, monospace;
}
.receipt-container {
max-width: 400px;
margin: 2rem auto;
padding: 2rem;
background-color: #fff;
border: 1px dashed #ccc;
}
.receipt-header {
text-align: center;
margin-bottom: 1.5rem;
}
.receipt-header h2 {
margin: 0;
font-size: 1.5rem;
}
.receipt-item {
display: flex;
justify-content: space-between;
margin-bottom: 0.5rem;
}
.receipt-total {
font-weight: bold;
border-top: 1px dashed #000;
margin-top: 1rem;
padding-top: 1rem;
}
@media print {
body {
background-color: #fff;
}
.receipt-container {
margin: 0;
max-width: 100%;
border: none;
box-shadow: none;
}
.no-print {
display: none;
}
}
</style>
</head>
<body>
<div class="receipt-container">
<div class="receipt-header">
<h2>Your Store Name</h2>
<p>123 Main Street, Anytown, USA</p>
<p>Date: <?php echo htmlspecialchars(date("m/d/Y H:i", strtotime($sale['sale_date']))); ?></p>
<p>Receipt #: <?php echo htmlspecialchars($sale['id']); ?></p>
</div>
<div class="receipt-body">
<div class="receipt-item fw-bold">
<span>Item</span>
<span>Price</span>
</div>
<?php foreach ($items as $item): ?>
<div class="receipt-item">
<span>
<?php echo htmlspecialchars($item['product_name']); ?><br>
<small>(<?php echo htmlspecialchars($item['quantity']); ?> @ $<?php echo htmlspecialchars(number_format($item['price'], 2)); ?>)</small>
</span>
<span>$<?php echo htmlspecialchars(number_format($item['quantity'] * $item['price'], 2)); ?></span>
</div>
<?php endforeach; ?>
</div>
<div class="receipt-footer">
<div class="receipt-item receipt-total">
<span>Total</span>
<span>$<?php echo htmlspecialchars(number_format($sale['total_amount'], 2)); ?></span>
</div>
<div class="receipt-item">
<span>Payment Method</span>
<span><?php echo htmlspecialchars($sale['payment_method']); ?></span>
</div>
</div>
<div class="text-center mt-4">
<p>Thank you for your business!</p>
</div>
<div class="text-center mt-4 no-print">
<button class="btn btn-primary" onclick="window.print();">Print Receipt</button>
<a href="pos.php" class="btn btn-secondary">New Sale</a>
</div>
</div>
</body>
</html>