<?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);

$vouch = $_GET['vouchno'];

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

$maindb = 'salemain';
$trandb = 'saletran';

$getqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as vouchdt   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);

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

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


    <?php
//        include("includes/files.php");
//        include("includes/tabsuf.php");
    ?>
    <style>
        body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            /*background-color: #FAFAFA;*/
            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;
            /*background: white;*/

        }
        .subpage {
            padding: 0cm;
            /*        border: 1px solid;*/
            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>

<!--<link href="MyStyle/rep_format.css" rel="stylesheet">-->

<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">
            <!--<div class="subpage">-->
            <!--   ************Header************  -->
            <!--            <div style="border:solid 1px;" class="col-md-12" >
                            <h2><center><? Echo $getcmpname['pname']; ?></center></h2>
                            <center><?php echo $getcmpname['add1'] . " " . $getcmpname['add2'] . " " . $getcmpname['add3']; ?></center>
                            <center><?php echo "Email :" . $getcmpname['email'] . " &nbsp " . "Contact No :" . $getcmpname['tel'] . "/" . $getcmpname['mobile']; ?></center>
                            <h5 style="margin-top:12px;margin-bottom: 12px;"><center><b><?php echo $formname; ?></b></center></h5>
            
                        </div>-->
            <div style="border:solid 1px;" class="col-md-12" >
                <center><p style="margin-top:2px;margin-bottom: 2px;font-size:11px; "><u>Subject To Mumbai Jurisdiction</u></p></center>
                <h1 style="margin-top:2px;margin-bottom: 11px;"><center><? Echo $getcmpname['pname']; ?></center></h1>
                <center><?php echo $getcmpname['add1'] . " " . $getcmpname['add2'] . " " . $getcmpname['add3']; ?></center>
                <center><?php echo "Email :" . $getcmpname['email'] . " &nbsp " . "Contact No :" . $getcmpname['tel'] . " " . $getcmpname['mobile']; ?></center>
                <h5 style="margin-top:2px;margin-bottom: 2px;"><center><b><?php echo $formname; ?></b></center></h5>

            </div>
            <!--            <div style="border:solid 1px;" class="col-md-12" style="padding-left: 1px ; padding-right: 1px">
            <?php
            mysqli_select_db($conn, $zdb);

            $gcust = mysqli_query($conn, "SELECT * FROM `accmast` where accode = '$getdata[party]' ") or die(mysqli_error($conn));
            $cust = mysqli_fetch_array($gcust);
            ?>
                            <table class="table table-border table-hover" style="width:100%">
                                <tr>
                                    <td style="text-align: left; width:5%"><b>M/s.</b></td>
                                    <td style="width:1%">:</td>
                                    <td style="text-align: left; width:40%"><?php echo "$showparty[name]"; ?></td>
                                    <td style="text-align: right ; width:30%"><b>Invoce No</b></td>
                                    <td style="width:1%">:</td>
                                    <td style="text-align: left; width:20%"><?php echo" $getdata[vouchno]"; ?></td>
                                </tr>
                                <tr>
                                    <td style="text-align: left; width:7%"><b>Shop.</b></td>
                                    <td style="width:1%">:</td>
                                    <td style="text-align: left; width:40%"><?php echo "$cust[add1]  $cust[add2]"; ?></td>
                                    <td style="text-align: right ; width:30%"><b>Date</b></td>
                                    <td style="width:1%">:</td>
                                    <td style="text-align: left; width:20%"><?php echo "$getdata[vouchdt]"; ?></td>
                                </tr>
                                <tr>
                                    <td style="text-align: left; width:10%">GST No.</td>
                                    <td style="width:1%">:</td>
                                    <td style="text-align: left; width:38%"><?php echo "$cust[gstno]"; ?></td>
                                    <td style="text-align: right ; width:27%">State</td>
                                    <td style="width:1%"></td>
                                    <td style="text-align: left; width:20%"><?php echo "$cust[state]"; ?></td>
                                </tr>
                                <tr>
                                    <td style="text-align: left; width:7%"><b>Mobile</b></td>
                                    <td style="width:1%">:</td>
                                    <td style="text-align: left; width:40%"><?php echo "$cust[mobile]"; ?></td>
                                    <td style="text-align: right ; width:30%">State Code</td>
                                    <td style="width:1%"></td>
                                    <td style="text-align: left; width:20%"><?php echo "$cust[statecode]"; ?></td>
                                </tr>
                                <tr>
                                    <td style="text-align: left; width:7%"><b>City</b></td>
                                    <td style="width:1%">:</td>
                                    <td style="text-align: left; width:40%"><?php echo "$cust[city]"; ?></td>
                                    <td style="text-align: right ; width:30%"></td>
                                    <td style="width:1%"></td>
                                    <td style="text-align: left; width:20%"></td>
                                </tr>
                            </table>
                        </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: center; width:50%;border:1px solid black"><b>Bill To Party</b></td>
                        <td style="text-align: center; width:50%;border:1px solid black"><b>Ship To Party</b></td>

                    </tr>
                    <tr>
                        <td style="text-align: center; width:50%;">
                            <div style="border-collapse: collapse" class="col-md-12">
                                <?php
                                        if($getdata["nameprint"] != ''){
                                            $printname   = $getdata["nameprint"];
                                            $printmobile = $getdata["printmobile"];
                                        }else{
                                            $printname   = $showparty[name];
                                            $printmobile = $showparty[mobile];
                                        }
                                        ?>

                                <table class="table table-bordered table-hover" style="width:100%;border:1px solid black">
                                    <tr>
                                        <td style="text-align: left; width:5%"><b>M/s.</b></td>
                                        <td style="width:1%">:</td>
                                        <td style="text-align: left; width:90%"><b><?php echo "$printname"; ?></b></td>

                                    </tr>
                                    <tr>
                                        <td style="text-align: left; width:7%">Address</td>
                                        <td style="width:1%">:</td>
                                        <td style="text-align: left; width:90%"><?php echo "$showparty[add1]  $showparty[add2]"; ?></td>
                                    </tr>
                                    <tr>
                                        <td style="text-align: left; width:7%">&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                        <td style="width:1%"></td>
                                        <td style="text-align: left; width:90%"><?php echo "$showparty[add3]  $showparty[city] $showparty[pin]"; ?></td>
                                    </tr>
                                    <tr>
                                        <td style="text-align: left; width:7%">Mobile</td>
                                        <td style="width:1%">:</td>
                                        <td style="text-align: left; width:40%"><?php echo "$printname"; ?></td>

                                    </tr>
                                    <tr>
                                        <td style="text-align: left; width:17%">GST No.</td>
                                        <td style="width:1%">:</td>
                                        <td style="text-align: left; width:38%"><?php echo "$showparty[gstno]"; ?></td>

                                    </tr>
                                    <tr>
                                        <td style="text-align: left; width:10%">State</td>
                                        <td style="width:1%">:</td>
                                        <td style="text-align: left; width:30%"><?php echo "$showparty[state]"; ?></td>

                                    </tr>
                                    <tr>
                                        <td style="text-align: left; width:23%">State Code</td>
                                        <td style="width:1%">:</td>
                                        <td style="text-align: left; width:30%"><?php echo "$showparty[statecode]"; ?></td>
                                    </tr>

                                </table>
                            </div>


                        </td>
                        <td style="text-align: center; width:50%">
                            <div style="border-collapse: collapse" class="col-md-12">

                                <table class="table table-bordered table-hover" style="width:100%;border:1px solid black">
                                    <tr>
                                        <td style="text-align: left; width:5%"><b>M/s.</b></td>
                                        <td style="width:1%">:</td>
                                        <td style="text-align: left; width:90%"><b><?php echo "$printname"; ?></b></td>

                                    </tr>
                                    <tr>
                                        <td style="text-align: left; width:7%">Address</td>
                                        <td style="width:1%">:</td>
                                        <td style="text-align: left; width:90%"><?php echo "$showparty[add1]  $showparty[add2]"; ?></td>

                                    </tr>
                                    <tr>
                                        <td style="text-align: left; width:7%">&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                        <td style="width:1%"></td>
                                        <td style="text-align: left; width:90%"><?php echo "$showparty[add3]  $showparty[city] $showparty[pin]"; ?></td>
                                    </tr>
                                    <tr>
                                        <td style="text-align: left; width:7%">Mobile</td>
                                        <td style="width:1%">:</td>
                                        <td style="text-align: left; width:40%"><?php echo "$printmobile"; ?></td>

                                    </tr>
                                    <tr>
                                        <td style="text-align: left; width:17%">GST No.</td>
                                        <td style="width:1%">:</td>
                                        <td style="text-align: left; width:38%"><?php echo "$showparty[gstno]"; ?></td>

                                    </tr>
                                    <tr>
                                        <td style="text-align: left; width:10%">State</td>
                                        <td style="width:1%">:</td>
                                        <td style="text-align: left; width:30%"><?php echo "$showparty[state]"; ?></td>

                                    </tr>
                                    <tr>
                                        <td style="text-align: left; width:23%">State Code</td>
                                        <td style="width:1%">:</td>
                                        <td style="text-align: left; width:30%"><?php echo "$showparty[statecode]"; ?></td>
                                    </tr>

                                </table>
                            </div>


                        </td>

                    </tr>
                    <tr style="">
                        <td style="text-align: center; width:50%;border:1px solid black;border-right: 1px solid black ">
                            <div style="border-collapse: collapse" class="col-md-12" >

                                <table class="table table-bordered table-hover" style="width:100%">
                                    <tr st>
                                        <td style="text-align: left; width:25%;"><b>Invoice No</b></td>
                                        <td style="width:1%">:</td>
                                        <td style="text-align: left; width:74%"><b><?php echo "$getdata[vouchno]"; ?></b></td>

                                    </tr>
                                    <tr>
                                        <td style="text-align: left; width:25%;"><b>Date</b></td>
                                        <td style="width:1%">:</td>
                                        <td style="text-align: left; width:74%"><b><?php echo "$getdata[vouchdt]"; ?></b></td>

                                    </tr>

                                </table>
                            </div>
                        </td>
                        <td style="text-align: center; width:50%;border:1px solid black">
                            <div style="border-collapse: collapse" class="col-md-12" >

                                <table class="table table-bordered table-hover" style="width:100%">
                                    <tr>
                                        <td style="text-align: left; width:35%;"><b>Team Member</b></td>
                                        <!--<td style="width:1%">:</td>-->
                                        <td style="text-align: left; width:75%"><?php echo "$showsalesm[name]"; ?></td>

                                    </tr>
                                    <?php
                                    if ($getdata[cashamt] > 0) {
                                        $paytype = "Cash";
                                    } else {
                                        $paytype = "Credit";
                                    }
                                    ?>
                                    <tr>
                                        <td style="text-align: left; width:24%;"><b>Paid By</b></td>
                                        <!--<td style="width:1%">:</td>-->
                                        <td style="text-align: left; width:90%"><h4 style="margin-top:0px;margin-bottom: 0px;"><?php echo $paytype ?></h4></td>

                                    </tr>

                                </table>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
            <div>
                <table  border="solid 1px" style="border-collapse: collapse; width:100%">
                    <tr>
                        <th style="width:5%; color:black;"><label>Sr.</label></th>
                        <th style="width:25%; color:black;"><label>Itemname.</label></th>
                        <th style="width:10%; color:black;"><label>Hsn Code</label></th>
                        <th style="width:10%; color:black; text-align: right;"><label>Qty.</label></th>
                        <th style="width:10%; color:black;"><label>Unit</label></th>
                        <th style="width:10%; color:black; text-align: right;"><label>Mrp</label></th>
                        <th style="width:10%; color:black; text-align: right;"><label>Rate</label></th>
                        <th style="width:10%; color:black; text-align: right;"><label>Amount</label></th>
                    </tr>

                    <?php
                    $ctr = 0;
                    $ctab = 0;
                    $gettran = mysqli_query($conn, "SELECT `srno`,`item`,`unit`,`qty`,`mrp`,`rate`,hsncode,`amount`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`,`nameprint`  From `item` WHERE `code` = $showtran[item] ")or die(mysqli_error($conn));
                        $showitem = mysqli_fetch_array($getitem);

                        $getuint = mysqli_query($conn, "SELECT `name`,`code`  From `unit` WHERE `code` = '$showtran[unit]' ")or die(mysqli_error($conn));
                        $showunit = mysqli_fetch_array($getuint);

                        $nameprint = $showitem["nameprint"];
                        $name      = $showitem["name"];
                        
                        if($nameprint != ''){
                            $itemname = $nameprint;
                        }else{
                            $itemname = $name;
                        }

                        Echo"<tr>";
                        Echo"<td style=''>$showtran[srno]</td>";
                        Echo"<td style=''>$showitem[name]</td>";
                        Echo"<td style=''>$showtran[hsncode]</td>";
                        Echo"<td style='text-align: right;'>$showtran[qty]</td>";
                        Echo"<td style=''>$showunit[name]</td>";
                        Echo"<td style=' text-align:right;'>$showtran[mrp]</td>";
                        Echo"<td style=' text-align:right;'>$showtran[rate]</td>";
                        Echo"<td style=' text-align:right;'>$showtran[amount]</td>";
                        Echo"</tr>";

                        $ctr++;
                        $ctab = $ctab + 1;
                    }
                    if ($ctab < 18) {
                        for ($i = $ctab; $i <= 18; $i++) {
                            $ctab = $ctab + 1;
                            ?>
                            <tr style="height:26px;">
                                <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
                        }
                    }
                    ?>  

                    <tr style="">
                        <td colspan="4" style="border:none" ><? echo "$getdata[remark1]" . " &nbsp;" . "$getdata[remark2]"; ?></td>
                        <td colspan="" style="text-align: right;border:none" > Subtotal  </td>
                        <td style="text-align: right;border:none "> <? echo $totqty; ?>  </td>
                        <td style="border:none"></td>
                        <td style="text-align: right;border-left: none;"> <? echo $getdata[subtotal]; ?>  </td>

                    </tr>

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

                            <td colspan="5" 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[lesother] > 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[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="5" style="text-align: right;" class="rnone"> Taxable Value  </td>

                            <td style="text-align: right; " class="lnone rnone">   </td>
                            <td class="lnone rnone"></td>
                            <td style="text-align: right;" class="lnone "> <? echo $getdata[tottaxamt]; ?>  </td>
                        </tr>
                        <?php
                    }
                    if ($getdata[cgstperc] > 0) {
                        ?> 
                        <tr>
                            <td colspan="5" style="text-align: right;" class=" rnone" > Add CGST  </td>
                            <td style="text-align: right;" class="lnone rnone"> <? Echo $getdata[cgstperc]; ?>  </td>
                            <td class="lnone rnone">%</td>
                            <td style="text-align: right; " class="lnone "> <? Echo $getdata[totcgst]; ?>  </td>
                        </tr>
                        <?php
                    }
                    if ($getdata[sgstperc] > 0) {
                        ?> 
                        <tr>
                            <td colspan="5" style="text-align: right;" class=" rnone" > Add SGST  </td>
                            <td style="text-align: right;" class="lnone rnone"> <? Echo $getdata[sgstperc]; ?>  </td>
                            <td class="lnone rnone">%</td>
                            <td style="text-align: right; " class="lnone "> <? Echo $getdata[totsgst]; ?>  </td>
                        </tr>
                        <?php
                    }
                    if ($getdata[igstperc] > 0) {
                        ?> 
                        <tr>
                            <td colspan="5" style="text-align: right;" class=" rnone" > Add IGST  </td>
                            <td style="text-align: right;" class="lnone rnone"> <? Echo $getdata[igstperc]; ?>  </td>
                            <td class="lnone rnone">%</td>
                            <td style="text-align: right; " class="lnone "> <? Echo $getdata[totigst]; ?>  </td>
                        </tr>
                        <?php
                    }


