
<!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: 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>

</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['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="1000px;" >
          
              <tr> 
              <td>
                       
                                    
         <?php
                $i=1;  
                $part="";
                $BAL=0;
                 $sql1 = "Select * from s_salma  where CANCELL='0' and TRN_TYPE='INV' AND SDATE >='" . $_GET["dtfrom"] . "' and SDATE <='" . $_GET["dtto"] . "'";
                 
                 if($_GET['Txtcusco'] !=""){
                     $sql1.=" and C_CODE='".$_GET['Txtcusco']."'"; 
                }
                
                if($_GET['company'] !=""){
                     $sql1.=" and DEPARTMENT='".$_GET['company']."'"; 
                }
                if($_GET['company'] !=""){
                     $sql1.=" and DEPARTMENT='".$_GET['company']."'"; 
                }
                
                
                  
                foreach ($conn->query($sql1) as $row) {
                     
                    ?>
     

    <table class="tb" width="1000px;"  >
        <tr class='linehover'>

            <td colspan="6" style="background-color:#0099ab;">Customer Name :<?php echo $row['CUS_NAME'] ?></td>
             
            <td  colspan="1" class="right">Date:   <?php echo $row['SDATE'] ?></td>
        </tr>
         <tr class='linehover'>

            <td colspan="6">City :<?php echo $row1['C_DD1'] ?> </td>
            
            <td colspan="1" class="right" ><?php echo" <a href=\"rep_inv_new.php?invno=" . $row['REF_NO']. "\" target=\"_blank\"  >".$row['REF_NO']."</a>";?></td>
        </tr>
         
        
        <tr class='linehover' >

            <!--<th width="30px;">No</th>-->
            <th width="80px;">CODE</th>
            <th width="200px;">PRODUCT</th>
            <th width="100px;">RATE</th> 
            <th width="80px;">Qty</th> 
            <th width="80px;">DIS 1</th> 
            <th width="80px;">DIS 2</th> 
            <th width="100px;">SUB TOTAL</th>
        </tr>
        <?php
        $i=1;  
        $part="";
        $qty=0;
        $sql1 = "Select * from s_invo where REF_NO='" . $row['REF_NO'] . "'    order by id asc";   
        foreach ($conn->query($sql1) as $row1) {
            $sql_smas = "SELECT * from s_mas where STK_NO='".$row1['STK_NO']."'";
            $result_smas = $conn->query($sql_smas);
            $row_smas= $result_smas->fetch(); 
            
         ?>
                  <tr class='linehover'>
  
                
                <td class="left" ><?php echo $row1['STK_NO']; ?> </td>
                <td class="left" ><?php echo $row1['DESCRIPT']; ?> </td>
                <td class="right"><?php echo number_format($row1['PRICE'], 2, ".", ","); ?></td> 
                <td class="right"><?php echo number_format($row1['QTY'], 0, ".", ","); ?></td>
                <td class="right"><?php echo number_format($row1['Print_dis1'], 2, ".", ","); ?></td> 
                <td class="right"><?php echo number_format($row1['Print_dis2'], 2, ".", ","); ?></td> 
                 <td class="right"><?php echo number_format($row1['subtot'], 2, ".", ","); ?></td> 
            </tr>
                 
        
            <?php
            $i=$i+1;
            
             $qty=$qty+$row1['QTY'];
        }
        ?>

      
    
  
     
   
    <tr class='linehover'>

           <td  class="right" colspan='5' rowspan="3">
               <?php
               if($row['GRAND_TOT']-$row['TOTPAY']=="0.00"){ 
                 echo "   <center><h1 style=\"color:red\">PAID</h1></center>";
                 
              }
               ?>
           </td> 
           
        <td  class="right" colspan='1' style='font-size:15px;'><b>TOTAL</b></td> 
        <td class="right" style='font-size:20px;'><b><?php 
        echo number_format($row['GRAND_TOT'], 2, ".", ",");

        ?><b/></td>
    </tr>
     <tr class='linehover'>

       
        <td  class="right" colspan='1' style='font-size:15px;'><b>PAID</b></td> 
        <td class="right" style='font-size:20px;'><b><?php 
        echo number_format($row['TOTPAY'], 2, ".", ",");

        ?><b/></td>
    </tr>
    <tr class='linehover'>

       
        <td  class="right" colspan='1' style='font-size:15px;'><b>BALANCE</b></td> 
        <td class="right" style='font-size:20px;'><b><?php 
        echo number_format($row['GRAND_TOT']-$row['TOTPAY'], 2, ".", ",");

        ?><b/></td>
    </tr>
    <tr class='linehover'> <td colspan='7'>&nbsp;</td></tr>
    <tr>
        <td colspan="12">
            <table class="tb2"   >
         <tr class='linehover' style="background-color:#4aef84" > 
            <th colspan="12">PAYMENT HISTORY</th>  
        </tr>
        <tr class='linehover' > 
           
            <th colspan="2">REFNO</th>
            <th colspan="1">DATE</th>
            <th colspan="3">AMOUNT</th>  
            <th colspan="2">TYPE</th>  
            <th colspan="2">CHK NO</th>  
            <th colspan="2">CHK DATE</th>  
        </tr>
        
        <?php
        $i=1;  
        $part="";
        $qty=0;
        $sql2 = "Select * from s_sttr where ST_INVONO='" . $row['REF_NO'] . "'    order by id asc";   
        foreach ($conn->query($sql2) as $row2) {
            
            ?>
            <tr class='linehover'>
  
                   <td class="left" colspan="2"><?php echo $row2['ST_REFNO']; ?> </td>
                  <td class="center" colspan="1"><?php echo $row2['ST_DATE']; ?> </td>
                    <td class="right" colspan="3"><?php echo number_format($row2['ST_PAID'], 2, ".", ","); ?></td> 
                    <td class="center" colspan="2"><?php 
                        if($row2['ST_FLAG'] =="CAS"){
                            echo "CASH";  
                        }else if($row2['ST_FLAG'] =="CHK"){    
                            echo "CHEQUE";
                        }else{
                            echo "OTHER";
                        } 
                         ?> 
                    </td>
                    <td class="center" colspan="2"><?php 
                      if($row2['ST_FLAG']=="CAS"){
                            echo "";  
                        }else if($row2['ST_FLAG']=="CHK"){    
                           echo $row2['ST_CHNO']; 
                        }else{
                           echo $row2['ST_CHNO']; 
                        } 
                    ?>
                    </td>
                    <td class="center" colspan="2"><?php 
                         if($row2['ST_FLAG']=="CAS"){
                            echo "";  
                        }else if($row2['ST_FLAG']=="CHK"){    
                           echo $row2['st_chdate']; 
                        }else{
                           echo $row2['st_chdate']; 
                        } 
                        ?> 
                 </td>
            </tr>
            
             
        <?php }?>
         
</table> 
 
        </td>
    </tr>
    <tr class='linehover'> <td colspan='7'>&nbsp;</td></tr>
    <tr class='linehover'> <td colspan='7'>&nbsp;</td></tr>
    <tr class='linehover'> <td colspan='7'>&nbsp;</td></tr>
    <tr class='linehover'> <td colspan='7'>&nbsp;</td></tr>
</table>


    



 
    <?php  }
    ?>  
        
                                        </td>
                                    
     </tr > 
    </table>
    
    
    
        
    
    <!--===================================================================================-->
    
    
    
 
<!-- ************************************************************************** -->
</center>
</body>

</html>
