<?php session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cheque Report</title>
<style>
body
{
font-size:14px;
}

</head>
</style>
<body>
<?php


date_default_timezone_set('Asia/Colombo'); 




	include('connectioni.php');
	
$table .= "<table width=\"922\" border=\"0\">
  <tr>
    <td colspan=\"3\" align=\"center\"><span class=\"companyname\">"; 
		if ($_SESSION['company']=="EF"){
			$table .= "E-Friendly";
		}
		
		if ($_SESSION['company']=="BE"){
			$table .= "Benedicsons (Pvt) Ltd";
		}
		
		if ($_SESSION['company']=="TH"){
			$table .= "Tyre House Trading (Pvt) Ltd";
		}
	
	$table .= "  </span></td>
  </tr>
 
  
  
  <tr>";
  if ($_GET["optext"]=="true"){
   $table.=" <td height=\"21\">Extra Income Report Date From - ".$_GET["repdatefrom"]." To - ".$_GET["repdateto"]."</td>";
  } else if ($_GET["optbankdepo"]=="true"){
   $table.=" <td height=\"21\">Bank Deposit Report Date From - ".$_GET["repdatefrom"]." To - ".$_GET["repdateto"]."</td>";
  } else if ($_GET["opttt"]=="true"){
   $table.=" <td height=\"21\">TT Report Date From - ".$_GET["repdatefrom"]." To - ".$_GET["repdateto"]."</td>";
  } 
    $table.="<td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  
  
  <tr>
    <td height=\"199\" colspan=\"3\">";
	
	
	$table.="<table width=\"904\" height=\"81\" border=\"1\" cellspacing=\"0\">
		
      	<tr>
        <th width=\"70\" height=\"23\">Date</th>
        <th width=\"80\">Ref No</th>
        <th width=\"80\">Code</th>
        <th width=\"200\">Ledger Name</th>
        <th width=\"300\">Narration</th>
        <th width=\"100\">Cheque No</th>
        <th width=\"100\">Amount</th>
		
        </tr>";
	
        $strsql = "select * from view_ledger  where  l_yearfl != '2' and  l_yearfl != '1' and  l_date >='" . $_GET["repdatefrom"] . "' and l_date <='". $_GET["repdateto"] . "' and l_flag1 = 'DEB' ";
	
        if ($_GET["optbankdepo"]=="true"){
            $strsql .= "and dep_type = 'dep' ";
	}
        if ($_GET["opttt"]=="true"){
            $strsql .= "and dep_type = 'tt' ";
	}
        if ($_GET["optext"]=="true"){
            $strsql .= "and dep_type = 'ext' ";
	}
        if ($_GET["accno"]!="all"){
            $strsql .= "and l_code = '" . $_GET["accno"] . "' ";
	}
        
        if ($_GET["optdate"]=="true"){
            $strsql .= "order by l_date";
        }else{
            $strsql .= "order by l_refno";
        }
                
	//echo $strsql;
	
		$deb=0;
		$cre=0;
	
			$result_strsql=mysqli_query($GLOBALS['dbacc'],$strsql);
			while ($row_strsql = mysqli_fetch_array($result_strsql)){
			
			if ($row_strsql["l_refno"]!=$l_refno){	
				$table.="
		
      				<tr>
        <td width=\"70\" height=\"23\" colspan=7>&nbsp;</td>
       
	    </tr>";	
			}
			
	
				$table.="
		
      	<tr>
        <td width=\"70\" height=\"23\">".$row_strsql["l_date"]."</td>
        <td width=\"400\">".$row_strsql["l_refno"]."</td>
        <td width=\"100\">".$row_strsql["l_code"]."</td>
		<td width=\"100\">".$row_strsql["name"]."</td>
		<td width=\"100\">".$row_strsql["l_head"]."</td>
        <td width=\"100\">".$row_strsql["chno"]."</td>
        <td width=\"100\">".$row_strsql["l_amount"]."</td>
	    </tr>";	
			
			
			if ($row_strsql["l_flag1"]=="DEB"){
				$deb=$deb+$row_strsql["l_amount"];
			}
			
//			if ($row_strsql["l_flag1"]=="CRE"){
//				$cre=$cre+$row_strsql["l_amount"];
//			}
			
			$l_refno=$row_strsql["l_refno"];
		
		}
		
		$table.="
		
      				<tr>
        <td width=\"70\" height=\"23\" colspan=5><b>Debit Total - ".number_format($deb, 2, ".", ",")."</b></td>
       
	    </tr>";
		
//		$table.="
//		
//      				<tr>
//        <td width=\"70\" height=\"23\" colspan=5><b>Credit Total - ".number_format($cre, 2, ".", ",")."</b></td>
//       
//	    </tr>";	
		echo $table;
//$file="report/rpt_jou_datewise.xls";
//   
//    $f = fopen($file, "w+");
//  
//    fwrite($f,$table);
  
//	echo "<a href=\"report/rpt_jou_datewise.xls\">Download Excel Report</a>";

?>
</body>
</html>
