
<!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>
<script language="javascript" type="text/javascript">
        <!--
            /****************************************************
             Author: Eric King
             Url: http://redrival.com/eak/index.shtml
             This script is free to use as long as this info is left in
             Featured on Dynamic Drive script library (http://www.dynamicdrive.com)
             ****************************************************/
             var win = null;
             function NewWindow(mypage, myname, w, h, scroll, pos) {
                if (pos == "random") {
                    LeftPosition = (screen.width) ? Math.floor(Math.random() * (screen.width - w)) : 100;
                    TopPosition = (screen.height) ? Math.floor(Math.random() * ((screen.height - h) - 75)) : 100;
                }
                if (pos == "center") {
                    LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
                    TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;
                } else if ((pos != "center" && pos != "random") || pos == null) {
                    LeftPosition = 0;
                    TopPosition = 20
                }
                settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
                win = window.open(mypage, myname, settings);
            }
            // -->
        </script>
</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['fromdep']."'";
            $result_sto= $conn->query($sql_sto);
            $row_sto = $result_sto->fetch(); 
            
             $sql_sto_1 = "SELECT * from s_stomas where CODE='".$_GET['todep']."'";
            $result_sto_1= $conn->query($sql_sto_1);
            $row_sto_1 = $result_sto_1->fetch(); 
