<?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);
$zyear = $myyear;

$vouch = $_GET['vouchno'];

$cond = '';
$lcond = '';
$formname = "Tax Invoice";

$maindb = 'gstmain';
$trandb = 'gsttran';

$getqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as mydt, DATE_FORMAT(`chaldate`, '%d-%m-%Y')as chaldt   FROM `$maindb` WHERE vouchno='$vouch' ORDER BY `vouchno`") or die(mysqli_error($conn));
$getdata = mysqli_fetch_array($getqry);


$cmpname = mysqli_query($conn, "SELECT * From $zroot.`company` where `code`='$zcomp'") or die(mysqli_error($conn));
$getcmpname = mysqli_fetch_array($cmpname);

$getparty = mysqli_query($conn, "SELECT * From accmast WHERE `accode` = '$getdata[party]'") or die(mysqli_error($conn));
$showparty = mysqli_fetch_array($getparty);
//browse($showparty['city']);

$getsalesm = mysqli_query($conn, "SELECT `accode`,`name` From accmast WHERE `accode` = '$getdata[salesman]'") or die(mysqli_error($conn));
$showsalesm = mysqli_fetch_array($getsalesm);

$terms = "1. Subject to Mumbai Jurisdiction Only.
2. Any Complaints or claims regarding the material should be notified within 72 hrs or else the claim will not be entertained.
3. Goods once sold will not be taken back.
4. Weight tolerance of +/- 0.50% variation shall be considered as acceptable.
5. Our responsibility ceases once goods leaves our premises.
6. Delayed payment after due date will attract interest @ 30 % p.a .";

$oms = $getdata['oms'];
?>

