37650-vm/receipt.php
Flatlogic Bot 73e14b3353 sad
2026-01-21 17:27:41 +00:00

111 lines
3.9 KiB
PHP

<?php
session_start();
require_once __DIR__ . '/db/config.php';
if (!isset($_SESSION['user_id']) || empty($_GET['id'])) {
header("Location: index.php");
exit();
}
$pdo = db();
$bookingId = $_GET['id'];
// Fetch Sale Details
$stmt = $pdo->prepare("
SELECT b.*, c.make, c.model, c.year, c.price, c.mileage, u.username as buyer_name, u.role
FROM bookings b
JOIN cars c ON b.car_id = c.id
JOIN users u ON b.user_id = u.id
WHERE b.id = ?
");
$stmt->execute([$bookingId]);
$sale = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$sale || ($sale['user_id'] != $_SESSION['user_id'] && $_SESSION['role'] !== 'admin')) {
die("Receipt not found or access denied.");
}
$pageTitle = "Sale Receipt";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Receipt #<?= $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; }
.receipt-container {
max-width: 800px;
margin: 50px auto;
background: white;
padding: 40px;
box-shadow: 0 0 15px rgba(0,0,0,0.1);
}
@media print {
body { background: white; }
.receipt-container { box-shadow: none; margin: 0; padding: 0; }
.no-print { display: none; }
}
</style>
</head>
<body>
<div class="container">
<div class="receipt-container">
<div class="text-center mb-5">
<h1 class="display-6 fw-bold text-primary">Car Sells Afghanistan</h1>
<p class="text-muted">Official Sale Receipt</p>
</div>
<div class="row mb-4">
<div class="col-6">
<h5 class="fw-bold">Buyer Details</h5>
<p class="mb-0">Name: <strong><?= htmlspecialchars($sale['buyer_name']) ?></strong></p>
<p class="mb-0">Bank Province: <?= htmlspecialchars($sale['bank_province']) ?></p>
<p>Account: ****<?= substr($sale['bank_account_number'], -4) ?></p>
</div>
<div class="col-6 text-end">
<h5 class="fw-bold">Receipt Info</h5>
<p class="mb-0">Receipt #: <?= str_pad($sale['id'], 6, '0', STR_PAD_LEFT) ?></p>
<p class="mb-0">Date: <?= date('F j, Y', strtotime($sale['booking_date'])) ?></p>
<p>Status: <span class="badge bg-success text-uppercase">Paid</span></p>
</div>
</div>
<table class="table table-bordered mb-4">
<thead class="table-light">
<tr>
<th>Description</th>
<th class="text-end">Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<strong><?= htmlspecialchars($sale['year'] . ' ' . $sale['make'] . ' ' . $sale['model']) ?></strong><br>
<small class="text-muted">Mileage: <?= number_format($sale['mileage']) ?> km</small>
</td>
<td class="text-end">$<?= number_format($sale['sale_price'] ?? $sale['price'], 2) ?></td>
</tr>
<tr>
<td class="text-end fw-bold">Total</td>
<td class="text-end fw-bold">$<?= number_format($sale['sale_price'] ?? $sale['price'], 2) ?></td>
</tr>
</tbody>
</table>
<div class="text-center mt-5 mb-4">
<p class="lead">Thank you for your business!</p>
<p class="small text-muted">This receipt is electronically generated and valid without signature.</p>
</div>
<div class="text-center no-print mt-4">
<button onclick="window.print()" class="btn btn-primary btn-lg"><i class="bi bi-printer"></i> Print Receipt</button>
<a href="index.php" class="btn btn-link">Back to Home</a>
</div>
</div>
</div>
</body>
</html>