<?php include('includes/fun-php.php') ?>
<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <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 width="20%"><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="12%" align="right">Party</td>
	<td><?php  
  		$sql=DB_query("select * from clientmaster",$db);		
		if(!$sql)
		{
		   die('Error.'.DB_error_msg($db));
		}
		echo "<select name='vender'>";
		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['c_name']."</option>";
		}
		echo "</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'];
 ?>
<br>
<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
  <tr>
    <th width="10%">Bill No.</th>
    <th width="8%" style="text-align:center;">Bill Date</th>
    <th>Party Name</th>
    <th width="8%" style="text-align:center;">Bill Amount</th>
	<th width="8%" style="text-align:center;">Pending amount</th>
    <th width="8%" style="text-align:center;">Due Date</th>
	<th width="8%" style="text-align:center;">Due Days</th>
	<th width="8%" style="text-align:center;">&lt;30 days</th>
	<th width="8%" style="text-align:center;">30 to 60 Days</th>
	<th width="8%" style="text-align:center;">60 to 90 Days</th>
	<th width="8%" style="text-align:center;">90 to 120 days</th>
	<th width="5%" style="text-align:center;">View</th>
  </tr>
  
  <?php $apr=0;
  $GT=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  client_id = '$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><?php  echo $row['invoiceNo']?></td>
	<td style="text-align:center;"><?php  echo ConvertSQLDate($row['invoiceDate'])?></td>
	<td><?php   //echo $row['vendor'];	
	echo $s->getField('clientmaster','id',$row['client_id'],'c_name');
	?></td>
	<td align="right"><?php  echo $row['grandTotal'];
	$GT[]= $row['grandTotal'];
	?></td>
	<td align="right"><?php  echo $row['pending_amount']?></td>
	<td style="text-align:center;"><?php  echo ConvertSQLDate($row['created_date'])?></td>
	<td style="text-align:center;"><?php echo $duedate= daysLeftForday($row['invoiceDate']) ;?></td>
	<td align="right"><?php  echo $duedate<30?$row['grandTotal']:''?></td>	
	<td align="right"><?php  echo ( $duedate>30 && $duedate<60)?$row['grandTotal']:''?></td>
	<td align="right"><?php  echo  ( $duedate>60 && $duedate<90)?$row['grandTotal']:''?></td>
	<td align="right"><?php  echo  ( $duedate>90)?$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 $apr++;
	}
  ?>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td align="right"><?php  echo array_sum($GT); ?></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
</table>
<?php } ?>
