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

$formname = 'Delivery Challan';
$maindb = 'purmain';
$trandb = 'purtran';
/*$accdb = 'actran';*/
$file = 'purchase.php';
$source = "PU";
/*$grid = 'salemain.php';*/

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

$mht = 'height:20px;';
                                            
$admin    = $_SESSION["admin_" . $dbname];
$vouchno  = $_REQUEST["vouchno"];
$mainqry  = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') AS vouchdt FROM `$maindb` WHERE vouchno='$vouchno'") or die(mysqli_error($conn));
$getmdata = mysqli_fetch_array($mainqry);

$godownqry  = mysqli_query($conn, "SELECT * FROM `godown` WHERE code='$getmdata[godown]'") or die(mysqli_error($conn));
$getgd = mysqli_fetch_array($godownqry);
?>

<!DOCTYPE HTML>
<html lang="en-US">

    
        <?php
        include("includes/files.php");
        include("includes/tabsuf.php");
        ?>
    </head>
    <style>
            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: 148mm;
        min-height: 200mm;
        padding: 2mm;
        margin: 4mm auto;
        border: 1px #D3D3D3 solid;
        border-radius: 3px;
        /*background: white;*/
        
    }
    .subpage {
        padding: 0cm;
/*        border: 1px solid;*/
        height: 2mm;
        outline: 2cm #ffffff solid;
    }
    
    @page {
        size: A5;
        margin: 0;
    }
    @media print {
        html, body {
            width: 210mm;
            height: 290mm;        
        }
        .page {
            margin: 0;
            border: initial;
            border-radius: initial;
            width: initial;
            min-height: initial;
            box-shadow: initial;
            background: initial;
            page-break-after: always;
        }
    }
    .border{
        border: 1px solid;
    }
    </style>

    <body id="main_container">
        <div class="book">
            <div class="page">
                <!--<div class="subpage">-->
                    <!--   ************Header************  -->
                    <div style="border:solid 1px;" class="col-md-12" >
                        <?php
                        require("includes/dbconnect.php");
                        $comp = mysqli_query($conn, "SELECT * FROM `company`") or die(mysqli_error($conn));
                        $zcomp = mysqli_fetch_assoc($comp);
                        ?>
                        <b><center><?php echo $zcomp['compname']; ?></center></b>
                        <h5><center><?php echo $formname; ?></center></h5>
                        
                    </div>
                    <div style="border:solid 1px;" class="col-md-12" style="padding-left: 1px ; padding-right: 1px">
                        <?php
                        mysqli_select_db($conn, $zdb);

                        $gcust = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`='$getmdata[accode]'") or die(mysqli_error($conn));
                        $cust = mysqli_fetch_array($gcust);
                        ?>
                        <table width="100%">
                            <tr>
                                
                                <td style="text-align: left;">
                                    <b>M/s.</b><font size="3px" weight="bold"><?php echo "$cust[name]"; ?></font></td>
                                <td style="text-align: center;">
                                    <b>Voucher :</b>
                                    <?php echo "$getmdata[vouchno]"; ?> 
                                </td>
                            </tr>
                            <tr>
                                <td style="text-align: left;"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><?php echo "$cust[add1]"; ?></td>
                                <td style="padding-left: 74px;text-align: center;">
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b style="text-align:right;">Date :</b>
                                    <?php echo "$getmdata[vouchdt]"; ?> 
                                </td>
                            </tr>
                            <tr>
                                <td style="text-align: left;"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><?php echo "$cust[mobile]"; ?></td>
                                <td style="text-align: center">
                                    &nbsp;&nbsp;&nbsp;<b style="text-align:right;">Godown :</b>
                                    <?php echo "$getgd[gdcode]"; ?> 
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div style="border:1px solid black;">
                        <table width="100%">
                            <tr>
                                <th width="5%" class="border" style="height:33px; text-align: center;"><font size="2px">Sr</font></th>
<!--                                <th width="10%" class="border" style="height:33px; text-align: center;"><font size="2px">Barcode</font></th>-->
                                <th width="25%" class="border" style="height:33px; text-align: center;"><font size="2px">Item</font></th>
                                <th width="8%" class="border" style="height:33px; text-align: center;"><font size="2px">Qty.</font></th>
                                <th width="9%" class="border" style="height:33px; text-align: center;"><font size="2px">Rate</font></th>
                                <th width="9%" class="border" style="height:33px; text-align: center;"><font size="2px">Amount</font></th>
<!--                                <th width="6%" class="border" style="height:33px; text-align: center;"><font size="2px">Disc%</font></th>
                                <th width="9%" class="border" style="height:33px; text-align: center;"><font size="2px">Discount</font></th>
                                <th width="6%" class="border" style="height:33px; text-align: center;"><font size="2px">VAT%</font></th>
                                <th width="9%" class="border" style="height:33px; text-align: center;"><font size="2px">VAT</font></th>
                                <th width="9%" class="border" style="height:33px; text-align: center;"><font size="2px">Total</font></th>
                                <th width="9%" class="border" style="height:33px; text-align: center;"><font size="2px">MRP</font></th>-->
                            </tr>

                            <?php
                            $tranpart = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`=$getmdata[vouchno] order by srno") or die(mysqli_error($conn));
                            $mht='20px';
                            $ctab = 0;
                            $grqty = 0;
                            while ($row = mysqli_fetch_array($tranpart)) {
                                $getitem = mysqli_query($conn, "SELECT * FROM `item` WHERE `code`=$row[itemcode]") or die(mysqli_error($conn));
                                $gtit = mysqli_fetch_array($getitem);
                                ?>
                                <tr class="" style="height: 25px;">
                                    <td class="border" style="text-align: center;"><b><?php echo "$row[srno]"; ?></b></td>
<!--                                    <td class="border" ><?php echo "$row[barcode]"; ?></td>-->
                                    <td class="border"><b><?php echo "$gtit[name]"; ?></b></td>
                                    <td class="border" style="text-align: right;"><b><?php echo "$row[qty]"; ?></b></td>
                                    <td class="border" style="text-align: right"><b><?php echo "$row[rate]"; ?></b></td>
                                    <td class="border" style="text-align: right"><b><?php echo "$row[amt]"; ?></b></td>
<!--                                    <td class="border" style="text-align: right"><?php echo "$row[discperc]"; ?></td>
                                    <td class="border" style="text-align: right"><?php echo "$row[discamt]"; ?></td>
                                    <td class="border" style="text-align: right"><?php echo "$row[totamt]"; ?></td>
                                    <td class="border" style="text-align: right"><?php echo "$row[mrp]"; ?></td>-->
                                </tr>
                                <?
                                $ctab = $ctab + 1;
                                $grqty = $grqty + $row['qty'];

                            }
                            if ($ctab < 15) {
                                for ($i = $ctab; $i <= 25; $i++) {
                                    $ctab = $ctab + 1;
                                    ?>
                                    <tr style="height: 25px;">
<!--                                        <td class="border"></td>
                                        <td class="border"></td>
                                        <td class="border"></td>
                                        <td class="border"></td>
                                        <td class="border"></td>
                                        <td class="border"></td>
                                        <td class="border"></td>-->
                                        <td class="border"></td>
                                        <td class="border"></td>
                                        <td class="border"></td>
                                        <td class="border"></td>
                                        <td class="border"></td>
                                    </tr>      
                                    <?php
                                }
                            }
                            ?>  
                        </table>
                        <table class="" style="" width="">
                            <tr>
                                <td class="" style="text-align: center; width: 472px;">Total</td>
                                <td class="" style="text-align: left; width: 151px"><span style="font-weight: 600"><?= $grqty ?></span></td>
                                <td class="" style="text-align: right; width: 136px"><span style=" "><? echo "Rs. $getmdata[subtotal]"; ?></span></td>
                            </tr>
