
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<?php

session_start();
date_default_timezone_set('Asia/Colombo');
?>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">


    <title><?php echo $_GET['type']?>STOCK REPORT</title>

    <style>
        .center {
            text-align: center;
        }

        .right {
            text-align: right;
        }

        .tb  {
           width: 1000px;
           border: 1px solid black;


           border-collapse: collapse;
       }
        
       .tb td  {

           border-top: 1px solid black;
           border-left: 1px solid black;
           font-size:18px;

           border-collapse: collapse;
       }
       .tb th  {

           border-top: 1px solid black;
           border-left: 1px solid black;


           border-collapse: collapse;
       }
       .tb2  {
           
           border: 1px solid black;


           border-collapse: collapse;
       }
       .tb2 td  {

           border-top: 1px solid black;
           border-left: 1px solid black;
           font-size:18px;

           border-collapse: collapse;
       }
       .tb2 th  {

           border-top: 1px solid black;
           border-left: 1px solid black;


           border-collapse: collapse;
       }

       .tb1 {

           border: 1px solid #000000;
       }
 

   </style>
<script language="javascript" type="text/javascript">
        <!--
            /****************************************************
             Author: Eric King
             Url: http://redrival.com/eak/index.shtml
             This script is free to use as long as this info is left in
             Featured on Dynamic Drive script library (http://www.dynamicdrive.com)
             ****************************************************/
             var win = null;
             function NewWindow(mypage, myname, w, h, scroll, pos) {
                if (pos == "random") {
                    LeftPosition = (screen.width) ? Math.floor(Math.random() * (screen.width - w)) : 100;
                    TopPosition = (screen.height) ? Math.floor(Math.random() * ((screen.height - h) - 75)) : 100;
                }
                if (pos == "center") {
                    LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
                    TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;
                } else if ((pos != "center" && pos != "random") || pos == null) {
                    LeftPosition = 0;
                    TopPosition = 20
                }
                settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
                win = window.open(mypage, myname, settings);
            }
            // -->
        </script>
</head>
<?php
require_once ("connection_sql.php");

 

$sql_invpara = "SELECT * from invpara";
$result_invpara = $conn->query($sql_invpara);
$row_invpara = $result_invpara->fetch(); 






?>
<body>
    <center>
    <table width="1000px;" cellspacing="0" border="0">

        <tr>
            <th class="center"  colspan=5 ><?php echo $row_invpara['COMPANY']; ?></th>
        </tr> 
        
        <tr> 
            <th class='center' colspan='5'> <?php echo $_GET['type']?> REPORT - (<?php echo date('Y-m-d H:i:s');?>)</th> 
        </tr>
         
        <tr> 
            <th class='center' colspan='5'> <?php echo $_GET['dtfrom']?> To - <?php echo $_GET['dtfrom']?></th> 
        </tr>
          
        <tr> 
        <?php 
         if($_GET['dep'] !="ALL"){
            $sql_sto = "SELECT * from s_stomas where CODE='".$_GET['dep']."'";
            $result_sto= $conn->query($sql_sto);
            $row_sto = $result_sto->fetch(); 
?>
            <th class='center' colspan='5'>Department Wise - (<?php echo $row_sto['DESCRIPTION']?> ) </th> 
           <?php } ?>
        </tr> 
        <tr>

            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td align="right">&nbsp;</td>
        </tr>
        
        <tr>

            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>

            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>

            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        
        <tr>

            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
       
    </table>
<!--==================================================================================-->

                <table class="tb" width="1000px;" >
                <tr >
        
                   <th width="30px;">NO</th> 
                    <th width="100px;">STK NO</th> 
                    <th width="120px;">DESCRIPT</th> 
                    <th width="100px;">COST</th> 
                    <th width="100px;">SELLING</th> 
                    <th width="100px;">QTYINHAND</th> 
                    <th width="100px;">STOCK VALUE</th> 
                </tr>
                <?php
                $i=1;  
                $part="";
                $BAL=0;
                $sql1 = "Select * from view_smas_submas  where category != 'NoneStockControll' ";
                  
                if($_GET['dep'] !="ALL"){
                     $sql1.=" and STO_CODE='".$_GET['dep']."'"; 
                }
                 if($_GET['brandname'] !="ALL"){
                     $sql1.=" and BRAND_NAME='".$_GET['brandname']."'"; 
                }
                 
                $sql1.=" group by STK_NO"; 
              
     
                $i=1;
                foreach ($conn->query($sql1) as $row1) {
                    $sql_sto1 = "SELECT * from s_stomas where CODE='".$row1['STO_CODE']."'";
                    $result_sto1= $conn->query($sql_sto1);
                    $row_sto1 = $result_sto1->fetch(); 
                    
                    if($row1['BRAND_NAME'] !=$brand){
                    ?>
                     <tr style="font-size:13px;">
            
                        <td class="left"  style='font-size:20px;' colspan='8'><b><?php echo $row1['BRAND_NAME'] ?></b> </td>  
                          
                    </tr>
                <?php    } ?>
                    <tr style="font-size:13px;">
           
                        <td class="center" style='font-size:20px;'><?php echo $i ?></td>
                        <td class="left"  style='font-size:20px;'><?php echo $row1['STK_NO']; ?> </td> 
                        <td class="left"  style='font-size:20px;'><?php echo $row1['DESCRIPT']; ?> </td> 
                        <td align="right" style='font-size:20px;'><?php echo number_format($row1['COST'], 2, ".", ","); ?></td> 
                        <td align="right" style='font-size:20px;'><?php echo number_format($row1['SELLING'], 2, ".", ","); ?></td> 
                        
                        <?php  if($_GET['dep'] !="ALL"){?>
                          <td align="right" style='font-size:20px;'><?php echo number_format($row1['SUBQTYINHAND'], 2, ".", ","); ?></td> 
                          <td align="right" style='font-size:20px;'><?php echo number_format($row1['COST']*$row1['SUBQTYINHAND'], 2, ".", ","); ?></td> 
                         <?php  }else{?>
                          <td align="right" style='font-size:20px;'><?php echo number_format($row1['SQTYINHAND'], 2, ".", ","); ?></td> 
                          <td align="right" style='font-size:20px;'><?php echo number_format($row1['COST']*$row1['SQTYINHAND'], 2, ".", ","); ?></td> 
                         <?php  }?>
                        
                    </tr>
                    <?php
                     $i=$i+1;
                  if($_GET['dep'] !="ALL"){ 
                         $QTYTOT=$QTYTOT+$row1['SUBQTYINHAND'];
                         $COSTTOT=$COSTTOT+($row1['COST']*$row1['SUBQTYINHAND']); 
                  }else{
                      $QTYTOT=$QTYTOT+$row1['SQTYINHAND'];
                      $COSTTOT=$COSTTOT+($row1['COST']*$row1['SQTYINHAND']); 
                  }
                    
                         $brand=$row1['BRAND_NAME'] ;
                }
                ?>
           
           
            <tr> 
                <td  align="right" colspan='5' style='font-size:20px;'><b></b></td> 
                <td align="right" style='font-size:24px;'><b><?php   echo number_format($QTYTOT, 2, ".", ",");  ?><b/></td>
                <td align="right" style='font-size:24px;'><b><?php   echo number_format($COSTTOT, 2, ".", ",");  ?><b/></td> 
            </tr>
            
            
        </table>
    
  
    <!--===================================================================================-->
    
    
    
 
<!-- ************************************************************************** -->
</center>
</body>

</html>
