<?php
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"];
$zcomp = $_SESSION["comp_" . $dbname];

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

$vouch = $_GET['vouchno'];

$cond = '';
$lcond = '';
$formname = "Purchase Order";

$maindb = 'production';
$trandb = 'prodpack';

$mainqry = mysqli_query($conn, "SELECT DATE_FORMAT(`prepdate`, '%d-%m-%Y')as prepdate , DATE_FORMAT(`expdate`, '%d-%m-%Y')as expdate ,
                       `refno`, batchno, batchsize, `product`,DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as vouchdt FROM `$maindb` 
                        WHERE vouchno='$vouch' ORDER BY `vouchno`")or die(mysqli_error($conn));
$fmain = mysqli_fetch_array($mainqry);
$prepdate = $fmain['prepdate'];
$expdate = $fmain['expdate'];
$vouchno = $fmain['vouchno'];
$vouchdt = $fmain['vouchdt'];
$prodcode = $fmain['product'];
$refno = $fmain['refno'];
$batchsize = $fmain['batchsize'];
$batchno = $fmain['batchno'];
$rem2 = $fmain['rem2'];
$gprod = mysqli_query($conn, "SELECT `code`, name FROM `finprod` WHERE code = '$prodcode'") or die(mysqli_error($conn));
$fprod = mysqli_fetch_array($gprod);
$product = $fprod['name'];

$getcomp = mysqli_query($conn, "SELECT * From $zroot.`company` ")or die(mysqli_error($conn));
$company = mysqli_fetch_array($getcomp);
$compcode = $company['code'];
$compinit = $company['init'];
$compname = $company['compname'];
$add1 = $company['fadd1'];
$add2 = $company['fadd2'];
$add3 = $company['fadd3'];
$city = $company['fcity'];
$pin = $company['fpin'];
$tel = $company['ftel'];
$gstno = $company['gstno'];

include("includes/linkshead.php");
?>
<link href="MyStyle/rep_format.css" rel="stylesheet">
<style>
    @media print {
        .noprint {
            display: none;
        }
    }
    table{
        width:100%;
    }
    td{
        padding:3px;
    }
    .nopadd{
        padding:0px;
    }
    .border{
        border:1px solid black;
    }
    .add{
        font-size: 11px;
    }
</style>
</head>
<body id="main_container">
    <div class="page">
        <div class="subpage">
            <!------------HEADER---------->
            <table>
                <tr> <td class="text-center nopadd"><h3><b><?php echo $compname; ?></b></h3></td></tr>
                <tr><td class="text-center  add"><b>Factory Address : </b><?php echo $add1; ?></h2></td></tr>
                <tr><td class="text-center add"><?php echo $add2 . $add3; ?></td></tr>
                <tr><td class="text-center add"><?php echo $city . " - " . $pin; ?></td></tr>
                <?php if ($tel != '') { ?>
                    <tr><td class="text-center add">Telephone <?php echo $tel; ?></td></tr>
                <?php } ?>
                <tr><td class="text-center "><b>GST NO. : <?php echo $gstno; ?></b></td></tr>
            </table>
            <!---------HEADER CLOSE------->

            <!---------MAIN PART------->

            <table class="border">
                <tr>
                    <td colspan="2" class="border" style="padding:5px;">BMR</td>
                    <td colspan="2" class="border" style="padding:5px;">Document Title</td>
                    <td colspan="3" class="border" style="padding:5px;">Verification & Released Record</td>
                </tr>
                <tr>
                    <td colspan="2" class="border" style="padding:5px;">Rev No.</td>
                    <td colspan="2" class="border" style="padding:5px;">Effective Date : <?php ?></td>
                    <td colspan="1" class="border" style="padding:5px;">Sr No. : <?php ?></td>
                    <td colspan="2" class="border" style="padding:5px;">Document No. : <?php echo $refno ;?></td>
                </tr>
                <tr>
                    <td colspan="2" class="border">Product</td>
                    <td class="border" colspan="5"><?php echo $product ?></td>
                </tr>
                <tr>
                    <td colspan="2" class="border">Batch No.</td>
                    <td colspan="2" class="border"><?php echo $batchno; ?></td>
                    <td colspan="1" class="border">REF MFR No.</td>
                    <td colspan="2" class="border"><?php echo $refno; ?></td>
                </tr>
                <tr>
                    <td colspan="2" class="border">MFG Date</td>
                    <td colspan="2" class="border"><?php echo $vouchdt ?></td>
                    <td colspan="1" class="border">Batch Size : (in kgs)</td>
                    <td colspan="2" class="border"><?php echo $batchsize ?></td>
                </tr>
                <tr>
                    <td colspan="2" class="border">EXP Date</td>
                    <td colspan="2" class="border"><?php echo $expdate; ?></td>
                    <td colspan="1" class="border">Date of Preparation  </td>
                    <td colspan="2" class="border"><?php echo $prepdate; ?></td>
                </tr>

             <tr class="">
                    <td colspan="7" class="text-center border"><h4><b>DATA SHEET (PACKING  MATERIAL REQUISITION)</b></h4>
                        <br><u><i style="font-size: 15px">Prodution Department</i></u><br>&nbsp;</td>
                </tr>
                <tr class="">
                    <td width="2%" class="border text-center"><b>Sr.</b></td>
                    <td width="23%" class="border"><b>Packing Material</b></td>
                    <td width="12%" class="border text-center"><b>AR No.</b></td>
                    <td width="18%" class="text-right border"><b>Actual Qty Required</b></td>
                    <td width="16%" class="text-right border"><b>Issued Qty.</b></td>
                    <td width="13%" class="text-right border"><b>Issued By</b></td>
                    <td width="15%" class="text-right border"><b>Checked by</b></td>
                </tr>
                <?php
                $ctr = 0;
                $totactqty = 0;
                $totissuedqty = 0;
                $tranqry = mysqli_query($conn, "SELECT * FROM $trandb WHERE `vouchno`='$vouch'")or die(mysqli_error($conn));

                while ($ftran = mysqli_fetch_array($tranqry)) {
                    $ctr++;
                    $arno = $ftran['arno'];
                    $material = $ftran['itemname'];
                    $amount = $ftran['amount'];
                    $actqty = $ftran['actqty'];
                    $issuedqty = $ftran['issuedqty'];
                    

                    echo "<tr>";
                    echo "<td class='border text-center'>$ctr</td>";
                    echo "<td class='border'>$material</td>";
                    echo "<td class='border text-right'>$arno</td>";
                    echo "<td class='border text-right'>".number_format($actqty,2)."</td>";
                    echo "<td class='border text-right'>".number_format($issuedqty,2)."</td>";
                    echo "<td class='border text-right'></td>";
                    echo "<td class='text-right border'></td>";
                    echo "</tr>";

                    $totactqty = $totactqty + $actqty;
                    $totissuedqty = $totissuedqty + $issuedqty;
                }
                ?>
                <tr>
                    <td colspan="3" class="border text-right"><b>Total</b></td>
                    <td class="border text-right"><b><?php echo number_format($totactqty,2); ?></b></td>
                    <td class="border text-right"><b><?php echo number_format($totissuedqty,2); ?></b></td>
                    <td colspan="2" class="border"></td>
                </tr>

                <!-----MAIN PART CLOSE----->

                <!-----LAST PART----->

                <tr>
                    <td colspan="7"  class="text-right"><b>TECHNICAL INCHARGE (MFG)</b></td>
                </tr>
                <tr>
                    <td colspan="7" class="" width=""><b>&nbsp;<br><br><br><br></b></td>
                </tr>
                <tr>
                    <td colspan="7" class="text-right" width=""><b><?php echo $compname; ?></b></td>
                </tr>

            </table>
            <!-----LAST PART CLOSE----->
        </div>
    </div>    
</div>
<?php
include("includes/linksfoot.php");
?>
<script>
    $(function () {
        formGeneral();
    });
</script>
</body>
</html>
