<?php
session_start();

if ($_SESSION['company'] == "") { 
    exit("Please Login");
}
if ($_SESSION['CURRENT_USER'] == "") { 
    exit("Please Login");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Shipment Details</title>

        <style>
            table
            {
                border-collapse:collapse;
            }
            table, td, th
            {
                
                font-family:Arial, Helvetica, sans-serif;
                padding:5px;
            }
            th
            {
                font-weight:bold;
                font-size:13px;

            }
            td
            {
                font-size:12px;

            }
        </style>
        <style type="text/css">
            <!--
            .style1 {
                color: #0000FF;
                font-weight: bold;
                font-size: 24px;
            }
            -->
        </style>
    </head>

    <body> 

        <?php
        require_once("connectioni.php");
        
        









        $sql_head = "select * from invpara where flag='".$_SESSION['company']."'";  
        $result_head = mysqli_query($GLOBALS['dbinv'],$sql_head);
        $row_head = mysqli_fetch_array($result_head);

        echo "<center><span class=\"style1\">" . $row_head["COMPANY"] . "</span></center><br>";

        $heading = "<center>Shipment Details From  " . $_GET["DT1"] . " To ".  $_GET["DT2"]  . " <br><br>";
        echo $heading;


        $sql = "SELECT LCNO,SDATE,BRAND,REFNO from view_sh_de where SDATE>='" . $_GET["DT1"] . "' AND SDATE<='" . $_GET["DT2"] . "'   AND cancel=0  ";
        if ($_GET["cmbcat"] != "All") {
            $sql .=" and cat1 ='" . $_GET["cmbcat"] . "'";
        }
        if ($_GET["cmbbrand"] != "All") {
            $sql .=" and brand ='" . $_GET["cmbbrand"] . "'"; 
        }
        

        $sql .="  group by LCNO,SDATE,BRAND,REFNO order by refno ";
        $result = mysqli_query($GLOBALS['dbinv'],$sql) ; 

       
        echo "<table border='1' ><tr> <td><b>LC NO</td> <td><b>DATE</td> <td><b>BRAND</td><td><b>STK NO</td><td><b>DESCRIPTION</td><td><b>QTY</td></tr>";

        while ($row = mysqli_fetch_array($result)) {
            $sql_02 = "SELECT * from view_sh_de where REFNO = '" . $row['REFNO'] . "'";

            echo "<tr> <td>" . $row['LCNO'] . "</td> <td>" . $row['SDATE'] . "</td> <td>" . $row['brand'] . "</td>  <td colspan='3'>" . $row['REFNO'] . "</td>    </tr>";

            $result1 = mysqli_query($GLOBALS['dbinv'],$sql_02);


$mtot=0;

            while ($row1 = mysqli_fetch_array($result1)) {
                echo "<tr> <td colspan='3'></td>            "
                
                . "<td>" . $row1['STK_NO'] . "</td>"
                . "<td>" . $row1['DESCRIPT'] . "</td>"
                . "<td align = 'right'>" . $row1['REC_QTY'] . "</td>"
                . " </tr>";
                $mtot = $mtot +$row1['REC_QTY'] ;
            }
            echo "<tr> <td colspan='5'></td>            "
                
                 
                . "<td align = 'right'><b>" . $mtot . "</b></td>"
                . " </tr>";
        }

        
                
        
        echo "</table><br>";

 
        
         echo "<table border='1' width = '300'><tr>";
        $sql2 = "select sum(rec_qty) as qty,cat1 from view_sh_de where SDATE>='" . $_GET["DT1"] . "' AND SDATE<='" . $_GET["DT2"] . "'   and cancel='0'";
        if ($_GET["cmbbrand"] != "All") {
            $sql2 .=" and brand ='" . $_GET["cmbbrand"] . "'";
        }
        $sql2 .="  group by cat1";
        $totalqty=0;
        $result2 = mysqli_query($GLOBALS['dbinv'],$sql2);
         while ($row2 = mysqli_fetch_array($result2)) {
             echo "<tr><td>".$row2['cat1']."</td><td  align = 'right'>".$row2['qty']."</td></tr>"; 
             $totalqty +=$row2['qty'];
         }
         
         echo "<tr><td><b>Total</b> </td><td  align = 'right'><b>".number_format($totalqty,2)."</b></td></tr>"; 
        echo"</table>";

        echo"<br><br><br><table width = '500' > <tr><td>Signature </td> <td>..............................................</td>          <td colspan = '4'>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp </td>         </tr>      "
        . "<tr><td>Working Director </td> <td>..............................................</td>       <td colspan = '4'>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp </td>              </tr> "
        . "<tr><td>Managing Director </td> <td>..............................................</td>     <td colspan = '4'>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp </td>                </tr>  </table>"
        ?>



    </body>
</html>
