<?php
session_start();
include './connection_sql.php';
if ($_SESSION["CURRENT_USER"] == "") { 
    exit('Please Logging Again..');
} 
if ($_SESSION['company'] == "") { 
    exit('Please Logging Again..');
} 
?>
<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>Pending Cheque Report</title>


    <style>
        @media print {
            a[href]:after {
                content: none !important;
            }
        }
        a:link, a:visited {

            text-decoration: none;
            color:#000000;
        }
        

        a:hover {
            text-decoration: underline;
        }
        body {
            color: #333;
            font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
            font-size: 12px;
            line-height: 1.42857;
        }
        .table > tbody > tr > td, .table > tbody > tr > th, .table > tfoot > tr > td, .table > tfoot > tr > th, .table > thead > tr > td, .table > thead > tr > th {
            border-top:1px solid #DDDDDD;
            line-height:1.42857;
            padding:2px;
            vertical-align:top;
        }
        .right {
            text-align: right;
        }    
        .center {
            text-align: center;
        }
    </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>

<body> 
    <?php
   
    require_once './gl_posting.php';


        $sql_rspara = "select * from a_dep_mas where COMCODE='".$_SESSION['company']."'";
        $result_rspara = $conn->query($sql_rspara);  
        if (!$row_rspara = $result_rspara->fetch()) {
            exit();
        }
   
    $txtdes = "Pending  Cheque Payments Report ";
    
    
    $table = "";
      $table .=  "<h3>" .  $row_rspara['COMPANY']  . "</h3>";
      $table .=  "<h4>" .  $txtdes  . "</h4>"; 

    
  
      
        $table .= "<table class='table' >
		
      	<tr>
            <th class='center'  style='width: 150px;'>Ref No</th>
            <th class='center'  style='width: 150px;'>Entry Date</th>
            <th class='center'  style='width: 300px;'>Supplier</th>
            <th class='center'  style='width: 100px;'>Cheque No	</th>
            <th class='center'  style='width: 100px;'>Cheque Date</th>   
            <th class='center'  style='width: 300px;'>Bank</th>   
            <th class='center'  style='width: 150px;'>Amount</th>     		
        </tr>";
 
        $sql_rsPrInv = "select  * from a_paymas where cancel='0' AND PAY_TYPE !='CASH'";
        if($_GET["chk_date"] == true){
            $sql_rsPrInv .= "   and chqdt>='" . $_GET["dtfrom"] . "' and chqdt<='" . $_GET["dtto"] . "' " ; 
        }
        if($_GET["c_code"] !=''){
            $sql_rsPrInv .= "   and VEN_CODE = '" . $_GET["c_code"].  "' " ; 
        }
        // company = '" . $_SESSION['company'] .  "'
        $sql_rsPrInv .= "   ORDER BY chqdt,VEN_CODE  " ; 
         $i=0;
     $chqdt ==""; 
        foreach ($conn->query($sql_rsPrInv) as $row_rsPrInv) {
            
            $sql_lcode = " SELECT * from a_lcodes where C_CODE='" . $row_rsPrInv["CODE"] . "' ";
            $result_lcode = $conn->query($sql_lcode);
            $row_lcode = $result_lcode->fetch();
                        
                        if($chqdt!=$row_rsPrInv['chqdt']){
                           if($i !=0){
                               $table .= "<tr>
                                 <td colspan='6'><b>   </b></td>
                                <td colspan='1' align=right><b>  ".number_format($AMOUNT, 2, ".", ",") ."   </b></td>
                                </tr>";
                                
                           } 
                            $i = 1;
                           $table .= "<tr>
                                    <td colspan='7'><b>  ". $row_rsPrInv["chqdt"] ."   </b></td> </tr>";
                             $AMOUNT =$row_rsPrInv['AMOUNT'];
                             
                        }else{
                            $AMOUNT +=$row_rsPrInv['AMOUNT'];
                        }
                       
    
                    $table .= "<tr><td>" . $row_rsPrInv["REFNO"] . "</td>
			                    <td>" . $row_rsPrInv["BDATE"] . "</td>
			                    <td>" . $row_rsPrInv["VEN_CODE"] . " " . $row_rsPrInv["Barer"] . "</td> 
			                    <td>" . $row_rsPrInv["CHENO"] . "</td> 
			                    <td>" . $row_rsPrInv["chqdt"] . "</td>
			                    <td>" . $row_lcode["C_NAME"] . "</td> 
			                    <td  class='right'>" . number_format($row_rsPrInv['AMOUNT'], 2, ".", ",") . "</td>"; 
                    $table .= "</tr>";
                    
            $chqdt= $row_rsPrInv["chqdt"];
                
            $AMOUNT_TOT +=$row_rsPrInv['AMOUNT'];
        }
     
    
    
         $table .= "<tr><td colspan=6>&nbsp;</td>
    		<th  class='right'>" . number_format($AMOUNT, 2, ".", ",") . "</th>";
    		
    		 $table .= "<tr><td colspan=6>&nbsp;</td>
    		<th  class='right'>" . number_format($AMOUNT_TOT, 2, ".", ",") . "</th>";
    		 
    
    
    $table .= "</table>
 
</body>
</html>";

    echo $table;

    