//                    if ($getdata[vatamt] > 0) {
//                        
                    ?> 
<!--                        <tr>
    <td colspan="4" style="text-align: right;" class=" rnone"> Add: V.A.T  </td>
    <td style="text-align: right;" class="lnone rnone"> //<? Echo $getdata[vatperc]; ?>  </td>
    <td class="lnone rnone">%</td>
    <td style="text-align: right;" class="lnone "> //<? Echo $getdata[vatamt]; ?>  </td>
</tr>-->
                    <?php
//                    }
                    if ($getdata[packing] > 0) {
                        ?> 
                        <tr>
                            <td colspan="5" style="text-align: right; " class=" rnone"> Add: Packing  </td>
                            <td style="text-align: right;"class="lnone rnone">   </td>
                            <td class="lnone rnone"></td>
                            <td style="text-align: right; "class="lnone "> <? Echo $getdata[packing]; ?>  </td>
                        </tr>
                        <?php
                    }

                    if ($getdata[netamt] > 0) {
                        ?> 
                        <tr>
                            <td colspan="4" style="text-align:  " class=" rnone">GST No:<?php Echo $getcmpname['gst']; ?></td>
                            <td colspan="2" 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
                    }
                    if ($getdata[ladvance] > 0) {
                        ?> 
                        <tr>
                            <td colspan="4" style="text-align: right; "class=" rnone">Less Advance</td>
                            <td style="text-align: right; "class="lnone rnone"></td>
                            <td class="lnone rnone"></td>
                            <td style="text-align: right; "class="lnone "><? Echo $getdata[ladvance]; ?></td>
                        </tr>
                        <?php
                    }
                    if ($getdata[balance] > 0) {
                        ?> 
                        <tr>
                            <td colspan="4" style="text-align: right; "class=" rnone"> Balance</td>
                            <td style="text-align: right; "class="lnone rnone"></td>
                            <td class="lnone rnone"></td>
                            <td style="text-align: right; "class="lnone "><? Echo $getdata[balance]; ?></td>
                        </tr>
                    <?php } ?>
                    <tr>
                        <td colspan="9">
                            Amount In Words: 
                            <?php echo rsword(round($getdata[netamt])); ?>
                        </td>

                    </tr>
                </table>
            </div>

            <div>
                <table class="border">
                    <tr>
                        <td class="border" style="width: 541px; font-size: 14px;">
                            <p 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 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>  
                                <!--<img src="images/taximg.png">-->
                        </td>
                        <td class="border" style="width: 216px">
                            <?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: 51px; font-size: 11px">AUTHORISED SIGNATORY</div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>    
        <!--</div>-->
    </div>
    <?php
    include("includes/linksfoot.php");
    ?>
    <script>
        $(function () {
            formGeneral();
        });
    </script>
</body>
</html>
