<?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');
setlocale(LC_MONETARY, 'en_IN');
 ?>
  <?php
header("Content-type: application/x-msdownload"); 
header("Content-Disposition: attachment; filename=APROutstandingReport.xls"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
?>
<style type="text/css">
.f12{font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000; font-weight:bold;}
.f11{font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#000;}
</style>
 <title>Vendor Wise Purchase 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;">Columnar Purchase Register
</div>

 <table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse;">
<tr bgcolor="#CCCCCC" class="f12" height="25">
<td width="7%" align="left" valign="middle">Voucher Date </td>
<td width="8%" align="left" valign="middle" >Voucher No. </td>
<td width="15%" align="left" valign="middle">Vendor </td>
<td width="5%" align="left" valign="middle">Bill Ref. </td>
<td width="6%" align="left" valign="middle">Bill Ref date </td>
<td align="left" valign="middle">Bill Amount </td>
<td align="left" valign="middle">Due Date </td>
<td align="left" valign="middle">Due Days </td>
<td align="left" valign="middle">&lt;30 days </td>
<td align="left" valign="middle">30 to 60 Days </td>
<td align="left" valign="middle">60 to 90 Days </td>
<td align="left" valign="middle">90 to 120 days </td>

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


  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 money_format('%!i',$row['GrandTotal']);
   $GT[]= $row['GrandTotal'];?></td>
  <td align="left" valign="top"><?php  echo ConvertSQLDate($row['due_date'])?></td>
  <td align="right" valign="top"><?php echo $duedate;?></td>
  <td align="right" valign="top"><?php  echo $duedate<30 ?money_format('%!i',$row['GrandTotal']):''?></td>
   
  
  <td align="right" valign="top"><?php  echo ( $duedate>30 && $duedate<60)?$row['GrandTotal']:''?></td>
  <td align="right" valign="top"><?php  echo  ( $duedate>60 && $duedate<90)?money_format('%!i',$row['GrandTotal']):''?></td>
  <td align="right" valign="top"><?php  echo  ( $duedate>90)?money_format('%!i',$row['GrandTotal']):''?></td>

  




  </tr> 
 <?php } } ?>
  <tr >
      <td>&nbsp;</td>
      <td>&nbsp;</td>
       <td>&nbsp;</td>
      <td class="f12">&nbsp;</td>
      <td class="f12">Total</td>
      <td class="f12" style="text-align:right;"><?php  echo money_format('%!i',array_sum($GT)) ;  ?></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      </tr>

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