<?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 = "Sale Cash";

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

$depa = mysqli_query($conn, "SELECT `code`,`name`,`dptcode` FROM `dept` WHERE `dptcode`= '$getdata[dept]'") or die(mysqli_error($conn));
    $getdept = mysqli_fetch_array($depa);

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

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

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


    <style>
        @media print {
            .noprint {
                display: none;
            }
        }
        body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            /*background-color: #FAFAFA;*/
            font: 12pt "Tahoma";
        }
        * {
            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; 
        }
        .text-right{
            text-align:right;
        }
        .text-center{
            text-align:center;
        }
    </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: #26A69A ;color:white;">Go Back</button>
        <div class="page">
            <!--<div class="subpage">-->
            <!--   ************Header************  -->
            <div style="border:solid 1px;" class="col-md-12" >
                <h2><center><? Echo $getcmpname['compname']; ?></center></h2>
                <center><?php echo $getcmpname['hoadd1'] . " " . $getcmpname['hoadd2'] . " " . $getcmpname['hoadd3']; ?></center>
                <center><?php // echo "Contact No :" . $getcmpname['htel']; ?></center>
                <h2><center><b><?php echo $formname; ?></b></center></h2>

            </div>
            <div style="border:solid 0px;" class="col-md-12" style="padding-left: 1px ; padding-right: 1px">
                <?php
                $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%;border:solid 1px;">
                        <td style="text-align: left; width:20%;border-right:solid 1px;"><b>Bill No.:</b></td>
                        <td style="text-align: left; width:30%;border-right:solid 1px;"><?php echo $getdata['vouchno']; ?></td>
                        <td style="text-align: left; width:20%;border-right:solid 1px;"><b>Bill Date:</b></td>
                        <td style="text-align: left; width:30%;"><?php echo $getdata['vouchdt']; ?></td>
                    </table>
                <table class="table table-border table-hover" style="width:100%;border:solid 1px;">
                        <td style="text-align: center; width:50%;border-right:solid 1px;"><b>Details of Supplier</b></td>
                        <td style="text-align: center; width:50%;border-right:solid 0px;"><b>Recipient Detail</b></td>
                    </table>
                        
                <table class="table table-border table-hover" style="width:100%;border:solid 1px;">
                <tr style="width:100%;border:solid 0px;">
                        <td style="text-align: left; width:50%;border-right:solid 1px;"><b>Supplier:</b><?php echo $cust['name']; ?></td>
                        <td style="text-align: left; width:50%;border-right:solid 0px;"><b>M/s.:</b><?php echo $cust['name']; ?></td>
                    </tr>
                <tr style="width:100%;border:solid 0px;">
                        <td style="text-align: left; width:50%;border-right:solid 1px;"><b>Address:</b><?php echo $cust['add1']; ?></td>
                        <td style="text-align: left; width:50%;border-right:solid 0px;"><b>Address:</b><?php echo $cust['add1']; ?></td>
                    </tr>
                <tr style="width:100%;border:solid 0px;">
                        <td style="text-align: left; width:50%;border-right:solid 1px;"><?php echo $cust['add2']; ?></td>
                        <td style="text-align: left; width:50%;border-right:solid 0px;"><?php echo $cust['add2']; ?></td>
                    </tr>
                <tr style="width:100%;border:solid 0px;">
                        <td style="text-align: left; width:50%;border-right:solid 1px;"><?php echo $cust['add3']; ?></td>
                        <td style="text-align: left; width:50%;border-right:solid 0px;"><?php echo $cust['add3']; ?></td>
                    </tr>
                <tr style="width:100%;border:solid 0px;">
                        <td style="text-align: left; width:50%;border-right:solid 1px;"><b>GST No:</b><?php echo $getdata['gstno']; ?></td>
                        <td style="text-align: left; width:50%;border-right:solid 0px;"><b>GST No:</b><?php echo $getdata['gstno']; ?></td>
                    </tr>
                <tr style="width:100%;border:solid 0px;">
                        <td style="text-align: left; width:50%;border-right:solid 1px;"><?php echo $cust['add3']; ?></td>
                        <td style="text-align: left; width:50%;border-right:solid 0px;"><?php echo $cust['add3']; ?></td>
                    </tr>
                </table>
                      
            </div>
            <div>
                <table border="solid 1px" style="border-collapse: collapse; width:100%">
                    <tr>
                        <th style="width:4%;  color:black;">                      <label>Sr.</label>     </th>
                        <th style="width:19%; color:black;  text-align: left;">   <label>Item</label>    </th>
                        <th style="width:13%; color:black;  text-align: left;">   <label>HSN Code</label></th>
                        <th style="width:10%; color:black;  text-align: right;">  <label>Qty.</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;
