<?php
ob_start();
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');


$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION['zdir'];

$zyear = right($zdb, 4);
$mfrdate = getzdates($zyear, 'S');
$mtodate = getzdates($zyear, 'E');

$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);


$result = mysqli_query($conn, "SELECT * FROM `product` WHERE code='$_GET[code]'") or die(mysqli_error($conn));
$get = mysqli_fetch_array($result);

$product_name = $get["name"];
$mrp = $get["rate"];
// $product_name = "MU 3344D GREY";
// $mrp = 1349.00;

$label_count =  10 ; // total labels
$label_count = $_GET['number'] ; // total labels
$per_page = 48;

$total_pages = ceil($label_count / $per_page);
$counter = 0;

include("includes/linkshead.php");
?>



<style>
@page {
    size: A4;
    margin: 0;
}

body {
    margin: 0;
}

/* EACH PAGE */
.sheet {
    width: 210mm;
    height: 297mm;

    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(12, 1fr);

    gap: 2.5mm;
    padding: 5mm;

    box-sizing: border-box;

    page-break-after: always;
}

/* LABEL */
.label {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;

    font-size: 11px;
    color: black;
    /* DEBUG (REMOVE LATER) */
    /* border: 1px solid red; */
}

.title {
    font-weight: bold;
}
</style>
</head>

<body>

<?php
for ($p = 1; $p <= $total_pages; $p++) {

    echo '<div class="sheet">';

    for ($i = 1; $i <= $per_page; $i++) {

        if ($counter >= $label_count) break;

        echo '<div class="label">
                <div class="title">' . $product_name . '</div>
                <div class="title">M.R.P. ' . number_format($mrp,2) . '</div>
              </div>';

        $counter++;
    }

    echo '</div>';
}
?>

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

</body>
</html>