<?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 = "Item Print";

$maindb = 'item';
$trandb = 'itemtran';


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

$finditemgrp = mysqli_query($conn, "SELECT * FROM `itemgrp` WHERE `code`='$get[itemgrp]'") or die(mysqli_error($conn));
$fitemgrp = mysqli_fetch_array($finditemgrp);

$finditemsub = mysqli_query($conn, "SELECT * FROM `itemsubgrp` WHERE `code`='$get[itemsubgrp]'") or die(mysqli_error($conn));
$fitemsub = mysqli_fetch_array($finditemsub);

$getimg = mysqli_query($conn, "SELECT * FROM `itemimage` WHERE `vouchno`='$vouch'")or die(mysqli_error($conn));
$img = mysqli_fetch_array($getimg);
$imgpath = $img[imgpath] . "?a=" . mt_rand();
?>
<!DOCTYPE HTML>
<html lang="en-US">


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

        }
        .subpage {
            padding: 0cm;
            /*        border: 1px solid;*/
            height: 288mm;
            outline: 2cm #ffffff solid;
        }

        @page {
            size: A4;
            margin: 0;
        }
        @media print {
            html, body {
                width: 210mm;
                height: 297mm;        
            }
            .page {
                margin: 0;
                border: initial;
                border-radius: initial;
                width: initial;
                min-height: initial;
                box-shadow: initial;
                background: initial;
                page-break-after: always;
            }
        }
        .numeric{
            text-align: right;
        }
        .rnone{
            border-right:none; 
        }
        .lnone{
            border-left:none; 
        }
    </style>
</head>

<!--<link href="MyStyle/rep_format.css" rel="stylesheet">-->