<!--                            <tr>
                                <td class="" style="text-align: left; width: 471px;"><span style="font-weight: 600"><?  ?></span></td>
                                <td class="" style="text-align: right; width: 150px"><span style="font-weight: 600"><? echo "Less Discount"; ?></span></td>
                                <td class="" style="text-align: right; width: 136px"><span style=" font-weight: "><? echo "Rs. $getmdata[discount]"; ?></span></td>
                            </tr>
                            <tr>
                                <td class="" style="text-align: left; width: 471px;"><span style="font-weight: 100"><? echo "$getmdata[rem1]";  ?></span></td>
                                <td class="" style="text-align: right; width: 150px"><span style="font-weight: 600"><? echo "Add VAT"; ?></span></td>
                                <td class="" style="text-align: right; width: 136px"><span style=" font-weight: "><? echo "Rs. $getmdata[vat]"; ?></span></td>
                            </tr>
                            <tr>
                                <td class="" style="text-align: left; width: 471px;"><span style="font-weight: 100"><? echo "$getmdata[rem2]"; ?></span></td>
                                <td class="" style="text-align: right; width: 150px"><span style="font-weight: 600">Total</span></td>
                                <td class="" style="text-align: right; width: 136px"><span style=" font-weight: 00"><? echo "Rs. $getmdata[billamt]"; ?></span></td>
                            </tr>-->
                            <tr style="">
                                <td>
                                    <b>(<?php echo rsword(round($getmdata["billamt"])) . ' Rupees' ; ?>)</b>
                                </td>
                                <td></td>
                                <td></td>
                            </tr>
                        </table>
                    </div>
                    
                    <div style="border:1px solid black;">
                        <table class="">
                            <tr>
                                <td class="border" style="width: 541px; font-size: 14px;">
                                    
                                </td>
                                <td class="" style="width: 216px">
                                    <div style=" font-size: 14px; font-weight: 900"><? echo "For $zcomp[compname]"; ?></div>
                                    <br>
                                    <br>
                                    <div style=" margin-left: 51px; font-size: 14px">AUTHORISED SIGNATORY</div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>    
            <!--</div>-->
        </div>
        <?php
        include("includes/files_footer.php");
        ?>
        <script>
            $(function() {
                formGeneral();
            });
        </script>
    </body>
</html>
