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

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);
$maindb = 'dispmain';
$trandb = 'disptran';
$formname = 'Delivery Challan Print';
$zroot = $_SESSION["zdir"];
$vouchno = $_GET['vouchno'];
$root = $_SESSION["zdbroot"];
$zzroot = "apps4rea_khoj_root";


##############################Print Start Here##################################
$getcomp2 = mysqli_query($conn, "SELECT * FROM $zzroot.`company`")or die(mysqli_error($conn));
$comp2 = mysqli_fetch_array($getcomp2);


$qmain = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as mydt FROM $maindb  WHERE vouchno='$vouchno' order by vouchno") or die(mysqli_error($conn));
$fmain = mysqli_fetch_array($qmain);

$gtransp = mysqli_query($conn, "SELECT * FROM `transport` WHERE `code`='$fmain[transmode]'")or die(mysqli_error($conn));
$transport = mysqli_fetch_array($gtransp);

$ggodwn = mysqli_query($conn, "SELECT * FROM `godown` WHERE `code`='$fmain[tgodwn]'")or die(mysqli_error($conn));
$godwn = mysqli_fetch_array($ggodwn);

include("includes/linkshead.php");
?>
<link href="MyStyle/rep_format.css" rel="stylesheet">
<style>

    body{
        font-size: 15px;

    }
    .fsize{
        font-size:15px;
    }

    td,th{
        padding:0px;
        font-size:15px;
    }

    .padd{
        padding:5px;
    }
    .border{
        border:1px solid black;
    }

    table{
        width:100%;
        /*border : 1px solid black;*/
    }
</style>
</head>
<body>    
    <div class="page">
        <div class="col-lg-11"></div>
        <div class="col-lg-1">
            <a  class="btn btn-primary goback"  onclick="window.close()">Go Back</a>
        </div>

        <div class="subpage" style="margin-top:5px;width:100%;">

            <table style="width:100%;height: 7%;  border: 1px solid black;border-bottom:  0;">
                <tr>
                    <td style="width:25%">
                        <table style="width:100%">
                            <tr>
                                <td><img src="images/logo/KH150.jpg" style="width: 120px;height: 80px"></td> 
                            </tr>
                        </table>
                    </td>
                    <td style="width:50%">
                        <table style="width:100%">
                            <tr>
                                <td class="uppercase" style="text-align: center;width: 100%;font-size: 35px;font-family: 'Times New Roman';">
                                    <b><? Echo $comp2['compname'] ?></b></td> 
                            </tr>
                        </table> 
                    </td>
                    <td style="width:25%">
                        <table style="width:100%">
                            <tr>
                                <td style="text-align: right"><img src="images/logo/khlogo.jpg" style="width: 120px;height: 80px"></td> 
                            </tr>
                        </table> 
                    </td>
                </tr>
            </table>
            <table style="width:100%;border: 1px solid black;border-top:  0;">
                <tr>
                    <td class="text-left"><b>Factory :</b>
                        <?php echo $comp2['fadd1'] . ' ' . $comp2['fadd2'] . ' ' . $comp2['fadd3']; ?>   
                    </td>
                </tr>
                <tr><td class="text-left"><b>Head Office :</b>
                        <?php echo $comp2['hoadd1'] . ' ' . $comp2['hoadd2'] . ' ' . $comp2['hoadd3'] . ' ' . $comp2['hocity'] . '-' . $comp2['hopin']; ?>   
                    </td>
                </tr>
                <tr>
                    <td class="text-left"><b>Sales :</b>
                        <?php echo $comp2['sadd1']; ?>   
                    </td>
                </tr>
                <tr>
                    <td class="text-left"><b>Telephone No. :</b>
                        <?php echo $comp2['sadd2'] . ' ' . $comp2['sadd3']; ?>   
                    </td>
                </tr>

<!--                <tr>
    <td style="font-size: 12px;" class="text-center"><span style="padding-left:50px"></span><b>
            GST NO :&nbsp;
                <?php echo $comp2['gstno'] ?>   
        </b>
    </td>
