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

$formname = 'Delivery Challan';
$maindb = 'gstmain';
$trandb = 'gsttran';

$file = 'salegst.php';
$source = "SL";

$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = "apps2ai_lominos_root";

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) or die(mysqli_error($conn));

if ($getmdata['billtype'] == 'RT') {
    $billtype = 'RTGS';
} elseif ($getmdata['billtype'] == 'CR') {
    $billtype = 'CREDIT';
} elseif ($getmdata['billtype'] == 'CH') {
    $billtype = 'CASH';
} elseif ($getmdata['billtype'] == 'NF') {
    $billtype = 'NEFT';
} elseif ($getmdata['billtype'] == 'CQ') {
    $billtype = 'CHEQUE';
}



$tranqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') AS vouchdt FROM `$trandb` WHERE vouchno='$vouchno'") or die(mysqli_error($conn));
//$gettdata = mysqli_fetch_array($tranqry);

$getparty = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`= '$getmdata[accode]' ") or die(mysqli_error($conn));
$party = mysqli_fetch_array($getparty);

$prtyname = $party['nameprin'];
if ($prtyname != '') {
    $pname = $party['nameprin'];
} else {
    $pname = $party['name'];
}

$gsttype = $getmdata['gsttype'];
$oms = $getmdata['oms'];

$getgstype = mysqli_query($conn, "SELECT * FROM `gsttype` WHERE `code`= '$gsttype'") or die(mysqli_error($conn));
$fetgst = mysqli_fetch_array($getgstype);
$per = $fetgst['per'];

$gstperci = '';
$gstperc = '';
if ($oms == 1) {
    $gstperci = round($per, 2);
} else {
    $gstperc = round($per / 2, 2);
}

if ($getmdata['discperc'] == 0) {
    $discperc = '';
} else {
    $discperc = round($getmdata['discperc'], 2);
}


$getcomp = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_error($conn));
$comp = mysqli_fetch_array($getcomp);

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

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


<?php
include("includes/files.php");
include("includes/tabsuf.php");
?>

</head>
<link href="css/rep_format.css" rel="stylesheet">
<style>
    body {
        font-size: 15px;

    }

    .right {
        text-align: right;
    }

    .left {
        text-align: left;
    }

    .center {
        text-align: center;
    }

    .fsize {
        font-size: 15px;
    }

    .fsize2 {
        font-size: 12px;
    }

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

    .padd {
        padding: 3px;
    }

    .padd2 {
        padding: 5px;
    }

    .border {
        border-top-style: solid;
        border-right-style: solid;
        border-left-style: solid;
        border-bottom-style: solid;
        border-width: 1px;
    }

    /*
    .border2{
        border-top-style:none;
        border-right-style:solid;
        border-left-style:solid;
        border-bottom-style:solid;
        border-width:1px;
    }*/
    .bankbd {
        border-bottom-style: solid;
        border-top-style: none;
        border-left-style: none;
        border-right-style: solid;
        border-width: 1px;
    }

    .bottom1 {
        border-bottom-style: solid;
        border-top-style: none;
        border-left-style: none;
        border-right-style: none;
        border-width: 1px;
    }

    .border2 {
        border-bottom-style: solid;
        border-top-style: solid;
        border-left-style: solid;
        border-right-style: solid;
        border-width: 1px;
    }

    .border3 {
        border-bottom-style: none;
        border-top-style: solid;
        border-left-style: solid;
        border-right-style: solid;
        border-width: 1px;
    }

    .bottom {
        border-bottom-style: solid;
        border-top-style: none;
        border-left-style: none;
        border-right-style: solid;
        border-width: 1px;
    }

    table {
        width: 100%;
        /*border : 1px solid black;*/
    }

    #lab1 {
        font-size: 25px;
    }

    #lab2 {
        font-size: 20px;
    }

    #lab3 {
        font-size: 20px;
    }

    .subpage {
        padding-right: 0.5cm;
        padding-left: 0.5cm;
        /*                padding: 0cm; 
                         border: 1px solid;*/
        height: 281mm;
    }

    .page {

        background: white;
        display: block;
        margin: 0 auto;
    }

    .logodiv {
        margin: 10px !important;
    }
    .table>tbody>tr>td{
        border-top: none;
    }
</style>


<div class="page">


    <div class="">
        <!-- <div class="row align-items-center logodiv">
            <div class="col-lg-12">
                <div class="col-lg-3 col-md-10 col-sm-10 "></div>
                <div class="col-lg-6 col-md-10 col-sm-10 ">
                    <div>
                        <div class="d-flex align-items-center mb-2">
                            <img src="images/lomino1.png" alt="Logo" style="height:160px; width: 70%;"> -->
        <!-- <img src="images/logomain.jpg" alt="Logo 1" style="height: 70px; width: 100px; margin-right: 5px;">
                            <img src="images/mainlogo.png" alt="Logo 2" style="height: 70px; width: 200px;">
                            <img src="images/Rlogo.png" alt="RLogo" style="height:20px; width:20px;margin-top:-25px"> -->
        <!-- </div>
                    </div>
                </div>
                <div class="col-lg-3 col-md-2 col-sm-2 text-right">
                    <div>
                        <h4 class="mb-0">
                            9930409535<br>
                            8108863806<br>
                            9122151229</h4>
                    </div>
                </div>
            </div>
        </div> -->
        <div class="row align-items-center logodiv">
            <div class="col-lg-12 text-center">
                <p>TAX INVOICE</p>
            </div>
        </div>
        <table class="table table-borderless" style="width:100%">
            <tr>
                <td style="width:80%;text-align:center;">
                    <img style="height:auto;width:60%; " src="images/lominonew.png">
                </td>
                <td style="width:20%;text-align: right;">
                    <h4 class="mb-0">
                        9930409535<br>
                        8108863806<br>
                        9122151229</h4>
                </td>
            </tr>
        </table>

        <div class="row align-items-center logodiv">
            <div class="col-lg-12">
                <p>Manufactures of All Kinds of Ladies Bags, College Bags, School Bags,</p>
                <p> Laptop Bags, Executive Bags & Complementary Items </p>
            </div>
        </div>


        <div class="row align-items-center logodiv">
            <div class="col-lg-12">
                <address class="mb-0"><?= $comp['add1'] . " " . $comp['add2'] . " " . $comp['add3']; ?></address>
            </div>
        </div>

    </div>

    <table>
        <td width="50%" class="border2">
            <table>
                <tr>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                </tr>
                <tr class="bottom1">
                    <td class="fsize" style="color:red; text-align: center; padding:5px 0px 7px 0px;">GSTNO :
                        <?php echo $comp['gstno']; ?>
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="100%" class="padd">Details of Receiver | Billed to : </td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="10%" class="padd">Name: </td>
                    <td width="87%" class="bottom1 fsize"><b><?php echo $pname; ?></b></td>
                    <td width="3%" class=""></td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="12%" class="padd">Address: </td>
                    <td width="85%" class="bottom1 fsize"><?php echo $party['add1']; ?></td>
                    <td width="3%" class=""></td>
                </tr>
                <tr>
                    <td class=''></td>
                    <td class="bottom1 fsize">&nbsp;<?php echo $party['add2']; ?></td>
                    <td class=""></td>
                </tr>
                <tr>
                    <td class=''>&nbsp;</td>
                    <td class="bottom1 fsize">&nbsp;<?php echo $party['add3']; ?></td>
                    <td class=""></td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="13%" class="padd">Gst No.</td>
                    <td width="84%" class="bottom1 fsize"><?php echo $party['gstno']; ?></td>
                    <td width="3%" class=""></td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="10%" class="padd">State </td>
                    <td width="34%" class="bottom1 fsize"><?php echo $party['state']; ?></td>
                    <td width="19%" class=''>&nbsp;&nbsp;State Code:</td>
                    <td width="34%" class="bottom1 fsize"><?php echo $party['statecode']; ?></td>
                    <td width="3%" class=""></td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="25%" class="padd">Place Of Supply : </td>
                    <td width="70%" class="bottom1 fsize"><?php echo $party['placeofsupply']; ?></td>
                    <td width="5%" class=""></td>
                </tr>
            </table>


        </td>
        <td width="50%" class="border2">
            <table>
                <tr>
                    <td width="30%" class="padd">Reverse Charge</td>
                    <td width="70%" class="bottom1"></td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="18%" class="padd">Invoice No.</td>
                    <td width="32%" class="bottom1 fsize"><?php echo $getmdata['vouchno']; ?></td>
                    <td width="21%" class=''>&nbsp;&nbsp;Invoice Date</td>
                    <td width="29%" class="bottom1 fsize"><?php echo $getmdata['vouchdt']; ?></td>
                </tr>
                <tr>
                    <td width="18%" class="padd">Bill Type</td>
                    <td width="32%" class="bottom1 fsize"><?php echo $billtype; ?></td>
                    <td width="21%" class=''></td>
                    <td width="29%" class="bottom1 fsize"></td>
                </tr>
            </table>
            <table class="">
                <tr>
                    <td width="10%" class="padd">State </td>
                    <td width="35%" class="bottom1 fsize"><?php echo $comp['state'] ?></td>
                    <td width="21%" class="padd">&nbsp;&nbsp;State Code</td>
                    <td width="34%" class="bottom1 fsize"><?php echo $comp['statecode'] ?></td>
                </tr>
            </table>
            <table class="bottom1">
                <tr>
                    <td width="10%" class="padd"></td>
                    <td width="35%" class=""></td>
                    <td width="21%" class="padd"></td>
                    <td width="34%" class="">&nbsp;</td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="100%" class="padd">Details of consignee | shipped to : </td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="10%" class="padd">Name: </td>
                    <td width="87%" class="bottom1 fsize"><b><?php echo $party['shname']; ?></b></td>
                    <td width="3%" class=""></td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="12%" class="padd">Address: </td>
                    <td width="85%" class="bottom1 fsize"><?php echo $party['shadd1']; ?></td>
                    <td width="3%" class=""></td>
                </tr>
                <tr>
                    <td class=''></td>
                    <td class="bottom1 fsize">&nbsp;<?php echo $party['shadd2']; ?></td>
                    <td class=""></td>
                </tr>
                <tr>
                    <td class=''>&nbsp;</td>
                    <td class="bottom1 fsize">&nbsp;<?php echo $party['shadd3']; ?></td>
                    <td class=""></td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="13%" class="padd">Gst No.</td>
                    <td width="84%" class="bottom1 fsize"><?php echo $party['shgstno']; ?></td>
                    <td width="3%" class=""></td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="10%" class="padd">State </td>
                    <td width="34%" class="bottom1 fsize"><?php echo $party['shstate']; ?></td>
                    <td width="19%" class=''>&nbsp;&nbsp;State Code:</td>
                    <td width="34%" class="bottom1 fsize"><?php echo $party['shstatecode']; ?></td>
                    <td width="3%" class=""></td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="28%" class="padd">Place Of Delivery : </td>
                    <td width="67%" class="bottom1 fsize"><?php echo $party['shdelivery']; ?></td>
                    <td width="5%" class=""></td>
                </tr>
            </table>
            <br>
        </td>
    </table>
    <table class="border">
        <tr class="border">
            <td width='5%' class="border center padd">Sr.No</td>
            <td width='35%' class="border center padd">Description</td>
            <td width='11%' class="border center padd">HSN Code</td>
            <td width='12%' class="border center padd">Qty.</td>
            <td width='12%' class="border center padd">Rate</td>
            <td width='16%' class="border center padd">Amount</td>
        </tr>
        <?php
        $ctr = 0;
        while ($gettdata = mysqli_fetch_array($tranqry)) {
            $getitem = mysqli_query($conn, "SELECT * FROM `item` WHERE `code`= $gettdata[itemcode]") or die(mysqli_error($conn));
            $item = mysqli_fetch_array($getitem);
            $ctr++;
            ?>
            <tr style='height:25px;' class="border">
                <td class="border center"><strong><?= $ctr ?></strong></td>
                <td class="border center"><strong><?= $gettdata['descrip']; ?></strong></td>
                <td class="border center"><strong><?= $gettdata['hsncode']; ?></strong></td>
                <td class="border center"><strong><?= $gettdata['qty']; ?></strong></td>
                <td class="border center"><strong><?= $gettdata['rate']; ?></strong></td>
                <td class="border center"><strong><?= $gettdata['taxval']; ?></strong></td>
            </tr>
            <?php
        }

        //        $ctab = $ctab + 1;
        //        if ($ctab < 15) {
        //            for ($i = $ctab; $i <= 5; $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>
        </tr>      -->
        <?php
        //            }
        //        }
        ?>


    </table>
    <table class=" border2">
        <tr border3>
            <td width="15%" class="bottom padd">Bank</td>
            <td width="25%" class="bottom  padd"><?= $comp['bank'] ?></td>
            <td width="11%" class="bottom  padd right">Total</td>
            <td width="12%" class="bottom  padd right"><?= $getmdata['subqty'] ?></td>
            <td width="12%" class="bottom  padd right">Subtotal</td>
            <td width="16%" class="bottom  padd right"><?php echo round($getmdata['subtotal'], 0) ?></td>
        </tr>
        <tr>
            <td class="bottom  padd">Branch</td>
            <td class="bottom  padd"><?= $comp['branch'] ?></td>
            <td class="padd bottom1"></td>
            <td class="padd bottom1"></td>
            <td class="bottom  padd right">Discount&nbsp;<?php echo $discperc; ?>%</td>
            <td class="bottom  padd right"><?php
            if ($getmdata['discount'] == 0) {
                $discamt = '';
            } else {
                $discamt = round($getmdata['discount'], 0);
            }
            echo $discamt;
            ?></td>
        </tr>
        <tr>
            <td class="bottom  padd">A/c. No. </td>
            <td class="bottom  padd"><?= $comp['acno'] ?></td>
            <td class="padd bottom1"></td>
            <td class="padd bottom1">No. of Boxes&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $getmdata['nobox'] ?></td>
            <td class="bottom  padd right">Packing</td>
            <td class="bottom  padd right"><?php
            if ($getmdata['packing'] == 0) {
                $packamt = '';
            } else {
                $packamt = round($getmdata['packing'], 0);
            }
            echo $packamt;
            ?></td>
        </tr>
        <tr>
            <td class="bottom  padd">IFSC Code</td>
            <td class="bottom  padd"><?= $comp['ifsc'] ?></td>
            <td class="padd bottom1"></td>
            <td class="padd bottom1"></td>
            <td class="bottom  padd right">Taxable Value</td>
            <td class="bottom  padd right"><?php echo round($getmdata['tottaxamt'], 0) ?></td>
        </tr>
        <tr>
            <td class="bottom  padd">PAN </td>
            <td class="bottom  padd"><?= $comp['panno'] ?></td>
            <td class="padd bottom1"></td>
            <td class="padd bottom1"></td>
            <?php
            if ($getmdata['totcgst'] == 0) {
                $totcgst = '';
            } else {
                $totcgst = round($getmdata['totcgst'], 2);
            }
            ?>
            <td class="bottom   right">Add : CGST&nbsp;<?php echo $gstperc; ?>%</td>
            <td class="bottom   right"><?php echo $totcgst; ?></td>
        </tr>
        <tr>
            <?php if ($getmdata['rem1'] > 0) { ?>
                <td class="bottom  padd">Remarks </td>
            <?php } else { ?>
                <td class="bottom  padd"></td>
            <?php } ?>
            <td class="bottom  padd"><?php echo $getmdata['rem1']; ?></td>
            <td class="padd bottom1"></td>
            <td class="padd bottom1"></td>
            <?php
            if ($getmdata['totsgst'] == 0) {
                $totsgst = '';
            } else {
                $totsgst = round($getmdata['totsgst'], 2);
            }
            ?>
            <td class="bottom   right">Add : SGST&nbsp;<?php echo $gstperc; ?>%</td>
            <td class="bottom   right"><?php echo $totsgst; ?></td>
        </tr>
        <tr>
            <td class="bottom  padd"></td>
            <td class="bottom  padd"><?php echo $getmdata['rem2']; ?></td>
            <td class="padd bottom1"></td>
            <td class="padd bottom1"></td>
            <?php
            if ($getmdata['totigst'] == 0) {
                $totigst = '';
            } else {
                $totigst = round($getmdata['totigst'], 2);
            }
            ?>
            <td class="bottom   right">Add : IGST&nbsp;<?php echo $gstperci; ?>%</td>
            <td class="bottom   right"><?php echo $totigst; ?></td>
        </tr>
        <tr>

            <td class="padd bottom1"></td>
            <td class="padd bottom1"></td>
            <td class="padd bottom1"></td>
            <td class="padd bottom1"></td>
            <td class="bottom  padd right" style="font-size: 14px;"><b>Bill Amount</b></td>
            <td class="bottom  padd right" style="font-size: 14px;"><b><?php echo round($getmdata['billamt'], 0) ?></b>
            </td>
        </tr>
    </table>
    <table class=" border2" width="100%">
        <tr>
            <td width="16%" class=" padd bottom">Amount in words </td>
            <td width="84%" class=" padd "><i class="fa fa-inr"></i>&nbsp;<?= rsword(round($getmdata["billamt"])); ?>
            </td>
        </tr>
    </table>
    <table>

        <td width="50%">
            <table>
                <tr>
                    <td width="40%">&nbsp;</td>
                </tr>
                <tr>
                    <td width="40%">
                        <p>" I / We hereby certify that my/our registration certificate under Rule 1 of GST invoice
                            rules 2017 is in force 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 effected by
                            me / us and it shall be accounted of 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. "</p>
                    </td>
                </tr>
            </table>
        </td>
        <td width="50%">
            <table>
                <tr>
                    <td width="60%" class="right">Certified that the particulars given above are true and correct</td>
                </tr>
            </table>
            <br>
            <table>
                <tr class="">
                    <td width="60%" class="right fsize"><b>For <?= $comp['compname']; ?></b></td>
                </tr>
            </table>
            <br>
            <br>
            <br>
            <table>
                <tr>
                    <td width="60%" class="right">Proprieter</td>
                </tr>
            </table>
        </td>
    </table>
</div>
<!--</div>-->
</body>

</html>