<?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['type'];

$cond = '';
$lcond = '';
$formname = "PURCHASE VOUCHER";
$maindb = 'purmain';
$trandb = 'purtran';
$root = $_SESSION["zdbroot"];
$fseries = $_SESSION["series_" . $dbname];

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

$getcomp = mysqli_query($conn, "SELECT * FROM $root.`series` WHERE `code`='$fseries'")or die(mysqli_error($conn));
$comp = mysqli_fetch_array($getcomp);

//$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="MyStyle/inv_format.css" rel="stylesheet">
<style>
    body{
        font-size: 13px;
    }
    .table > tbody > tr > td{
        padding: 0px;
    }
    .f-s{
        font-size: 12px;
    }

</style>
</head>
<!--<body onload="window.print();">-->
<?php
$tdhg = "24px";
$qry = mysqli_fetch_array($getqry);
$oms = $qry[oms];
$salty = $qry[cashcred];
if ($salty == "C") {
    $nametype = "Cash";
} elseif ($salty == "R") {
    $nametype = "Credit";
}
?>
<div class="page">
    <div class="subpage" style="padding-top: 16px">
        <table style="width:100%;height: 7%">
                <tr>
                    <td style="width:25%">
                        <table style="width:100%">
                            <tr>
                                <td style="width:33.33%"><img src="images/cycle_logo.png" style="width: 100px;height: 60px"></td> 
                            </tr>
                        </table>
                    </td>
                    <td style="width:50%">
                        <table style="width:100%">
                            <tr>
                                <td style="text-align: center;width: 100%;font-size: 24px;font-family: 'Times New Roman';"><b><? Echo $comp[compname] ?></b></td> 

                            </tr>
                            <tr>
                                <td style="text-align: center"><label class="label-control" style=""><? Echo "$comp[address]"; ?></label></td> 
                            </tr>
                            <tr>
                                <td style="width:33.33%;text-align: center"><label class="label-control"><? Echo $formname; ?></label></td> 
                            </tr>
                        </table> 
                    </td>
                    <td style="width:25%">
                        <table style="width:100%">
                            <tr>
                                <td style="width:33.33%;text-align: right"><img src="images/since_logo.png" style="width: 70px;height: 60px"></td> 
                            </tr>
                        </table> 
                    </td>
                </tr>
            </table>
        <div class="border">
            <div class="row">
                <?
                if ($qry[cashcred] != "R") {
                    $partyname = $qry["partyname"];
                } else {
                    $getpartyname = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`='$qry[accode]' 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];
                    $panno = $mpartyname[vattin];
                    $gstno = $mpartyname[gstno];
                }
                ?>
                <table style="width:100%;">
                    <tr>
                        <td style="width:60%;">
                            <table width="100%" class="table-hover pad">
                                <tr>
                                    <td width="15%" valign="top" style="text-align: right">
                                        <label class="" style="font-size: 11px">M/s.&nbsp;&nbsp;&nbsp;</label>
                                    </td>
                                    <td width="85%" class="">
                                        <label style="font-size: 11px"><? Echo $partyname; ?></label>
                                    </td>
                                </tr>
                                <?php
                                if ($qry[location] != '') {
                                    ?>

                                    <tr>
                                        <td width="15%">
                                            <label class=""></label>
                                        </td>
                                        <td width="85%" class="">
                                            <label class="smfont"><? Echo $qry[location]; ?></label>
                                        </td>
                                    </tr>
                                    <?php
                                }
                                if ($add1 != '') {
                                    ?>
                                    <tr>
                                        <td width="15%">
                                            <label class=""></label>
                                        </td>
                                        <td width="75%" class="">
                                            <label class="smfont"><? Echo $add1 . '' . $add2; ?></label>
                                        </td>
                                    </tr>
                                    <?php
                                }
                                if ($add3 != '' || $city != '') {
                                    ?>
                                    <tr>
                                        <td width="15%">
                                            <label class=""></label>
                                        </td>
                                        <td width="85%" class="">
                                            <label class="smfont"><? Echo $add3 . $city . $pin ?></label><br>
                                        </td>
                                    </tr>
                                    <?php
                                }
                                if ($gstno != '') {
                                    ?>
                                    <tr>
                                        <td width="15%">
                                            <label class=""></label>
                                        </td>
                                        <td width="85%" class="">
                                            <label class="smfont"><? Echo 'GST No.' . $gstno ?></label><br>
                                        </td>
                                    </tr>
                                    <?php
                                }
                                if ($panno != '') {
                                    ?>
                                    <tr>
                                        <td width="15%">
                                            <label class=""></label>
                                        </td>
                                        <td width="85%" class="">
                                            <label class="smfont"><? echo 'Pan No.' . $panno ?></label><br>
                                        </td>
                                    </tr>
                                <?php } ?>
                            </table>
                        </td>
                        <td style="width:40%;">
                            <table width="100%" class="table-hover pad" style="float: left">
                                <tr>
                                    <td width="15%" class="text-right"><label class="label-control">Voucher No  :</label></td>
                                    <td width="35%"><label class="label-control"><? Echo $qry[billno]; ?></label></td>
                                </tr>
                                <tr>
                                    <td width="15%" class="text-right"><label class="label-control">Date  :</label></td>
                                    <td width="35%"><label class="label-control"><? Echo $qry[mydt]; ?></label></td>
                                </tr>
                                <tr>
                                    <td width="15%" class="text-right"><label class="label-control">Type  :</label></td>
                                    <td width="35%"><label class="label-control"><? Echo $nametype; ?></label></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div style="border-right: 1px solid black;border-left: 1px solid black;">
            <div class="row">
                <div class="col-sm-12 pad">
                    <table class="table-condensed table-hover" style="width: 100%">
                        <tr style="background-color:#cccccc;border: 1px solid black; height: <?= $tdhg; ?>">
                            <th class="numeric" style="font-size:12px;width:3%">Sr</th>
                            <th style="font-size:12px;width:25%">Item</th>
                            <th style="font-size:12px;width:7%">HSN Code</th>
                            <th class="numeric" style="font-size:12px;width:3%">Qty.</th>
                            <th class="numeric" style="font-size:12px;width:4%">Unit.</th>
                            <th class="numeric" style="font-size:12px;width:7%">Rate</th>
                            <th class="numeric" style="font-size:12px;width:7%">Amount</th>
                            <th class="numeric" style="font-size:12px;width:6%">Disc. Amt.</th>
                            <th class="numeric" style="font-size:12px;width:7%">Taxable Value</th>
                            <?php if ($oms == '') { ?>
                                <th class="numeric" style="font-size:12px;width:5%">CGST Rate</th>
                                <th class="numeric" style="font-size:12px;width:7%">CGST Amt.</th>
                                <th class="numeric" style="font-size:12px;width:5%">SGST Rate</th>
                                <th class="numeric" style="font-size:12px;width:7%">SGST Amt.</th>
                            <?php } else { ?>
                                <th class="numeric" style="font-size:12px;width:5%">IGST Rate</th>
                                <th class="numeric" style="font-size:12px;width:7%">IGST Amt.</th>
                            <?php } ?>
                            <th class="numeric" style="font-size:12px;width:7%">Total</th>
                        </tr>
                        <?
                        $ctab = 0;
                        $gettran = mysqli_query($conn, "SELECT * FROM `purtran` WHERE `vouchno`='$qry[vouchno]' ORDER BY `srno`")or die(mysqli_error($conn));
                        while ($tran = mysqli_fetch_array($gettran)) {
                            $getitem = mysqli_query($conn, "SELECT `name` FROM `item` WHERE `code`='$tran[itemcode]'")or die(mysqli_error($conn));
                            $item = mysqli_fetch_array($getitem);
                            ?>
                            <tr style="height: <?= $tdhg; ?>">
                                <td class="numeric"><? Echo $tran[srno]; ?></td>
                                <td><? Echo $item[name]; ?></td>
                                <td><? Echo $tran[hsncode]; ?></td>
                                <td class="text-right"><? Echo round($tran[qty], 0); ?></td>
                                <td class=""><? Echo $tran[unit]; ?></td>
                                <td class="text-right"><? Echo $tran[rate]; ?></td>
                                <td class="text-right"><? Echo $tran[amount]; ?></td>

                                <td class="text-right"><? Echo $tran[discamt]; ?></td>
                                <td class="text-right"><? Echo $tran[subtot]; ?></td>
                                <?php if ($oms == '') { ?>
                                    <td class="text-right"><? Echo $tran[cgstrate]; ?></td>
                                    <td class="text-right"><? Echo $tran[cgstamt]; ?></td>
                                    <td class="text-right"><? Echo $tran[sgstrate]; ?></td>
                                    <td class="text-right"><? Echo $tran[sgstamt]; ?></td>
                                <?php } else { ?>
                                    <td class="text-right"><? Echo $tran[igstrate]; ?></td>
                                    <td class="text-right"><? Echo $tran[igstamt]; ?></td>
                                <?php } ?>
                                <td class="text-right"><? Echo $tran[total]; ?></td>
                            </tr>

                            <tr style="height: <?= $tdhg; ?>">
                                <td class="numeric"></td>
                                <td><? Echo $tran[brand] ?></td>
                                <td><? Echo $tran[size] . '   ' . $tran[colour] ?></td>
                                <td></td>
                                <td></td>
                                <td class="text-right"></td>
                                <td class="numeric"></td>
                                <td class="numeric"></td>
                                <td class="numeric"></td>
                                <?php if ($oms == '') { ?>
                                    <td class="numeric"></td>
                                    <td class="numeric"></td>
                                    <td class="numeric"></td>
                                    <td class="numeric"></td>
                                <?php } else { ?>
                                    <td class="numeric"></td>
                                    <td class="numeric"></td>
                                <?php } ?>
                                <td class="numeric"></td>
                            </tr>

    <!--                            <tr style="height: <?= $tdhg; ?>">
                                    <td class="numeric"></td>
                                    <td><? Echo 'Size :' . $tran[size] . '   ' . $tran[colour] ?></td>
                                    <td class=""><? Echo $tran[frame]; ?></td>
                                    <td></td>
                                    <td></td>
                                    <td class="text-right"></td>
                                    <td class="numeric"></td>
                                    <td class="numeric"></td>
                                    <td class="numeric"></td>
                            <?php if ($oms == '') { ?>
                                            <td class="numeric"></td>
                                            <td class="numeric"></td>
                                            <td class="numeric"></td>
                                            <td class="numeric"></td>
                            <?php } else { ?>
                                            <td class="numeric"></td>
                                            <td class="numeric"></td>
                            <?php } ?>
                                    <td class="numeric"></td>
                                </tr>-->


                            <?
                            $ctab = $ctab + 3;
                        }
                        if ($ctab < 18) {
                            for ($i = $ctab; $i < 19; $i++) {
                                ?>
                                <tr style="height: <?= $tdhg; ?>">
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <?php if ($oms == '') { ?>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                    <?php } else { ?>
                                        <td></td>
                                        <td></td>
                                    <?php } ?>
                                    <td></td>
                                </tr>
                                <?php
                            }
                        }
                        ?> 
                    </table>
                </div>
            </div>
        </div>
        <div class="border">
            <div class="row">
                <div class="col-sm-12" style="padding: 0px">
                    <table class="table-hover pad" style="float: left;width:50%">
                        <tr>
                            <td><label class="smfont pad"><? Echo $qry[rem1] ?></label></td>
                        </tr>
                        <tr>
                            <td><label class="smfont pad"><? Echo $qry[rem2]; ?></label></td>
                        </tr>
                    </table>
                    <table class="table-hover  pad" style="float:left;width:50%">
                        <tr>
                            <td><label class="smfont pad">Sub Total</label></td>
                            <td class="numeric" style="text-align:left "><label class="smfont pad"></label></td>
                            <td class="numeric"><label class="smfont pad" style="text-align:right"><? echo $qry[grossamt]; ?></label></td>
                        </tr>
                        <tr>
                            <td><label class="smfont pad">Discount</label></td>
                            <td><label class="smfont pad" style="text-align:left "><? $qry[discperc]; ?></label></td>
                            <td class="numeric"><label class="smfont pad"><? Echo $qry[discamt]; ?></label></td>
                        </tr>
                        <tr>
                            <td><label class="smfont pad">Taxable Value</label></td>
                            <td class="numeric" style="text-align:left "><label class="smfont pad"></label></td>
                            <td class="numeric"><label class="smfont pad"><? Echo $qry[taxableamt]; ?></label></td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12" style="padding: 0px">
                    <table class="table-hover " style="float: left;width:50%">
                        <table class="table-hover " style="float: left;width:50%">
                            <tr>
                                <td><label class="smfont pad">GST NO. : </label> <? Echo $comp2[gstno]; ?></td>
                            </tr>
                            <tr>
                                <td><label class="smfont pad">Bank Name : </label> <? Echo $comp2[bankname]; ?></td>
                            </tr>
                            <tr>
                                <td><label class="smfont pad">Branch Name : </label> <? Echo $comp2[branchname]; ?></td>
                            </tr>
                            <tr>
                                <td><label class="smfont pad">Account No. : </label> <? Echo $comp2[acno]; ?></td>
                            </tr>
                            <tr>
                                <td><label class="smfont pad">IFC Code : </label> <? Echo $comp2[ifccode]; ?></td>
                            </tr>
                        </table>
                    </table>
                    <table class="table-hover table-bordered" style="float: left;width:50%">
                        <tr style="height: 21px">
                            <td width="10%"></td>
                            <td width="18%" class='text-right'>CGST</td>
                            <td width="18%" class='text-right'>SGST</td>
                            <td width="18%" class='text-right'>IGST</td>
                            <td width="35%"></td>
                        </tr>
                        <?php
                        Echo "<tr style='height: 21px'>";
                        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'><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'><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'><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>";
                        ?>
                    </table>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12" style="padding: 0px">
                    <table class="table-hover " style="float: left;width:50%">
                        <tr>
                            <td><label class="smfont pad"> </label> <? ?></td>
                        </tr>
                    </table>
                    <table class="table-hover " style="float: left;width:50%">
                        <tr>
                            <td><label class="smfont pad">Roundoff</label></td>
                            <td class="numeric" style="text-align:left "><label class="smfont pad"></label></td>
                            <td class="numeric"><label class="smfont pad"><? Echo $qry[roundoff]; ?></label></td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12" style="padding: 0px">
                    <table class="table-hover " style="float: left;width:50%">
                        <tr>
                            <td><label class="smfont pad"> </label> <? ?></td>
                        </tr>
                    </table>
                    <table class="table-hover tborder" style="float: left;width:50%">
                        <tr>
                            <td><label class="smfont pad">Bill Amount</label></td>
                            <td class="numeric"><label class="smfont pad"><i class="fa fa-rupee"></i></label></td>
                            <td class="numeric"><label class="smfont pad"><? Echo number_format(round($qry[nettotal]), 2); ?></label></td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        <?php
        $mwords = round($qry[totbillamt]);
//            $words = convert_number_to_words($mwords);
        $words = rsword($mwords);
        ?>
        <div class="border">
            <div class="row">
                <div class="col-sm-6" style="padding: 0px">
                    <label class="smfont pad"><?php Echo $words . " Only"; ?></label>
                </div>
            </div>
        </div>
        <?php $content = "Certified that the particulars given above are true and correct." ?>
        <div class="">
            <div class="row">
                <div class="col-sm-12" style="padding:0px">
                    <table class="" width='50%' style="float:left">
                        <tr>
                            <td><label class="smfont">E.O.& E.</label></td>
                            <td><label style="font-size:10px">Subject to Navi Mumbai Jurisdiction</label></td>
                        </tr>
                    </table>
                    <table width='50%'>
                        <tr>
                            <td class="numeric">
                                <label class="smfont"><?php Echo "For " . $comp["compname"] ?></label><br>
                            </td>
                        </tr>
                    </table>
                    <table>
                        <tr>
                            <td><label class="smfont pad" style="text-align:right;"><?php Echo $content ?></td>
                        </tr>
                    </table>
                </div>
            </div>
            <br>
            <div class="row">
                <div class="col-sm-12" style="padding:0px">
                    <table  style="float:right">
                        <tr>
                            <td>
                                <label class="smfont" style="text-align:right;" ><?php Echo "Authorised Signatory"; ?></label><br>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>


























            <!--                <div class="row">
                                <div class="col-sm-12" style="padding:0px">
                                    <table class="" width='50%' style="float:left">
                                        <tr>
                                            <td>
                                                <label style="font-size:10px">
                                                    " I / We hereby certify that  my / our registration  certificate  under  the  
                                                    Maharashtra Value Added Tax Act  2002  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='50%'>
                                        <tr>
                                            <td class="numeric">
                                                <label class="smfont" style="margin-top: 15%;">Authorized Signatory</label><br>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>-->
        </div>
    </div>
</div>
<?php include('includes/linksfoot.php'); ?>
