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

$cond = '';
$lcond = '';
$formname = "Purchase Return";
$maindb = 'debmain';
$trandb = 'debtran';

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

if (mysqli_num_rows($getqry) <= 0) {
    browse("Record Not Found");
}
include("includes/linkshead.php");
?>
<link href="MyStyle/rep_format.css" rel="stylesheet">
<style>
    body{
        font-size: 15px;
    }
    .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">
                <?php // include("includes/head_rep.php"); ?>
                <div class="col-sm-12 " style="height: 120px"></div>
            </div>
            <div class="row">
                <div class="col-sm-12 text-center">
                    <label class="label-control"><? Echo $formname; ?></label>
                </div>
            </div>
            <div class="border">
                <div class="row" style="margin-top: 15px">
                    <table style="width: 100%">
                        <tr>
                            <td width="25%"></td>
                            <td width="25%"><label class="label-control">No  : <? Echo $qry[invno]; ?></label></td>
                            <td width="25%" class="text-right"><label class="label-control">Date: <? Echo $qry[mydt]; ?></label></td>
                            <td width="25%"></td>
                        </tr>
                    </table>
                </div>
                <div class="row">
                    <?
                    $getsupp = mysqli_query($conn, "SELECT * FROM `accmast` WHERE  `accode`='$qry[party]' AND `grpcode`='009'")or die(mysqli_error($conn));
                    $supp = mysqli_fetch_array($getsupp);
                    ?>
                    <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 $supp[name]; ?></label><br>
                                <label class="smfont"><? Echo $supp[add1]; ?></label><br>
                                <label class="smfont"><? Echo $supp[add2]; ?></label><br>
                                <label class="smfont"><? Echo $supp[add3]; ?></label><br>
                            </td>
                        </tr>
                    </table>
                </div>