<body id="main_container">
    <div class="book">
        <!--<button class="btn btn-primary goBack noprint" onclick="window.close()"  style="float: right;width: 150px;height:35px;background-color: white;color:#A0B1BA;">Go Back</button>-->
        <div class="page">
            <!--<div class="subpage">-->
            <!--   ************Header************  -->
            <?php include("includes/head_rep.php"); ?>
            <div style="border:solid 1px;" class="col-md-12" style="padding-left: 1px ; padding-right: 1px">

                <table class="table table-border table-hover" style="width:100%">
                    <tr>
                        <td style="width:60%;">
                            <table>
                                <tr>
                                    <td style="text-align:right">
                                        <label class="control-labele">Code </label>	
                                    </td>
                                    <td style="padding-left:14px">
                                        <b><?= $get['code']; ?></b>
                                    </td>
                                </tr>
                                <tr>		
                                    <td style="text-align:right">
                                        <label class="control-label">Name </label>	
                                    </td>
                                    <td style="padding-left: 14px" colspan="3">
                                        <b> <?= $get['name']; ?></b>

                                    </td>
                                </tr>
                                <tr>		
                                    <td style="text-align:right">
                                        <label class="control-label">Sub Name</label>	
                                    </td>
                                    <td style="padding-left: 14px" colspan="2">
                                        <b><?= $get[subname]; ?></b>
                                    </td>
                                </tr>
                                <tr>		
                                    <td style="text-align:right">
                                        <label class="control-label">Item-Group </label>	
                                    </td>
                                    <td style="padding-left: 14px" colspan="2">
                                        <b> <?= $fitemgrp[name]; ?></b>
                                    </td>
                                </tr>

                                <tr>		
                                    <td style="text-align:right">
                                        <label class="control-label">Item-Sub-Group </label>	
                                    </td>
                                    <td style="padding-left: 14px" colspan="2">
                                        <b><?= $fitemsub[name]; ?></b>
                                    </td>
                                </tr>
                                <tr>		
                                    <td style="text-align:right">
                                        <label class="control-label">Name To Print </label>	
                                    </td>
                                    <td style="padding-left: 14px" colspan="3">
                                        <b><?= $get[nameprint]; ?></b>

                                    </td>
                                </tr>
                                <tr>		
                                    <td style="text-align:right">
                                        <label class="control-label">Karigar Name</label>	
                                    </td>
                                    <td style="padding-left: 14px" colspan="3">
                                        <b><?= $get[kargname]; ?></b>

                                    </td>
                                </tr>
                                <tr>		
                                    <td style="text-align:right">
                                        <label class="control-label">HSN Code </label>	
                                    </td>
                                    <td style="padding-left: 14px">
                                        <b> <?= $get[hsncode]; ?> </b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <!--                        </td>
                                                                <td style="text-align:right" width="10%">-->
                                        <label class="control-label">GST %</label>	
                                        <!--                        </td>
                                                                <td style="padding-left: 10px">-->
                                        <b>  <?= $get[gstperc]; ?></b>
                                    </td>
                                </tr>
                                <tr>		
                                    <td style="text-align:right">
                                        <label class="control-label">Material PCS per </label>	
                                    </td>
                                    <td style="padding-left: 14px">
                                        <?php
                                        if ($get["pcsper"] == "Y") {
                                            $pcsper = "YARD";
                                        } elseif ($get["pcsper"] == "M") {
                                            $pcsper = "METERS";
                                        }
                                        ?>
                                        <b><?= $pcsper; ?></b>
                                        <?php if ($get["pcsper"] == "Y") { ?>
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <?php } else { ?>
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                                        <?php } ?>
                                        <!--                        </td>
                                                                <td style="text-align:right" width="5%">-->
                                        <label class="control-label">PCS</label>	
                                        <!--                        </td>
                                                                <td style="padding-left: 10px">-->
                                        <b><?= $get[totpcs]; ?></b>

                                    </td>
                                </tr>
                                <tr>		
                                    <td style="text-align:right">
                                        <label class="control-label">Aster PCS per </label>	
                                    </td>
                                    <td style="padding-left: 14px">
                                        <?php
                                        if ($get["pcspera"] == "Y") {
                                            $pcspera = "YARD";
                                        } elseif ($get["pcspera"] == "M") {
                                            $pcspera = "METERS";
                                        }
                                        ?>
                                        <b><?= $pcspera; ?></b>
                                        <?php if ($get["pcspera"] == "Y") { ?>
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <?php } else { ?>
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                                        <?php } ?>
                                        <!--                        </td>
                                                                <td style="text-align:right" width="5%">-->
                                        <label class="control-label">PCS</label>	
                                        <!--                        </td>
                                                                <td style="padding-left: 10px">-->
                                        <b><?= $get[totpcsa]; ?></b>

                                    </td>
                                </tr>
                                <tr>		
                                    <td style="text-align:right">
                                        <label class="control-label">Cost </label>	
                                    </td>
                                    <td style="padding-left: 14px">
                                        <b><?= $get[cost]; ?></b>

                                    </td>
                                </tr>
                                <tr>		
                                    <td style="text-align:right">
                                        <label class="control-label">Rate </label>	
                                    </td>
                                    <td style="padding-left: 14px">
                                        <b><?= $get[rate]; ?></b>

                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td style="width:40%;">
                            <img id="preview" src="<?php Echo $imgpath; ?>" alt="your image" style="height: 200px;"/>
                        </td>
                    </tr>

                </table>
            </div>
            <div>
                <table  border="solid 1px" style="border-collapse: collapse; width:100%">
                    <tr class="mySearchTr">
                        <th style="width:5%; color:black;"><label>Sr.</label></th>
                        <th style="width:25%; color:black;"><label>Material</label></th>
                        <th style="width:10%; color:black; text-align: right;"><label>Qty.</label></th>
                        <th style="width:10%; color:black; text-align: right;"><label>Rate</label></th>
                        <th style="width:10%; color:black; text-align: right;"><label>Amount</label></th>
                    </tr>

                    <?php
                    $ctr = 0;
                    $ctab = 0;
                    $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `code`='$vouchno' order by srno")or die(mysqli_error($conn));

                    while ($showtran = mysqli_fetch_array($gettran)) {
                        $getitem = mysqli_query($conn, "SELECT `name`,`code`  From `rawmat` WHERE `code` = $showtran[material] ")or die(mysqli_error($conn));
                        $showitem = mysqli_fetch_array($getitem);


                        Echo"<tr>";
                        Echo"<td style=''>$showtran[srno]</td>";
                        Echo"<td style=''>$showitem[name]</td>";
                        Echo"<td style='text-align: right;'>$showtran[qty]</td>";
                        Echo"<td style=' text-align:right;'>$showtran[rate]</td>";
                        Echo"<td style=' text-align:right;'>$showtran[amount]</td>";
                        Echo"</tr>";

                        $ctr++;
                        $ctab = $ctab + 1;
                    }
                    ?>  

                    <tr style="">
                        <td colspan="4" style="text-align: right;border:none" > Total  </td>
                        <td style="text-align: right;border:none "> <? echo $get['totamt']; ?>  </td>
                    </tr>


                </table>
            </div>


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