<?php
require_once "../assets/db_connect.php";

$id = $_GET['id'];

$sale = $pdo->query("SELECT * FROM sales WHERE id=$id")->fetch();
$items = $pdo->query("
    SELECT p.product_name, si.quantity, si.price
    FROM sale_items si
    JOIN products p ON p.id=si.product_id
    WHERE si.sale_id=$id
")->fetchAll();
?>

<h3>Receipt #<?= $id ?></h3>
<hr>
<?php foreach ($items as $i): ?>
<?= $i['product_name'] ?> × <?= $i['quantity'] ?> =
<?= number_format($i['quantity']*$i['price'],2) ?><br>
<?php endforeach; ?>
<hr>
<strong>Total: <?= number_format($sale['total_amount'],2) ?></strong>

<script>window.print()</script>
