<?php
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
if($_REQUEST['Save'])
{
$fstatus=true;
  if($_REQUEST['site']=='000')
  {
  	  $msgErr[]="Please Select Branch Name"	;
      $fstatus=false;
  }
  if($_REQUEST['vouchar']=='')
  {
  	  $msgErr[]="Please Enter Vouchar  no"	;
      $fstatus=false;
  }	
	 if($_REQUEST['fright_amount']=='')
  {
  	  $msgErr[]="Please Enter Fright Amount Enquiry Date";
      $fstatus=false;
  }
   if($_REQUEST['bill_no']=='000')
  {
  	  $msgErr[]="Please Enter Bill No"	;
      $fstatus=false;
  }
   if($_REQUEST['party']=='000')
  {
  	  $msgErr[]="Please Select Party Name"	;
      $fstatus=false;
  }
	
	
	
	
}
if(isset($_POST['Save']))
{
$sql="select * from local_fright where branch_code='".$_REQUEST['site']."' and vouchar_no='".$_REQUEST['vouchar']."' and party='".$_REQUEST['party']."'
          and bill_no='".$_REQUEST['bill_no']."'";
$query=DB_query($sql,$db);
$num=DB_num_rows($query);
if($num<=0)
{
 $insert="insert into local_fright set branch_code='".$_REQUEST['site']."',vouchar_no='".$_REQUEST['vouchar']."'
        ,party='".$_REQUEST['party']."',bill_no='".$_REQUEST['bill_no']."',fright_amount='".$_REQUEST['fright_amount']."',
          description='".$_REQUEST['description']."',narration='".$_REQUEST['narration']."',CompanyId='".$_SESSION['ACGCompanyId']."'"; 
		  
		  $query1=DB_query($insert,$db);
}
	$s->pageLocation("index.php?route=viewlocal_fright&daction=Updated".$rurl);
}

 ?>

<h2 align="center"><strong>Add Local Freight Payment</strong></h2>
<form name="form1" action="" method="post">
<div align="center">
<table width="60%" cellpadding="2" cellspacing="2" align="center">
<tr>
    <th><strong>Branch</strong></th>
    <td>
	<?php
		$sql = 'SELECT loccode, locationname FROM locations';
		$resultStkLocs = DB_query($sql,$db);
		?>
	<select name="site" style="width:100px" onchange="generateCode(this.value);">
	<option value="000">Select</option>
      <?php 
			while ($myrow=DB_fetch_array($resultStkLocs))
				{
				?>
      <option value="<?php echo $myrow['loccode']; ?>"><?php echo $myrow['locationname'];?></option>
      <?php  }	?>
    </select></td>
    <th>Vouchar No</th>
    <td id="codeId"><input type="text" name="vouchar" id="vouchar" value="<?php echo $_SESSION['enquiryNo'];?>"></td>
</tr>
<tr>
	<th><strong>Party</strong></th>
    <td>
	<?php
		$sql21= 'SELECT vendor_code, vendor_name FROM suppliers ';
		$resultStkLocs1 = DB_query($sql21,$db);
		?>
	<select name="party" style="width:100px">
	<option value="0">Select</option>
      <?php 
			while ($myrow1=DB_fetch_array($resultStkLocs1))
				{
				?>
      <option value="<?php echo $myrow1['vendor_code']; ?>"><?php echo $myrow1['vendor_name'];?></option>
      <?php  }	?>
    </select></td>
     <th>Bill No</th>
    <td><input type="text" name="bill_no" id="vouchar"></td>
	
</tr>
<tr>	
     <th >Fright Amount</th>
    <td ><input type="text" name="fright_amount" id="fright_amount"></td>
	<th ><strong>Description</strong></th>
    <td ><textarea  name="description"></textarea></td>
</tr>

<tr>
<th colspan="2"> Narration</th>
    <td colspan="2"><textarea name="narration" id="narration" cols="45" rows="5" style="width:100%; height:40px;">
	</textarea></td>
	
</tr>
  
</table>
</div>
<p align="center"><input type="submit" name="Save" value="Save" /></p>
</form>
<script language="JavaScript">
function generateCode(str)
{
	
	if (str.length==0)
  {
  document.getElementById("codeId").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("codeId").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getlocalcode.php?site="+str,true);
xmlhttp.send();
}
	
	
</script>