<?php
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');
//browse(1);
$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
$zcomp = $_SESSION["comp_" . $dbname];

$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$vouch = $_GET['vouchno'];

$cond = '';
$lcond = '';


$maindb = 'estmain';
$trandb = 'esttran';

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

$getdata = mysqli_fetch_array($getqry);

$cmpname = mysqli_query($conn, "SELECT * From $zroot.`company`") or die(mysqli_error($conn));
$getcmpname = mysqli_fetch_array($cmpname);

//$getparty = mysqli_query($conn, "SELECT `accode`,`name` From accmast WHERE `accode` = '$getdata[party]'")or die(mysqli_error($conn));
//$showparty = mysqli_fetch_array($getparty);
//include("includes/linkshead.php");  
?>

<!DOCTYPE HTML>
<html lang="en-US">
<style>
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        /*background-color: #FAFAFA;*/
        font: 12pt "Tahoma";
    }

    @media print {
        .noprint {
            display: none;
            position: fixed;
            bottom: 0;
        }
    }

    * {
        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 {
        .noPrint {
            display: none;
        }

        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;
    }

    .outer {
        width: 100%;
        border-collapse: collapse;
        border: 1px solid black;
    }

    .center {
        text-align: center;
    }

    .B {
        padding-left: 15px;
    }


    .d {
        border-collapse: inherit;
    }


    .w {
        width: 40%;
    }
</style>

</head>

<body id="main_container">
    <div class="book tablerep">
        <!--        <div class="col-lg-12 pad text-right">
                        <button id="create_pdf" name="create_pdf" style="color: #26A69A;background: white; border: 1px black solid" type="button" class="btn btn-danger"><span style="text-align: right;">&nbsp;&nbsp;PDF&nbsp;&nbsp;</span></button>
                    </div>-->
        <button onclick="window.print();
                return false;" class="btn btn-primary noPrint" style="width: 150px;height:35px;background-color: #A0B1BA;color:white;">Print</button>
        &nbsp;&nbsp;&nbsp;
        <button class="btn btn-primary goBack noPrint" onclick="window.close()" style="width: 150px;height:35px;background-color: white;color:#A0B1BA;padding-left: 1%">Go Back</button>
        <div class="page">
            <!--<div class="subpage">-->
            <!--   ************Header************  -->

            <div class="">
                <div class="row">
                    <?php include('includes/inv_head1_print.php'); ?>
                </div>


                <br>
                <?php include('includes/inv_head2_print.php'); ?>
                <div>
                    <table border="solid 1px" style="border-collapse: collapse; width:100%">
                        <tr style="background-color:#CEA962 !important; -webkit-print-color-adjust: exact;">
                            <th style="width:5%" class="text-right">SR.</th>
                            <th style="width:40%" class="text-left">PARTICULARS</th>
                            <th style="width:10%" class="text-left">IMAGE</th>
                            <th style="width:7%;text-align:right" class="text-right">QTY.</th>
                            <th style="width:7%;">Unit</th>
                            <th style="width:10%" class="text-center">SQ.FT</th>
                            <th style="width:10%;text-align:right" class="text-right">RATE</th>
                            <th style="width:10%;text-align:right" class="text-right">AMOUNT</th>
                        </tr>

                        <?php
                        $ctr = 0;
                        $ctab = 0;
                        $totqty = 0;
                        $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$vouch' order by srno") or die(mysqli_error($conn));
                        while ($row = mysqli_fetch_array($gettran)) {
                            if ($row['qty'] > 0) {
                                $qty = $row['qty'];
                            } else {
                                $qty = "";
                            }
                            if ($row['rate'] > 0) {
                                $rate = $row['rate'];
                            } else {
                                $rate = "";
                            }
                            if ($row['amount'] > 0) {
                                $amount = $row['amount'];
                            } else {
                                $amount = 0;
                            }
                            $ctr++;

                            echo "<tr>";

                            echo "<td class='text-left'>$ctr</td>";
                            echo "<td class='text-left'>$row[particulars]</td>";
                            echo "<td class='text-left'><img src='$row[image]' alt=''Ali style='height:50px;width:70px;'></td>";
                            echo "<td class='text-right' style='text-align:'>$qty</td>";
                            echo "<td class='text-right' style='text-align:center'>$row[unitname]</td>";
                            echo "<td style='text-align:center'>$row[unit]</td>";
                            echo "<td class='text-right' style='text-align:right'>$rate</td>";
                            echo "<td class='text-right' style='text-align:right'>$amount</td>";
                            echo "</tr>";

                            $ctab++;
                            if ($ctab > 5) {
                        ?>
                                <tr>
                                    <td colspan="8" style="text-align:right">Continued...</td>
                                </tr>
                    </table>
                </div>
                <?php include('includes/inv_foot1_print.php'); ?>
                <?php include('includes/inv_foot2_print.php'); ?>
            </div>
            <div class="">
                <div class="row">
                    <?php include('includes/inv_head1_print.php'); ?>
                </div>
                <br>
                <?php include('includes/inv_head2_print.php'); ?>
                <div>
                    <table border="solid 1px" style="border-collapse: collapse; width:100%">
                        <tr style="background-color:#CEA962 !important; -webkit-print-color-adjust: exact;">
                            <th style="width:5%" class="text-right">SR.</th>
                            <th style="width:40%" class="text-left">PARTICULARS</th>
                            <th style="width:10%" class="text-left">IMAGE</th>
                            <th style="width:7%;text-align:right" class="text-right">QTY.</th>
                            <th style="width:7%;">Unit</th>
                            <th style="width:10%" class="text-center">SQ.FT</th>
                            <th style="width:10%;text-align:right" class="text-right">RATE</th>
                            <th style="width:10%;text-align:right" class="text-right">AMOUNT</th>
                        </tr>

                    <?php
                                $ctab = 0;
                            }
                        }
                        $ctr = 0;
                        $totqty = 0;
                        if ($ctab < 5) {
                            for ($i = $ctab; $i <= 5; $i++) {
                                $ctab = $ctab + 1;
                                ?>
                                 <tr>
                            <td style="height: 50px;"></td>
                            <td style="height: 50px;"></td>
                            <td style="height: 50px;"></td>
                            <td style="height: 50px;"></td>
                            <td style="height: 50px;"></td>
                            <td style="height: 50px;"></td>
                            <td style="height: 50px;"></td>
                            <td style="height: 50px;"></td>
                        </tr>
                                <?php
                            }
                        }
                ?>

                <tr>
                    <td colspan="5" style="border-top:1px solid black"><? echo "$getdata[remark]" . " &nbsp;" . "$getdata[remark2]"; ?></td>
                    <td colspan="2" style="border-top:1px solid black;text-align: right;">Total</td>
                    <td style="text-align: right;border-left: none;"> <b><?php echo number_format($totamt, 2); ?> </b></td>
                </tr>

                <tr>
                    <td colspan="4">Created By : <b><? echo "$getdata[createby]"; ?></b></td>
                    <td colspan="4" style="text-align:right">Advance : <b><? echo "$getdata[advance]"; ?></b></td>
                </tr>
                <?php if ($getdata["discount"] > 0){ ?>
                    <tr>
                        <td colspan="4">&nbsp;</td>
                        <td colspan="4" style="text-align:right">Discount : <b><? echo "$getdata[discount]"; ?></b></td>
                    </tr>
                <?php } ?>
                <tr>
                    <td colspan="8" style="text-align:right">Final Total: <b><? echo "$getdata[finaltot]"; ?> </b></td>
                </tr>
                    </table>
                </div>
                <br>
                <?php include('includes/inv_foot1_print.php'); ?>
                <br>
                <?php include('includes/inv_foot2_print.php'); ?>
            </div>
        </div>
    </div>
    <?php
    include("includes/linksfoot.php");
    ?>

</body>

</html>