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

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

        .right {
            text-align: right;
        }

        .tb  {
           width: 1200px;
           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>

</head>
<?php
require_once ("connection_sql.php");

 

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




 $sql25 = "update s_trn set tru_qty = QTY where  (ledindi = 'ARN' or ledindi ='GRN' or ledindi = 'GINR' or ledindi ='IIN' or ledindi = 'TRN')  ";
 $result25 = $conn->query($sql25);
  
$sql26 = "update s_trn set tru_qty = QTY * -1 where     (ledindi = 'ISO' or ledindi = 'ARR' or ledindi ='INV' or ledindi = 'GINI' or ledindi ='IOU')  ";
$result26 = $conn->query($sql26);


?>
<body>
    <center>
    <table width="1200px;" 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']?> MOVMENT REPORT - (<?php echo date('Y-m-d H:i:s');?>)</th> 
        </tr>
          <tr> 
            <th class='center' colspan='5'>( <?php echo $_GET['dtfrom']?> - <?php echo $_GET['dtto']?>)</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'] !=""){
            $sql_s_stomas= "SELECT * from s_stomas where CODE='".$_GET['dep']."'";
            $result_stomas = $conn->query($sql_s_stomas);
            $row_stomas = $result_stomas->fetch();
?>
            <th class='center' colspan='5'>Department Wise - (<?php echo $row_stomas['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="1200px;" >
                
                <?php
                
                   
                
                $month1 = date("m", strtotime($_GET["dtfrom"]));
            	$month1_y = date("Y", strtotime($_GET["dtfrom"]));
            	
            	$month2 = date("m", strtotime($_GET["dtto"]));
            	$month2_y = date("Y", strtotime($_GET["dtto"]));
                
                $startedDate=$_GET["dtfrom"];
                $endDate=$_GET["dtto"]; 
                
                $date1 = new DateTime($startedDate);
                $date2 = new DateTime($endDate);
                $interval = $date1->diff($date2);  
                $count=$interval->format('%m');
                 
                $newstartedDate=date_create($startedDate);
                $newstartedDatetable=date_create($startedDate);
                $heading1color='#bb98a1';
                echo "<tr class='info'>                                 
                <td width='40' class='fixed-side' colspan='3'></td>";    
                $monthcolor='yellow';
                for ($x = 0; $x <= $count; $x++) { 
                    echo "  <td align='center' colspan='9' style='background-color:$monthcolor'>".  date_format($newstartedDate,"Y-m")."</td>";  
                    $newstartedDate= date_add($newstartedDate,date_interval_create_from_date_string("1 month"));   
                    
                } 
                echo "</tr>"; 
                echo "<tr class='info'>                                 
                <td width='40' class='fixed-side' style='background-color:$heading1color'>No</td>                          
                <td align='left'  class='fixed-side' style='background-color:$heading1color'>Code</td>                  
                <td align='left'  class='fixed-side' style='background-color:$heading1color'>Name</td>"; 
                $headingcolor='#e9e9af';
                for ($x = 0; $x <= $count; $x++) { 
                    echo "  <td align='center' style='background-color:$headingcolor;font-size:12px;'>ARN</td>";   
                    echo "  <td align='center' style='background-color:$headingcolor;font-size:12px;'>ARR</td>";   
                    echo "  <td align='center' style='background-color:$headingcolor;font-size:12px;'>ST IN</td>";   
                    echo "  <td align='center' style='background-color:$headingcolor;font-size:12px;'>ST OUT</td>";   
                    echo "  <td align='center' style='background-color:$headingcolor;font-size:12px;'>AD IN</td>";   
                    echo "  <td align='center' style='background-color:$headingcolor;font-size:12px;'>AD OUT</td>";   
                    echo "  <td align='center' style='background-color:$headingcolor;font-size:12px;'>INV</td>";   
                    echo "  <td align='center' style='background-color:$headingcolor;font-size:12px;'>RTN</td>";   
                    echo "  <td align='center' style='background-color:$headingcolor;font-size:12px;'>Bal</td>";
                }
            
                echo "</tr>"; 
                	
                $i=1; 
                $arn=0;
                $arr=0;
                $gini=0;
                $ginr=0;
                $iin=0;
                $iou=0;
                $inv=0;
                $grn=0;
                $bal=0;  
                 
                $sql = "SELECT *   FROM viewstran WHERE (LEDINDI='INV' or LEDINDI = 'GRN' or LEDINDI = 'ARN' or LEDINDI = 'ARR'  or LEDINDI='GINI' or LEDINDI='GINR'  or LEDINDI = 'IIN'  or LEDINDI = 'IOU'  ) AND STK_NO <> '' AND month(SDATE)>='".$month1."' AND year(SDATE)>='".$month1_y."' AND month(SDATE) <='".$month2."' AND year(SDATE) <='".$month2_y."'   "; 
                 
                if($_GET['dep'] !=""){
                     $sql.=" and DEPARTMENT='".$_GET['dep']."'"; 
                }
                if($_GET['brandname'] !=""){
                     $sql.=" and BRAND_NAME='".$_GET['brandname']."'"; 
                }
                
                if($_GET['stk_no'] !=""){
                     $sql.=" and STK_NO='".$_GET['stk_no']."'"; 
                } 
                
                //  $sql.=" and (STK_NO='UTG/IT-3555' OR STK_NO='UTG/IT/2216')	"; 
                $sql.="  group by STK_NO"; 
                $valuecolor='#eaffec';
                $descolor='#d6bce7';  
                foreach ($conn->query($sql) as $row) { 
            
                
                    echo  "<tr>                                 
                    <td width='40' class='fixed-side' style='background-color:$descolor;font-size:12px;'>" . $i . "</td>                        
                    <td align=left class='fixed-side' style='background-color:$descolor;font-size:12px;'>" . $row['STK_NO'] . "</td>           
                    <td align=left class='fixed-side ' style='background-color:$descolor;font-size:12px;'>" . $row['DESCRIPT'] . "</td> ";
            
                    for ($x = 0; $x <= $count; $x++) { 
                     
                        $sql_inv = "SELECT SUM(QTY) AS QTY  from s_trn where    month(SDATE) >='".$month1."' and year(SDATE) >='".$month1_y."' and month(SDATE) <='".$month1."' and year(SDATE) <='".$month1_y."'  and (   LEDINDI='INV'  ) and STK_NO='".$row['STK_NO']."' " ;
                        if($_GET['dep'] !=""){
                             $sql_inv.=" and DEPARTMENT='".$_GET['dep']."'"; 
                        } 
                        $result_inv = $conn->query($sql_inv);  
                        $row_inv = $result_inv->fetch(); 
                        
                        $sql_grn = "SELECT SUM(QTY) AS QTY  from s_trn where    month(SDATE) >='".$month1."' and year(SDATE) >='".$month1_y."' and month(SDATE) <='".$month1."' and year(SDATE) <='".$month1_y."'  and (   LEDINDI='GRN'  ) and STK_NO='".$row['STK_NO']."' " ;
                        if($_GET['dep'] !=""){
                             $sql_grn.=" and DEPARTMENT='".$_GET['dep']."'"; 
                        } 
                        $result_grn = $conn->query($sql_grn);  
                        $row_grn = $result_grn->fetch(); 
                        
                        $sql_iin = "SELECT SUM(QTY) AS QTY  from s_trn where    month(SDATE) >='".$month1."' and year(SDATE) >='".$month1_y."' and month(SDATE) <='".$month1."' and year(SDATE) <='".$month1_y."'  and (   LEDINDI='IIN'  ) and STK_NO='".$row['STK_NO']."' " ;
                        if($_GET['dep'] !=""){
                             $sql_iin.=" and DEPARTMENT='".$_GET['dep']."'"; 
                        } 
                        $result_iin = $conn->query($sql_iin);  
                        $row_iin = $result_iin->fetch(); 
                        
                        $sql_iou = "SELECT SUM(QTY) AS QTY  from s_trn where    month(SDATE) >='".$month1."' and year(SDATE) >='".$month1_y."' and month(SDATE) <='".$month1."' and year(SDATE) <='".$month1_y."'  and (   LEDINDI='IOU'  ) and STK_NO='".$row['STK_NO']."' " ;
                        if($_GET['dep'] !=""){
                             $sql_iou.=" and DEPARTMENT='".$_GET['dep']."'"; 
                        } 
                        $result_iou = $conn->query($sql_iou);  
                        $row_iou = $result_iou->fetch(); 
                        
                        $sql_gini = "SELECT SUM(QTY) AS QTY  from s_trn where    month(SDATE) >='".$month1."' and year(SDATE) >='".$month1_y."' and month(SDATE) <='".$month1."' and year(SDATE) <='".$month1_y."'  and (   LEDINDI='GINI'  ) and STK_NO='".$row['STK_NO']."' " ;
                        if($_GET['dep'] !=""){
                             $sql_gini.=" and DEPARTMENT='".$_GET['dep']."'"; 
                        } 
                        $result_gini = $conn->query($sql_gini);  
                        $row_gini = $result_gini->fetch(); 
                        
                        $sql_ginr = "SELECT SUM(QTY) AS QTY  from s_trn where    month(SDATE) >='".$month1."' and year(SDATE) >='".$month1_y."' and month(SDATE) <='".$month1."' and year(SDATE) <='".$month1_y."'  and (   LEDINDI='GINR'  ) and STK_NO='".$row['STK_NO']."' " ;
                        if($_GET['dep'] !=""){
                             $sql_ginr.=" and DEPARTMENT='".$_GET['dep']."'"; 
                        } 
                        $result_ginr = $conn->query($sql_ginr);  
                        $row_ginr = $result_ginr->fetch(); 
                        
                        $sql_arn = "SELECT SUM(QTY) AS QTY  from s_trn where    month(SDATE) >='".$month1."' and year(SDATE) >='".$month1_y."' and month(SDATE) <='".$month1."' and year(SDATE) <='".$month1_y."'  and (   LEDINDI='ARN'  ) and STK_NO='".$row['STK_NO']."' " ;
                        if($_GET['dep'] !=""){
                             $sql_arn.=" and DEPARTMENT='".$_GET['dep']."'"; 
                        } 
                        $result_arn = $conn->query($sql_arn);  
                        $row_arn = $result_arn->fetch(); 
                        
                        $sql_arr = "SELECT SUM(QTY) AS QTY  from s_trn where    month(SDATE) >='".$month1."' and year(SDATE) >='".$month1_y."' and month(SDATE) <='".$month1."' and year(SDATE) <='".$month1_y."'  and (   LEDINDI='ARR'  ) and STK_NO='".$row['STK_NO']."' " ;
                        if($_GET['dep'] !=""){
                             $sql_arr.=" and DEPARTMENT='".$_GET['dep']."'"; 
                        } 
                        $result_arr = $conn->query($sql_arr);  
                        $row_arr = $result_arr->fetch(); 
                        
                        $arn=$row_arn['QTY'];
                        $arr=$row_arr['QTY'];
                        $gini=$row_gini['QTY'];
                        $ginr=$row_ginr['QTY']; 
                        $iin=$row_iin['QTY']; 
                        $iou=$row_iou['QTY']; 
                        $inv=$row_inv['QTY']; 
                        $grn=$row_grn['QTY']; 
                        $bal=$row_inv['QTY']-$row_grn['QTY'];  
                         
                    
            
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'>".  number_format($arn,2)."</td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'>".  number_format($arr,2)."</td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'>".  number_format($gini_1,2)."</td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'>".  number_format($ginr,2)."</td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'>".  number_format($iin,2)."</td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'>".  number_format($iou,2)."</td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'>".  number_format($inv,2)."</td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'>".  number_format($grn,2)."</td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'>".  number_format($bal,2)."</td>"; 
                
                        $month1=$month1+1;
                        $month2=$month2+1;
                        
                        
                        $tot_arn +=$arn;
                        $tot_arr +=$arr;
                        $tot_gini +=$gini;
                        $tot_ginr +=$ginr; 
                        $tot_iin +=$iin; 
                        $tot_iou +=$iou; 
                        $tot_inv +=$inv; 
                        $tot_grn +=$grn; 
                        $tot_bal +=$bal;  
                 
            }
             $month1 = date("m", strtotime($_GET["dtfrom"]));
         	 $month2 = date("m", strtotime($_GET["dtto"]));
            
            echo"</tr>";    
                $i=$i+1; 
            }
            
            echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'></td>
            <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'></td>
            <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'></td>
            <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'><b>".  number_format($tot_arn,2)."</b></td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'><b>".  number_format($tot_arr,2)."</b></td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'><b>".  number_format($tot_gini_1,2)."</b></td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'><b>".  number_format($tot_ginr,2)."</b></td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'><b>".  number_format($tot_iin,2)."</b></td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'><b>".  number_format($tot_iou,2)."</b></td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'><b>".  number_format($tot_inv,2)."</b></td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'><b>".  number_format($tot_grn,2)."</b></td>";  
                        echo "  <td align='center' colspan='1' style='background-color:$valuecolor;font-size:12px;'><b>".  number_format($tot_bal,2)."</b></td>"; 
            
            
            echo"</table>";

                 
                
               ?> 
                
                 
    
    <!--===================================================================================-->
    
    
    
 
<!-- ************************************************************************** -->
</center>
</body>

</html>
