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

$formname = 'Barcode Label';
$font_size = "2px";
$barcode_width = "170px";
$barcode_height = "25px";

$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: 3px;
                margin-top: 3px;
            }
            td.one{
                width:50%;
                border:0px solid black;                
            }

            .page {

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

            }
        </style>
<!--        <style>

            @media screen
            {


                body {
                    width: 100%;
                    height: 100%;
                    margin: 0;
                    padding: 0;
                    background-color: #FAFAFA;
                    font: 12pt "Tahoma";
                }
                * {
                    box-sizing: border-box;
                    -moz-box-sizing: border-box;
                }
                .page {
                    width: 210mm;
                    min-height: 297mm;
                    margin: auto;
                    padding-left: 17px;
                    /*              margin: 10mm auto;
                                    border: 1px #D3D3D3 solid;
                                    border-radius: 5px;
                                    background: white;*/

                }
                .myTable{
                    width:50%;
                    height:11%;
                    float:left;
                    margin-top: 2%;

                }
            }

            @page {
                size: A4;
                margin: 0;
            }
            @media print{
                body {
                    width: 100%;
                    height: 100%;
                    margin: 0;
                    padding: 0;
                    background-color: #FAFAFA;
                    font: 12pt "Tahoma";
                }
                * {
                    box-sizing: border-box;
                    -moz-box-sizing: border-box;
                }
                .page {
                    width: 210mm;
                    min-height: 297mm;
                    margin: auto;
                    padding-left: 17px;
                    /*              margin: 10mm auto;
                                    border: 1px #D3D3D3 solid;
                                    border-radius: 5px;
                                    background: white;*/

                }
                .myTable{
                    width:50%;
                    height:11%;
                    float:left;
                    margin-top: 2%;

                }
                .labeltabl{
                    width:50%;
                    height:12.5%;
                }
                .labeltr{
                    border-top: 1px solid black;
                }
                .labeltd{
                    border-top: 1px solid black;
                    border-right: 1px solid black;
                    border-left: 1px solid black;
                }
                .labeltdrt{
                    border-top: 1px solid black;
                    border-right: 1px solid black;
                }
                .labeltdwdt{
                    width:4%;
                }
                .bordlb{
                    border:1px solid black;
                }
                .bordrbt{
                    border-top: 1px solid black;
                    border-bottom:  1px solid black;
                    border-right:  1px solid black;
                }
                .trhgt{
                    height:25px;
                }

            }
        </style>-->
    </head>
    <body >
        <table width='' class="page" border='0' cellspacing='0' cellpadding='0' style=''>
            <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 TO clen
//       c1 = SUBSTR(charmsp,i,1) 
//       
//       SELECT * FROM msp WHERE no = VAL(c1) INTO CURSOR chget
//       GO top
//       STORE chget->code TO c1code
//       
//       dcode = dcode + c1code
//   endf
//   
//   m.mspcode = dcode

                for ($i = 1; $i <= $num_qty; $i++) {
                    echo "<td width='50%' class='one'>";
                    echo "<table width='100%' cellspacing='0' cellpadding='5'  style='border:0px solid red;'>";
                    echo "<tr>";

                    echo "<td align='center' class='one'>";
                    echo "<center><font size='1px'>" . $barcode . "</font></center>";
                    echo "<img alt='$itemcode' src='barcode.php?text=$barcode' style='width:$barcode_width;height:$barcode_height;'/>";
                    echo "</td>";
                    echo "</tr>";
                    echo "<tr>";
                    echo "<td>";
                    echo "<table width='50%' style='border:0px solid blue;'>";

                    echo "<tr>";
                    echo "<center><font size='1px'>" . strtoupper($itemname) . "</font></center>";
                    echo "<tr>";

                    echo "<td align='right'>";
                    echo "<font size='$font_size'><b> Qty. : </b></font>";
                    echo "</td>";
                    echo "<td>";
                    echo "<font size='$font_size'><b>1 PCS.</b></font>";
                    echo "</td>";
                    echo "</tr>";
                    echo "<tr>";
                    echo "<td align='right'>";
                    echo "<font size='$font_size'><b> MRP : </b></font>";
                    echo "</td>";
                    echo "<td>";
                    echo "<font size='$font_size'><b>" . $mrp . "</b></font>";
                    echo "</td>";
                    echo "</tr>";
                    echo "<tr>";
                    echo "<td align='right'>";
                    echo "<font size='$font_size'><b</b></font>";
                    echo "</td>";
                    echo "<td>";
                    echo "<font size='$font_size'><b>" . $dcode . "</b></font>";
                    echo "</td>";
                    echo "</tr>";

                    echo "</td>";
                    echo "</tr>";
//                    echo "<tr>";
//
//                    echo "</tr>";
                    echo "</td>";
                    echo "</tr>";
                    echo "<tr style='width:20px;'>";
                    echo "</tr>";
                    echo "</table>";
                    echo "</td>";
                    echo "</tr>";
                    echo "</table>";
                    echo "</td>";

                    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>