<?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 = "Inward Export";
$maindb = 'inwexpmain';
$trandb = 'inwexptran';
$root = 'apps4rea_khoj_root';
$fseries = $_SESSION["series_" . $dbname];

$getqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as mydt FROM `$maindb` WHERE vouchno='$vouch' AND `series`='$fseries' 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;
    }

</style>
</head>
<body>
    <?php
    $tdhg = "24px";
    $qry = mysqli_fetch_array($getqry);
    ?>
    <div class="page">
        <div class="subpage">
            <div class="row">
                <div class="col-sm-12 text-center">
                    <table style="width:100%">
                        <tr>
                            <td style="width:33.33%"></td> 
                            <td style="width:33.33%;text-align: center"><label class="label-control"><? Echo $formname; ?></label></td> 
                            <td style="width:33.33%;text-align: right"><label class="label-control">ESTD : 1952</label></td> 
                        </tr>
                    </table>
                </div>
            </div>
            <div class="row" style="margin-top:70px">
                <div class="col-sm-12"></div>
            </div>
            <div class="row">
                <div class="col-sm-12 text-right"><label class="label-control">www.everestcycle.com</label></div>
            </div>
            <div class="row">
                <div class="col-sm-12 text-justify">
                    <label class="label-control">
                        <? if($comp[address] == ""){ Echo "$comp2[add1]" . "$comp2[add2]" . "$comp2[add3]"; }else{Echo "$comp[address]"; } ?>
                    </label>
                </div>
            </div>
            <div class="border">
                <div class="row">
                    <table style="width: 100%">
                        <tr>
                            <td width="5%" class="text-right"><label class="label-control">No  :</label></td>
                            <td width="20%"><label class="label-control"><? Echo $qry[billno]; ?></label></td>

                            <td width="25%"></td>
                            <td width="25%"></td>

                            <td width="5%" class="text-right"><label class="label-control">Date  :</label></td>
                            <td width="20%"><label class="label-control"><? Echo $qry[mydt]; ?></label></td>

                        </tr>
                    </table>
                </div>
                <div class="row">
                    <?
                    $getcust = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`='$qry[accode]' AND `grpcode`='010'")or die(mysqli_error($conn));
                    $cust = mysqli_fetch_array($getcust);
                    ?>
                    <table width="50%" class="table-hover pad">
                        <tr>
                            <td width="20%" valign="top" class="numeric">
                                <label class="smfont pad">M/s.</label>
                            </td>
                            <td width="80%" class="pad">
                                <label class="smfont"><? Echo $cust[name]; ?></label><br>
                                <label class="smfont"><? Echo $cust[add1]; ?></label><br>
                                <label class="smfont"><? Echo $cust[add2]; ?></label><br>
                                <?php if (!empty($cust[add3])) { ?>
                                    <label class="smfont"><? Echo $cust[add3]; ?></label><br>
                                <?php } ?>
                            </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 width="5%" class="numeric">Sr</th>
                                <th width="15%">Barcode</th>
                                <th width="20%">Item</th>
                                <th width="10%">Brand</th>
                                <th width="10%">Size</th>
                                <th width="10%">Colour</th>
                                <th width="10%">Unit</th>
                                <th class="numeric" width="15%">Qty.</th>
                            </tr>
                            <?
                            $ctab = 0;
                            $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$qry[vouchno]' AND `series`='$fseries' 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 $tran['barcode']; ?></td>
                                    <td ><? Echo $item['name']; ?></td>
                                    <td ><? Echo $tran['brand']; ?></td>
                                    <td ><? Echo $tran['size']; ?></td>
                                    <td ><? Echo $tran['colour']; ?></td>
                                    <td ><? Echo $tran['unit']; ?></td>
                                    <td class="numeric"><? Echo $tran[qty]; ?></td>
                                </tr>
                                <?
                                $ctab = $ctab + 1;
                            }
                            if ($ctab < 4) {
                                for ($i = $ctab; $i < 5; $i++) {
                                    ?>
                                    <tr style="height: <?= $tdhg; ?>">
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <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 rborder pad" style="float: left;width:65%">
                            <tr>
                                <td><label class="smfont pad"><? Echo $qry[remark1] . $qry[remark2]; ?></label></td>
                            </tr>
                            <tr>
                                <td><label class="smfont pad">VAT TIN : </label> <? Echo $comp[cstno]; ?></td>
                            </tr>
                            <tr>
                                <td><label class="smfont pad">CST TIN : </label> <? Echo $comp[cstno]; ?></td>
                            </tr>
                        </table>
                        <table class="table-hover" style="float: left;width:35%">
                            <tr>
                                <td><label class="smfont pad">Total Qty.</label></td>
                                <td><label class="smfont pad"></label></td>
                                <td class="numeric"><label class="smfont pad"><? Echo $qry[totqty]; ?></label></td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12" style="padding: 0px">
                        <table class="table-hover rborder" style="float: left;width:65%">
                            <tr>
                                <td><label class="smfont pad">NMMC LBT NO. : </label> <? Echo $comp2[nmmc]; ?></td>
                            </tr>
                        </table>
                        <table class="table-hover tborder" style="float: left;width:35%">
                            <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[billamt]), 2); ?></label></td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
            <?php
            $mwords = round($qry[billamt]);
//            $words = convert_number_to_words($mwords);
            $words = rsword($mwords);
            ?>
            <div class="border">
                <div class="row">
                    <div class="col-sm-12" style="padding: 0px">
                        <label class="smfont pad"><?php Echo $words . " Only"; ?></label>
                    </div>
                </div>
            </div>
            <?php
            ?>
            <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>
                    </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'); ?>