?>
            <th class='center' colspan='5'>Frpm Company - (<?php echo $row_sto['DESCRIPTION']?> ) TO Company - (<?php echo $row_sto_1['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>
<!--==================================================================================-->
   <?php if($_GET['type'] == "SUMMERY"){?>
                <table class="tb" width="1000px;" >
                <tr >
        
                   <th width="30px;">NO</th> 
                    <th width="100px;">REFNO</th> 
                    <th width="120px;">DATE</th> 
                    <th width="100px;">FROM DEP</th> 
                    <th width="100px;">TO DEP</th> 
                </tr>
                <?php
                $i=1;  
                $part="";
                $BAL=0;
                $sql1 = "Select * from s_ginmas  where cancel='0' AND TYPE='GIN TRANSFER'  AND SDATE >='" . $_GET["dtfrom"] . "' and SDATE <='" . $_GET["dtto"] . "'";
                  
                if($_GET['todep'] !=""){
                     $sql1.=" and DEP_TO='".$_GET['todep']."'"; 
                }
                if($_GET['fromdep'] !=""){
                     $sql1.=" and DEP_FROM='".$_GET['fromdep']."'"; 
                }
                 
                
                
     
                $i=1;
                foreach ($conn->query($sql1) as $row1) {
                    $sql_sto1 = "SELECT * from s_stomas where CODE='".$row1['DEP_FROM']."'";
                    $result_sto1= $conn->query($sql_sto1);
                    $row_sto1 = $result_sto1->fetch(); 
                    
                     $sql_sto2 = "SELECT * from s_stomas where CODE='".$row1['DEP_TO']."'";
                    $result_sto2= $conn->query($sql_sto2);
                    $row_sto2 = $result_sto2->fetch(); 
                    ?>
                    <tr style="font-size:13px;">
           
                        <td class="center" style='font-size:20px;'><?php echo $i ?></td> 
                        <td class="center"  style='font-size:20px;'><a onfocus="this.blur()" onclick="NewWindow('../gin_display.php?refno=<?php echo $row1['REF_NO']; ?>&amp;trn_type=GINR','mywin','900','700','yes','center');return false"  href=""><?php echo $row1['REF_NO']; ?></a></td>
                         
                        <td class="center"  style='font-size:20px;'><?php echo $row1['SDATE']; ?> </td> 
                        <td class="left"  style='font-size:20px;'><?php echo $row_sto1['DESCRIPTION']; ?> </td> 
                        <td class="left"  style='font-size:20px;'><?php echo $row_sto2['DESCRIPTION']; ?> </td>  
                    </tr>
                    <?php
                     $i=$i+1;
                    //  $company=$row1['DEPARTMENT']; 
                     
                    
                }
                ?>
           
           
           
            
            
        </table>
    
 <?php }else{?>
       <table class="tb" width="1000px;" >
                <tr >
        
                    <th width="30px;">NO</th> 
                    <th width="100px;">REFNO</th>
                    <th width="50px;">DATE</th>
                    <th width="300px;">CUSTOMER</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 * from s_trn  where CANCELL='0' AND TYPE='GIN TRANSFER' and TRN_TYPE='INV' AND SDATE >='" . $_GET["dtfrom"] . "' and SDATE <='" . $_GET["dtto"] . "'";
                
                 
                
                
                if($_GET['company'] !=""){
                     $sql1.=" and DEPARTMENT='".$_GET['company']."'"; 
                }
                 
                $sql1.=" order by DEPARTMENT,REF_NO"; 
                
     
                $i=0;
                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;">
          
                        <?php  
                        
                        if($company!=$row1['DEPARTMENT']){
                           if($i !=0){
                                echo "<tr>
                                 <td colspan='4'><b>   </b></td>
                                <td colspan='1' align=right><b>  ".number_format($GTOT, 2, ".", ",") ."   </b></td>
                                <td colspan='1' align=right><b>  ". number_format($TOTPAY, 2, ".", ",") ."   </b></td>
                                <td colspan='1' align=right><b>  ". number_format($BAL, 2, ".", ",") ."   </b></td>
                                </tr>";
                                
                           } 
                            $i = 1;
                            echo "<tr>
                                    <td colspan='7'><b>  ". $row_sto1['DESCRIPTION'] ."   </b></td> </tr>";
                            $GTOT=$row1['GRAND_TOT'];
                            $TOTPAY=$row1['TOTPAY'];
                            $BAL=($row1['GRAND_TOT']-$row1['TOTPAY']);
                             
                        }else{
                            $GTOT=$GTOT+$row1['GRAND_TOT'];
                            $TOTPAY=$TOTPAY+$row1['TOTPAY'];
                            $BAL=$BAL+($row1['GRAND_TOT']-$row1['TOTPAY']);
                        }
                        ?>
                        <td class="center" style='font-size:12px;'><?php echo $i ?></td>
                        <td class="left"  style='font-size:12px;'><?php echo $row1['REF_NO']; ?> </td>
                        <td class="left"  style='font-size:12px;'><?php echo $row1['SDATE']; ?> </td> 
                        <td class="left"  style='font-size:12px;'><?php echo $row1['C_CODE']; ?>&nbsp;-&nbsp;<?php echo $row1['CUS_NAME']; ?> </td>  
                        <td align="right" style='font-size:12px;'><?php echo number_format($row1['GRAND_TOT'], 2, ".", ","); ?></td> 
                        <td align="right" style='font-size:12px;'><?php echo number_format($row1['TOTPAY'], 2, ".", ","); ?></td> 
                        <td align="right" style='font-size:12px;'><?php echo number_format($row1['GRAND_TOT']-$row1['TOTPAY'], 2, ".", ","); ?></td> 
                    </tr>
                    <?php
                     $i=$i+1;
                     $company=$row1['DEPARTMENT']; 
                     
                     $GTOT_TOT=$GTOT_TOT+$row1['GRAND_TOT'];
                     $TOTPAY_TOT=$TOTPAY_TOT+$row1['TOTPAY'];
                     $BAL_TOT=$BAL_TOT+($row1['GRAND_TOT']-$row1['TOTPAY']);
                }
                ?>
           
           
            <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($GTOT, 2, ".", ",");  ?><b/></td>
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($TOTPAY, 2, ".", ",");  ?><b/></td>
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($BAL, 2, ".", ",");  ?><b/></td>
            </tr>
            
            <tr> 
                <td  align="right" colspan='4' style='font-size:20px;'><b>Total</b></td> 
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($GTOT_TOT, 2, ".", ",");  ?><b/></td>
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($TOTPAY_TOT, 2, ".", ",");  ?><b/></td>
                <td align="right" style='font-size:20px;'><b><?php   echo number_format($BAL_TOT, 2, ".", ",");  ?><b/></td>
            </tr>
        </table>
    
    
     <?php }?>
    <!--===================================================================================-->
    
    
    
 
<!-- ************************************************************************** -->
</center>
</body>

</html>
