<?php
$PageSecurity = 1;
session_name('CAKEPHP'); session_start();
ob_start();
$PageSecurity = 1;
include('config.php');
include('includes/ConnectDB.inc');
include('includes/function_lib.php');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');
include('Account/fun-Trial.php');
?>
<?php
header("Content-type: application/x-msdownload"); 
header("Content-Disposition: attachment; filename=Account_payble_Export.xls"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
?>
<style type="text/css">
.f12{font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000;}
.f11{font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#000;}
</style>
<title>Account Payble Bill wise Report</title>
<?php 
$sql1 = "SELECT CompanyName FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
$sqlres = DB_query($sql1,$db);
$companyRow = DB_fetch_array($sqlres);
?>
<div style="text-align:center; color:#006699; margin:0px; border:#000000 solid 0px;">
<?php 

if($companyRow['CompanyName']!="") {echo "<b>".$companyRow['CompanyName']."</b>"; } else { echo "";}
if($companyRow['Address1']!="") {echo "<br>".$companyRow['Address1']; } else { echo "";}
if($companyRow['Address2']!="") {echo ",".$companyRow['Address2']; } else { echo "";}
if($companyRow['Address3']!="") {echo ",".$companyRow['Address3']; } else { echo "";}
if($companyRow['City']!="") {echo "<br>".$companyRow['City']; } else { echo "";}
if($companyRow['State']!="") {echo ",".$companyRow['State']; } else { echo "";}
if($companyRow['Country']!="") {echo ",".$companyRow['Country'];
if($companyRow['Zipcode']!="") {echo " - ".$companyRow['Zipcode']; } else { echo "";}

} else { echo "";}

?>
<div style="width:100%; color:#006699; font-size:16px; font-weight:900; padding-bottom:10px; text-align:center;">Account Payble Bill wise Report
</div>

 <table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse;">
<tr bgcolor="#CCCCCC" class="f12" height="25">
<td align="left" valign="middle"><strong>Voucher Date</strong></td>
<td align="left" valign="middle" ><strong>Voucher No.</strong></td>
<td align="left" valign="middle"><strong>Vendor</strong></td>
<td align="left" valign="middle"><strong>Bill Ref.</strong></td>
<td align="left" valign="middle"><strong>Bill Ref date</strong></td>
<td align="left" valign="middle"><strong>Bill Amount</strong></td>
<td align="left" valign="middle"><strong>Pending amount</strong></td>
<td align="left" valign="middle"><strong>Due Date</strong></td>
<td align="left" valign="middle"><strong>Due Days</strong></td>
<td align="left" valign="middle"><strong>Status</strong></td>

  </tr>
  <?php 
  $searched2=$_SESSION['acc_payble'];


  if(!empty($searched2))
  {
  foreach($searched2 as $key=>$row)
  {
    $duedate=$row['due_days'];
    if($row['pending_amt']!=0)
	{
   ?>
   <tr class="f11">
   <td align="left" valign="top"><?php  echo ConvertSQLDate($row['bill_date'])?></td>
	<td align="left" valign="top"><?php  echo $row['bill_book_no']?></td>
	<td align="left" valign="top"><?php echo $row['vendor'];	?></td>	
	<td align="left" valign="top"><?php  echo $row['bill_no']?></td>
	<td align="left" valign="top"><?php  echo ConvertSQLDate($row['bill_book_date']);	?></td>
	<td align="right" valign="top"><?php  echo $row['GrandTotal'];
	 $GT[]= $row['GrandTotal'];?></td>

	 <td align="right" valign="top"><?php  echo $row['pending_amt'];
     $duedate=$row['due_days'];
    if($duedate>0)
    {
          $PT1[]=$row['pending_amt'];
        }else{
          $PT2[]=$row['pending_amt'];
        }
    ?></td>
	<td align="left" valign="top"><?php  echo ConvertSQLDate($row['due_date'])?></td>
	<td align="left" valign="top">
    <?php 
    //echo $row['due_days'];
    $cur_date=date('Y-m-d');
              $date1=date_create($row['due_date']);
              $date2=date_create($cur_date);
              $diff=date_diff($date1,$date2);
              echo $remdays=$diff->format("%a");
  ?> 
  </td>
	<td align="left" valign="top"><?php  echo $row['status'];?></td>
  </tr> 
 <?php } } ?>
    <tr class="f11">
       <td align="left" valign="top"><strong></strong></td>
        <td align="left" valign="top"><strong></strong></td>
         <td align="left" valign="top"><strong></strong></td>
         <td align="left" valign="top"><strong></strong></td>
         <td align="left" valign="top"><strong></strong></td>
          <td align="left" valign="top">Over Due:</td>
           <td align="right" valign="top"><?php  echo $PGT1=(!empty($PT1))?array_sum($PT1):0; ?></td>
            <td align="left" valign="top"><strong></strong></td>
          <td align="left" valign="top"><strong></strong></td>
           <td align="left" valign="top"><strong></strong></td>
          
        </tr>
        <tr class="f11">
       <td align="left" valign="top"><strong></strong></td>
        <td align="left" valign="top"><strong></strong></td>
         <td align="left" valign="top"><strong></strong></td>
         <td align="left" valign="top"><strong></strong></td>
         <td align="left" valign="top"><strong></strong></td>
          <td align="left" valign="top">Pending:</td>
           <td align="right" valign="top"><?php  echo $PGT2=(!empty($PT2))?array_sum($PT2):0; ?></td>
            <td align="left" valign="top"><strong></strong></td>
          <td align="left" valign="top"><strong></strong></td>
           <td align="left" valign="top"><strong></strong></td>
          
        </tr>
        <tr class="f11">
      <td align="left" valign="top">&nbsp;</td>
      <td align="left" valign="top">&nbsp;</td>
      <td>&nbsp;</td>
      <td align="left" valign="top"><strong></strong></td>
         <td align="left" valign="top"><strong></strong></td>
      <td align="left" valign="top">Grand Total:&nbsp;</td>
      <td align="right" valign="top"><?php  echo $PGT1+$PGT2; ?>&nbsp;</td>
      <td align="left" valign="top">&nbsp;</td>
      <td align="left" valign="top">&nbsp;</td>
      <td align="left" valign="top">&nbsp;</td>
    </tr>

 <?php } else {?>
 <tr class="f11">
 <td colspan="19">No Result Found.</td>
 </tr>
 <?php } ?>
</table>
