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

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

$vouch = $_GET['vouchno'];
$type = $_GET['para'];

$cond = '';
$lcond = '';
$formname = "TAX INVOICE";
$maindb = 'invoice';
$trandb = 'challan';
$root = $_SESSION["zdbroot"];

$party = $_POST["party"];
$month = $_POST["month"];
$frmdt = $_POST["frmdt"];
$todt = $_POST["todt"];

$partycond = '';
$monthcond = '';

if (!empty($party)) {
    $partycond = " AND `party` = '$party' ";
}

if (!empty($month)) {
    $monthcond = " AND `monthno` = '$month' ";
}

$getqry = mysqli_query($conn,"SELECT *, DATE_FORMAT(`vouchdt`, '%d/%m/%Y') as mydt FROM `$maindb` WHERE vouchno != '' $partycond $monthcond ORDER BY `vouchno`")or die(mysqli_error($conn));

$getcomp2 = mysqli_query($conn,"SELECT * FROM $root.`company`")or die(mysqli_error($conn));
$comp2 = mysqli_fetch_array($getcomp2);

if (mysqli_num_rows($getqry) <= 0) {
    browse("Record Not Found");
}
include("includes/linkshead.php");
?>
<link href="styles/inv_format.css" rel="stylesheet">
<style>
    body{
        font-size: 13px;
    }
    .table > tbody > tr > td{
        padding: 0px;
    }

    .bor{
        border-left: 1px solid black;
        border-right:  1px solid black;
    }

    .numeric{
        text-align: right
    }

    .fontnew{
        font-family: 'Verdana';
        font-size : 13px;
        font : 'bold';
    }
    /*    .border{
            border-top-style:solid; 
            border-right-style:solid; 
            border-bottom-style:none; 
            border-left-style:solid;
            border-width:1px black;
        }*/
    .border{
        border-top:1px solid black;
        border-right:1px solid black; 
        border-bottom:none; 
        border-left:1px solid black;
    }
    .border2{
        border-top-style:solid; 
        border-right-style:solid; 
        border-bottom-style:none; 
        border-left-style:none;
        border-width:1px ;
    }
    .uppercase{
        text-transform:uppercase;
    }
    th{
        font-size: 11px;
    }
    .table-condensed > tbody > tr > td {
        padding:3px;
        font-size:10px
    }
    .padd{
        padding-left: 2px;
    }
    @media print 
    {
        @page {
            size: A4; /* DIN A4 standard, Europe */
            margin:0;
        }
        html, body {
            width: 210mm;
            height: 282mm;
        }
        .footer {
            page-break-after: always;
        }
    }
