<?php

include "../../root.class.php";
$db = new db_safeguard();

$res = $db->query("stock_take_stock", "SELECT sto.description,st.amount_in_stock,st.amount_counted FROM `stock_take_stock` as st LEFT JOIN stock as sto on st.item_id = sto.record_id WHERE st.stock_take_id = '" . $_GET['record_id'] . "' ORDER BY st.record_id ASC");

while ($row = $res->fetch_assoc()) {
    header("Content-Type: application/vnd.ms-excel");
    header("Content-Disposition: attachment; filename=stock_take_" . $_GET['record_id'] . ".xls");
    echo pack("CCC", 0x1F, 0x08, 0x08);
    echo "<table border=\"1\">";
    echo "<tr><th>Item Description</th><th>Amount in Stock</th><th>Amount Counted</th></tr>";
    while ($row = $res->fetch_assoc()) {
        echo "<tr><td>" . $row['description'] . "</td><td>" . $row['amount_in_stock'] . "</td><td>" . $row['amount_counted'] . "</td></tr>";
    }
    echo "</table>";
}
echo "<script>window.location.href='show_stock_take.php?stock_take_id=" . $_GET['record_id']."';</script>";