<?php 
	setlocale(LC_MONETARY, 'en_IN');
?>

<form action="" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
  <tr class="row1">
  	<td width="7%" align="right">Branch</td>
  	<td width="18%"><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="7%" align="right">Month</td>
    <td width="18%"><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="7%" align="right">Year</td>
    <td width="18%"><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>
	<td width="7%" align="right">Vendor</td>
    <td><?php 
  		$sql=DB_query("select * from suppliers",$db);		
		if(!$sql)
		{
		   die('Error.'.DB_error_msg($db));
		}
		echo "<select name='vender' style='width:98%;'>";
		echo "<option value='0'>----</option>";
		while($row=DB_fetch_array($sql))
		{
		   $p='';
		   if($row['id']==$_REQUEST['vender'])
		   $p='selected';
		  echo "<option value='".$row['id']."' $p >".$row['vendor_name']."</option>";
		}
		echo "</select>";?></td>
</tr>
<tr class="row1">
  <td colspan="8" 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="APRColumnarRport_print.php" target="_blank" class="search">Print</a> <a href="APRColumnarRport_print_export.php?vat=true" class="search">Export</a>
  </p>
  <div style="width:100%; overflow:auto; float:left; padding:0;">
<table width="140%" border="0" cellpadding="3" cellspacing="0" class="thborder">
 <tr>
<th width="6%">Bill Date</th>
<th width="6%">Bill No.</th>
<th>Vendor</th>
<th width="6%">Tin No.</th>
<th width="6%">Bill Ref.</th>
<th width="6%" style="text-align:center;">Bill Ref. Date</th>
<th width="6%" style="text-align:center;">Basic Amount</th>
<th width="6%" style="text-align:center;">Discount</th>
<th width="6%" style="text-align:center;">Dis. Amount</th>
<th width="6%" style="text-align:center;">Pkg. Charges</th>
<th width="6%" style="text-align:center;">Non Tax Insurance</th>
<th width="6%" style="text-align:center;">Excise Duty</th>
<th width="3%" style="text-align:center;">E Cess</th>
<th width="3%" style="text-align:center;">SHE Cess</th>        
<th width="6%" style="text-align:center;">Taxable Amount</th>
<th width="3%" style="text-align:center;">Sales Tax</th>
<th width="3%" style="text-align:center;">SGST</th>
<th width="3%" style="text-align:center;">CGST</th>
<th width="3%" style="text-align:center;">IGST</th>
<th width="3%" style="text-align:center;">UTGST</th>
<th width="3%" style="text-align:center;">Surcharge Tax</th>
<th width="3%" style="text-align:center;">Entry Tax</th>
<th width="4%" style="text-align:center;">Insurance</th>
<th width="4%" style="text-align:center;">Freight</th>
<th width="4%" style="text-align:center;">Round Off</th>
<th width="6%" style="text-align:center;">Grand Total</th>
<th width="6%" style="text-align:center;">Branch</th>
<th width="3%" style="text-align:center;">View</th>
  </tr>
