
<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
  	<td width="12%" align="right">Site</td>
  	<td width="20%"><select name="site"  onchange="getLedgerName(this.value);">
  <option value="0">All</option>
  <?php 
 	   $ss="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'"; 
$site_sql=DB_query($ss,$db);
while($site_row=DB_fetch_array($site_sql))
{?>
  <option value="<?php echo $site_row['loccode'];?>"<?php echo($_REQUEST['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
  <?php 	
}
?>
</select></td>
    <td width="12%" align="right">Month</td>
    <td width="20%"><select name="month" >
	<?php $amonth=array('ALL','Jan','Feb','March','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec');
	  for($i=0;$i<count($amonth) ;$i++)
	  {
	   $p='';
	   if($_REQUEST['month']==$i)
	   $p='selected';
	   
	    echo "<option value='".$i."' $p>$amonth[$i]</option>";
	  }
	?></select></td>
    <td width="12%" align="right">Year</td>
    <td>
	<select name="years" >
	<?php 
	  for($i=date('Y');$i>=2000;$i--)
	  {
	  $p='';
	   if($_REQUEST['years']==$i)
	   $p='selected';
	    echo "<option value='".$i."' $p>$i</option>";
	  }
	?></select>
	</td>
</tr>
<tr class="row1">
    <td colspan="6" style="text-align:center;"><input type="submit" name="search" value="Search" class="search" /></td>
  </tr>
</table>
</form>

<?php

if($_REQUEST['search'])
{
$month=$_REQUEST['month'];
$years=$_REQUEST['years'];
$vendor_code=$_REQUEST['vender'];
 ?>
  <p align="right">
  <a href="ASRColumnarRport_print.php" target="_blank" class="search">Print</a> <a href="ASRColumnarRport_print_export.php?vat=true" class="search">Export</a>
  </p>
  <div style="width:100%; overflow:auto; float:left;">
<table width="140%" border="0" cellpadding="3" cellspacing="0" class="thborder">
  <tr>
    <th width="4%" style="text-align:center;">Date</th>
    <th>Party</th>
    <th width="5%">Tin No.</th>
    <th width="5%">Bill Ref.</th>
    <th width="5%" style="text-align:center;">Bill Date</th>
	<th width="5%" style="text-align:center;">Basic</th>
	<th width="5%" style="text-align:center;">Dis.</th>
	<th width="5%" style="text-align:center;">Dis. Amt.</th>
	<th width="5%">Pkg.</th>
	<th width="6%" style="text-align:center;">Assessable</th>
	<th width="6%" style="text-align:center;">Excise</th>
	<th width="4%" style="text-align:center;">E-Cess</th>
	<th width="4%" style="text-align:center;">SAH-E Cess</th>
	<th width="4%" style="text-align:center;">Taxable</th>
	<th width="4%" style="text-align:center;">Sales Tax</th>
	<th width="4%" style="text-align:center;">Surcharge</th>
	<th width="4%" style="text-align:center;">Insurance</th>
	<th width="5%" style="text-align:center;">Other</th>
	<th width="5%" style="text-align:center;">Freight</th>
	<th width="5%" style="text-align:center;">Grand Total</th>
	<th width="8%">Unit Branch</th>   
	<th width="4%" style="text-align:center;">View</th>
  </tr>
<?php $apr=0;
  $GT=array();
  $Basic=array();
  $dis_amt= array();
	$discounted_amt=array();
	$packagingCharges=array();
	$total_assessable_amt=array();
	$exciseValue=array();
	$ECessValue=array();
	$SAHCessValue=array();
	$taxableAmount=array();
	$VatCstValue=array();
	$surcharge_amt=array();
	$insurance=array();
	$additionalCharges=array();
	$freightValue=array();
$asr_datav=array();
 
  
  if($month!=0)
$condition="1=1 and month(invoiceDate)='".$month."' and  year(invoiceDate)='".$years."'  ";else
$condition="1=1 and  year(invoiceDate)='".$years."'  "; 
  
  if($vendor_code!=0)
   $query= "select *,basicAmount as BSM from $table_name where   vendor = '$vendor_code'and  $condition  ";
  else
  
 $query= "select *,basicAmount as BSM from $table_name where $condition ";
	 
	 
	$result=DB_query($query,$db);
	while($row=DB_fetch_array($result))
	{
	  if($apr%2!=0)
	  $bg="bgcolor='#CCCCCC'";
	  else
	   $bg="bgcolor='#FFFFFF'";
	   ?>
    <tr  <?php //echo $bg;?>  >
	<td style="text-align:center;"><?php  echo 
ConvertSQLDate($row['created_date'])?></td>
	<td><?php   //echo $row['vendor'];	
	echo $clientId=$s->getField('clientmaster','id',$row['client_id'],'c_name');
	?></td>
	<td><?php 	echo $tinNo=$s->getField('clientmaster','id',$row['client_id'],'tin_no');?></td>
	<td><?php  echo $row['invoiceNo']?></td>
	<td style="text-align:center;"><?php  echo ConvertSQLDate($row['invoiceDate']);	?></td>
	<td style="text-align:right;"><?php  echo money_format('%!i',$row['basicAmount']); ?></td>
	<td style="text-align:right;"><?php  echo money_format('%!i',$row['dis_amt']); ?></td>
	<td style="text-align:right;"><?php  echo money_format('%!i',$row['discounted_amt']);?></td>
	<td style="text-align:right;"><?php  echo money_format('%!i',$row['packagingCharges']);?></td>
	<td style="text-align:right;"><?php  echo money_format('%!i',$row['total_assessable_amt']); ?></td>
	<td style="text-align:right;"><?php  echo money_format('%!i',$row['exciseValue']); ?>&nbsp; </td>
	<td style="text-align:right;"><?php  echo money_format('%!i',$row['ECessValue']); ?></td>
	<td style="text-align:right;"><?php  echo money_format('%!i',$row['SAHCessValue']); ?></td>
	<td style="text-align:right;"><?php  echo money_format('%!i',$row['taxableAmount']); ?></td>
	<td style="text-align:right;"><?php  echo money_format('%!i',$row['VatCstValue']); ?></td>
	<td style="text-align:right;"><?php  echo money_format('%!i',$row['surcharge_amt']); ?></td>
	<td style="text-align:right;"><?php  echo money_format('%!i',$row['insurance']); ?></td>
	<td style="text-align:right;"><?php  echo money_format('%!i',$row['additionalCharges']); ?></td>
	<td style="text-align:right;"><?php  echo money_format('%!i',$row['freightValue']); ?></td>
	<td style="text-align:right;"><?php  echo money_format('%!i',$row['grandTotal']); ?></td>
	<td><?php  echo $row['branch_name'];
	 
	 $Basic[]=$row['basicAmount'];
	$dis_amt[]= $row['dis_amt'];
	$discounted_amt[]=$row['discounted_amt'];
	$packagingCharges[]=$row['packagingCharges'];
	$total_assessable_amt[]=$row['total_assessable_amt'];
	$exciseValue[]=$row['exciseValue'];
	$ECessValue[]=$row['ECessValue'];
	$SAHCessValue[]=$row['SAHCessValue'];
	$taxableAmount[]=$row['taxableAmount'];
	$VatCstValue[]=$row['VatCstValue'];
	$surcharge_amt[]=$row['surcharge_amt'];
	$insurance[]=$row['insurance'];
	$additionalCharges[]=$row['additionalCharges'];
	$freightValue[]=$row['freightValue'];
	$GT[]=$row['grandTotal'];
	 ?></td>
	 <td style="text-align:center;"><a href="index.php?route=InvoiceDetails<?php echo $rurl;?>&action=view&InvoiceId=<?php echo $row['invoice_id'] ?>" target="_blank"><img src="images/search.gif" width="15" height="15" /></a></td>
  </tr>
   
	   <?php 
$asr_datav[]=array("created_date"=>$row['created_date'],"clientId"=>$clientId,"tinNo"=>$tinNo,$invoiceNo=$row['invoiceNo'],"invoiceDate"=>$row['invoiceDate'],"basicAmount"=>$row['basicAmount'],"dis_amt"=>$row['dis_amt'],"discounted_amt"=>$row['discounted_amt'],"packagingCharges"=>$row['packagingCharges'],"total_assessable_amt"=>$row['total_assessable_amt'],"exciseValue"=>$row['exciseValue'],"ECessValue"=>$row['ECessValue'],"SAHCessValue"=>$row['SAHCessValue'],"taxableAmount"=>$row['taxableAmount'],"VatCstValue"=>$row['VatCstValue'],"surcharge_amt"=>$row['surcharge_amt'],"insurance"=>$row['insurance'],"additionalCharges"=>$row['additionalCharges'],"freightValue"=>$row['freightValue'],"grandTotal"=>$row['grandTotal'],"branch_name"=>$row['branch_name']);
	   $apr++;
	}
	$_SESSION['colornrv']=$asr_datav;

  ?>
   <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td style="text-align:right;">Total</td>
      <td style="text-align:right;"><?php echo money_format('%!i',array_sum($Basic)); ?></td>
      <td style="text-align:right;"><?php echo money_format('%!i',array_sum($dis_amt)); ?></td>
      <td style="text-align:right;"><?php echo money_format('%!i',array_sum($discounted_amt)); ?></td>
      <td style="text-align:right;"><?php echo money_format('%!i',array_sum($packagingCharges)); ?></td>
      <td style="text-align:right;"><?php echo array_sum($total_assessable_amt); ?></td>
      <td style="text-align:right;"><?php echo money_format('%!i',array_sum($exciseValue)); ?></td>
      <td style="text-align:right;"><?php echo money_format('%!i',array_sum($ECessValue)); ?></td>
      <td style="text-align:right;"><?php echo money_format('%!i',array_sum($SAHCessValue)); ?></td>
      <td style="text-align:right;"><?php echo money_format('%!i',array_sum($taxableAmount)); ?></td>
      <td style="text-align:right;"><?php echo money_format('%!i',array_sum($VatCstValue)); ?></td>
      <td style="text-align:right;"><?php echo money_format('%!i',array_sum($surcharge_amt)); ?></td>
      <td style="text-align:right;"><?php echo money_format('%!i',array_sum($insurance)); ?></td>
      <td style="text-align:right;"><?php echo money_format('%!i',array_sum($additionalCharges)); ?></td>
      <td style="text-align:right;"><?php echo money_format('%!i',array_sum($freightValue)); ?></td>
      <td style="text-align:right;"><?php echo money_format('%!i',array_sum($GT)); ?></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr> 
 
</table>
</div>
<?php } ?>
