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

$formname = 'Excess';
$maindb = 'excmain';
$trandb = 'exctran';
/*$accdb = 'actran';*/
$file = 'excess.php';
$source = "EX";
/*$grid = 'salemain.php';*/

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);

//$zdb1 = 'cepheisy_sis_zyc_1_1516';
$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));
?>

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

    
        <?php 
        include("includes/files.php");
        include("includes/tabsuf.php");
        ?>
    </head>
    <style>
            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;
        }
    }
    .border{
        border: 1px solid;
    }
    </style>

    <body id="main_container">
        <div class="book">
            <div class="page">
                <!--<div class="subpage">-->
                    <!--   ************Header************  -->
                    <div style="border:solid 1px;" class="col-md-12" >
                        <?php
                        require("includes/dbconnect.php");
                        $comp = mysqli_query($conn, "SELECT * FROM `company`") or die(mysqli_errno($conn));
                        $zcomp = mysqli_fetch_assoc($comp);
                        ?>
                        <b><center><?php echo $zcomp["compname"]; ?></center></b>
                        <h5><center><?php echo $formname; ?></center></h5>
                        
                    </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[accode]") or die(mysqli_error($conn));
                        $cust = mysqli_fetch_array($gcust);
                        ?>
                        <table width="100%">
                            <tr>                                                                
                                <td style="text-align: left;">
                                    <b>Voucher :</b>
                                    <?php echo "$getmdata[vouchno]"; ?> 
                                </td>
                                <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>Godown :</b>
                                    <?php echo "$getmdata[godown]"; ?> 
                                </td>
                            </tr>
                            <tr>
                                <td style="text-align: left;"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><?php echo "$cust[add2]"; ?></td>
                            </tr>
                            <tr>
                                <td style="text-align: left;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo "$cust[add3]"; ?></td>
                            </tr>
                        </table>
                    </div>
                    <div>
                        <table width="100%" border="solid 1px">
                            <tr>
                                <th width="5%" class="border" style="height:33px; text-align: center;"><font size="2px">Sr</font></th>
                                <th width="10%" class="border" style="height:33px; text-align: center;"><font size="2px">Barcode</font></th>
                                <th width="25%" class="border" style="height:33px; text-align: center;"><font size="2px">Item</font></th>
                                <th width="8%" class="border" style="height:33px; text-align: center;"><font size="2px">Qty.</font></th>
                                <th width="9%" class="border" style="height:33px; text-align: center;"><font size="2px">Rate</font></th>
                                <th width="9%" class="border" style="height:33px; text-align: center;"><font size="2px">Total</font></th>                                                                
                                <th width="9%" class="border" style="height:33px; text-align: center;"><font size="2px">MRP</font></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 * FROM `item` WHERE `code`=$row[itemcode]") or die(mysqli_error($conn));
                                $gtit = mysqli_fetch_array($getitem);
                                ?>
                                <tr class="border" style="height: 25px;">
                                    <td class="border" style="text-align: center;"><?php echo "$row[srno]"; ?></td>
                                    <td class="border" ><?php echo "$row[barcode]"; ?></td>
                                    <td class="border"><?php echo "$gtit[name]"; ?></td>
                                    <td class="border" style="text-align: right"><?php echo "$row[qty]"; ?></td>
                                    <td class="border" style="text-align: right"><?php echo "$row[rate]"; ?></td>
                                    <td class="border" style="text-align: right"><?php echo "$row[amt]"; ?></td>                                                                        
                                    <td class="border" style="text-align: right"><?php echo "$row[mrp]"; ?></td>
                                </tr>
                                <?
                                $ctab = $ctab + 1;
                            }
                            if ($ctab < 15) {
                                for ($i = $ctab; $i <= 20; $i++) {
                                    $ctab = $ctab + 1;
                                    ?>
                                    <tr style="height: 25px;">
                                        <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
                                }
                            }
                            ?>  
                        </table>
                        <table class="" style="border: 1px solid black;" width="">
                            <tr>
                                <td class="" style="text-align: right;"></td>             
                                <td class="" style="text-align: right;"></td>             
                                <td class="" style="text-align: right;"></td>
                                <td class="" style="text-align: right;padding-left: 0px; ">Total Qty.</td>
                                <td class="" style="text-align: right; "><? echo "$getmdata[totqty]"; ?></td>                            
                                <td class="" style="text-align: right;padding-left:70px; "><span style="font-weight: 600">Net Amount</span></td>
                                <td class="" style="text-align: right; "><span style=" font-weight: 00"><? echo "Rs. $getmdata[billamt]"; ?></span></td>
                            </tr>
                            <tr>
                                <td>
                                    <?php echo rsword(round($getmdata["billamt"])); ?>
                                </td>
                                <td></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td class="" style="text-align: left; "><span style="font-weight: 00"><? echo "$getmdata[rem1]"; ?></span></td>
                                <td class="" style="text-align: right;"><span style=" "></span></td>                            
                                <td class="" style="text-align: right;"><span style=" "></span></td>             
                                <td class="" style="text-align: right;padding-left:70px; "><span style="font-weight: 600"></span></td>
                                <td class="" style="text-align: right; "><span style=" font-weight: 00"><? ?></span></td>
                            </tr>
                            
                        </table>
                    </div>
                    
                    <div>
                        <table class="border">
                            <tr>
                                <td class="border" style="width: 541px; font-size: 14px;">
                                    
                                </td>
                                <td class="border" style="width: 216px">
                                    <div style=" font-size: 14px; font-weight: 900"><? echo "For $zcomp[compname]"; ?></div>
                                    <br>
                                    <br>
                                    <br>
                                    <div style=" margin-left: 51px; font-size: 14px">AUTHORISED SIGNATORY</div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>    
            <!--</div>-->
        </div>
        <?php
        include("includes/files_footer.php");
        ?>
        <script>
            $(function() {
                formGeneral();
            });
        </script>
    </body>
</html>
