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

$vouch = $_GET['vouchno'];
/*$ztit = $_SESSION["tit"];*/
$zdb = $_SESSION["zdbyear_$dbname"];
mysqli_select_db($conn, $zdb);

$maindb = 'outmain';
$trandb = 'outtran';

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

if (!empty($_POST['frmiv']) && !empty($_POST['toinv'])) {
    $frmiv = trim($_POST['frminv']);
    $toinv = trim($_POST['toinv']);
    $cond = "AND a.locker >= '$frmiv' AND a.locker <='$toinv'  ";
}

if (!empty($_POST['frmledger']) && !empty($_POST['toledger'])) {
    $frmledger = trim($_POST['frmledger']);
    $toledger = trim($_POST['toledger']);
    $lcond = "AND a.custcode >= '$frmiv' AND a.custcode <='$toinv'  ";
}


$qry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as mydt FROM `$maindb`  WHERE vouchno='$vouch'") or die(mysqli_error($conn));
$get = mysqli_fetch_object($qry);

$getengine = mysqli_query($conn, "SELECT `name` FROM `engine` WHERE code ='$get->engine'") or die(mysqli_error($conn));
$mengine = mysqli_fetch_object($getengine);


$getsite = mysqli_query($conn, "SELECT `name` FROM `site` WHERE code ='$get->site'") or die(mysqli_error($conn));
$msite = mysqli_fetch_object($getsite);

$getstaff = mysqli_query($conn, "SELECT `name` FROM `staff` WHERE code ='$get->staff'") or die(mysqli_error($conn));
$mstaff = mysqli_fetch_object($getstaff);

$getdtl = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE vouchno='$vouch' ORDER BY `srno`") or die(mysqli_error($conn));
?>
<html>
    <head>
        <title>Outward</title>
        <meta name="msapplication-TileColor" content="#5bc0de"/>
        <meta name="msapplication-TileImage" content="assets/img/metis-tile.png"/>

        <link rel="stylesheet" href="assets/lib/bootstrap/css/bootstrap.css">
        <link rel="stylesheet" href="assets/css/main.css"/>
        <link rel="stylesheet" href="assets/lib/Font-Awesome/css/font-awesome.css"/>

        <link rel="stylesheet" href="assets/css/theme.css">
        <style>
            .table{
                font-size: 13px;
            }
            #table{
                font-size: 13px;
            }
        </style>
    </head>
    <body>
<!--        <div class="toolbar">
             <ul class="nav">
                 <li>
                     <a class="accordion-toggle minimize-box" data-toggle="collapse" href="#div-1">
                        <i class="fa fa-chevron-up"></i>
                     </a>
                  </li>
              </ul>
                            </div>-->
        <table border="1" align="left" class="table " style="width: 100%;margin-top:0px;">        
            <tr>
                <td style='border-top: 1px solid black;'>
            <center><h3>OUTWARD</h3></center>
            <center><b>CHALLAN</b></center>
        </td>
        
    </tr>
    <tr>
        <td style='border-top: 1px solid black;'>
            <table style='width:100%' class='table'>
                <tr>
                    <td style='width:50%;border-top: 0px solid #dddddd;padding: 2px;'>
                        <table style='width:100%' class='table'>
                            <tr  style="height:30px">
                                <td style='float:left;border-top: 1px solid black;border-bottom: 1px solid black;border-left: 1px solid black;'>
                                    <b>Engine</b>
                                </td>
                                <td style='float:left;border-top: 1px solid black;border-bottom: 1px solid black;border-right: 1px solid black;'>
                                    : <b><?= $mengine->name ?></b>
                                </td>
                            </tr>
                            <tr>
                                <td style='float:left;border-bottom: 1px solid black;border-left: 1px solid black;height:30px;'>
                                    <b>Site</b>
                                </td>
                                <td style='float:left;border-bottom: 1px solid black;border-right: 1px solid black;height:30px;'>
                                    : <b><?= $msite->name ?></b>
                                </td>
                            </tr>
                           <tr>
                                <td style='float:left;border-left: 1px solid black;border-bottom: 1px solid black;width:30%;height:30px'>
                                    <b>Staff</b>
                                </td>
                               <td style='float:left;border-right: 1px solid black;border-bottom: 1px solid black;height:30px'>
                                    : <b><?= $mstaff->name ?></b>
                                </td>
                            </tr>                             