</style>
</head>
<body onload="">

    <?php
    $tdhg = "24px";

    while ($qry = mysqli_fetch_array($getqry)) {

        $vouchno = $qry['vouchno'];

        $stafcode = $qry['staff'];
        $getstaf = mysqli_query($conn,"SELECT accode,name FROM `accmast` where accode = '$stafcode' ")or die(mysqli_error($conn));
        $staff = mysqli_fetch_array($getstaf);
        ?>
        <div class="container footer">
            <div class="page">
                <div class="subpage" style="padding-top: 16px">
                    <!--                    <div class="row">
                                            <div class="col-lg-12 col-md-12 col-sm-12 text-right">
                                                <button onclick="window.print();return false;" class="btn btn-primary noPrint" style="text-align: right">Print</button>
                                            </div>
                                        </div><br>-->
                    <div class="border" style="border-bottom: none">
                        <table style="width:100%;height: 7%">
                            <tr>
                                <td style="width:25%">
                                    <table style="width:100%">
                                        <tr>
                                            <td><img src="images/nspw.jpg" style="width: 100px;height: 80px; margin-left: 6px;"></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['name'] ?></b></td> 
                                        </tr>
                                    </table> 
                                </td>
                                <td style="width:25%">
                                </td>
                            </tr>
                        </table>
                        <table style="width:100%">
                            <tr><td class="text-center"><b>Address :</b>
                                    <?php echo $comp2['add1'] . ' ' . $comp2['add2'] . ' ' . $comp2['add3'] . ' ' . $comp2['city'] . '-' . $comp2['pin'] . " " . "Tel :" . " " . $comp2["tel"] ?>                      
                                </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>
                            <tr>
                                <td style="font-size: 15px;" class="text-center">
                                    <b>
                                        TAX INVOICE
                                    </b>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div class="border">
                        <div class="row">
                            <?
                            $getpartyname = mysqli_query($conn,"SELECT * FROM `accmast` WHERE `accode`='$qry[party]' AND `grpcode`='010'")or die(mysqli_error($conn));
                            $mpartyname = mysqli_fetch_array($getpartyname);

                            $partyname = $mpartyname['name'];
                            $add1 = $mpartyname['add1'];
                            $add2 = $mpartyname['add2'];
                            $add3 = $mpartyname['add3'];
                            $city = $mpartyname['city'];
                            $pin = $mpartyname['pin'];
                            $gstno = $mpartyname['gstno'];
                            ?>
                            <table width="100%">
                                <tr>
                                    <td style="width:55%; border-right: 1px solid black;" class="text-left padd">
                                        <label class="fontnew" style="text-align: left; width: 10%"><b>M/s.&nbsp;:</b></label>
                                        <label class="fontnew" style="text-align: left; width: 45%"><b><? Echo $partyname; ?></b></label>
                                    </td>
                                    <td style="width:10%" class="text-left padd">
                                        <label class="fontnew" style="text-align: left;"><b>Invoice No. &nbsp; </b></label>
                                    </td>
                                    <td  class="padd" style="width:20%">
                                        <label style="font-size: 12px;font-family: 'verdana'">:&nbsp;
                                            <? Echo $qry['vouchno']; ?></label>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="padd" style="width:55%;border-right: 1px solid black">
                                        <label class="fontnew" style="text-align: left; width: 10%; border-right: 1px solid black"></label>
                                        <?php
//                                        if ($add1 != '') {
                                        ?>
                                        <label class="fontnew" style="width: 45%; text-align: left"><? Echo $add1 . '' . $add2; ?></label>
                                        <?php // }
                                        ?>
                                    </td>
                                    <td style="width:15%" class="text-left padd">
                                        <label class="fontnew" style="text-align: left;" >Date &nbsp;&nbsp;</label>
                                    </td>
                                    <td  class="text-left" style="width:15%">
                                        <label class="fontnew">:&nbsp;<? Echo $qry['mydt']; ?></label>
                                    </td>
                                </tr>
                                <tr>
                                    <td  class="padd" style="width:55%;border-right: 1px solid black">
                                        <label class="fontnew" style="text-align: left; width: 10%; border-right: 1px solid black"></label>
                                        <?php
//                                        if ($add3 != '') {
                                        ?>
                                        <label class="fontnew" style="width: 45%; text-align: left"><? Echo $add3 ?></label>
                                        <?php // }
                                        ?>
                                    </td>
                                </tr>
                                <tr>
                                    <td style = "width:55%;border-right: 1px solid black;" class = "text-left padd">
                                        <?php
//                                        if ($gstno != '') {
                                        ?>
                                        <label style="font-size: 13px;font-family: 'verdana';text-align: left; width: 10%" >GST NO&nbsp;:</label>
                                        <label class="fontnew" style="width: 45%; text-align: left"><? Echo $gstno ?></label>
                                        <?php
//                                        }
                                        ?>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <!--                    <div class="border">
                                            <div class="row">-->
                    <table class="table-condensed table-hover" style="width: 100%">
                        <tr style="background: #0098DA;color: white;border: 1px solid black; height: <?= $tdhg; ?>">
                            <!--<th class="uppercase bor" style="width:1%">Sr</th>-->
                            <th class="uppercase bor" style="width:12%">Date</th>
                            <!--<th class="uppercase bor" style="width:1%;">P/R/D</th>-->
                            <th class="uppercase bor" style="width:12%">Delv. Date</th>
                            <th class="uppercase bor" style="width:25%">Description</th>
                            <th class="uppercase bor numeric " style="width:4%">Nags</th>
                            <th class="uppercase bor numeric " style="width:4%">Size (MM)</th>
                            <th class="uppercase bor numeric " style="width:4%">T(MM)</th>
                            <th class="uppercase bor numeric " style="width:4%">Make (MM)</th>
                            <th class="uppercase bor numeric " style="width:2%">Dia</th>
                            <th class="uppercase bor" style="width:2%">A/P</th>
                            <th class="uppercase bor" style="width:2%">Wld</th>
                            <th class="uppercase bor" style="width:3%">STRT</th>
                            <th class="uppercase bor numeric" style="width:4%">FTS</th>
                            <th class="uppercase bor numeric" style="width:5%">T.FTS</th>
                            <th class="uppercase bor numeric" style="width:5%">Wt.</th>
                            <th class="uppercase bor numeric" style="width:5%">Rate</th>
                            <th class="uppercase bor numeric" style="width:7%">Amount</th>
                        </tr>
                        <?
                        $ctr = 0;
                        $ctab = 0;
                        $totamt = 0;
                        $gettran = mysqli_query($conn,"SELECT *, DATE_FORMAT(`delvdate`, '%d-%m-%Y') as delvdate, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as vouchdt FROM `$trandb`
                                            WHERE `gstinvno`='$qry[vouchno]' ORDER BY `srno`")or die(mysqli_error($conn));
                        $getno = mysqli_num_rows($gettran);

                        while ($tran = mysqli_fetch_array($gettran)) {
                            $ctr++;
                            ?>
                            <tr style="height: <?= $tdhg; ?>;">
                                <!--<td class="bor "><? Echo $ctr; ?></td>-->
                                <td class="bor "><? Echo $tran['vouchdt']; ?></td>
                                <!--<td class="bor " style="text-align: center"><? Echo $tran['delv']; ?></td>-->
                                <td class="bor "><? Echo $tran['delvdate']; ?></td>
                                <td class="bor "><? Echo $tran['descrip']; ?></td>
                                <td class="bor numeric "><? Echo $tran['nag']; ?></td>
                                <td class="bor numeric "><? Echo $tran['sizemm']; ?></td>
                                <td class="bor numeric "><? Echo $tran['guagemm']; ?></td>
                                <td class="bor numeric "><? Echo $tran['makemm']; ?></td>
                                <td class="bor numeric "><? Echo $tran['dia']; ?></td>
                                <td class="bor "><? Echo $tran['ap']; ?></td>
                                <td class="bor "><? Echo $tran['weld']; ?></td>
                                <td class="bor "><? Echo $tran['straight']; ?></td>
                                <td class="bor numeric "><? Echo $tran['foot']; ?></td>
                                <td class="bor numeric "><? Echo $tran['totfeet']; ?></td>
                                <td class="bor numeric "><? Echo $tran['weight']; ?></td>
                                <td class="bor text-right "><? Echo $tran['rate']; ?></td>
                                <td class="bor text-right "><? Echo round($tran['amount']); ?></td>
                            </tr>
                            <?
                            $totamt = $totamt + $tran[amount];
                            $ctab = $ctab + 1;
                        }
                        if ($ctr < 10) {
                            for ($i = $ctab; $i < 16; $i++) {
                                $ctab = $ctab + 1;
                                ?>
                                <tr style="height: <?= $tdhg; ?>">
                                    <!--<td class="bor"></td>-->
                                    <!--<td class="bor"></td>-->
                                    <td class="bor"></td>
                                    <td class="bor"></td>
                                    <td class="bor"></td>
                                    <td class="bor"></td>
                                    <td class="bor"></td>
                                    <td class="bor"></td>
                                    <td class="bor"></td>
                                    <td class="bor"></td>
                                    <td class="bor"></td>
                                    <td class="bor"></td>
                                    <td class="bor"></td>
                                    <td class="bor"></td>
                                    <td class="bor"></td>
                                    <td class="bor"></td>
                                    <td class="bor"></td>
                                    <td class="bor"></td>
                                </tr>
                                <?php
                            }
                        }
                        ?> 
                    </table>
                    <!--                        </div>
                                        </div>-->
                    <div class="border">
                        <div class="row">
                            <div class="col-sm-12" style="padding: 0px">
                                <table class="table-hover pad" style="float:right;width:50%">
                                    <tr>
                                        <td style="text-align: right;font-size:13px"><label class="">Sub Total</label></td>
                                        <td class="numeric"><label class="" style="text-align:right;font-size:13px"><? echo $totamt; ?></label></td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12" style="padding: 0px">
                                <table class="table-hover table-bordered" style="float: left;width:50%">
                                    <tr style="height: 21px">
                                        <td width="50%" class='text-center' colspan="2"><b>Payment Details</b></td>
                                    </tr>
                                    <tr style="height: 21px">
                                        <td width="10%" class=''>Bank Name</td>
                                        <td width="40%" class=''><?php echo $comp2['bankname']; ?></td>
                                    </tr>
                                    <tr style="height: 21px">
                                        <td width="10%" class=''>Branch Name</td>
                                        <td width="40%" class=''><?php echo $comp2['branchname']; ?></td>
                                    </tr>
                                    <tr style="height: 21px">
                                        <td width="10%" class=''>A/C. Name</td>
                                        <td width="40%" class=''><?php echo $comp2['acname'] ?></td>
                                    </tr>
                                    <tr style="height: 21px">
                                        <td width="10%" class=''>Account No.</td>
                                        <td width="40%" class=''><?php echo $comp2['acno']; ?></td>
                                    </tr>
                                    <tr>
                                        <td width="10%">IFSC Code</td>
                                        <td width="40%"><? echo $comp2['bankcode']; ?></td>
                                    </tr>
                                </table>
                                <table class="table-hover table-bordered" style="float: right;width:50%">
                                    <tr style="height: 21px">
                                        <!--<td width="10%" class='text-right'>Taxable Amt.</td>-->
                                        <td width="8%" class='text-right'>%</td>
                                        <td width="8%" class='text-right'>CGST</td>
                                        <td width="8%" class='text-right'>SGST</td>
                                        <!--<td width="8%" class='text-right'>IGST</td>-->
                                        <td width="8%"></td>
                                    </tr>
                                    <?php
                                    Echo "<tr style='height: 21px'>";
//                                    Echo "<td class='text-right'>$qry[tottaxble1]</td>";
                                    Echo "<td class='text-right'><b>3%</b></td>";
                                    Echo "<td class='text-right'>$qry[cgst1]</td>";
                                    Echo "<td class='text-right'>$qry[sgst1]</td>";
//                                    Echo "<td class='text-right'>$qry[igst1]</td>";
                                    Echo "<td class='text-right'>$qry[totgst1]</td>";
                                    Echo "</tr>";
                                    Echo "<tr style='height: 21px'>";
//                                    Echo "<td class='text-right'>$qry[tottaxble5]</td>";
                                    Echo "<td class='text-right'><b>5%</b></td>";
                                    Echo "<td class='text-right'>$qry[cgst5]</td>";
                                    Echo "<td class='text-right'>$qry[sgst5]</td>";
//                                    Echo "<td class='text-right'>$qry[igst5]</td>";
                                    Echo "<td class='text-right'>$qry[totgst5]</td>";
                                    Echo "</tr>";
                                    Echo "<tr style='height: 21px'>";
//                                    Echo "<td class='text-right'>$qry[tottaxble12]</td>";
                                    Echo "<td class='text-right'><b>12%</b></td>";
                                    Echo "<td class='text-right'>$qry[cgst12]</td>";
                                    Echo "<td class='text-right'>$qry[sgst12]</td>";
//                                    Echo "<td class='text-right'>$qry[igst12]</td>";
                                    Echo "<td class='text-right'>$qry[totgst12]</td>";
                                    Echo "</tr>";
                                    Echo "<tr style='height: 21px'>";
//                                    Echo "<td class='text-right'>$qry[tottaxble18]</td>";
                                    Echo "<td class='text-right'><b>18%</b></td>";
                                    Echo "<td class='text-right'>$qry[cgst18]</td>";
                                    Echo "<td class='text-right'>$qry[sgst18]</td>";
//                                    Echo "<td class='text-right'>$qry[igst18]</td>";
                                    Echo "<td class='text-right'>$qry[totgst18]</td>";
                                    Echo "</tr>";
                                    Echo "<tr style='height: 21px'>";
//                                    Echo "<td class='text-right'>$qry[tottaxble28]</td>";
                                    Echo "<td class='text-right'><b>28%</b></td>";
                                    Echo "<td class='text-right'>$qry[cgst28]</td>";
                                    Echo "<td class='text-right'>$qry[sgst28]</td>";
//                                    Echo "<td class='text-right'>$qry[igst28]</td>";
                                    Echo "<td class='text-right'>$qry[totgst28]</td>";
                                    Echo "</tr>";
                                    ?>
                                    <tr>
                                        <td colspan="3" class="text-right"><label class="text-right" style="font-family: 'verdana';font-size: 12px">Bill Amount</label></td>
        <!--                                <td class="numeric"><label class=""><i style="font-size:12px" class="fa fa-rupee"></i></label></td>-->
                                        <td class="numeric padd" colspan="3"><label class="" style="font-family: 'verdana';font-size: 12px"><b><i style="font-size:12px" class="fa fa-rupee"></i>&nbsp;<? Echo number_format(round($qry['billamt']), 2); ?></b></label></td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                    <?php
                    $mwords = round($qry['billamt']);
                    $words = rsword($mwords);
                    ?>
                    <div style="">
                        <div class="row">
                            <div class="col-lg-12" style="padding: 0px; border: 1px solid black">
                                <label class="pad fa fa-inr">&nbsp;<?php Echo $words . " Only"; ?></label>
                            </div>
                        </div>
                    </div>
                    <div class="" style="padding-top: 5px;">
                        <div class="row">
                            <div class="col-sm-12" style="padding:0px">
                                <table width='100%'>
                                    <tr>
                                        <td style="width: 50%">
                                            <label style="font-family: 'verdana';font-size: 16px">E.O.& E.</label>
                                        </td>
                                        <td style="width: 50%" class="text-right">
                                            <label><b style="font-family: 'verdana';font-size: 16px"><?php Echo "For " . $comp2['name'] ?></b></label>
                                        </td>
                                    </tr>
                                </table>
                                <table width='50%'>
                                    <tr>
                                        <td>
                                            <label style="font-size:10px">
                                                " 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>
                                <table width='100%'>
                                    <tr>
                                        <td class="text-right" style="font-size: 12px;">
                                            <label>Authorized Signatory</label><br>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php
    }

    include('includes/linksfoot.php');
    ?>
