<?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=APRColumnarRport.xls"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
?>
 <title>Columnar Purchase Register</title>
 <?php 
$sql1 = "SELECT CompanyName FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
$sqlres = DB_query($sql1,$db);
$companyRow = DB_fetch_array($sqlres);
?>
<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>
<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" height="25">
 <td align="left" valign="middle" class="f12">Branch</td>
<td align="left" valign="middle" class="f12">Voucher Date </td>
<td align="left" valign="middle" class="f12">Voucher No.</td>
<td align="left" valign="middle" class="f12">Vendor</td>
<td align="left" valign="middle" class="f12">Tin No.</td>
<td align="left" valign="middle" class="f12">Bill Ref.</td>
<td align="left" valign="middle" class="f12">Bill Ref date</td>
<td align="left" valign="middle" class="f12">Basic Amount</td>
<!-- <td align="left" valign="middle" class="f12">Discount</td>
<td align="left" valign="middle" class="f12">Discounted Amount</td> -->
<td align="left" valign="middle" class="f12">Pkg.Charges</td>
<!-- <td align="left" valign="middle" class="f12"><strong>Non Tax Insurance</strong></td> -->
<td align="left" valign="middle" class="f12">Excise Duty </td>
<td align="left" valign="middle" class="f12">E Cess</td>
<td align="left" valign="middle" class="f12">SHE Cess</td>        
<!-- <td align="left" valign="middle" class="f12">Taxable Amount</td> -->
<td align="left" valign="middle" class="f12">Freight</td>
<td align="left" valign="middle" class="f12">Purchase Tax </td>
<td align="left" valign="middle" class="f12">SGST</td>
<td align="left" valign="middle" class="f12">CGST</td>
<td align="left" valign="middle" class="f12">IGST</td>
<td align="left" valign="middle" class="f12">UGST</td>
<td align="left" valign="middle" class="f12">Surcharge Tax</td>
<!-- <td align="left" valign="middle" class="f12">Entry Tax</td> -->
<td align="left" valign="middle" class="f12">Insurance</td>
<td align="left" valign="middle" class="f12">Round Off</td>
<td align="left" valign="middle" class="f12">Grand Total</td>

  </tr>
  <?php 
   $GT=array();
	 $Basic=array();
	 $pkg=array();
	 $excise=array();
	 $ecess=array();
	 $shecess=array();
	 $discAM=array();
	 $discountedAM=array();
	 $taxable_fright=0;
	 $inputtax=array();
	 $surcharge=array();
	 $freight=array();
	 $other=array();
	 $roundoff=array();
	 $taxable_fright=array();
	 $sgst=array();
	 $cgst=array();
	 $igst=array();
	 $ugst=array();
  $searched2=$_SESSION['colornr'];
  if(!empty($searched2))
  {
  foreach($searched2 as $key=>$row)
  {
   ?>
   <tr> 
   <td align="left" valign="top" class="f11"><?php echo $row['site'];?></td>
   <td align="left" valign="top" class="f11"><?php  echo ConvertSQLDate($row['bill_date'])?></td>
	<td align="left" valign="top" class="f11"><?php  echo $row['bill_book_no']?></td>
	<td align="left" valign="top" class="f11"><?php echo $row['vendor_name'];	?></td>
	<td align="left" valign="top" class="f11"><?php   echo $row['tin_no'];?></td>
	<td align="left" valign="top" class="f11"><?php  echo $row['bill_no']?></td>
	<td align="left" valign="top" class="f11"><?php  echo ConvertSQLDate($row['bill_book_date']);	?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['basic']); ?></td>
	<!-- <td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['discount_amt']); ?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['discounted_amt']); ?></td> -->
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['pkg_charges']); ?></td>
	<!-- <td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['non_insurance']); ?></td> -->
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['excise_amt']); ?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['ecess_amt']); ?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['shecess_amt']);?></td>
	<!-- <td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['tot_tax_amt']); ?></td> -->
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['freight']); ?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['taxvalue']);?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['sgst']);?></td>
     <td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['cgst']);?></td>
     <td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['igst']);?></td>
     <td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['ugst']);?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['sur_oct_amt']);?></td>
	<!-- <td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['add_charges']);?></td> -->
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['insurance']);?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['roundoff']); ?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['GrandTotal']);?></td>
	<?php  
	 $Basic[]=$row['basic'];
	// $discAM[]=$row['discount_amt'];
	 //$discountedAM[]=$row['discounted_amt'];
	 $pkg[]=$row['pkg_charges'];
	// $non_insurance[]=$row['non_insurance'];
	 $excise[]=$row['excise_amt'];
	 $ecess[]=$row['ecess_amt'];
	 $shecess[]=$row['shecess_amt'];
	 $tot_taxamt[]=$row['tot_tax_amt'];
	 $inputtax[]=$row['taxvalue'];
	 $surcharge[]=$row['sur_oct_amt'];
	 $addCharge[]=$row['add_charges'];
	 $insurence[]=$row['insurance'];
	 $freight[]=$row['freight'];
	 $other[]=$row['roundoff'];
	 $GT[]=$row['GrandTotal'];
	 $sgst[]=$row['sgst'];
	 $cgst[]=$row['cgst'];
	 $igst[]=$row['igst'];
	 $ugst[]=$row['ugst'];


	 ?>
  </tr> 
 <?php }
  ?>
 <tr  style="height:20px;"  >
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td class="f12">Total</td>    
     <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($Basic)); ?>&nbsp;</td>
     <!--  <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($discAM)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($discountedAM)); ?>&nbsp;</td> -->
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($pkg)); ?>&nbsp;</td>
         <!-- <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($non_insurance)); ?>&nbsp;</td> -->
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($excise)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($ecess)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($shecess)); ?>&nbsp;</td>
     <!-- <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($tot_taxamt)); ?>&nbsp;</td> -->
     <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($freight)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($inputtax)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($sgst)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($cgst)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($igst)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($ugst)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($surcharge)); ?>&nbsp;</td>
       <!-- <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($addCharge)); ?>&nbsp;</td> -->
       <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($insurence)); ?>&nbsp;</td>
       <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($other)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($GT)); ?>&nbsp;</td>
    
    </tr> 

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