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

$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 = "Purchase Voucher";

$maindb = 'purmain';
$trandb = 'purtran';

$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));
$getmdata = mysqli_fetch_array($getqry);


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

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


    <?php
//        include("includes/files.php");
//        include("includes/tabsuf.php");
    ?>
    <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; 
    }
</style>
</head>

<!--<link href="MyStyle/rep_format.css" rel="stylesheet">-->

<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: white;color:#A0B1BA;">Go Back</button>
        <div class="page">
            <!--<div class="subpage">-->
            <!--   ************Header************  -->
            <div style="border:solid 1px;" class="col-md-12" >
                <center><p style="margin-top:2px;margin-bottom: 2px;font-size:11px; "><u>Subject To Mumbai Jurisdiction</u></p></center>

                <?php include("includes/head_print.php"); ?>

                <!--            <div style="border:solid 1px;" class="col-md-12" >
                                <h1 style="margin-top:2px;margin-bottom: 11px;"><center><? Echo $getcmpname['pname']; ?></center></h1>
                                <center><?php echo $getcmpname['add1'] . " " . $getcmpname['add2'] . " " . $getcmpname['add3']; ?></center>
                                <center><?php echo "Email :" . $getcmpname['email'] . " &nbsp " . "Contact No :" . $getcmpname['tel'] . " " . $getcmpname['mobile']; ?></center>
                                <h5 style="margin-top:2px;margin-bottom: 2px;"><center><b><?php echo $formname; ?></b></center></h5>
                
                            </div>-->
            </div>
            <div style="border:solid 1px;" class="col-md-12" style="padding-left: 1px ; padding-right: 1px">
                <?php
                mysqli_select_db($conn, $zdb);

                $gcust = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`=$getmdata[party]") or die(mysqli_error($conn));
                $cust = mysqli_fetch_array($gcust);
                ?>
                
                <table class="table table-border table-hover" style="width:100%">
                    <tr>
                        <td style="text-align: left;">
                            <b>M/s.</b><font size="3px" weight="bold"><?php echo "$cust[name]"; ?></font>
                        </td>
                        <td style="text-align: center;">
                            <b>Voucher :</b>
                            <?php echo "$getmdata[vouchno]"; ?> 
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: left;"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><?php echo "$cust[add1]"; ?></td>
                        <td style="padding-left: 74px;text-align: center;">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b style="text-align:right;">Date :</b>
                            <?php echo "$getmdata[vouchdt]"; ?> 
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: left;"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><?php echo "$cust[add2] $cust[add3]"; ?></td>
                        <td style="text-align: center;">
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: left;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mobile :- <?php echo "$cust[mobile]"; ?></td>
                    </tr>
                </table>
            </div>
            <div>
                <table  border="solid 1px" style="border-collapse: collapse; width:100%">
                    <tr>
                        <th style="width:7%">Sr.</th>
                        <th style="width:47%">Itemname</th>
                        <th style="width:15%">Color</th>  
                        <th class="numeric" style="width:8%">Qty.</th>
                        <th class="numeric" style="width:8%">Rate</th>
                        <th class="numeric" style="width:15%">Amount</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;

                    while ($row = mysqli_fetch_array($tranpart)) {
                        $getitem = mysqli_query($conn, "SELECT code,name FROM `item` WHERE `code`=$row[itemcode]") or die(mysqli_error($conn));
                        $gtit = mysqli_fetch_array($getitem);
                        $getcolor = mysqli_query($conn, "SELECT code,name FROM `color` WHERE `code`=$row[color]") or die(mysqli_error($conn));
                        $gtcl = mysqli_fetch_array($getcolor);
                        ?>
                        <tr class="" style="height: 27px;">
                            <td class="" style="text-align: center;"><?php echo "$row[srno]"; ?></td>
                            <td><? Echo $gtit['name']; ?></td>
                            <td><? Echo $gtcl['name']; ?></td>
                            <td class="numeric"><? Echo $row['qty']; ?></td>
                            <td class="numeric"><? Echo $row['rate']; ?></td>
                            <td class="numeric"><? Echo $row['amount']; ?></td>
                        </tr>
                        <?
                        $ctab = $ctab + 1;
                        $totqty = $row['qty'] + $totqty;
                    }
                    if ($ctab < 20) {
                        for ($i = $ctab; $i <= 20; $i++) {
                            $ctab = $ctab + 1;
                            ?>
                                                                <!--<tr style="height:25px;"></tr>-->
                            <tr style="height: 25px;">
                                <td></td> 
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                            </tr>      
                            <?php
                        }
                    }
                    ?>  
                    <!--                </table>
                                    <table class="" style="border: 1px solid black;" width="100%">-->
                    <tr style="">
                        <td colspan="2" style="border:none" ><? echo "$getmdata[remark1] $getmdata[remark2]"; ?></td>
                        <td colspan="" style="text-align: right;border:none" > Total</td>
                        <td style="text-align: right;border:none "> <? echo $totqty; ?>  </td>
                        <td style="border:none;text-align: right">Subtotal  </td>
                        <td style="text-align: right;border-left: none;"> <? echo  $getmdata['subtotal']; ?>  </td>

                    </tr>
                    
                    <?php  
                    
                     if($getmdata['lesother'] > 0) {?> 
                    <tr>
                        <td colspan="3" style="text-align: right;" class="rnone"> Less Discount  </td>
                        <td style="text-align: right; " class="lnone rnone">   </td>
                        <td class="lnone rnone"></td>
                        <td style="text-align: right;" class="lnone "> <? echo  $getmdata['lesother']; ?>  </td>
                    </tr>
                     <?php }
                     
                     
                     if($getmdata['netamt'] > 0) {?> 
                    <tr>
                        <td colspan="3" style="text-align: right; "class=" rnone"><b>Total Amount</b></td>
                        <td style="text-align: right; "class="lnone rnone"><b></b></td>
                        <td class="lnone rnone"></td>
                        <td style="text-align: right; "class="lnone "><b><? Echo $getmdata['netamt']; ?></b></td>
                    </tr>
                    <?php } ?>
                    <tr>
                        <td colspan="8">
                            Rupees 
                            <?php echo rsword(round($getmdata['netamt'])); ?>
                        </td>

                    </tr>
                </table>
            </div>

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