//                    $qry = mysqli_query($conn, "SELECT * FROM  `$trandb` WHERE vouchno='$getvouch' and saletype !='C' ORDER BY srno") or die(mysqli_error($conn));
                    $ctab = $totqty = $totamt = 0;
                    $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$vouch' and saletype ='C' order by srno")or die(mysqli_error($conn));
                    while ($showtran = mysqli_fetch_array($gettran)) {

                        $icode = $showtran['product'];

                        $gitemname = mysqli_query($conn, "SELECT `code`,`name` FROM `product` WHERE `code`='$icode'")or die(mysqli_error($conn));
                        $fitemname = mysqli_fetch_array($gitemname);
                        
                        $item = $fitemname["name"];
                        $amount = $showtran['total'];
                        $unit = $showtran['unit'];
                        $hsncode = $showtran['hsncode'];
                        $qty = $showtran['qty'];
                        $rate = $showtran['rate'];
                     
                        $ctr++;

                        Echo"<tr>";
                        Echo"<td style='text-align:center'>$ctr</td>";
                        Echo"<td style=''>$item</td>";
                        Echo"<td style=' text-align: left;'>$hsncode</td>";
                        Echo"<td style=' text-align: right;'>$qty</td>";
                        Echo"<td style=' text-align:right;'>$rate</td>";
                        Echo"<td style=' text-align:right;'>$amount</td>";
                        Echo"</tr>";

                        $totqty = $totqty + $qty;
                        $totamt = $totamt + $amount;
                        $ctab = $ctab + 1;
                    }
                    if ($ctab < 12) {
                        for ($i = $ctab; $i <= 12; $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>
                            </tr>      
                            <?php
                        }
                    }
                            
                                                
                            $ptotqty = number_format($totqty,2);
                            $ptotamt = number_format($totamt,2);
                    ?>  

                    <tr style="height:26px;">
                        <td class="text-right border"><?php // echo ; ?></td>
                        <td class="text-right border"><b>Total</b></td>
                        <td class="text-right border"><b><?php echo $ptotqty; ?></b></td>
                        <td class="text-right border"><?php // echo ; ?></td>
                        <td class="text-right border"><?php //  echo ; ?></td>
                        <td class="text-right border"><b><?php echo $ptotamt; ?></b></td>
                    </tr>
                 
                    <? if ($getdata[litemdisc] > 0 ){ ?>
                        <tr style="height:26px;">
                            <td class="text-right border"  colspan="5">Less Item Discount</td>
                            <td class="text-right border"><b><?php echo $getdata['litemdisc']; ?></b></td>
                        </tr>
                    <? } ?>
                    <tr style="height:26px;">
                        <td class="text-right border"  colspan="5">Taxable Value</td>
                        <td class="text-right border"><b><?php echo $getdata['tottaxamt']; ?></b></td>
                    </tr>
                       
                        
                        
                    <tr>
                        <td class="border"  colspan="2"></td>
                        <th class='text-right'>CGST</th>
                        <th class='text-right'>SGST</th>
                        <th class='text-right'>IGST</th>
                        <th></th>
                    </tr>
                    <?
                    Echo "<tr>";
                    Echo "<td class='text-right' colspan='2'><b>5%</b></td>";
                    Echo "<td class='text-right'>$getdata[cgst5]</td>";
                    Echo "<td class='text-right'>$getdata[sgst5]</td>";
                    Echo "<td class='text-right'>$getdata[igst5]</td>";
                    Echo "<td class='text-right'>$getdata[totgst5]</td>";
                    Echo "</tr>";
                    Echo "<tr>";
                    Echo "<td class='text-right' colspan='2'><b>12%</b></td>";
                    Echo "<td class='text-right'>$getdata[cgst12]</td>";
                    Echo "<td class='text-right'>$getdata[sgst12]</td>";
                    Echo "<td class='text-right'>$getdata[igst12]</td>";
                    Echo "<td class='text-right'>$getdata[totgst12]</td>";
                    Echo "</tr>";
                    Echo "<tr>";
                    Echo "<td class='text-right' colspan='2'><b>18%</b></td>";
                    Echo "<td class='text-right'>$getdata[cgst18]</td>";
                    Echo "<td class='text-right'>$getdata[sgst18]</td>";
                    Echo "<td class='text-right'>$getdata[igst18]</td>";
                    Echo "<td class='text-right'>$getdata[totgst18]</td>";

                    Echo "</tr>";
                    Echo "<tr>";
                    Echo "<td class='text-right' colspan='2'><b>28%</b></td>";
                    Echo "<td class='text-right'>$getdata[cgst28]</td>";
                    Echo "<td class='text-right'>$getdata[sgst28]</td>";
                    Echo "<td class='text-right'>$getdata[igst28]</td>";
                    Echo "<td class='text-right'>$getdata[totgst28]</td>";
                    Echo "</tr>";
                    ?>
                    
                    
                    <tr style="height:26px;">
                            <td class="text-right border"  colspan="5">Total GST</td>
                            <td class="text-right border"><b><?php echo $getdata['totalgst']; ?></b></td>
                    </tr>
                    
                    
                    <tr>
                        <td colspan="5" style="text-align: right; "class=""><b>Bill Amount</b></td>
                        <td style="text-align: right; "class="lnone" colspan=""><b><? Echo $getdata['netamt'] ; ?></b></td>
                    </tr>
                    
                    <tr>
                        <td colspan="6">
                            Rupees 
                            <?php echo rsword(round($getdata['netamt'])); ?>
                        </td>
                    </tr>
                   
                     <tr style="width:100%;border:solid 1px;">
                        <td colspan="" style="text-align: left; "class=""><b>Remarks:</b></td>
                        <td colspan="5"style="text-align: left;"><? Echo $getdata['rem1'] ; ?></td>
                    </tr>
                     <tr>
                        <td colspan="" style="text-align: left; "class=""><b></b></td>
                        <td colspan="5"style="text-align: left;padding-left: 5px"><? Echo $getdata['rem2'] ; ?></td>
                    </tr>
                    
                </table>
            </div>

            <div>
                <table class="border">
                    <tr>
                        <td class="border" style="width: 541px; font-size: 14px;">
                        </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[compname]"; ?></div>
                            <br>
                            <br>
                            <br>
                            <div style=" margin-left: 86px; font-size: 11px">AUTHORISED SIGNATORY</div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>    
    </div>
    <?php
    include("includes/linksfoot.php");
    ?>
    <script>
        $(function () {
            formGeneral();
        });
    </script>
</body>
</html>