<?php $apr=0;
  $GT=array();$Basic=array();
 
    $filter=array();
    if($_REQUEST['month']!='0')
    $filter[]="month(bill_book_date)='".$month."'";
    if($_REQUEST['site']!='0')
    $filter[]="site='".$_REQUEST['site']."'";	   
    if($_REQUEST['vender']!='0')
    $filter[]="vendor='".$vendor_code."'";
    if(!empty($filter))
    $condition=implode(" and ",$filter);
    else 
    $condition="1=1";
  $query= "select *,total_item_amount as BSM from $table_name where  $condition and year(bill_book_date)='".$years."' ";
	
	 $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();
	$result=DB_query($query,$db);
	if(DB_num_rows($result)>0){
	while($row=DB_fetch_array($result))
	{
	  if($apr%2!=0)
	  $bg="bgcolor='#CCCCCC'";
	  else
	   $bg="bgcolor='#FFFFFF'";
	   ?>
    <tr <?php //echo $bg;?> >
	<td><?php  echo ConvertSQLDate($row['bill_book_date'])?></td>
	<td><?php  echo $row['bill_book_no']?></td>
	<td><?php echo $acname=$s->getField('suppliers','id',$row['vendor'],'vendor_name');	?></td>
	<td><?php   echo $tinno=$s->getField('suppliers','id',$row['vendor'],'tin_no');?></td>
	<td><?php  echo $row['bill_no']?></td>
	<td style="text-align:center;"><?php  echo ConvertSQLDate($row['bill_date']);	?></td>
	<td align="right"><?php  echo money_format('%!i',$row['total_item_amount']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['discount_amt']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['discounted_amt']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['pkg_charges']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['non_tax_insurance']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['excise_value']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['educess_value']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['she_ecess_value']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['tot_tax_amt']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['taxvalue']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['sgst_amt']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['cgst_amt']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['igst_amt']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['ugst_amt']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['sur_oct_amt']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['add_charges']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['insurance']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['freight']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['round_off']);?></td>
	<td align="right"><?php  echo money_format('%!i',$row['GrandTotal']);?></td>
	<td><?php  echo $row['site'];
	 $Basic[]=$row['total_item_amount'];
	 $discAM[]=$row['discount_amt'];
	 $discountedAM[]=$row['discounted_amt'];
	 $pkg[]=$row['pkg_charges'];
	 $non_tax_insurance[]=$row['non_tax_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['round_off'];
	 $GT[]=$row['GrandTotal'];
	 $sgst[]=$row['sgst_amt'];
	 $cgst[]=$row['cgst_amt'];
	 $igst[]=$row['igst_amt'];
	 $ugst[]=$row['ugst_amt'];
 ?></td>
	 <td><a href="index.php?route=Edit_DirectpurchBillBook&action=Edit&editId=<?php echo $row['id'];?>&action=viewReport&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>" target="_blank"><img src="images/search.gif" width="15" /></a></td>
  </tr>   
	   <?php $apr++;
	    $data_array[]=array("bill_date"=>$row['bill_book_date'],"bill_book_no"=>$row['bill_book_no'],"vendor_name"=>$acname,"tin_no"=>$tinno,"bill_no"=>$row['bill_no'],"bill_book_date"=>$row['bill_date'],"basic"=>$row['total_item_amount'],"discount_amt"=>$row['discount_amt'],"discounted_amt"=>$row['discounted_amt'],"pkg_charges"=>$row['pkg_charges'],"non_insurance"=>$row['non_tax_insurance'],"excise_amt"=>$row['excise_amt'],"ecess_amt"=>$row['ecess_amt'],"shecess_amt"=>$row['shecess_amt'],"tot_tax_amt"=>$row['tot_tax_amt'],"taxvalue"=>$row['taxvalue'],"sur_oct_amt"=>$row['sur_oct_amt'],"add_charges"=>$row['add_charges'],"insurance"=>$row['insurance'],"freight"=>$row['freight'],"roundoff"=>$row['round_off'],"GrandTotal"=>$row['GrandTotal'],"site"=>$row['site'],"sgst"=>$row['sgst_amt'],"cgst"=>$row['cgst_amt'],"igst"=>$row['igst'],"ugst"=>$row['ugst_amt']);
	}
}else{
	echo "<tr bgcolor='#fff'><td colspan='28'><center>There are no Result Found</center></td></tr>";
}
  ?>
<?php 
	if(DB_num_rows($result)>0){
?>
   <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>Total</td>    
      <td align="right"><?php echo money_format('%!i',array_sum($Basic)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($discAM)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($discountedAM)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($pkg)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($non_tax_insurance)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($excise)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($ecess)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($shecess)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($tot_taxamt)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($inputtax)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($sgst)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($cgst)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($igst)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($ugst)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($surcharge)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($addCharge)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($insurence)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($freight)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($other)); ?></td>
      <td align="right"><?php echo money_format('%!i',array_sum($GT)); ?></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>    
    </tr> 
 <?php } ?>
</table>
</div>
<?php 
$_SESSION['colornr']=$data_array;

} ?>
