
<!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: 1100px;
           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="1100px;" 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['company'] !=""){
            $sql_sto = "SELECT * from s_stomas where CODE='".$_GET['company']."'";
            $result_sto= $conn->query($sql_sto);
            $row_sto = $result_sto->fetch(); 
?>
            <th class='center' colspan='5'>Company 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="1100px;" >
   
            
            <tr style='background-color:#e2e288'>
                    <td class="center" colspan='12'><b>EXPENSES</b></td> </tr>
            </tr>  
            
            <tr >
                <th width="30px;">NO</th> 
                <th width="100px;">REFNO</th>
                <th width="80px;">DATE</th>
                <th width="300px;">TYPE</th>   
                <th width="100px;">AMOUNT</th> 
                 
            </tr>
            
            <?php
                $j=1;  
                $ii=0;
                $sql_exp = "Select * from s_expenses where  SDATE >='" . $_GET["dtfrom"] . "' and SDATE <='" . $_GET["dtto"] . "' and CANCELL='0'";
                 
                if($_GET['company'] !=""){
                     $sql_exp.=" and COMPANY='".$_GET['company']."'"; 
                }
                
                if($_GET['type'] !=""){
                     $sql_exp.=" and TYPE='".$_GET['type']."'"; 
                }
                 
                $sql_exp.=" order by DEPARTMENT,REFNO"; 
                foreach ($conn->query($sql_exp) as $row_exp) {
                    $sql_ext = "SELECT * from s_expense_type where REFNO='".$row_exp['TYPE']."'";
                    $result_ext= $conn->query($sql_ext);
                    $row_ext = $result_ext->fetch(); 
                    
                    
                      $sql_sto11 = "SELECT * from s_stomas where CODE='".$row_exp['DEPARTMENT']."'";
                    $result_sto11= $conn->query($sql_sto11);
                    $row_sto11 = $result_sto11->fetch(); 
                      
                        if($expdep!=$row_exp['DEPARTMENT']){
                           if($ii !=0){
                                echo "<tr>
                                 <td colspan='4'><b>   </b></td>
                                <td colspan='1' align=right><b>  ".number_format($exp_sub, 2, ".", ",") ."   </b></td> 
                                </tr>";
                                
                           } 
                            $ii = 1;
                            echo "<tr>
                                    <td colspan='6'><b>  ". $row_sto11['DESCRIPTION'] ."   </b></td> </tr>";
                            $exp_sub=$row_exp['AMOUNT'];
                             
                        }else{
                            $exp_sub=$exp_sub+$row_exp['AMOUNT'];
                        }
                    ?>
                    <tr style="font-size:13px;">
          
                        <td class="center" style='font-size:12px;'><?php echo $j ?></td>
                        <td class="left"  style='font-size:12px;'><?php echo $row_exp['REFNO']; ?> </td>
                        <td class="left"  style='font-size:12px;'><?php echo $row_exp['SDATE']; ?> </td> 
                        <td class="left"  style='font-size:12px;'><?php echo $row_ext['NAME']; ?> </td>
                        <td class="right"  style='font-size:12px;'><?php echo $row_exp['AMOUNT']; ?> </td> 
                    </tr>
                    
                     
                    <?php
                     $j=$j+1;
                     $expdep=$row_exp['DEPARTMENT']; 
                     $exp_tot= $exp_tot+$row_exp['AMOUNT'];
                     
                }
            ?>
            
            <tr>
                <td  align="right" colspan='4' style='font-size:20px;'><b></b></td>
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($exp_sub, 2, ".", ",");  ?><b/></td> 
            </tr>
             <tr>
                <td  align="right" colspan='4' style='font-size:20px;'><b></b></td>
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($exp_tot, 2, ".", ",");  ?><b/></td> 
            </tr>
            
            
        </table>
    
    
    
    <!--===================================================================================-->
    
    
    
 
<!-- ************************************************************************** -->
</center>
</body>

</html>
