<?php 
if($_REQUEST['Save']!='')
{
	$data['site']=$_REQUEST['site'];
	$data['EONumber']=$_REQUEST['EONumber'];
	$data['PORefNo']=$_REQUEST['PORefNo'];
	$data['PORefDate']=FormatDateForSQL($_REQUEST['PORefDate']);
	$data['saleContractNo']=$_REQUEST['saleContractNo'];
	$data['saleContractDate']=FormatDateForSQL($_REQUEST['saleContractDate']);
	$data['shipmentDate']=FormatDateForSQL($_REQUEST['shipmentDate']);
	$data['orderConfirmDate']=FormatDateForSQL($_REQUEST['orderConfirmDate']);
	$data['preCarriageBy']=$_REQUEST['preCarriageBy'];
	$data['receiptPlace']=$_REQUEST['receiptPlace'];
	$data['vesselFlightNo']=$_REQUEST['vesselFlightNo'];
	$data['portOfLoading']=$_REQUEST['portOfLoading'];
	$data['portOfDischarge']=$_REQUEST['portOfDischarge'];
	$data['deliveryPlace']=$_REQUEST['deliveryPlace'];
	$data['originCountry']=$_REQUEST['originCountry'];
	$data['destinationCountry']=$_REQUEST['destinationCountry'];
	$data['consignee']=$_REQUEST['consignee'];
	$data['otherThanConsignee']=$_REQUEST['otherThanConsignee'];
	$data['shippingAgent']=$_REQUEST['shippingAgent'];
	$data['commissionAgent']=$_REQUEST['commissionAgent'];
	$data['nomineeAgent']=$_REQUEST['nomineeAgent'];
	$data['LCNo']=$_REQUEST['LCNo'];
	$data['LCDate']=FormatDateForSQL($_REQUEST['LCDate']);
	$data['paymentTerms']=$_REQUEST['paymentTerms'];
	$data['paymentDesc']=$_REQUEST['paymentDesc'];
	$data['notify']=$_REQUEST['notify'];
	$data['bank']=$_REQUEST['bank'];
	$data['shippingMark']=$_REQUEST['shippingMark'];
	$data['partialShippment']=$_REQUEST['partialShippment'];
	$data['currency']=$_REQUEST['currency'];	
	$data['salesExecutive']=$_REQUEST['salesExecutive'];	
	$data['remarks1']=$_REQUEST['remarks1'];	
	$data['remarks2']=$_REQUEST['remarks2'];	
	$data['basicAmt']=$_REQUEST['basicAmt'];	
	$data['discountPerc']=$_REQUEST['discountPerc'];	
	$data['discountAmount']=$_REQUEST['discountAmount'];
	$data['advance']=$_REQUEST['advance'];
	$data['freight']=$_REQUEST['freight'];
	$data['finalTotal']=$_REQUEST['finalTotal'];
	$data['finalTotalForeign']=$_REQUEST['finalTotalForeign'];
	$data['roundOff']=$_REQUEST['roundOff'];
	$data['grandTotal']=$_REQUEST['grandTotal'];
	$data['createdDate']=date('Y-m-d');
	$data['createdBy']=$_SESSION['UserID'];
	$data['CompanyId']=	$_SESSION['ACGCompanyId'];
	
	
	$insert1=$fnLib->insertRecord('export_sales_order', $data);	
	$result1=DB_query($insert1,$db);
	$lastId=DB_Last_Insert_id($db,'export_sales_order','id');
	
	if($lastId!='')
	{
		for($i=0;$i<count($_REQUEST['itemCode']);$i++)
		{
			$details['parentId']=$lastId;	
			$details['itemCode']=$_REQUEST['itemCode'][$i];
			$details['quantity']=$_REQUEST['quantity'][$i];
			$details['price']=$_REQUEST['price'][$i];
			$details['pricePer']=$_REQUEST['pricePer'][$i];
			$details['totalValue']=$_REQUEST['totalValue'][$i];
			$details['discountType']=$_REQUEST['discountType'][$i];
			$details['discount']=$_REQUEST['discount'][$i];
			$details['discountedValue']=$_REQUEST['discountedValue'][$i];
			
			$insert2=$fnLib->insertRecord('export_order_details', $details);	
			$result2=DB_query($insert2,$db);
		}
	}
}
?>
<script language="JavaScript" type="text/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","codeGenerator.php?site="+str,true);
xmlhttp.send();
}
function partyAddress1(str)
{
	if (str.length==0)
  {
  document.getElementById("party1").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("party1").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getPartyAddress.php?q="+str,true);
xmlhttp.send();
}
function partyAddress2(str)
{
	if (str.length==0)
  {
  document.getElementById("party2").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("party2").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getPartyAddress.php?p="+str,true);
xmlhttp.send();
}
function showRate(str)
{
	if (str.length==0)
  {
  document.getElementById("rateDiv").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("rateDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getCurrencyRate.php?q="+str,true);
xmlhttp.send();
}
function openPopupProfile(i)
{ 
		window.open("pickExportItems.php?rowcount="+i,"profiles_popup_window","height=425,width=640,toolbar=no,menubar=no,dependent=yes,resizable=yes");
}
function calculateTotalValue(str)
{
	brk=str.split('_');
	$ctr=brk[1];
	if($ctr==undefined)
	{
		var qty=document.getElementById("quantity").value;
		var price=document.getElementById("price").value;
		var unitPrice=price/1000;
		var total=unitPrice*qty;
		document.getElementById("totalValue").value=total.toFixed(2);
	}
	else
	{
		var qty=document.getElementById("quantity_"+$ctr).value;
		var price=document.getElementById("price_"+$ctr).value;
		var unitPrice=price/1000;
		var total=unitPrice*qty;
		document.getElementById("totalValue_"+$ctr).value=total.toFixed(2);
	}
}
function dispVal(str)
{
	brk=str.split('_');
	$ctr=brk[1];
	if($ctr!=undefined)
	{document.getElementById("pricePer_"+$ctr).value=1000;}
}
function calculateDiscounted(str)
{
	brk=str.split('_');
	$ctr=brk[1];
	if($ctr==undefined)
	{
		var discountType=document.getElementById("discountType").value;
		var totalValue=document.getElementById("totalValue").value;
		var discount=document.getElementById("discount").value;
		if(discount==''){discount=0;}
		if(discountType=='Amount')
		{
			var discountedValue=parseFloat(totalValue)-parseFloat(discount);
		}
		else if(discountType=='Percent')
		{
			var finalDisc=totalValue*discount/100;
			var discountedValue=parseFloat(totalValue)-parseFloat(finalDisc);
		}
		document.getElementById("discountedValue").value=discountedValue.toFixed(2);
	}
	else
	{
		var discountType=document.getElementById("discountType_"+$ctr).value;
		var totalValue=document.getElementById("totalValue_"+$ctr).value;
		var discount=document.getElementById("discount_"+$ctr).value;
		if(discount==''){discount=0;}
		if(discountType=='Amount')
		{
			var discountedValue=parseFloat(totalValue)-parseFloat(discount);
		}
		else if(discountType=='Percent')
		{
			var finalDisc=totalValue*discount/100;
			var discountedValue=parseFloat(totalValue)-parseFloat(finalDisc);
		}
		document.getElementById("discountedValue_"+$ctr).value=discountedValue.toFixed(2);
	}
}
function calculateBasic()
{
		var table = document.getElementById('dataTable');
		var rowCount = table.rows.length;
		var basicVal=0;
		var subTotal1=document.getElementById("discountedValue").value;
		//alert(rowCount);
		if(rowCount>1)
		{
			for(var i=1;i<rowCount;i++)
			{
				var subTotal2=document.getElementById("discountedValue_"+i).value;
				basicVal=parseFloat(basicVal)+parseFloat(subTotal2);
			}
			var basic=parseFloat(basicVal)+parseFloat(subTotal1);
			document.getElementById("basic").value=basic.toFixed(2);
		}
		else if(rowCount=='1')
		{
			var basic=document.getElementById("discountedValue").value;
			document.getElementById("basic").value=basic;
		}
		
}
function calculateFinalTotal()
{
	var basic= document.getElementById("basic").value;
	var discountAmount= document.getElementById("discountAmount").value;
	var advance= document.getElementById("advance").value;
	var freight= document.getElementById("freight").value;
	
	if(basic==''){basic=0;}
	if(discountAmount==''){discountAmount=0;}
	if(advance==''){advance=0;}
	if(freight==''){freight=0;}
	
	var final=parseFloat(basic)-parseFloat(discountAmount)-parseFloat(advance)+parseFloat(freight);
	document.getElementById("finalTotal").value=final.toFixed(2);
	document.getElementById("grandTotal").value=final.toFixed(2);
	
}
function calculateForeignTotal()
{
	var currencyRate=document.getElementById("currencyRate").value;
	if(currencyRate==''){alert("Kindly please choose a foreign currency in the Other Details section"); return false;}
	//alert(currencyRate);
	var finalTotal=document.getElementById("finalTotal").value;
	//alert(finalTotal);
	var totalForeign=finalTotal/currencyRate;
	document.getElementById("finalTotalForeign").value=totalForeign.toFixed(2);
}
function validate()
{
	if(document.getElementById("site").value=='0')
	{
		alert("Please Choose A Branch");
		return false;
	}
}
</script>
<p><h2 align="center">Export Sales Order</h2></p>
<form action="" method="post">
	
<div style="overflow: auto; width:800px">
<table width="100%" align="center" cellpadding="0" cellspacing="0" border="0">	
	<tr>
    	<td>
        	<table width="30%" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF" style="border:1px solid #CCC;">
          <tr>
            <th width="41%">Branch Name</th>
            <td width="59%"><select name="site" id="site" style="width: 98%; height: 20px" onchange="generateCode(this.value)" >
              <option value="0">Select</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>
          </tr>
        </table>
        </td>
    </tr>
    <tr>
    <td>
    <fieldset style="background:#CCC;">
    <legend><strong>Order Information</strong></legend>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td bgcolor="#FFFFFF">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="33%">
    <fieldset>
        <legend><strong>Order Details</strong></legend>
        <table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
          <tr>
            <th width="50%" scope="row">EO No.</th>
            <td width="50%"><input name="EONumber" type="text" value="" size="25"  style="width:100%;"/></td>
            </tr>
          <tr>
            <th scope="row">PO Ref. No./Date</th>
            <td nowrap="nowrap"><input name="PORefNo" type="text" value="" size="25"  style="width:49%;"/> <input name="PORefDate" type="text" value="" size="25"  style="width:49%;" class="datepicker"/></td>
            </tr>
          <tr>
            <th scope="row">Sale Contract No. &amp; Date</th>
            <td nowrap="nowrap"><input name="saleContractNo" type="text" value="" size="25"  style="width:49%;"/>
              <input name="saleContractDate" type="text" value="" size="25"  style="width:49%;" class="datepicker"/></td>
          </tr>
          <tr>
            <th scope="row">Shipment Date</th>
            <td><input name="shipmentDate" type="text" value="" size="25"  style="width:100%;" class="datepicker"/></td>
          </tr>
          <tr>
            <th scope="row">Order Confirm Date</th>
            <td><input name="orderConfirmDate" type="text" value="" size="25"  style="width:100%;" class="datepicker"/></td>
          </tr>
        </table>
    </fieldset>
    </td>
  </tr>
  <tr>
  	<td height="8"></td>
  </tr>
  <tr>
    <td>
    	<fieldset>
        <legend><strong>Shipment Details</strong></legend>
        <table width="100%" border="0" cellspacing="1" cellpadding="3">
          <tr  bgcolor="#B7B7B7">
            <td width="47%"><strong>Pre Carriage By</strong></td>
            <td width="53%"><strong>Reciept Place</strong></td>
          </tr>
          <tr>
            <td><select name="preCarriageBy" id="preCarriageBy" style="width: 100%">
              <option value="Air">Air</option>
              <option value="Ship">Ship</option>
              <option value="Road">Road</option>
            </select></td>
            <td><select name="receiptPlace" id="receiptPlace" style="width: 100%">
              <option value="0">Select</option>
              <?php $c_sql=DB_query("Select id, country from country_master where country !='India'",$db);
                while($c_row=DB_fetch_array($c_sql))
                {?>
              <option value="<?php echo $c_row['id'];?>"><?php echo $c_row['country'];?></option>
              <?php 	
                }
                ?>
            </select></td>
          </tr>
          <tr bgcolor="#B7B7B7">
            <td><strong>Vessel Flight No.</strong></td>
            <td><strong>Port of Loading</strong></td>
          </tr>
          <tr>
            <td><input name="vesselFlightNo" type="text" value="" size="25"  style="width:100%;" /></td>
            <td><select name="portOfLoading" style="width: 100%">
              <option value="0">Select</option>
              <?php $p_sql=DB_query("Select * from port_master",$db);
                while($p_row=DB_fetch_array($p_sql))
                {?>
              <option value="<?php echo $p_row['id'];?>"><?php echo $p_row['name'];?></option>
              <?php 	
                }
                ?>
            </select></td>
          </tr>
          <tr bgcolor="#B7B7B7">
            <td><strong>Port of Discharge</strong></td>
            <td><strong>Place of Delivery</strong></td>
          </tr>
          <tr>
            <td><select name="portOfDischarge" style="width: 100%" onchange="generateCode(this.value)" >
              <option value="0">Select</option>
               <?php $p_sql=DB_query("Select * from port_master",$db);
                while($p_row=DB_fetch_array($p_sql))
                {?>
              <option value="<?php echo $p_row['id'];?>"><?php echo $p_row['name'];?></option>
              <?php 	
                }
                ?>
            </select></td>
            <td><input name="deliveryPlace" type="text" value="" size="25"  style="width:100%;" /></td>
          </tr>
          <tr bgcolor="#B7B7B7">
            <td><strong>Country of Origin</strong></td>
            <td><strong>Country of Destination</strong></td>
          </tr>
          <tr>
            <td><select name="originCountry" style="width: 100%" onchange="generateCode(this.value)" >
              <option value="0">Select</option>
              <?php $c_sql=DB_query("Select id, country from country_master",$db);
                while($c_row=DB_fetch_array($c_sql))
                {?>
              <option value="<?php echo $c_row['id'];?>"><?php echo $c_row['country'];?></option>
              <?php 	
                }
                ?>
            </select></td>
            <td><select name="destinationCountry" style="width: 100%" onchange="generateCode(this.value)" >
              <option value="0">Select</option>
              <?php $c_sql=DB_query("Select id, country from country_master where country !='India'",$db);
                while($c_row=DB_fetch_array($c_sql))
                {?>
              <option value="<?php echo $c_row['id'];?>"><?php echo $c_row['country'];?></option>
              <?php 	
                }
                ?>
            </select></td>
          </tr>
        </table>
        </fieldset>
    </td>
  </tr>
</table>

</td>
<td bgcolor="#FFFFFF" valign="top" width="30%">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
    	<fieldset>
        <legend><strong>Consignee/Buyer Details</strong></legend>
        <table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
          <tr>
            <td width="31%">
              <select name="consignee" style="width: 100%" onchange="partyAddress1(this.value)" >
                <option value="0">Select</option>
                <?php $v_sql=DB_query("Select id, vendor_code, vendor_name from suppliers",$db);
                while($v_row=DB_fetch_array($v_sql))
                {?>
                <option value="<?php echo $v_row['vendor_code'];?>"><?php echo $v_row['vendor_name'];?></option>
                <?php 	
                }
                ?>
              </select></td>
            </tr>
          
          <tr><td id="party1"><table width="100%" border="0">
          <tr>
            <td><input name="address1" type="text" value="" size="25"  style="width:100%;" class=""/></td>
            </tr>
          <tr>
            <td><input name="address2" type="text" value="" size="25"  style="width:100%;" class=""/></td>
            </tr>
          <tr>
            <td><input name="address3" type="text" value="" size="25"  style="width:100%;" class=""/></td>
          </tr></table></td>
          </tr>
          
          
          <tr></tr>
        </table>
    </fieldset>
    </td>
    </tr>
  <tr>
    <td>
    	<fieldset>
        <legend><strong>Buyer (if other than consignee)</strong>        </legend>
        <table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
          <tr>
            <td width="31%">
              <select name="otherThanConsignee" style="width: 100%" onchange="partyAddress2(this.value)" >
                <option value="0">Select</option>
               <?php $v_sql=DB_query("Select id, vendor_code, vendor_name from suppliers",$db);
                while($v_row=DB_fetch_array($v_sql))
                {?>
                <option value="<?php echo $v_row['vendor_code'];?>"><?php echo $v_row['vendor_name'];?></option>
                <?php 	
                }
                ?>
              </select></td>
            </tr>
            <tr><td id="party2"><table width="100%" border="0">
          <tr>
            <td><input name="address1" type="text" value="" size="25"  style="width:100%;" class=""/></td>
            </tr>
          <tr>
            <td><input name="address2" type="text" value="" size="25"  style="width:100%;" class=""/></td>
            </tr>
          <tr>
            <td><input name="address3" type="text" value="" size="25"  style="width:100%;" class=""/></td>
          </tr>
          </table></td></tr>
          <tr></tr>
        </table>
    </fieldset>
    </td>
    </tr>
  <tr>
    <td>
        <fieldset>
        <legend><strong>Agent Details</strong></legend>
        <table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
        <tr>
        <th width="50%" scope="row">Shipping Agent</th>
        <td width="50%"><select name="shippingAgent" style="width: 100%" onchange="generateCode(this.value)" >
          <?php $a_sql=DB_query("Select * from agent_type_master where agentType='Shipping'",$db);
                while($a_row=DB_fetch_array($a_sql))
                {?>
          <option value="<?php echo $a_row['id'];?>"><?php echo $a_row['agentName'];?></option>
          <?php 	
                }
                ?>
        </select></td>
        </tr>
        <tr>
        <th scope="row">Commission Agent</th>
        <td nowrap="nowrap"><select name="commissionAgent" style="width: 100%" onchange="generateCode(this.value)" >
          <?php $a_sql=DB_query("Select * from agent_type_master where agentType='Commision'",$db);
                while($a_row=DB_fetch_array($a_sql))
                {?>
          <option value="<?php echo $a_row['id'];?>"><?php echo $a_row['agentName'];?></option>
          <?php 	
                }
                ?>
        </select></td>
        </tr>
        <tr>
        <th scope="row">Nominee Agent</th>
        <td nowrap="nowrap"><select name="nomineeAgent" style="width: 100%" onchange="generateCode(this.value)" >
         <?php $a_sql=DB_query("Select * from agent_type_master where agentType='Nominee'",$db);
                while($a_row=DB_fetch_array($a_sql))
                {?>
          <option value="<?php echo $a_row['id'];?>"><?php echo $a_row['agentName'];?></option>
          <?php 	
                }
                ?>
        </select></td>
        </tr>
        </table>
        </fieldset>
    </td>
    </tr>
</table>

</td><td bgcolor="#FFFFFF" valign="top" width="33%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td> 
    <fieldset>
        <legend>LC Details</legend>
        <table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
          <tr>
            <th width="19%" scope="row">LC No./Date</th>
            <td width="31%" nowrap="nowrap"><input name="LCNo" type="text" value="" size="25"  style="width:49%;"/>
              <input name="LCDate" type="text" value="" size="25"  style="width:49%;" class="datepicker"/></td>
            </tr>
          <tr>
            <th scope="row">Payment Terms</th>
            <td><input name="paymentTerms" type="text" value="" size="25"  style="width:100%;" class=""/></td>
            </tr>
          <tr>
            <th scope="row">Payment Desc.</th>
            <td><input name="paymentDesc" type="text" value="" size="25"  style="width:100%;" class=""/></td>
            </tr>
          <tr>
            <th scope="row">Notify</th>
            <td><input name="notify" type="text" value="" size="25"  style="width:100%;" class=""/></td>
          </tr>
          <tr>
            <th scope="row">Bank</th>
            <td><input name="bank" type="text" value="" size="25"  style="width:100%;" class=""/></td>
          </tr>
          <tr>
            <th scope="row">Shipping Mark</th>
            <td><input name="shippingMark" type="text" value="" size="25"  style="width:100%;" class=""/></td>
          </tr>
          <tr>
            <th scope="row">Partial Shipment</th>
            <td><input name="partialShippment" type="text" value="" size="25"  style="width:100%;" class=""/></td>
          </tr>
        </table>
    </fieldset>
   </td>
  </tr>
  <tr>
    <td> 
    <fieldset>
        <legend><strong>Other Details</strong></legend>
        <table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
          <tr bgcolor="#B7B7B7">
            <td width="46%"><strong>Currency</strong></td>
            <td width="54%"><strong>Conversion Rate</strong></td>
          </tr>
          <tr>
            <td><select name="currency" style="width: 100%" onchange="showRate(this.value)" >
              <option value="0">Select</option>
              <?php $curr_sql=DB_query("Select * from currency_master",$db);
                while($curr_row=DB_fetch_array($curr_sql))
                {?>
              <option value="<?php echo $curr_row['id'];?>"><?php echo $curr_row['currency'];?></option>
              <?php 	
                }
                ?>
            </select></td>
            <td id="rateDiv"><input name="currencyRate" id="currencyRate" type="text" value="" size="25"  style="width:100%;" /></td>
          </tr>
          <tr bgcolor="#B7B7B7">
            <td colspan="2"><strong>Sales Key Executive</strong></td>
            </tr>
          <tr>
            <td colspan="2"><select name="salesExecutive" style="width: 100%" onchange="generateCode(this.value)" >
              <option value="0">Select</option>
              <?php $salesman_sql=DB_query("Select * from salesman_master",$db);
                while($salesman_row=DB_fetch_array($salesman_sql))
                {?>
              <option value="<?php echo $salesman_row['id'];?>"><?php echo $salesman_row['sales_name'];?></option>
              <?php 	
                }
                ?>
            </select></td>
            </tr>
          <tr bgcolor="#B7B7B7">
            <td colspan="2"><strong>Remarks</strong></td>
            </tr>
          <tr>
            <td colspan="2"><input name="remarks1" type="text" value="" size="25"  style="width:100%;" /></td>
            </tr>
        </table>
    </fieldset>
   </td>
  </tr>
</table>

   
</td>
</tr>

</table>
</fieldset>
</td></tr></table>
</div>	

<p align="left">
<input type="button" onclick="addRow('dataTable')" value="Add More" />&nbsp;
<input type="button" class="crmbutton small delete"  onclick="deleteRow('dataTable')" value="Delete" />
</p>
<div style="overflow: auto; width:800px;">
  <table width="100%" border="0" cellpadding="2" cellspacing="2">
    <tr>
      <th></th>
      <th>Item Code</th>
      <th width="18%">Item Name</th>
      <th>Unit</th>
      <th>Qty</th>
      <th>Price</th>
      <th>Per Unit(s)</th>
      <th>Value</th>
      <th  width="8%">Discount Type</th>
      <th  width="8%">Discount</th>
      <th width="8%">Discounted Value</th>
      </tr>
   <tbody id="dataTable">
    <tr bgcolor="#FFFFFF">
      <td><input type="button" name="profile_popup" value="Pick Items" id="profile_popup"  onclick="openPopupProfile(this.id)" /></td>
      <td><input type="text" name="itemCode[]" id="itemCode" value="" readonly="true"/></td>
      <td width="20%"><input type="text" name="itemName[]" id="itemName" value="" readonly="true"/></td>
      <td><input type="text" name="unit[]" id="unit" value="" readonly="true"/></td>
      <td><input type="text" name="quantity[]" id="quantity" value="" /></td>
      <td><input type="text" name="price[]" id="price" value="" /></td>
      <td><input type="text" name="pricePer[]" id="pricePer" value="1000" readonly onfocus="dispVal(this.id)" /></td>
      <td><input type="text" name="totalValue[]" id="totalValue" value="" onfocus="calculateTotalValue(this.id)" /></td>
      <td><select name="discountType[]" id="discountType">
      	<option value="Amount">Amount</option>
      	<option value="Percent">Percent</option>
      </select></td>
      <td><input type="text" name="discount[]" id="discount" value="" /></td>
      <td><input type="text" name="discountedValue[]" id="discountedValue" value="" onfocus="calculateDiscounted(this.id)" /></td>
      </tr>
 </tbody>
    
  </table>
</div>
<div style="width:100%; margin:20px 0px 0px 0px;">
<table width="100%" border="0" cellspacing="0" cellpadding="5" style="border:1px solid #CCC;" bgcolor="#FFFFFF";>
  <tr>
    <td valign="top"><strong>Remarks</strong><br />
      <textarea name="remarks2" id="remarks2" cols="45" rows="5" style="width:100%;"></textarea>      </td>
    <td width="40%"><table width="95%" border="0" align="right" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF"; style="border:1px solid #CCC;">
  <tr>
    <th width="49%">Basic Value</th>
    <td width="51%" align="right"><input name="basicAmt" type="text" value="" size="25" id="basic"  style="width:100%;" onfocus="calculateBasic()" /></td>
  </tr>
  <tr>
    <th>Discount (if any)</th>
    <td align="right"><input name="discountPerc" id="discountPerc" type="text" value="" size="25"  style="width:20%;" />
       <input name="discountAmount" id="discountAmount" type="text" value="" size="25"  style="width:70%;" /></td>
  </tr>
  <tr>
    <th>Advance  (if any)</th>
    <td align="right"><input name="advance" id="advance" type="text" value="" size="25"  style="width:100%;" /></td>
  </tr>
  <tr>
    <th>Freight (if any)</th>
    <td align="right"><input name="freight" id="freight" type="text" value="" size="25"  style="width:100%;" /></td>
  </tr>
   <tr>
    <th>Sale Contract Rs.</th>
    <td align="right"><input name="finalTotal" id="finalTotal" type="text" value="" size="25"  style="width:100%;" onfocus="calculateFinalTotal()" /></td>
  </tr>
  <tr>
    <th nowrap="nowrap">Sale Contract (Foreign Currency)</th>
    <td align="right"><input name="finalTotalForeign" id="finalTotalForeign" type="text" value="" size="25"  style="width:100%;" onfocus="calculateForeignTotal()" /></td>
  </tr>
 
  <tr>
    <th>Round Off</th>
    <td align="right"><input type="checkbox" name="checkbox" id="checkbox" />
      <input name="roundOff" type="text" value="" size="25"  style="width:80%;" /></td>
  </tr>
  <tr>
    <th>Sale Contract Value</th>
    <td align="right"><input name="grandTotal" id="grandTotal" type="text" value="" size="25"  style="width:100%;" /></td>
  </tr>
</table></td>
  </tr>
</table>


<div style="clear:both;"></div>
</div>
<div>
<p align="center"><input type="submit" name="Save" value="Save" onclick="return validate();" /><input type="submit" name="Cancel" value="Cancel"></p>
</div>

</form>