<!--                <div class="row">
                    <?
                    $getbrok = mysqli_query($conn, "SELECT * FROM `accmast` WHERE  `accode`='$qry[broker]'")or die(mysqli_error($conn));
                    $brok = mysqli_fetch_array($getbrok);
                    $gettrsp = mysqli_query($conn, "SELECT * FROM `transport` WHERE  `code`='$qry[transporter]'")or die(mysqli_error($conn));
                    $trsp = mysqli_fetch_array($gettrsp);
                    ?>
                    <div class="col-sm-12">
                        <table style="width: 100%">
                            <tr>
                                <td width="50%" class="table-hover">
                                    <table width="100%">
                                        <tr>
                                            <td width="20%" class="numeric"><label class="smfont pad">Broker :</label></td>
                                            <td width="80%"><label class="smfont pad"><? Echo $brok[name]; ?></label></td>
                                        </tr>
                                    </table>
                                </td>
                                <td width="50%">
                                    <table width="100%">
                                        <tr>
                                            <td width="40%" class="numeric"><label class="smfont">Transporter :</label></td>
                                            <td width="60%"><label class="smfont"> <? Echo $trsp[name]; ?></label></td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12">
                        <table style="width: 100%">
                            <tr>
                                <td width="50%"></td>
                                <td width="50%">
                                    <table width="100%">
                                        <tr>
                                            <td width="40%" class="numeric"><label class="smfont">L.R.Date : </label></td>
                                            <td width="60%"><label class="smfont"><? Echo $qry[lrdate]; ?></label></td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </div>
                </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">
                                <th width="12%">Type</th>
                                <th width="35%">Description</th>
                                <th class="numeric" width="6%">Pcs.</th>
                                <th class="numeric" width="8%">Mtrs</th>
                                <th class="numeric" width="12%">Nett.Mtrs</th>
                                <th class="numeric" width="11%">Rate</th>
                                <th class="numeric" width="15%">Amount</th>
                            </tr>
                            <?
                            $ctab = 0;
                            $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE  `vouchno`='$qry[vouchno]' ORDER BY `brand`, itemcode")or die(mysqli_error($conn));
                            while ($tran = mysqli_fetch_array($gettran)) {

                                $getbrand = mysqli_query($conn, "SELECT * FROM `brand` WHERE `code`='$tran[brand]'")or die(mysqli_error($conn));
                                $brand = mysqli_fetch_array($getbrand);

                                $getitem = mysqli_query($conn, "SELECT * FROM `item` WHERE `code`='$tran[itemcode]'")or die(mysqli_error($conn));
                                $item = mysqli_fetch_array($getitem);

                                $gettype = mysqli_query($conn, "SELECT * FROM `type` WHERE `code`='$qry[type]'")or die(mysqli_error($conn));
                                $type = mysqli_fetch_array($gettype);
                                ?>
                                <tr>
                                    <td><? Echo $type[name]; ?></td>
                                    <td>
                                        <table width="100%">
                                            <tr>
                                                <td width="50%"><b><? Echo $brand[name]; ?></b></td>
                                            </tr>
                                            <tr>
                                                <td width="50%"><? Echo $item[name]; ?></td>
                                            </tr>
                                        </table>
                                    </td>
                                    <td class="numeric"><? Echo $tran[taka]; ?></td>
                                    <td class="numeric"><? Echo $tran[qty]; ?></td>
                                    <td class="numeric"><? Echo $tran[invqty]; ?></td>
                                    <td class="numeric"><? Echo $tran[rate]; ?></td>
                                    <td class="numeric"><? Echo $tran[amount]; ?></td>
                                </tr>
                                <?
                                $ctab = $ctab + 1;
                                $tottaka = $tran[taka] + $tottaka;
                                $totqty = $tran[invqty] + $totqty;
                            }
                            if ($ctab < 16) {
                                for ($i = $ctab; $i <= 15; $i++) {
                                    $ctab = $ctab + 1;
                                    ?>
                                    <tr style="height: 35px;">
                                        <td></td>
                                        <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"><? Echo $qry[remark1]; ?></label></td>
                            </tr>
                            <tr>
                                <td><label class="smfont"><? Echo $qry[remark2]; ?></label></td>
                            </tr>
                            <tr>
                                <td><label class="smfont"><? Echo $qry[remark3]; ?></label></td>
                            </tr>
                            <tr>
                                <td><label class="smfont"><? Echo $qry[remark4]; ?></label></td>
                            </tr>
                        </table>
                        <table class="table-hover" style="float: left;width:35%">
                            <tr>
                                <td><label class="smfont pad">Sub Total</label></td>
                                <td><label class="smfont pad"></label></td>
                                <td class="numeric"><label class="smfont pad"><? Echo $qry[subtotal]; ?></label></td>
                            </tr>
                            <tr>
                                <td><label class="smfont pad"></label></td>
                                <td><label class="smfont pad"></label></td>
                                <td class="numeric"><label class="smfont pad"></label></td>
                            </tr>
                            <tr>
                                <td><label class="smfont pad">Discount </label></td>
                                <td class="numeric"><label class="smfont pad"><? Echo $qry[discperc] . "%"; ?></label></td>
                                <td class="numeric"><label class="smfont pad"><? Echo $qry[discount]; ?></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">Total : </label></td>
                                <td><label class="smfont pad"><? Echo $tottaka . " Pcs."; ?></label></td>
                                <td><label class="smfont pad">Total : </label></td>
                                <td><label class="smfont pad"><? Echo $totqty . " Mtrs."; ?></label></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 $qry[netamt]; ?></label></td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
            <?php
            $mwords = round($qry[netamt]);
            $words = convert_number_to_words($mwords);
            ?>
            <div class="border">
                <div class="row">
                    <div class="col-sm-12" style="padding: 0px">
                        <label class="smfont"><?php Echo $words . " Only"; ?></label>
                    </div>
                </div>
            </div>
            <?php
            $getcomp = mysqli_query($conn, "SELECT * FROM cepheisy_fab_root.`company`")or die(mysql_errror());
            $comp = mysqli_fetch_array($getcomp);
            ?>
            <div class="">
                <div class="row">
                    <div class="col-sm-12" style="padding:0px">
                        <table class="table-hover" width='100%'>
                            <tr>
                                <td><label class="smfont">E.O.& E.</label></td>
                                <td class="numeric">
                                    <label class="smfont"><?php Echo "For " . $comp[name] ?></label><br>
                                    <img src="assets/img/sign.jpg" alt="sign">
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php include('includes/linksfoot.php'); ?>
