<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
	<div class="tab_div">
<?php 
if($_REQUEST['type']=='sales'){?>
<h1>Form C Recievable</h1><?php }elseif($_REQUEST['type']=='purchase'){?>
<h1>Form C Issuable</h1>
<?php }?>
<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="3" style="border:solid 1px #808080; border-collapse:collapse;">
  <tr class="row1">
  <td width="13%" align="right"><strong>Branch</strong></td>
    <td width="20%">
	<select name="branch" id="branch" style="width:98%">
	<option value="0">Select</option>
	<?php 
	$loc=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
	while($loc_row=DB_fetch_array($loc))
	{?><option value="<?php echo $loc_row['loccode'];?>" <?php if($_REQUEST['branch']==$loc_row['loccode']) echo "selected";?>><?php echo $loc_row['locationname'];?></option>
	<?php }	?>
	</select>
	</td>
    <td width="13%" align="right"><strong>Party</strong></td>
    <td width="20%"><?php if($_REQUEST['type']=='sales'){?>
	<select name="client" id="client" style="width:98%">
	<option value="">Select</option>
	<?php $party=DB_query("Select id,client_code,c_name from clientmaster",$db);
	while($party_row=DB_fetch_array($party))
	{?><option value="<?php echo $party_row['id'];?>" <?php if($_REQUEST['client']==$party_row['id']) echo "selected";?>><?php echo $party_row['c_name'];?></option>
	<?php }	?>
	</select><?php }else
	{?> 
	<select name="vendor" id="vendor" style="width:98%">
	<option value="">Select</option>
	<?php $party=DB_query("Select id,vendor_code,vendor_name from suppliers",$db);
	while($party_row=DB_fetch_array($party))
	{?><option value="<?php echo $party_row['id'];?>" <?php if($_REQUEST['vendor']==$party_row['id']) echo "selected";?>><?php echo $party_row['vendor_name'];?></option>
	<?php }	?>
	</select>
	<?php } ?>
	</td>	
    <td width="13%" align="right"><strong>Form Type</strong></td>
    <td>
    	<select name="form_type" id="form_type" style="width:98%;">
		<option value="">Select</option>
		<?php
			$formSql=DB_query("Select * from form_type_master",$db);
			while($formRow=DB_fetch_array($formSql))
			{?><option value="<?php  echo $formRow['id']?>"<?php echo ($_REQUEST['form_type']==$formRow['id']?'selected':'')?>><?php  echo $formRow['form_name']?></option><?php }?>
		</select> 
	</td>
</tr>
<tr class="row1"> 
    <td align="right"><strong>From Date</strong></td>
    <td><input type="text" name="from" id="from" value="<?php echo $_REQUEST['from'];?>" class="datepicker" style="width:98%;" /></td>
    <td align="right"><strong>To Date</strong></td>
    <td><input type="text" name="to" id="to" value="<?php echo $_REQUEST['to'];?>" class="datepicker" style="width:98%;" /></td>
    <td colspan="2"></td>
  </tr>
 <tr class="row1">
 	<td colspan="6" align="center"><input type="submit" name="Show" value="Show" class="search" onclick="return validateSearch()" /></td>
 </tr>
</table>
</form>

