<?php
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
if($_REQUEST['action']=='delete' and $_REQUEST['Id']!='')
{
$update="delete from local_fright where id='".$_REQUEST['Id']."'";
$query=DB_query($update,$db);	
}
	
?>
<h2 align="center">Local Freight List</h2>
<a href="index.php?route=local_fright_payment&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>">Add New</a>
<br><br>
<form action="" method="Post">
<table width="50%" border="0" cellpadding="2" cellspacing="2" align="center">
<tr><td><strong>Branch Wise</strong></td><td><select name="branch_id" style="width: 100%">
	<option value="000">Select Branch</option>
    	<?php $site_sql=DB_query("Select loccode, locationname from locations ",$db);
    	while($site_row=DB_fetch_array($site_sql))
		{?>
			<option value="<?php echo $site_row['loccode'];?>"<?php echo($_SESSION['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
		<?php 	
		}
    	?></select></td>
    	<td><strong>Party Wise</strong></td>
    	<td><select name="party_id" style="width: 80%">
    		<option value="000">Select Party</option>
	<?php 
	$vendor_sql=DB_query("select id,vendor_code,vendor_name from suppliers",$db);
	while($vendor=DB_fetch_array($vendor_sql))
	{
	?>
      <option value="<?php echo $vendor['vendor_code'];?>"<?php echo ($_REQUEST['party']==$vendor['vendor_code']?'selected':'')?>><?php echo $vendor['vendor_name'];?></option>
      <?php } ?>
			</select></td>
    	<td><input type="submit" name="Search" value="Search" /></td>	
</tr></table>	
</form>

<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr>
<th>Branch</th>
<th>Vouchar No.</th>
<th>Bill No</th>
<th>Fright Amount</th>
<th>Party</th>
<th>Description</th>
<th>Narration</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<?php 
if(isset($_POST['Search']))
{
if($_REQUEST['branch_id']!='000' and $_REQUEST['party_id']=='000')
{
	
$sql=DB_query("Select * from local_fright where branch_code='".$_REQUEST['branch_id']."' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
}
 if($_REQUEST['party_id']!='000' and $_REQUEST['branch_id']=='000') 
{
	
$sql=DB_query("Select * from local_fright where party='".$_REQUEST['party_id']."' and CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);	
}
if($_REQUEST['branch_id']!='000' and $_REQUEST['party_id']!='000')
{
$sql=DB_query("Select * from local_fright where party='".$_REQUEST['party_id']."' and branch_code='".$_REQUEST['branch_id']."'and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);	
}
if($_REQUEST['branch_id']=='000' and $_REQUEST['party_id']=='000')
 {
	
$sql=DB_query("Select * from local_fright  where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);	
}
$i=0;
$num=DB_num_rows($sql);

if($num>0)
{
while($myrow=DB_fetch_array($sql))
{
?>
<tr bgcolor="#FFFFFF">
<td><?php echo $myrow['branch_code'];?></td>
<td><?php echo $myrow['vouchar_no'];?></td>
<td><?php echo $myrow['bill_no'];?></td>
<td><?php echo $myrow['fright_amount'];?></td>
<td><?php echo  $unitName=$s->getField('suppliers','vendor_code',$myrow['party'],'vendor_name'); ?>	</td>
<td><?php echo $myrow['description'];?></td>
<td><?php echo $myrow['narration']; ?></td>
<td><div align="center"><a href="index.php?route=view_local_freight&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=edit&Id=<?php echo $myrow['id'];?>">Edit</a></div></td>
<td><div align="center"><a href="index.php?route=viewlocal_fright&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=del&Id=<?php echo $myrow['id'];?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a></div></td>
</tr>
<?php $i++; }}
else { ?>
	<tr bgcolor="#FFFFFF">
<td colspan="8">No Records Find</td>
</tr>
<?php }  } ?>
	
</table>
</script>