<!DOCTYPE HTML>
<html lang="en-US">
<style>
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        font: 10pt "Verdana";
    }

    @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;
    }

    .subpage {
        padding: 0cm;
        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>

<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">
            <!--   ************Header************  -->
            <div style="border:solid 1px;" class="col-md-12">
                <center>
                    <p style="margin-top:2px;margin-bottom: 2px;font-size:11px; "><u>Subject To Navi Mumbai Jurisdiction</u></p>
                </center>
                <?php include("includes/head_print.php"); ?>
            </div>

            <div style="border:solid 1px;border-collapse: collapse" class="col-md-12">

                <table class="table table-border table-hover" style="width:100%">
                    <tr>
                        <td style="text-align: left; width:50%;"><b>UDYAM REGISTRATION NUMBER</b></td>
                        <td style="text-align: right; width:30%;" colspan="2"><b>UDYAM-MH-18-0251651</b></td>
                    </tr>
                    <tr>
                        <td style="text-align: left; width:50%;"><b>M/s. <?= $showparty['name']; ?></b></td>
                        <td style="text-align: left; width:30%;"><b>Invoice No. <?= $getdata['invno']; ?></b></td>
                        <td style="text-align: left; width:20%;"><b>Date : <?= $getdata['mydt']; ?></b></td>
                    </tr>
                    <tr>
                        <td style="text-align: left; width:50%;font-size: 11px"><?= $showparty['add1']; ?></td>
                        <td style="text-align: left; width:30%;"><b>Challan No. <?= $getdata['chalno']; ?></b></td>
                        <td style="text-align: left; width:20%;"><b>Date : <?= $getdata['chaldt']; ?></b></td>
                    </tr>
                    <tr>
                        <td style="text-align: left; width:50%;font-size: 11px"><?= $showparty['add2']; ?></td>
                        <td style="text-align: left; width:30%;font-size: 11px" colspan="2"><b>Delivery Address </b><?= $getdata['siteadd1']; ?></td>
                    </tr>
                    <tr>
                        <td style="text-align: left; width:50%;font-size: 11px"><?= $showparty['city'] . " - " . $showparty['pin']; ?></td>
                        <td style="text-align: left; width:30%;font-size: 11px" colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;<?= $getdata['siteadd2']; ?></td>
                    </tr>
                    <tr>
                        <td style="text-align: left; width:50%;font-size: 13px">Mobile : <b><?= $showparty['mobile']; ?></b></td>
                        <td style="text-align: left; width:30%;font-size: 11px" colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;<?= $getdata['siteadd2']; ?></td>
                    </tr>
                    <tr>
                        <td style="text-align: left; width:50%;font-size: 11px">GST TIN &nbsp;&nbsp;<?= $showparty['gstno']; ?></td>
                        <td style="text-align: left; width:30%;font-size: 11px" colspan="2"></td>
                    </tr>
                </table>
            </div>

            <div>
                <table border="solid 1px" style="border-collapse: collapse; width:100%">
                    <tr>
                        <th style="width:3%; color:black;text-align:center;"><label>Sr.</label></th>
                        <th style="width:50%; color:black;"><label>Description</label></th>
                        <th style="width:12%; color:black;"><label>Hsn Code</label></th>
                        <th style="width:7%; color:black;text-align: right;"><label>Pcs.</label></th>
                        <th style="width:8%; color:black; text-align: right;"><label>Weight</label></th>
                        <th style="width:8%; color:black; text-align: right;"><label>Rate</label></th>
                        <th style="width:7%; color:black; text-align: left;"><label>Unit</label></th>
                        <th style="width:9%; color:black; text-align: right;"><label>Amount</label></th>

                    </tr>

                    <?php
                    $ctr = 0;
                    $ctab = 0;
                    $totqty = 0;
                    $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$vouch' order by srno") or die(mysqli_error($conn));
                    while ($showtran = mysqli_fetch_array($gettran)) {
                        $getitem = mysqli_query($conn, "SELECT `name`,`code`  From `item` WHERE `code` = $showtran[item] ") or die(mysqli_error($conn));
                        $showitem = mysqli_fetch_array($getitem);




                        echo "<tr style='height:24px'>";
                        echo "<td style='text-align:center;'>$showtran[srno]</td>";
                        echo "<td style=''>$showitem[name]</td>";
                        //                        Echo"<td style=''>$showcolor[name]</td>";
                        echo "<td style='text-align: center;'>$showtran[hsncode]</td>";
                        echo "<td style='text-align: right;'>$showtran[pcs]</td>";
                        echo "<td style='text-align: right;'>$showtran[qty]</td>";
                        echo "<td style=' text-align:right;'>$showtran[rate]</td>";
                        echo "<td style=''>$showtran[unit]</td>";
                        echo "<td style=' text-align:right;'>$showtran[amount]</td>";

                        $totqty = $totqty + $showtran['qty'];
                        $totpcs += $showtran['pcs'];


                        echo "</tr>";

                        $ctr++;
                        $ctab = $ctab + 1;
                    }
                    if ($ctab < 15) {
                        for ($i = $ctab; $i <= 15; $i++) {
                            $ctab = $ctab + 1;
                    ?>
                            <tr style="height:24px;">
                                <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
                        }
                    }
                    
                    // if ($totpcs > 0) {
                        ?>
                        <tr>
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border" style="text-align: right;"><b><?= $totpcs; ?></b></td>
                                <td class="border" style="text-align: right;"><b><?= $totqty; ?></b></td>
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border" style="text-align: right;"><b><?= $getdata['subtotal']; ?></b></td>
                            <!-- <td colspan="6" style="text-align: right;">Total Pcs</td>
                            <td colspan="6" style="text-align: right;border-left: none;"> </td> -->
                        </tr>
                  
                    <tr>
                        <td colspan="5" style="border:none"><? echo "$getdata[remark1]" . " &nbsp;" . "$getdata[remark2]"; ?></td>
                        
                    </tr>

                    <?php
                    if ($getdata['litemdisc'] > 0) {
                    ?>
                        <tr>

                            <td colspan="6" style="text-align: right; " class="lnone rnone"> Less Item Discount </td>
                            <td style="text-align: right; " class="lnone rnone"> </td>
                            <!--<td class="lnone rnone"></td>-->
                            <td style="text-align: right; " class="lnone "> <? echo $getdata['litemdisc']; ?> </td>
                        </tr>
                    <?php
                    }
                    if ($getdata['cdiscamt'] > 0) {
                    ?>
                        <tr>
                            <td colspan="5" style="text-align: right;" class=" rnone"> Less Cash Discount </td>
                            <td style="text-align: right;" class="lnone rnone"> <? echo $getdata['cdiscperc']; ?> </td>
                            <td class="lnone rnone">%</td>
                            <td style="text-align: right; " class="lnone "> <? echo $getdata['cdiscamt']; ?> </td>
                        </tr>
                    <?php
                    }

                    if ($getdata['taxdisc'] > 0) {
                    ?>
                        <tr>
                            <td colspan="5" style="text-align: right;" class="rnone"> Less Discount </td>
                            <td style="text-align: right; " class="lnone rnone"> </td>
                            <td class="lnone rnone"></td>
                            <td style="text-align: right;" class="lnone "> <? echo $getdata['taxdisc']; ?> </td>
                        </tr>
                    <?php
                    }
                    if ($getdata['lesother'] > 0) {
                    ?>
                        <tr>
                            <td colspan="5" style="text-align: right;" class="rnone"> Less Other</td>
                            <td style="text-align: right; " class="lnone rnone"> </td>
                            <td class="lnone rnone"></td>
                            <td style="text-align: right;" class="lnone "> <? echo $getdata['lesother']; ?> </td>
                        </tr>
                    <?php
                    }
                    if ($getdata['couamt'] > 0) {
                    ?>
                        <tr>
                            <td colspan="5" style="text-align: right; " class=" rnone">Add Courier <? echo $getdata['coukg']; ?> /Kg.</td>
                            <td style="text-align: right; " class="lnone rnone"><? echo $getdata['courate']; ?></td>
                            <td style="text-align: center;" class="lnone rnone ">Rate</td>
                            <td style="text-align: right; " class="lnone "><? echo $getdata['couamt']; ?></td>
                        </tr>
                    <?php
                    }
                    if ($getdata['tottaxamt'] > 0) {
                    ?>
                        <tr>
                            <td colspan="3">PAN NO : <?= $getcmpname['pan'] ?></td>
                            <td colspan="3" style="text-align: right;"> Taxable Value </td>
                            <td colspan="2" style="text-align: right;" class="lnone "> <? echo $getdata['tottaxamt']; ?> </td>
                        </tr>
                    <?php
                    }
                    if ($getdata['tottaxamt'] > 0) {
                    ?>
                        <tr>
                            <td colspan="3">GST No:<?php echo $getcmpname['gst']; ?></td>
                            <td colspan="3" style="text-align: right;"> Loading & Unloading </td>
                            <td colspan="2" style="text-align: right;" class="lnone "> <? echo $getdata['loading']; ?> </td>
                        </tr>
                    <?php
                    }
                    ?>
                    <tr>
                        <td colspan="3">
                            <table border="solid 1px" style="border-collapse: collapse; width:100%">
                                <tbody style="border-collapse: collapse;">

                                    <tr>

                                        <td style="width:25%;">Bank Name</td>
                                        <td style="width:75%;"><?= $getcmpname['bankname'] ?></td>
                                    </tr>

                                    <tr>

                                        <td style="width:25%;">A/c. Name</td>
                                        <td style="width:75%;"><?= $getcmpname['acname'] ?></td>
                                    </tr>
                                    <tr>

                                        <td style="width:25%;">Branch</td>
                                        <td style="width:75%;"><?= $getcmpname['branchname'] ?></td>
                                    </tr>
                                    <tr>

                                        <td style="width:25%;">Account No.</td>
                                        <td style="width:75%;"><?= $getcmpname['acno'] ?></td>
                                    </tr>
                                    <tr>

                                        <td style="width:25%;">IFSC Code</td>
                                        <td style="width:75%;"><?= $getcmpname['bankcode'] ?></td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                        <td colspan="5" style="border:none;border-collapse: collapse; ">
                            <table border="solid 1px" style="border-collapse: collapse; width:100%;font-size:11px;">
                                <tbody style="border-collapse: collapse;">

                                    <?php
                                    if ($getdata['totgst1'] > 0) {
                                        echo "<tr style='height: 21px;border:none'>";
                                        echo "<td class='text-right' style='text-align: right;' colspan='2'><b>CGST</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'>0.05 %</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[cgst1]</td>";
                                        echo "</tr>";
                                        echo "<tr style='height: 21px;border:none'>";
                                        echo "<td class='text-right' style='text-align: right;' colspan='2'><b>SGST</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'>0.05 %</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[sgst1]</td>";
                                        echo "</tr>";
                                        echo "<tr style='height: 21px;border:none'>";
                                        echo "<td class='text-right' style='text-align: right;' colspan='2'><b>IGST</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'>0.1 %</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[igst1]</td>";
                                        echo "</tr>";
                                        echo "<tr style='height: 21px;border:none'>";
                                        echo "<td class='text-right' style='text-align: right;' colspan='2'><b>Total GST</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'></td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[totgst1]</td>";
                                        echo "</tr>";
                                    } else {
                                    ?>
                                        <tr>
                                            <td style="width:32px;text-align: right">%</td>
                                            <td style="width:89px;text-align: right">CGST</td>
                                            <td style="width:89px;text-align: right">SGST</td>
                                            <td style="width:89px;text-align: right">IGST</td>
                                            <td style="width:99px;">&nbsp;</td>
                                        </tr>
                                    <?php
                                        if ($getdata['totgst5'] > 0) {
                                        
                                        echo "<tr style='height: 21px'>";
                                        echo "<td class='text-right' style='text-align: right;'><b>5%</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[cgst5]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[sgst5]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[igst5]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[totgst5]</td>";
                                        echo "</tr>";
                                    }else {
                                            echo "<tr style='height: 21px'>";
                                            echo "<td class='text-right' style='text-align: right;'><b>5%</b></td>";
                                            echo "<td class='text-right' style='text-align: right;'></td>";
                                            echo "<td class='text-right' style='text-align: right;'></td>";
                                            echo "<td class='text-right' style='text-align: right;'></td>";
                                            echo "<td class='text-right' style='text-align: right;'></td>";
                                            echo "</tr>";
                                        }       
                                        
                                        
                                        if ($getdata['totgst12'] > 0) {

                                        echo "<tr style='height: 21px'>";
                                        echo "<td class='text-right' style='text-align: right;'><b>12%</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[cgst12]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[sgst12]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[igst12]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[totgst12]</td>";
                                        echo "</tr>";
                                    }else {
                                            echo "<tr style='height: 21px'>";
                                            echo "<td class='text-right' style='text-align: right;'><b>12%</b></td>";
                                            echo "<td class='text-right' style='text-align: right;'></td>";
                                            echo "<td class='text-right' style='text-align: right;'></td>";
                                            echo "<td class='text-right' style='text-align: right;'></td>";
                                            echo "<td class='text-right' style='text-align: right;'></td>";
                                            echo "</tr>";
                                            
                                        }

                                        
                                        echo "<tr style='height: 21px'>";
                                        echo "<td class='text-right' style='text-align: right;'><b>18%</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[cgst18]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[sgst18]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[igst18]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[totgst18]</td>";
                                        echo "</tr>";


                                        if ($getdata['totgst28'] > 0) {

                                        echo "<tr style='height: 21px'>";
                                        echo "<td class='text-right' style='text-align: right;'><b>28%</b></td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[cgst28]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[sgst28]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[igst28]</td>";
                                        echo "<td class='text-right' style='text-align: right;'>$getdata[totgst28]</td>";
                                        echo "</tr>";
                                        }else {
                                            echo "<tr style='height: 21px'>";
                                            echo "<td class='text-right' style='text-align: right;'><b>28%</b></td>";
                                            echo "<td class='text-right' style='text-align: right;'></td>";
                                            echo "<td class='text-right' style='text-align: right;'></td>";
                                            echo "<td class='text-right' style='text-align: right;'></td>";
                                            echo "<td class='text-right' style='text-align: right;'></td>";
                                            echo "</tr>";
                                        }
                                    }
                                    ?>
                                </tbody>
                            </table>
                        </td>
                    </tr>





                    <?php
                    if ($getdata['netamt'] > 0) {
                    ?>
                        <tr>
                            <td colspan="3" style="text-align:  " class=" rnone"></td>
                            <td colspan="3" style="text-align: right; " class=" rnone"><b>Total Amount</b></td>
                            <td style="text-align: right; " class="lnone rnone"><b></b></td>
                            <td style="text-align: right; " class="lnone "><b><? echo $getdata['netamt']; ?></b></td>
                        </tr>
                    <?php
                    }
                    ?>
                    <tr>
                        <td colspan="8">
                            Amount In Words:
                            <?php echo rsword(round($getdata['netamt'])); ?>
                        </td>
                    </tr>
                    <tr><td colspan="8">Terms and Condition :<?= $terms; ?></td></tr>
                </table>
            </div>

            <div>
                <table class="border">
                    <tr>
                        <td class="border" style="width: 501px; font-size: 14px;">
                            <!--                            <p style="font-size:10px"><b>Terms & Conditions:</b> Goods Return without previous consent
                                will not be accepted.No Liability accepted any breakage or shortage in transit which is entirely at
                                your risk.All claims to be settled to Mumbai. Interest at 18% per annum will be charged if payment is 
                                not made within 8 days.Our responsibility cases when good leave our godown<br><b>Subject to Mumbai Jurisdiction.</b>
                                <br>You are required to provide GSTIN No.ones & ledger accounts periodically for enabling statuary compliance payment will be
                                accepted by Payee's by Payee's a/c cheque only.
                            </p>  -->
                            <!--<img src="images/taximg.png">-->
                        </td>
                        <td class="border" style="width: 256px">
                            <?php
                            require("includes/dbconnect.php");
                            ?>
                            <div style=" text-align:right; font-size: 14px; font-weight: 900"><? echo "For $getcmpname[pname]"; ?></div>
                            <br>
                            <br>
                            <br>
                            <div style=" margin-left: 75px; font-size: 10px">AUTHORISED SIGNATORY</div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <!--</div>-->
    </div>
    <?php
    include("includes/linksfoot.php");
    ?>
    <script>
        $(function() {
            formGeneral();
        });
    </script>
</body>

</html>