<?php if($_REQUEST['Show']!='')
{?>
<h3 align="center">Pending Forms</h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#808080 1px solid; border-collapse:collapse;">
	<tr bgcolor="#fff">
		<td width="40%"><strong>Branch :</strong> <strong><?php if($_REQUEST['branch']) echo $s->getField('locations','loccode',$_REQUEST['branch'],'locationname');?></strong></td>
		<td width="30%"><strong>Party :</strong> <strong>
			<?php 
				if($_REQUEST['type']=='sales')
				 {
				 	echo $s->getField('clientmaster','id',$_REQUEST['client'],'c_name');
				 }
				 else
				 {
				 	echo $s->getField('suppliers','id',$_REQUEST['vendor'],'vendor_name');
				 }?>
				</strong>
		</td>
		<td width="15%"><strong>From Date :</strong> <strong><?php if($_REQUEST['from']) echo $_REQUEST['from'];?></strong></td>
		<td><strong>To Date :</strong> <strong><?php if($_REQUEST['to']) echo $_REQUEST['to'];?></strong></td>
</tr>
</table>
<br />
<table width="100%" cellspacing="0" cellpadding="3" border="1" style="border:solid 1px #808080; border-collapse:collapse;">
<tr>
<th width="8%">Date</th>
<th>Vch. No./Ref. No.</th>
<th width="14%">Assessable value</th>
<th width="14%">CST Amount</th>
<th width="14%">Invoive Amount</th>
<th width="16%">Form Type</th>
<th width="9%">Status</th>
</tr>
<?php 
//$form_type=DB_query("SELECT * FROM form_type_master where form_name like '%FORM-C%'",$db);
//$form_id=DB_fetch_array($form_type);

if($_REQUEST['type']=='sales')
{

			if($_REQUEST['branch'])
			{
				$filter[]="branch_name='".$_REQUEST['branch']."'";
			}
			if($_REQUEST['form_type'])
			{
				$filter[]="formType='".$_REQUEST['form_type']."'";
			}
			if($_REQUEST['client'])
			{
				$filter[]="client_id='".$_REQUEST['client']."'";
			}
			if($_REQUEST['from']!='' && $_REQUEST['to']!='')
			{
				$filter[]="invoiceDate between '".FormatDateFORSQL($_REQUEST['from'])."' and '".FormatDateFORSQL($_REQUEST['to'])."'";
			}
			
			if($filter!='')
			{
				$filter1=implode(" and ",$filter);
				 $invoice="select * from invoice where $filter1 ";
			}
			//$invoice="Select * from invoice where formType='".$form_id['id']."' and invoiceDate between '".$from_Sqlformat."' and '".				$to_Sqlformat."' and client_id='".$_REQUEST['client']."'";
		

		$invoice_res=DB_query($invoice,$db);
		$assess_array='';
		$cst_array='';
		$total_array='';
		if(DB_num_rows($invoice_res)>0)
		{
			while($invoice_row=DB_fetch_array($invoice_res))
			{
		?>
		<tr bgcolor="#FFFFFF">
			<td><?php echo ConvertSQLDate($invoice_row['invoiceDate']);?></td>
			<td><?php echo $invoice_row['invoiceNo'];?></td>
			<td align="right"><?php echo $t=$invoice_row['total_assessable_amt']; $assess_array[]=$t;?> DR</td>
			<td align="right"><?php echo $u=$invoice_row['exciseValue']; $cst_array[]=$u;?> DR</td>
			<td align="right"><?php echo $v=$invoice_row['grandTotal']; $total_array[]=$v;?> DR</td>
			<td><?php echo $s->getField('form_type_master','id',$invoice_row['formType'],'form_name'); ?></td>
			<td><?php echo $invoice_row['form_c_status'];?></td>
		</tr>
<?php 	} 
?>
<tr bgcolor="#fff">
<td></td>
<td><strong>Total</strong></td>
<td align="right"><?php if(isset($assess_array)){echo round(array_sum($assess_array));}?> DR</td>
<td align="right"><?php if(isset($cst_array)){echo round(array_sum($cst_array));}?> DR</td>
<td align="right"><?php if(isset($total_array)){echo round(array_sum($total_array));}?> DR</td>
<td></td>
<td></td>
</tr>
<?php 
} 
else
	{echo "<tr bgcolor='#fff'><td colspan='7' align='center'><b>No Record Found</b></td></tr>";}
}
elseif($_REQUEST['type']=='purchase')
{
	if($_REQUEST['branch'])
			{
				$filter[]="site='".$_REQUEST['branch']."'";
			}
			if($_REQUEST['form_type'])
			{
				$filter[]="form_type='".$_REQUEST['form_type']."'";
			}
			if($_REQUEST['vendor'])
			{
				$filter[]="vendor='".$_REQUEST['vendor']."'";
			}
			if($_REQUEST['from']!='' && $_REQUEST['to']!='')
			{
				$filter[]="bill_book_date between '".FormatDateFORSQL($_REQUEST['from'])."' and '".FormatDateFORSQL($_REQUEST['to'])."'";
			}
			
			if($filter!='')
			{
				$filter1=implode(" and ",$filter);
				 $purchase_bill="Select * from purchase_billbook where $filter1 ";
			}
			
	$purchase_res=DB_query($purchase_bill,$db);
		$assess_array='';
	$cst_array='';
	$total_array='';
	if(DB_num_rows($purchase_res)>0)
	{
		while($purchase_row=DB_fetch_array($purchase_res))
		{
		?>
		<tr bgcolor="#FFFFFF">
		<td><?php echo ConvertSQLDate($purchase_row['bill_date']);?></td>
		<td><?php echo $purchase_row['bill_book_no'];?></td>
		<td align="right"><?php echo $t=$purchase_row['total_item_amount']+$purchase_row['pkg_charges']+$purchase_row['excise_value']+$purchase_row['educess_value']+$purchase_row['she_ecess_value']+$purchase_row['freight']; $assess_array[]=$t;?> DR</td>
		<td align="right"><?php echo $u=$purchase_row['taxvalue']; $cst_array[]=$u;?> DR</td>
		<td align="right"><?php echo $v=$purchase_row['GrandTotal']; $total_array[]=$v;?> DR</td>
		<td><?php echo $s->getField('form_type_master','id',$purchase_row['form_type'],'form_name');?></td>
		<td><?php echo $purchase_row['form_c_status'];?></td>
		</tr>
<?php 	} 
?>
<tr>
<td></td>
<td><strong>Total</strong></td>
<td align="right"><?php if(isset($assess_array)){echo round(array_sum($assess_array));}?> DR</td>
<td align="right"><?php if(isset($cst_array)){echo round(array_sum($cst_array));}?> DR</td>
<td align="right"><?php if(isset($total_array)){echo round(array_sum($total_array));}?> DR</td>
<td></td>
<td></td>
</tr>
<?php 
	} 
	else
	{echo "<tr bgcolor='#fff'><td colspan='7' align='center'><b>No Record Found</b></td></tr>";}
}
?>
</table>
<?php } ?>

<script type="text/javascript">
	function validateSearch()
	{
		if(document.getElementById('branch').value=='0')
		{
			alert('Please select branch');
			return false;
		}
	}
</script>
</div>
</div>