<?php
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$formname = 'Sale Invoice';
$maindb = 'salemain';
$trandb = 'saletran';
$file = '';
$source = "SL";
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
mysqli_select_db($conn, $zdb);
$mht = 'height:20px;';

$admin = $_SESSION["admin_" . $dbname];
$vouchno = $_REQUEST["vouchno"];
$mainqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') AS vouchdt FROM `$maindb` WHERE vouchno='$vouchno'") or die(mysqli_error($conn));
$getmdata = mysqli_fetch_array($mainqry) or die(mysqli_error($conn));

//$compqry = mysqli_query($conn, "SELECT * FROM $zroot.`company` WHERE `cono`= '1'") or die(mysqli_error($conn));
//$fcomp = mysqli_fetch_array($compqry);


$getpaccode = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`= '$getmdata[party]'") or die(mysqli_error($conn));
$getp = mysqli_fetch_array($getpaccode);
$add1 = $getp['add1'];
$add2 = $getp['add2'];
$add3 = $getp['add3'];
$city = $getp['city'];
$pin = $getp['pin'];
$paytype = $getmdata['paytype'];

//$gettrans = mysqli_query($conn, "SELECT name, code FROM `transpor` WHERE `code`= '$getmdata[transpor]'") or die(mysqli_error($conn));
//$ftrans = mysqli_fetch_array($gettrans);
?>

<!DOCTYPE HTML>
<html lang="en-US">
    <?php
    // include("includes/files.php");
    // include("includes/tabsuf.php");
    include("includes/linkshead.php");
    ?>
</head>
<link href="css/rep_format.css" rel="stylesheet" />
<style>
    /*    table tr td{
            font-size: 12px;
        }*/
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        padding-right:5px;
        padding-left:5px;
        padding-top:5px;
        padding-bottom:0px;

        /*background-color: #FAFAFA;*/
        font: 12pt "Tahoma";
    }
    .f12{
        font-size: 12px;
    }
    .f11{
        font-size: 11px;
    }
    .f13{
        font-size: 13px;
        font-weight: bold;
        padding:3px;
    }
    .f14{
        font-size: 14px;
    }
    .bold{
        font-weight: bold;
    }
    .page {
        width: 210mm;
        min-height: 290mm;
        padding: 1mm;
        margin: 1mm auto;
        border: 1px #D3D3D3 solid;
        border-radius: 1px;
        /*background: white;*/

    }

    .subpage{
        border: 1px solid black;


    }
    .border {
        border: 1px solid black;
        color: black;
        padding-right: 2px;
        padding-left: 3px;
    }
    th {
        font-weight: bold;
        font-size: 15px;
    }

    @media print {
        @page {
            size: a4;
            margin: 0;
        }

        .page {
            width: 208mm;
            min-height: 287mm;
            /* padding: 1mm; */
            /* margin: 1mm auto; */
            /*border: 1px  solid black;*/
            border-radius: 1px;
            /*background: white;*/

        }
        .border {
            border: 1px solid black;
            color: black;
            padding-right: 2px;
            padding-left: 3px;
        }
        th {
            font-weight: bold;
            font-size: 15px;
        } 
    }

</style>
<?php
//require("includes/dbconnect.php");
$comp = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_errno($conn));
$zcomp = mysqli_fetch_assoc($comp);
if ($paytype == 6) {
    $payno = $zcomp['gpaydno'];
} else {
    $payno = $zcomp['gpayno'];
}
?>
<!--<body id="main_container" onload="window.print();">-->
<body id="main_container" onload="">
    <div class="book">
        <div class="page">
            <div class="subpage">
                <table style="width:100%">

                    <tr>
                        <!--<td>-->
                        <!--<img src="images/kidslounge.png" align="center" style="width: 392px;height: 140px;">-->
                        <!--</td>-->
                        <td style=""><b style="font-size:32px;"><center><?php echo $zcomp['compname'] ?></center></b></td>
                    </tr>
                    <tr>
                        <td style=""><b style="font-size:32px;"><center>???? ????? ?????? ??????? ?</center></b></td>
                    </tr>
                    <tr>
                        <td><center><?php echo $zcomp['hoadd1'] . " " . $zcomp['hoadd2'] . " " . $zcomp['hoadd3'] . " " . $zcomp['hocity'] . " " . $zcomp['hopin']; ?></center></td>
                    </tr>
<!--                    <tr>
                        <td>Tel: <?php echo $zcomp['hotel']; ?></td>
                    </tr>
                    <tr>
                        <td>Email: <?php echo $zcomp['hoemail']; ?></td>
                    </tr>-->
                </table>

<!--                        <td style="width:50%">
    <table style="width:100%;">
        <tr>
            <td>&nbsp;<b>BUYER : <?= $getmdata['mobile']; ?></b></td>
        </tr>
        <tr>
            <td>&nbsp;<b><?= $getp['name']; ?></b></td>
        </tr>
        <tr>
            <td>&nbsp;<?= $add1; ?></td>
        </tr>
        <tr>
            <td>&nbsp;<?= $add2; ?></td>
        </tr>
        <tr>
            <td>&nbsp;<?= $add3; ?></td>
        </tr>
        <tr>
            <td>&nbsp;<?= $add4 . ' ' . $city . ' ' . $pin; ?></td>
        </tr>
        <tr>
            <td class="text-center">&nbsp;<b><?= $formname ?></b></td>
        </tr>
        <tr style="border-top:1px solid black">
            <td>&nbsp;<b>Invoice No. </b><?= $getmdata['vouchno']; ?>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                <span style="font-weight: bold"> Date </span> <?= $getmdata['vouchdt']; ?></td>
        </tr>
    </table>
</td>-->
                <!--                    </tr>
                                </table>-->
                <div style="border:1px solid black;">
                    <table style="width:100%" class="mc-table table-bordered">
                        <tr>
                            <th class="border" style="width:5%;  text-align: center;">Sr</th>
                            <th class="border" style="width:44%; text-align: center;">Product</th>
                            <!--<th class="border" style="width:10%; text-align: right;">Carton</th>-->
                            <th class="border" style="width:10%; text-align: right;">Qty.</th>
                            <!--<th class="border" style="width:10%; text-align: right;">Total</th>-->
                            <th class="border" style="width:10%; text-align: right;">Rate</th>
                            <th class="border" style="width:10%; text-align: right;">Amount</th>
<!--                            <th class="border" style="width:5%; text-align: right;">Disc.%</th>
                            <th class="border" style="width:7%; text-align: right;">Disc.</th>
                            <th class="border" style="width:5%; text-align: right;">Vat%</th>
                            <th class="border" style="width:7%; text-align: right;">Vat</th>-->
                            <!--<th class="border" style="width:12%; text-align: right;">Total</th>-->
                        </tr>

                        <?php
                        $tranpart = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$getmdata[vouchno]' order by srno") or die(mysqli_error($conn));
                        $mht = '20px';
                        $ctab = 0;
                        $grqty = 0;

                        while ($row = mysqli_fetch_array($tranpart)) {
                            $getbrand = mysqli_query($conn, "SELECT * FROM `product` WHERE code = '$row[itemcode]'") or die(mysqli_error($conn));
                            $getb = mysqli_fetch_array($getbrand);
                            ?>
                            <tr class="border" style="height:24px;">
                                <td class="border f12" style="text-align: center;"><?php echo "$row[srno]"; ?></td>
                                <td class="border f12"><?php echo "$getb[name]"; ?></td>
                                <!--<td class="border f12" style="text-align: right;"><?php echo "$row[cartqty]"; ?></td>--> 
                                <td class="border f12" style="text-align: right;"><?php echo "$row[qty]"; ?></td>
                                <!--<td class="border f12" style="text-align: right;"><?php echo "$row[totqty]"; ?></td>--> 
                                <td class="border f12" style="text-align: right"><?php echo "$row[rate]"; ?></td>
                                <td class="border f12" style="text-align: right"><?php echo "$row[amount]"; ?></td>
    <!--                                <td class="border f12" style="text-align: right"><?php // echo "$row[discperc]";    ?></td>
                                <td class="border f12" style="text-align: right"><?php // echo "$row[discamt]";    ?></td>
                                <td class="border f12" style="text-align: right"><?php // echo "$row[vatperc]";    ?></td>
                                <td class="border f12" style="text-align: right"><?php // echo "$row[vat]";    ?></td>
                                <td class="border f12" style="text-align: right"><?php // echo "$row[total]";    ?></td>-->
                            </tr>
                            <?
                            $ctab = $ctab + 1;
                            $grqty = $grqty + $row['qty'];
                            $totamt = $totamt + $row['amount'];
                        }
                        if ($ctab < 17) {
                            for ($i = $ctab; $i <= 17; $i++) {
                                $ctab = $ctab + 1;
                                ?>
                                <tr style="height:24px;">
                                    <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>
                                    <td class="border"></td>
                                    <td class="border"></td>-->

                                </tr>      
                                <?php
                            }
                        }
                        ?>  

                        <tr style="height:25px;">
                            <td class="border" colspan=""></td>        
                            <td class="border text-right f12 bold">Qty.</td>        
                            <td class="border text-right f12 bold"><?php echo number_format($grqty, 2) ?></td>        
                            <td class="border text-right f12 bold">Total</td>
                            <td class="border text-right f12 bold"><?php echo number_format(round($totamt), 2) ?></td>
                            <!--<td class="border"></td>-->
                        </tr> 
                        <?php if ($getmdata['totdisc'] > 0) { ?>
                            <tr style="height:25px;">
                                <td class="border" colspan="2"></td>        
                                <td class="border text-right f12 bold"></td>        
                                <td class="border text-right f11 bold">Discount</td>
                                <!--<td class="border text-right f11 bold"><?php // echo number_format(round($getmdata[cashdiscperc]),2) . " % &nbsp;&nbsp;" .number_format(round($getmdata[discount]),2)        ?></td>-->
                                <td class="border text-right f11 bold"><?php echo number_format(round($getmdata['totdisc']), 2) ?></td>
                                <!--<td class="border"></td>-->
                            </tr>    

                        <?php } ?>
                        <?php if ($getmdata['totvat'] > 0) { ?>
                            <tr style="height:25px;">
                                <td class="border" colspan="2"></td>        
                                <td class="border text-right f12 bold"></td>        
                                <td class="border text-right f11 bold">VAT</td>
                                <!--<td class="border text-right f11 bold"><?php // echo number_format(round($getmdata[cashdiscperc]),2) . " % &nbsp;&nbsp;" .number_format(round($getmdata[discount]),2)        ?></td>-->
                                <td class="border text-right f11 bold"><?php echo number_format(round($getmdata['totvat']), 2) ?></td>
                                <!--<td class="border"></td>-->
                            </tr>    

                        <?php } ?>
                        <tr style="height:25px;">
                            <td class="border" colspan="2"><?= $getmdata['rem1'] . ' ' . $getmdata['rem2']; ?></td>        

                            <td class="border text-right f10 bold" colspan="2">Bill Amount</td>
                            <td class="border text-right f10 bold"><?php echo rajnumformat(round($getmdata['billamt'])) ?></td>

                        </tr>  
                        <tr style="height:25px;">
                            <td class="border" colspan="5">AED <?php echo rsword(round($getmdata['billamt'])); ?> Only</td>        
                        </tr>    
<!--                        <tr style="height:25px;">
                            <td class="border" colspan="8">GPAY No. <?= $payno ?></td>        

                        </tr>    -->
                    </table>
                    <table class="cust-cal table " style="" style="width:100%">

                        <tr>
                            <td style="width:50%">

<!--                                <table style="width:100%">
                                <?php if ($zcomp['bank'] != '') { ?>
                                                    <tr>
                                                        <td style="width:25%">Bank Name</td>
                                                        <td style="width:75%"><?= $zcomp['bank']; ?></td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width:25%">A/c. No.  </td>
                                                        <td style="width:75%"><?= $zcomp['acno']; ?></td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width:25%">Branch</td>
                                                        <td style="width:75%"><?= $zcomp['branch']; ?></td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width:25%">IFSC</td>
                                                        <td style="width:75%"><?= $zcomp['bankcode']; ?></td>
                                                    </tr>
                                                    <tr>
                                                        <td colspan="2">&nbsp;</td>
                                                    </tr>
                                <?php } ?>
                                    <tr>
                                        <td colspan="2"><b>Proforma Validity for only 12 hrs.</b></td>
                                    </tr>
                                </table>-->
                            </td>
                            <td style="width:50%">
                                <table style="width:100%">
                                    <tr>

                                        <td class="" style="text-align: right; width: 50%"><b><? echo "For $zcomp[compname]"; ?></b></td>

                                    <tr>
                                        <td class="" style="text-align: left; height: 50px;">&nbsp;</td>

                                    </tr>
                                    <tr>

                                        <td class="" style="text-align: right; width: 50%">Authorised Signatory</td>

                                    </tr>
                                </table>
                            </td>
                        </tr>
<!--                        <tr>
                            <td colspan="2">
                                <b style="font-size:16px">Rupess <?php echo rsword(round($getmdata["billamt"])); ?> Only</b>
                            </td>
                        </tr>-->
                    </table>
                </div>
            </div>    
        </div>
    </div>
    <?php
    include("includes/linksfoot.php");
    ?>
    <script>
        $(function () {
            formGeneral();
        });
    </script>
</body>
</html>
