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

$formname = 'Barcode Label';
$font_size = "2px";
$barcode_width = "155px";
$barcode_height = "20px";

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);

$zroot = $_SESSION["zdbroot"];

$count = $_REQUEST["number"];
$num_qty = $count;

$barcode = $_REQUEST['barcode'];
//browse($barcode);
//browse($itemname);
$itemname = $_REQUEST['name'];
$mrp = $_REQUEST['mrp'];
$msp1 = $_REQUEST['msp'];
$msp = round($msp1, 0);
//browse($msp);
$costcode = '';
//browse($costcode);
?>

<html>
    <head>
        <title><?= $formname ?></title>
        <style type="text/css">
            table { page-break-inside:auto }
            tr    { page-break-inside:avoid; page-break-after:auto }
            thead { display:table-header-group }
            tfoot { display:table-footer-group }
            table {
                table-layout:fixed;
                width:100%;
                margin-left: 1px;
                margin-bottom: 1px;
                margin-top: 3px;
            }
            /*            td.one{
                            width:20%;
                            border:0px solid black;                
                        }*/

            .page {

                width: 210mm;
                min-height: 297mm;
                padding: 1mm;
                margin: 5mm auto;
                /*border: 1px #D3D3D3 solid;*/
                /*border-radius: 5px;*/
                background: white;

            }
        </style>
    </head>
    <body >
        <table width='' class="page">
            <tbody>
                <?php
                $ctr = 1;
                $breaker = 1;
                $location = '';

                $convmsp = (string) $msp;
                $clen = strlen($convmsp);
//                browse($clen);
//   
                $dcode = "";
                for ($i = 0; $i < $clen; $i++) {
                    $c1 = substr($convmsp, $i, 1);
                    $getmsp = mysqli_query($conn, "Select * from $zroot.msp where no = '$c1'") or die(mysqli_error($conn));
                    $fetmsp = mysqli_fetch_array($getmsp);
                    $codmsp = $fetmsp[code];
                    $dcode = $dcode . $codmsp;
//                    browse($dcode);
                }


                for ($i = 1; $i <= $num_qty; $i++) {
                    echo "<td style='width:20%;'>";
                    echo "<table width='100%' align='left'>";
                    echo "<tr>";
                    echo "<td align='' style='width:$barcode_width;height:$barcode_height;'  class=''>";
                    echo "<font size='1px'>Barcode : " . $barcode . "</font>";
                    echo "</td>";
                    
                    echo "</tr>";
                    
                    echo "<tr>";
                    echo "<td align='' style='width:$barcode_width;height:$barcode_height;'  class=''>";
                    echo "<img alt='$itemcode' src='barcode.php?text=$barcode' style=''/>";
                    echo "</td>";
                    echo "</tr>";

                    echo "<tr>";
                    echo "<td align='' style='width:$barcode_width;height:$barcode_height;'  class=''>";
                    echo "<font size='1px'>" . strtoupper($itemname) . "</font>";
                    echo "</td>";
                    echo "</tr>";
                    
                    echo "<tr>";
                    echo "<td align='' style='width:$barcode_width;height:$barcode_height;'  class=''>";
                    echo "<font size='$font_size'><b> Qty. : </b></font>";
                    echo "<font size='$font_size'><b>1 PCS.</b></font>";
                    echo "</td>";
                    echo "</tr>";

                    echo "<tr>";
                    echo "<td align='' style='width:$barcode_width;height:$barcode_height;'  class=''>";
                    echo "<font size='$font_size'><b> MRP : </b></font>";
                    echo "<font size='$font_size'><b>$mrp</b></font>";
                    echo "</td>";
                    echo "</tr>";

                    echo "<tr>";
                    echo "<td align='' style='width:$barcode_width;height:$barcode_height;'  class=''>";
                    echo "<font size='$font_size'><b></b></font>";
                    echo "<font size='$font_size'><b>$dcode</b></font>";
                    echo "</td>";
                    echo "</tr>";
                    echo "</table>";
                    echo "</td>";


                    browse($ctr);


                    if ($ctr == 5) {
                        if ($breaker == 40) {
                            
                        } else {
                            echo "<tr>";
                        }
                        $ctr = 1;
                    } else {
                        $ctr++;
                    }

                    if ($breaker == 40) {
                        echo "</tbody></table>";
                        echo "<div  style='page-break-before:always;'>";
                        //echo "<br/>";
                        echo "<table width='230px' border='0' cellspacing='0' cellpadding='0' style='height:20px;'>";
                        echo "</br>";
                        echo "</br>";
                        $breaker = 1;
                    } else {
                        $breaker++;
                    }
                }
                if ($breaker < 40) {
                    for ($j = $breaker; $j <= 40; $j++) {
                        $breaker++;
                    }
                }
                ?>
            </tbody>
        </table>
    </body>
</html>