
<!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: 1300px;
           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(); 






?>
<body>
    <center>
    <table width="1300px;" 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['Txtcusco'] !=""){
            
?>
            <th class='center' colspan='5'>Supplier Wise - (<?php echo $_GET['Txtcusco']?> ) </th> 
           <?php } ?>
        </tr> 
         <tr> 
        <?php 
         if($_GET['brandname'] !=""){
            
?>
            <th class='center' colspan='5'>Brand Wise - (<?php echo $_GET['brandname']?> ) </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>
<!--==================================================================================-->
   <?php if($_GET['type'] == "SUMMERY"){?>
                <table class="tb" width="1300px;" >
                <tr >
        
                   <th width="30px;">NO</th> 
                    <th width="100px;">COMPANY</th> 
                    <th width="120px;">GRAND TOTAL</th> 
                    <th width="100px;">PAID</th> 
                    <th width="100px;">BALANCE</th> 
                </tr>
                <?php
                $i=1;  
                $part="";
                $BAL=0;
                $sql1 = "Select sum(GRAND_TOT) AS GRAND_TOT,sum(TOTPAY) AS TOTPAY,sum(GRAND_TOT-TOTPAY) AS BAL,DEPARTMENT from s_salma  where CANCELL='0' and TRN_TYPE='INV' AND SDATE >='" . $_GET["dtfrom"] . "' and SDATE <='" . $_GET["dtto"] . "'";
                  
                if($_GET['company'] !=""){
                     $sql1.=" and DEPARTMENT='".$_GET['company']."'"; 
                }
                  if($_GET['Txtcusco'] !=""){
                     $sql1.=" and C_CODE='".$_GET['Txtcusco']."'"; 
                }
                
                $sql1.=" group by DEPARTMENT"; 
                
     
                $i=1;
                foreach ($conn->query($sql1) as $row1) {
                    $sql_sto1 = "SELECT * from s_stomas where CODE='".$row1['DEPARTMENT']."'";
                    $result_sto1= $conn->query($sql_sto1);
                    $row_sto1 = $result_sto1->fetch(); 
                    ?>
                    <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 $row_sto1['DESCRIPTION']; ?> </td> 
                        <td align="right" style='font-size:20px;'><?php echo number_format($row1['GRAND_TOT'], 2, ".", ","); ?></td> 
                        <td align="right" style='font-size:20px;'><?php echo number_format($row1['TOTPAY'], 2, ".", ","); ?></td> 
                        <td align="right" style='font-size:20px;'><?php echo number_format($row1['BAL'], 2, ".", ","); ?></td> 
                    </tr>
                    <?php
                     $i=$i+1;
                     $company=$row1['DEPARTMENT']; 
                     
                     $GTOT=$GTOT+$row1['GRAND_TOT'];
                     $TOTPAY=$TOTPAY+$row1['TOTPAY'];
                     $BAL=$BAL+$row1['BAL'] ;
                }
                ?>
           
           
            <tr> 
                <td  align="right" colspan='2' style='font-size:20px;'><b></b></td> 
                <td align="right" style='font-size:24px;'><b><?php   echo number_format($GTOT, 2, ".", ",");  ?><b/></td>
                <td align="right" style='font-size:24px;'><b><?php   echo number_format($TOTPAY, 2, ".", ",");  ?><b/></td>
                <td align="right" style='font-size:24px;'><b><?php   echo number_format($BAL, 2, ".", ",");  ?><b/></td>
            </tr>
            
            
        </table>
    
 <?php }else{?>
       <table class="tb" width="1300px;" >
                    
                <tr >
        
                    <th width="30px;">NO</th> 
                    <th width="100px;">REFNO</th>
                    <th width="80px;">DATE</th>
                    <th width="80px;">ARRIVAL</th>
                    <th width="400px;">SUPPLIER</th>   
                    <th width="80px;">BRAND</th> 
                    <th width="80px;">COUNTRY</th> 
                    
                    <?php
                     $sql3 = "Select * from s_provision where CANCELL='0'";
                    foreach ($conn->query($sql3) as $row3) {
                        echo "<th width='100px'>".$row3['NAME']."</th> ";
                    }
                    ?>
                    <th width="80px;">TOTAL</th> 
                    
                     
                </tr>
                <?php
                $i=1;  
                $part="";
                $BAL=0;
                $sql1 = "Select * from s_ordmas  where   SDATE >='" . $_GET["dtfrom"] . "' and SDATE <='" . $_GET["dtto"] . "' and cancel !='1'";
                
                
                if($_GET['brandname'] !="ALL"){
                     $sql1.=" and Brand='".$_GET['brandname']."'"; 
                }
                
                // if($_GET['paytype'] !=""){
                //      $sql1.=" and ST_FLAG='".$_GET['paytype']."'"; 
                // }
                  if($_GET['Txtcusco'] !=""){
                     $sql1.=" and SUP_CODE='".$_GET['Txtcusco']."'"; 
                }
                // $sql1.=" order by SALMA_DEP,ST_REFNO";
                 
 
                $i=0;
                $company="";
                
                foreach ($conn->query($sql1) as $row1) {
                    
                    ?>
                    <tr style="font-size:13px;">
          
                        <?php  
                        
                        if($company!=$row1['company']){
                           if($i !=0){
                                echo "<tr>
                                 <td colspan='12'><b>   </b></td>
                                <td colspan='1' align=right><b>  ".number_format($TRANSPORT, 2, ".", ",") ."   </b></td> 
                                <td colspan='1' align=right><b>  ".number_format($COMMISSION, 2, ".", ",") ."   </b></td> 
                                <td colspan='1' align=right><b>  ".number_format($UC, 2, ".", ",") ."   </b></td> 
                                <td colspan='1' align=right><b>  ".number_format($NBT, 2, ".", ",") ."   </b></td> 
                                <td colspan='1' align=right><b>  ".number_format($ESC, 2, ".", ",") ."   </b></td> 
                                <td colspan='1' align=right><b>  ".number_format($VAT, 2, ".", ",") ."   </b></td> 
                                <td colspan='1' align=right><b>  ".number_format($OTHERTAX, 2, ".", ",") ."   </b></td>  
                                </tr>";
                                
                           } 
                            $i = 1;
                            echo "<tr>
                                  <td colspan='16'><b>  ". $row1['company'] ."   </b></td> </tr>";
                               $cashpay_tot=0;  
                        }else{ 
                             $cashpay_tot +=0;  
                                                     }
                        ?>
                        <td class="center" style='font-size:12px;'><?php echo $i ?></td>
                        <td class="left"  style='font-size:12px;'><?php echo $row1['REFNO']; ?> </td>
                        <td class="left"  style='font-size:12px;'><?php echo $row1['SDATE']; ?> </td> 
                        <td class="left"  style='font-size:12px;'><?php echo $row1['S_date']; ?> </td> 
                        <td class="left"  style='font-size:12px;'><?php echo $row1['SUP_NAME']; ?> </td> 
                        <td class="left"  style='font-size:12px;'><?php echo $row1['Brand']; ?> </td> 
                        <td class="left"  style='font-size:12px;'> <?php echo $row1['COUNTRY']; ?> </td>  
                         <?php
                            $sql3 = "Select * from s_provision where CANCELL='0'";
                            foreach ($conn->query($sql3) as $row3) {
                                $sql4 = "Select * from s_ordmas_provision where REFNO ='" . $row1['REFNO'] . "' and NAME='" . $row3['REFNO'] . "'";
                                $result4 = $conn->query($sql4);
                                if ($row4 = $result4->fetch()) { 
                                    echo "<th width='100px' align=right>".$row4['AMOUNT']."</th> ";
                                    
                                     if($row4['NAME'] =='TRANSPORT'){
                                         $TRANSPORT=$row4['AMOUNT']; 
                                     } else if($row4['NAME'] =='COMMISSION'){
                                         $COMMISSION=$row4['AMOUNT']; 
                                     } else if($row4['NAME'] =='UC'){
                                         $UC=$row4['AMOUNT']; 
                                     } else if($row4['NAME'] =='NBT'){
                                         $NBT=$row4['AMOUNT']; 
                                     } else if($row4['NAME'] =='ESC'){
                                         $ESC=$row4['AMOUNT']; 
                                     } else if($row4['NAME'] =='VAT'){
                                         $VAT=$row4['AMOUNT']; 
                                     } else if($row4['NAME'] =='OTHER TAX'){
                                         $OTHERTAX=$row4['AMOUNT']; 
                                     } 
                                 
                                }else{
                                     echo "<th width='100px'></th> ";
                                }
                            }
                        ?>
                          <td class="right"  style='font-size:12px;'> <b><?php echo number_format(($TRANSPORT+$COMMISSION+$UC+$NBT+$ESC+$VAT+$OTHERTAX),2) ?></b> </td>  
                           
                    </tr>
                    
                     
                    <?php
                     $i=$i+1;
                     $company=$row1['company']; 
                      
                      $TRANSPORT_TOT += $TRANSPORT;
                      $COMMISSION_TOT += $COMMISSION;
                      $UC_TOT += $UC;
                      $NBT_TOT += $NBT;
                      $ESC_TOT += $ESC;
                      $VAT_TOT += $VAT;
                      $OTHERTAX_TOT += $OTHERTAX;
                      
                      $ALL=$TRANSPORT_TOT+$COMMISSION_TOT+$UC_TOT+$NBT_TOT+$ESC_TOT+$VAT_TOT+$OTHERTAX_TOT;
                }
                ?>
                
           
            <tr hidden> 
                <td  align="right" colspan='7' style='font-size:20px;'><b></b></td> 
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($TRANSPORT, 2, ".", ",");  ?><b/></td> 
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($COMMISSION, 2, ".", ",");  ?><b/></td> 
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($UC, 2, ".", ",");  ?><b/></td> 
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($NBT, 2, ".", ",");  ?><b/></td> 
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($ESC, 2, ".", ",");  ?><b/></td> 
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($VAT, 2, ".", ",");  ?><b/></td> 
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($OTHERTAX, 2, ".", ",");  ?><b/></td>  
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($OTHERTAX, 2, ".", ",");  ?><b/></td>  
            </tr>
            
            <tr> 
                <td  align="right" colspan='7' style='font-size:20px;'><b></b></td> 
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($TRANSPORT_TOT, 2, ".", ",");  ?><b/></td> 
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($COMMISSION_TOT, 2, ".", ",");  ?><b/></td> 
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($UC_TOT, 2, ".", ",");  ?><b/></td> 
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($NBT_TOT, 2, ".", ",");  ?><b/></td> 
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($ESC_TOT, 2, ".", ",");  ?><b/></td> 
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($VAT_TOT, 2, ".", ",");  ?><b/></td> 
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($OTHERTAX_TOT, 2, ".", ",");  ?><b/></td>  
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($ALL, 2, ".", ",");  ?><b/></td>  
            </tr>
            
           
             
                    
            
        </table>
    
    
     <?php }?>
    <!--===================================================================================-->
    
    
    
 
<!-- ************************************************************************** -->
</center>
</body>

</html>
