
<!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']?> REPORT</title>

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

        .right {
            text-align: right;
        }

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


           border-collapse: collapse;
       }
        
       .tb td  {

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

           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>

</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 id="itemdetails">
    <table width="1250px;" 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> 
        <?php 
         if($_GET['brandname'] !=""){?>
            <th class='center' colspan='5'>Brand Wise - <?php echo $_GET['brandname']?>  </th> 
           <?php } ?>
        </tr> 
        <tr> 
        <?php 
         if($_GET['dep'] !=""){?>
            <th class='center' colspan='5'>Department Wise - (<?php echo $_GET['dep']?> ) </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="1250px;" >
                <tr >
        
                    <th width="30px;">NO</th> 
                    <th width="100px;">STK NO</th>
                    <th width="350px;">DESCRIPTION</th>
                    <th width="150px;">PART NO</th>
                    <th width="120px;">CATEGORY</th>
                    <th width="120px;">DEPARTMENT</th> 
                    <th width="100px;">QTY</th> 
                    <?php if($_GET['type'] =="SELLING"){?> 
                        <th width="100px;">SELLING</th>
                    <?php    }else{?>
                        <th width="100px;">SELLING</th>
                        <th width="100px;">COST</th>
                        <th width="200px;">STOCK VALUE</th>
                    <?php } ?>
                </tr>
                <?php
                
                
                $i=0;  
               $BRAND_NAME="";
                $BAL=0;
                $sql1 = "Select * from viewsubmas where STK_NO <> ''";
                
                // if (isset($_GET['itemname'])) {
                //     if ($_GET['itemname'] != "") {
                //         $sql1 .= " and DESCRIPT like  '%$letters%'";
                //     }
                // }
                 
                
                
                if($_GET['dep'] !=""){
                     $sql1.=" and STO_CODE='".$_GET['dep']."'"; 
                }
                if($_GET['brandname'] !=""){
                     $sql1.=" and BRAND_NAME='".$_GET['brandname']."'"; 
                }
                if($_GET['cat'] !=""){
                     $sql1.=" and Cat1='".$_GET['cat']."'"; 
                }
                if($_GET['size'] !=""){
                     $sql1.=" and SIZE='".$_GET['size']."'"; 
                }
                if($_GET['stk_no'] !=""){
                     $sql1.=" and STK_NO='".$_GET['stk_no']."'"; 
                } 
                if($_GET['check'] =="on"){
                     $sql1.=" and QTYINHAND >0"; 
                }
                
                
                $sql1.=" order by  BRAND_NAME,STK_NO ";
                
                
                
                foreach ($conn->query($sql1) as $row1) {
                     
                    ?>
                    <tr style="font-size:11px;">
         
        
                        
                        
                       <?php  
                      
                        
                        if($BRAND_NAME!=$row1['BRAND_NAME']){
                           if($i !=0){
                                echo "<tr>
                                    <td colspan='6'><b>   </b></td>
                                    <td colspan='1' align=right><b>  ".number_format($QTYINHAND, 2, ".", ",") ."   </b></td>  ";
                                    if($_GET['type'] !="SELLING"){  
                                        echo "<td colspan='1'><b>   </b></td>
                                            <td colspan='1' align=right><b>  ". number_format($VALUE, 2, ".", ",") ."   </b></td> 
                                            <td colspan='1'><b>   </b></td>";
                                    } else{
                                        echo "<td colspan='1'><b>   </b></td>";
                                    }
                                   
                               echo " </tr>";
                                
                           } 
                            $i = 1;
                            if($_GET['type'] =="SELLING"){
                                    echo "<tr> <td colspan='8'><b>  ". $row1['BRAND_NAME'] ."   </b></td> </tr>";
                            }else{
                                echo "<tr> <td colspan='10'><b>  ". $row1['BRAND_NAME'] ."   </b></td> </tr>";
                            }
                            $COST=$row1['COST'];
                            $QTYINHAND=$row1['QTYINHAND'];
                            $VALUE=($row1['COST']*$row1['QTYINHAND']);
                             
                        }else{
                            $COST=$COST+$row1['COST'];
                            $QTYINHAND=$QTYINHAND+$row1['QTYINHAND'];
                            $VALUE=$VALUE+($row1['COST']*$row1['QTYINHAND']);
                        }
                        
                        ?>
                        <td class="center"><?php echo $i ?></td>
                        <td class="left" ><?php echo $row1['STK_NO']; ?> </td>
                        <td class="left" ><?php echo $row1['DESCRIPT1']; ?> </td> 
                        <td class="left" ><?php echo $row1['PART_NO']; ?> </td> 
                        <td class="left" ><?php echo $row1['Cat1']; ?> </td> 
                        <td class="left" ><?php echo $row1['DESCRIPTION']; ?> </td> 
                        <td align="right"><?php echo number_format($row1['QTYINHAND'], 2, ".", ","); ?></td> 
                        <?php if($_GET['type'] =="SELLING"){ ?> 
                            <td align="right"><?php echo number_format($row1['SELLING'], 2, ".", ","); ?></td>  
                         <?php }else{ ?>
                            <td align="right"><?php echo number_format($row1['SELLING'], 2, ".", ","); ?></td> 
                            <td align="right"><?php echo number_format($row1['COST'], 2, ".", ","); ?></td> 
                            <td align="right"><?php echo number_format($row1['COST']*$row1['QTYINHAND'], 2, ".", ","); ?></td> 
                        <?php } ?>
                        
                    </tr>
                    <?php
                    $i=$i+1;
                    $BRAND_NAME=$row1['BRAND_NAME']; 
                     
                    $QTYINHAND_TOT=$QTYINHAND_TOT+$row1['QTYINHAND'];
                    $VALUE_TOT=$VALUE_TOT+($row1['COST']*$row1['QTYINHAND']);
                             
                }
                ?>
           
           
            <tr>
                <td  align="right" style='font-size:20px;' colspan='6'><b></b></td> 
                <td align="right" style='font-size:20px;'><b><?php echo number_format($QTYINHAND, 2, ".", ","); ?><b/></td> 
                <?php if($_GET['type'] !="SELLING"){  ?>
                        <td colspan='1'><b>   </b></td>
                        <td colspan='1'><b>   </b></td>
                        <td colspan='1' align=right><b> <?php echo  number_format($VALUE, 2, ".", ",") ; ?><b/></td>
                <?php } else {?>
                           <td colspan='1'><b>   </b></td>
                <?php } ?>
                
            </tr>
            <tr>
                <td  align="right" style='font-size:20px;' colspan='6'><b></b></td> 
                <td align="right" style='font-size:20px;'><b><?php echo number_format($QTYINHAND_TOT, 2, ".", ","); ?><b/></td> 
                <?php if($_GET['type'] !="SELLING"){  ?>
                        <td colspan='1'><b>   </b></td>
                        <td colspan='1'><b>   </b></td>
                        <td colspan='1' align=right><b> <?php echo  number_format($VALUE_TOT, 2, ".", ",") ; ?><b/></td>
                <?php } else {?>
                           <td colspan='1'><b>   </b></td>
                <?php } ?>
            </tr>
        </table>
    
 
   
    
    <!--===================================================================================-->
    
    
    
 
<!-- ************************************************************************** -->
</center>
    <a  onclick="tableToExcel('itemdetails', 'Report')" class="btn btn-primary btn-sm "> <span class="fa fa-file-excel-o"></span> &nbsp; Export to Excel  	</a> 
    <a class="btn btn-primary btn-sm ">	 <span class="fa fa-file-excel-o"></span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </a> 
    <a onclick="printArea('printThis');" class="btn btn-warning  btn-sm  "> 	<span class="fa fa-print"></span> &nbsp; Print 	</a> 	 
</body>

</html>
<script type="text/javascript">

function printArea(areaName)
    {
        var printContents = document.getElementById('itemdetails').innerHTML;
        
        var originalContents = document.body.innerHTML;

        document.body.innerHTML = originalContents;

        window.print();

        
    } 
    
    
var tableToExcel = (function() {
  var uri = 'data:application/vnd.ms-excel;base64,'
    , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</body></html>'
    , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
    , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
  return function(table, name) {
    if (!table.nodeType) table = document.getElementById(table)
    var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
    window.location.href = uri + base64(format(template, ctx))
  }
})()
</script>