<!--                            <tr>
                                <td style='float:left;border-left: 1px solid black;border-bottom: 1px solid black;'>
                                    <b>Sale Order</b>
                                </td>
                                <td style='float:left;border-right: 1px solid black;border-bottom: 1px solid black;height:35px'>
                                     :<b><?= $get->saleord ?></b>
                                </td>

                            </tr>-->
                        </table>
                    <td style='width:50%;border-top: 0px solid #dddddd;padding: 2px;'>
                        <table style='width:100%' class='table'>
                            <tr  style="height:30px">
                                <td style='float:left;border-top: 1px solid black;border-bottom: 1px solid black;border-left: 1px solid black;'>
                                    <b>Bill No.</b>
                                </td>
                                <td style='float:left;border-top: 1px solid black;border-bottom: 1px solid black;border-right: 1px solid black;'>
                                    : <b><?= $get->vouchno ?></b>
                                </td>
                            </tr>
                            <tr>
                                <td style='float:left;border-bottom: 1px solid black;border-left: 1px solid black;height:30px;'>
                                    <b>Bill Date</b>
                                </td>
                                <td style='float:left;border-bottom: 1px solid black;border-right: 1px solid black;height:30px;'>
                                    : <b><?= $get->mydt ?></b>
                                </td>
                            </tr>
                           <tr>
                                <td style='float:left;border-left: 1px solid black;border-bottom: 1px solid black;width:30%;height:30px'>
                                    <b></b>
                                </td>
                               <td style='float:left;border-right: 1px solid black;border-bottom: 1px solid black;height:30px'>
                                    
                                </td>
                            </tr>                             
<!--                            <tr>
                                <td style='float:left;border-left: 1px solid black;border-bottom: 1px solid black;'>
                                    <b>Sale Order</b>
                                </td>
                                <td style='float:left;border-right: 1px solid black;border-bottom: 1px solid black;height:35px'>
                                     :<b><?= $get->saleord ?></b>
                                </td>

                            </tr>-->
                        </table>
                    </td>
                  
                </tr>
                <tr>
                    <td colspan='2'>
                        <table style='width:100%;border:1px solid black' id='table'>
                            <tr>
                                <th style='text-align: left;border:1px solid black;width:5%;'>Sr.</th>
                                <th style='text-align: left;border:1px solid black;width:50%;'>Item</th>
                                <th style='text-align: left;border:1px solid black;width:30%;'>Location</th>
                                <th style='text-align: right;border:1px solid black;width:15%;'>Qty.</th>
                            </tr>
                            <?php
                            $mrow = 0; 
                            $totqty = 0;
//                            $totpairs = 0;
                            
                            while ($row = mysqli_fetch_object($getdtl)) {
                                
                                $getitem = mysqli_query($conn, "SELECT * FROM `item` WHERE code ='$row->itemcode'") or die(mysqli_error($conn));
                                $mitem = mysqli_fetch_object($getitem);
                                
                                $getlocation = mysqli_query($conn, "SELECT * FROM `location` WHERE code ='$row->location'") or die(mysqli_error($conn));
                                $mlocation = mysqli_fetch_object($getlocation);
                                echo "<tr>";
                                echo "<td style='text-align: left;border:1px solid black;height:25px;'>$row->srno</td>";
                                echo "<td style='text-align: left;border:1px solid black;height:25px;'>$mitem->name</td>";
                                echo "<td style='text-align: left;border:1px solid black;height:25px;'>$mlocation->name</td>";
                                echo "<td style='text-align: right;border:1px solid black;height:25px;'>$row->qty</td>";
                                echo "</tr>";
                                echo "</tr>";
                                $mrow = $mrow + 1;
                                $totqty = $totqty + $row->qty;
                            }
                            if ($mrow < 10) {
                                for ($i = $mrow; $i <= 10; $i++) {
                                    echo "<tr>";
                                    echo "<td style='text-align: left;border:1px solid black;height:25px;'></td>";
                                    echo "<td style='text-align: left;border:1px solid black;height:25px;'></td>";
                                    echo "<td style='text-align: left;border:1px solid black;height:25px;'></td>";
                                    echo "<td style='text-align: left;border:1px solid black;height:25px;'></td>";
                                    
                                    echo "</tr>";
                                }
                            }
                            ?>
<!--                            <tr>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td><b>TOTAL</b></td>
                                <td style='border:1px solid black;text-align: right;'><b><?=$get->totqty?></b></td>
                            </tr>-->
                        </table>
                    </td>
                </tr>
             </table>
        </td> 
    </tr>
</table>
<table>
    <tr>
        <td style='float:left;'>
            <b>Remarks</b>
        </td>
        <td style='float:left;'>
            : <?= $get->rem1 ?>
        </td>
    </tr>
    <tr>
        <td style='float:left;'>
        </td>
        <td style='float:left;'>
            <?= $get->rem2 ?>
        </td>
    </tr>
</table>
                        
<!--    <h4>Declaration</h4>
    <p><font size="3px">
        We declare that this invoice shows actual price of the goods described inclusive of taxes and that all
        particulars are true and correct
        In case you find Selling Price on this Invoice<br> to be more than MRP mentioned on product,please
        inform wrong MRP @jasperindia.com
        </font>
    </p><br>-->
    <table>
        <tr>
            <td style='text-align: center;border-top:1px solid black;border-bottom:1px solid black;'>
               <center> <b>THIS IS A COMPUTER GENERATED INVOICE AND DOES NOT REQUIRE SIGNATURE</b></center>
            </td>
        </tr>
    </table>
</body>
</html>