</tr>-->
                <tr>
                    <td>&nbsp;</td>
                </tr>


            </table>
            <!--            <div class="row">
            <?php
            $comp = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_error($conn));
            $zcomp = mysqli_fetch_assoc($comp);
            ?>
                            <h3><b><center><?php echo $zcomp[compname]; ?></center></b></h3>
                            <b><center><?php echo $zcomp[hoadd1] . " " . $zcomp[hoadd2]; ?></center></b>
                            <b><center><?php echo $zcomp[hoadd3]; ?></center></b>
                        </div>-->

            <table style="border:2px solid black">
                <tr ><td style="font-size:17px" class="padd text-center"><b>GOODS TRANSFER FACTORY TO HEAD OFFICE ONLY</b></td></tr>
            </table>
            <table style="border:2px solid black">
                <tr>
                    <td width="40%">
                        <table class="">
                            <tr>
                                <td class="padd" width="10%">GST NO.</td>
                                <td class="padd" width="40%">27AAEFK0652J1ZD</td>
                            </tr>
                            <tr>
                                <td class="padd">TO</td>
                                <td class="padd">M/s Khojati Herbal 176/186, Hanifa Mansion, Erksin Road, Opp.Null Bazar Police Chowky,Mumbai-400003</td>
                            </tr>
                            <tr>
                                <td class="padd">Gst No: </td>
                                <td class="padd">&nbsp;</td>
                            </tr>
                            <tr>
                                <td class="padd">&nbsp;</td>
                                <td class="padd">&nbsp;</td>
                            </tr>
                            <tr>
                                <td class="padd">&nbsp;</td>
                                <td class="padd">&nbsp;</td>
                            </tr>
                        </table>
                    </td> 
                    <td width="20%">
                        <table>
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                        </table>
                    </td>
                    <td width="60%">
                        <table class="">
                            <tr>
                                <td width="6%" class="padd">Invoice No.</td>
                                <td width="44%">DC/GST/<?php echo $zcomp[init] . "/" . $myyear . "/" . $vouchno; ?></td>
                            </tr>
                            <tr>
                                <td class="padd">DATE</td>
                                <td class="padd"><?php echo $fmain[vouchdt] ?></td>
                            </tr>
                            <tr>
                                <td class="padd">Transportation</td>
                                <td class="padd"><?php echo $transport[name] ?></td>
                            </tr>
                            <tr>
                                <td class="padd">Veh. No.</td>
                                <td class="padd"><?php echo $fmain[vehicle]; ?></td>
                            </tr>
                            <tr>
                                <td class="padd">Place of Supply</td>
                                <td class="padd"><?php echo $fmain[plsply] ?></td>
                            </tr>
                            <tr>
                                <td class="padd"></td>
                                <td class="padd">&nbsp;</td>
                            </tr>
                        </table>
                    </td> 
                </tr>
            </table>
            <table style="border:1px solid black">
                <tr><td>&nbsp;</td></tr>
            </table>
            <table style="border:1px solid black">
                <tr>
                    <td></td>
                </tr>
            </table>

            <table class="border">

                <tr>
                    <td style="width:5%" class="border padd"><b>Sr.No</b></td>
                    <td style="width:10%;" class="border padd text-center"><b>Pro. Code</b></td>
                    <td style="width:20%;" class="border padd text-center"><b>Descripion</b></td>
                    <td style="width:10%;" class="border padd text-center"><b>Hsncode</b></td>
                    <td style="width:10%;" class="border padd text-center"><b>B.No</b></td>
                    <td style="width:10%;" class="border padd text-center"><b>Net.Wt</b></td>
                    <td style="width:7%;" class="border padd text-right"><b>MRP</b></td>
                    <td style="width:7%;" class="border padd text-right"><b>Qty</b></td>
                    <td style="width:10%;" class="border padd text-right"><b>Rate</b></td>
                    <td style="width:10%;" class="border padd text-right"><b>Net Amt</b></td>
                    <td style="width:10%;" class="border padd text-center"><b>Gst%</b></td>
                    <td style="width:10%;" class="border padd text-center"><b>Gst Amt</b></td>
                    <td style="width:10%;" class="border padd text-center"><b>Gross Amt</b></td>
                </tr>

                <?php
                $ctr = 0;
                $ctab = 0;
                $gross = 0;
                $gstam = 0;
                $net = 0;
                $gtran = mysqli_query($conn, "SELECT * FROM $trandb where `vouchno` = '$fmain[vouchno]'") or die(mysqli_error($conn));
                while ($tran = mysqli_fetch_array($gtran)) {
                    $ctr++;
                    echo "<tr>";
                    echo "<td class='border padd text-center'>$ctr</td>";
                    echo "<td class='border padd text-center'>$tran[prodcode]</td>";
                    echo "<td class='border padd text-center'>$tran[descrip]</td>";
                    echo "<td class='border padd text-center'>$tran[hsncode]</td>";
                    echo "<td class='border padd text-center'>$tran[batchno]</td>";
                    echo "<td class='border padd text-right'>$tran[netwt]</td>";
                    echo "<td class='border padd text-center'>$tran[mrp]</td>";
                    echo "<td class='border padd text-right'>$tran[qty]</td>";
                    echo "<td class='border padd text-right'>$tran[rate]</td>";
                    echo "<td class='border padd text-right'>$tran[netamt]</td>";
                    echo "<td class='border padd text-right'>$tran[gstperc]</td>";
                    echo "<td class='border padd text-right'>$tran[gstamt]</td>";
                    echo "<td class='border padd text-right'>$tran[grossamt]</td>";
                    echo "</tr>";
                    $ctab = $ctab + 1;
                    $gross = $gross + $tran[grossamt];
                    $gstam = $gstam + $tran[gstamt];
                    $net = $net + $tran[netamt];
                }

                if ($ctab < 13) {
                    for ($i = $ctab; $i <= 13; $i++) {
                        $ctab = $ctab + 1;
                        ?>
                        <tr>
                            <td class="border padd">&nbsp;</td>
                            <td class="border padd">&nbsp;</td>
                            <td class="border padd">&nbsp;</td>
                            <td class="border padd">&nbsp;</td>
                            <td class="border padd">&nbsp;</td>
                            <td class="border padd">&nbsp;</td>
                            <td class="border padd">&nbsp;</td>
                            <td class="border padd">&nbsp;</td>
                            <td class="border padd">&nbsp;</td>
                            <td class="border padd">&nbsp;</td>
                            <td class="border padd">&nbsp;</td>
                            <td class="border padd">&nbsp;</td>
                            <td class="border padd">&nbsp;</td>
                        </tr>

                        <?php
                    }
                }
                ?>
                <tr>
                    <td class="border padd">&nbsp;</td>
                    <td class="border padd">&nbsp;</td>
                    <td class="border padd">&nbsp;</td>
                    <td class="border padd">&nbsp;</td>
                    <td class="border padd">&nbsp;</td>
                    <td class="border padd">&nbsp;</td>
                    <td class="border padd">&nbsp;</td>
                    <td class="border padd">&nbsp;</td>
                    <td class="border padd">Gross Total</td>
                    <td class="border padd"><?php echo $net; ?></td>
                    <td class="border padd">&nbsp;</td>
                    <td class="border padd"><?php echo $gstam; ?></td>
                    <td class="border padd"><?php echo $gross; ?></td>
                </tr>
            </table>
            <br>
            <table>
                <tr>
                    <td width="60%">
                        <table>
                            <tr><td class="padd" style="font-size: 14px;"><b>Receiver's Signature</b></td></tr>
                            <tr><td class="padd" style="font-size: 14px;">E.& O. E.</td></tr>
                            <tr><td class="padd"><label style="font-size:12px">
                                        " I / We hereby certify that  my / our registration  certificate  under    
                                        Rule 1 of GST invoice rules 2017  is in force  on  the  date on which 
                                        the sale of the goods specified in this tax invoice is made by me/us  and 
                                        that the transaction of sale covered  by  this  tax invoice has been 
                                        affected by me/us and its shall be accounted for in the turnover of sales 
                                        while filling of return and the due tax, if any, payable on the sale has 
                                        been paid or shall be paid. "
                                    </label></td></tr>

                        </table>
                    </td>
                    <td width="40%">
                        <table>
                            <tr><td class="padd text-right"><h5><b>For KHOJATI HERBAL</b></h5></td></tr>
                            <tr><td class="padd text-right"><h5>&nbsp;</h5></td></tr>
                            <tr><td class="padd text-right"><h5><b>Authorized Signatory</b></h5></td></tr>
                            <tr><td class="padd">&nbsp;</td></tr>
                            <tr><td class="padd">&nbsp;</td></tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
    </div>