<?php 	
$PageSecurity = 1;
$tabindex=0;
include('includes/DefinePaymentClass.php');
$title = _('Process Order');
include('includes/SQL_CommonFunctions.inc');
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<link rel="stylesheet" href="/css/jquery.ui.all.css">
<!--	<script src="js1/jquery-1.7.2.js"></script>-->
<script src="js1/jquery.ui.widget.js"></script>
<script src="js1/jquery.ui.tabs.js"></script>
<script>
	$(function() {
		$( "#tabs" ).tabs();
	});
	</script>
<?php
if($_REQUEST['action']=='AddNew')
	{
	if(($_REQUEST['Save']))
	{
	
	$sitename=$s->GetFieldValue('locations',"loccode='".$_REQUEST['site']."'",'prefix');
	$sqlqut=DB_query("select * from salesorder where branch='".$_REQUEST['site']."'",$db);
	if(DB_num_rows($sqlqut)>0)
	{
	$SQLMax=DB_query("select orderNo as QutNo from salesorder where branch='".$_REQUEST['site']."' order by id desc limit 0,1",$db);
	$MaxQut=DB_fetch_array($SQLMax);
	$MXNo=substr($MaxQut['QutNo'],-2);
	$FinMx=$MXNo+1;
	$FinalCode=$sitename."/"."SO"."/".str_pad($FinMx,5,0,STR_PAD_LEFT);
	}
	else
	{
	$FinalCode=$sitename."/"."SO"."/".'00001';
	}
	
	
	$data['branch']=$_REQUEST['Site']; 
	$data['orderDate']=FormatDateForSQL($_REQUEST['TelephonicDate']);
	$data['orderNo']=$FinalCode;
	//$data['cost_center']=$FinalCostCeNo; 
	$data['client']=$_REQUEST['Client'];
	$data['Sale_Key_Exec']=$_REQUEST['Sale_Key_Exec'];  
	$data['PORefNo']=$_REQUEST['PONo'];  
	$data['customerPODate']=FormatDateForSQL($_REQUEST['PODate']);  
	$data['SalesOrderType']='Process';
	$data['quoteNo']=$_REQUEST['quotesId'];
	$data['DeliveryDate']=FormatDateForSQL($_REQUEST['DelieveryDate']);
	$data['RoadPermit']=$_REQUEST['RoadPermit'];
	$data['Transport']=$_REQUEST['Transport'];
	$data['freight']=$_REQUEST['freight'];
	$data['PendingPayment']=$_REQUEST['PendingPayment']; 
	$data['TelStatus']=$_REQUEST['Status'];
	$data['ContactPerson']=$_REQUEST['ContactPerson'];
	$data['basicAmount']=$_REQUEST['basicAmount'];
	$data['exciseDuty']=$_REQUEST['EDBillRate'];
	$data['TotalExciseValue']=$_REQUEST['totalDiscountedPrice'];
	$data['taxableAmount']=$_REQUEST['taxableAmount'];
	$data['ECessPercentage']=$_REQUEST['ECessPercentage'];
	$data['ECessId']=$_REQUEST['ECessID'];
	$data['ECessValue']=$_REQUEST['ECessValue'];
	$data['SHECessId']=$_REQUEST['SHECessId'];
	$data['VatCst']=$_REQUEST['VatCst'];
	$data['VatCstValue']=$_REQUEST['VatCstValue'];
	$data['SAHCessPercentage']=$_REQUEST['SAHCessPercentage'];  
	$data['SAHCessValue']=$_REQUEST['SAHCessValue'];
	$data['order_type']=$_REQUEST['order_type'];
	$data['grandTotal']=$_REQUEST['grandTotal']; 
	$data['createdBy']=$_SESSION['UserID'];
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	$data['cate']=$_REQUEST['cate'];
	//echo "<pre>";
	//print_r($data);
	
	$s->RecordInsert('salesorder', $data);
	$SalesId=DB_Last_Insert_ID($db,'salesorder','id');
	
	
	
	
	
	if(isset($SalesId))
	{
	for($i=0;$i<count($_REQUEST['item_code']);$i++)
	{
	if($_REQUEST['item_code'][$i]!=''){
	$data_arr['masterId']=$SalesId;
	$data_arr['ItemCode']=$_REQUEST['item_code'][$i];
	$data_arr['Quantity']=$_REQUEST['Qty'][$i];
	$data_arr['Rate']=$_REQUEST['price'][$i];
	$data_arr['pricePer']=1;
	$data_arr['Amount']=$_REQUEST['stock_qty'][$i];
	$data_arr['EDRate']=$_REQUEST['EDRate'][$i];
	$data_arr['EDAmt']=$_REQUEST['EDAmt'][$i];
	$data_arr['mrp_unit']=$_REQUEST['mrp_per'][$i];
	$data_arr['ass_price']=$_REQUEST['ass_price'][$i];
	$data_arr['total_ass_price']=$_REQUEST['total_ass_price'][$i];
	$data_arr['remarks']=$_REQUEST['remarks'][$i];
	$data_arr['ApprovalStatus']="1";
	
	$rowinsert= $s->RecordInsert('salesorder_details', $data_arr);
	if(!$rowinsert)
	{
	die('Error'.DB_error());
	}
	}
	}
	}
	
	if(isset($SalesId))
	{
	$sql_comment="insert into salesorder_comments set
	sopno='".$SalesId."',
	user='".$_SESSION['UserID']."',
	comment='".$_REQUEST['comt']."',
	posted_date=now()";
	if($_REQUEST['comt']!='')
	{
	$res_comment=DB_query($sql_comment,$db);
	}			  
	}
	$update=DB_query("update quotation set ConvertIntoSales='Y' where id='".$_REQUEST['quotesId']."'",$db);
	echo "<script>location.href='index.php?route=CRM/ViewSalesOrder&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
prnMsg( _('Sales Order inserted successfully'),'success');
}
}
?>
<script type="text/javascript">
function validation()
{
	if(document.getElementById('Site').value=='0')
	{
	alert('Please Select a branch');
	document.getElementById('Site').focus();
	return false;
	}
	if(document.getElementById("TelephonicDate").value=='')
	{
	alert('Please enter the memo date');
	document.getElementById('TelephonicDate').focus();
	return false;
	}
	if(document.getElementById('po_no').value==''){
	alert('PO No cannot be empty');
	document.getElementById('po_no').focus();
	return false;
	}
	if(document.getElementById('Client').value=='0'){
	alert('Please choose a client');
	document.getElementById('Client').focus();
	return false;
	}
	if(document.getElementById('Sale_Key_Exec').value=='0'){
	alert('Please choose a Sales Executive');
	document.getElementById('Sale_Key_Exec').focus();
	return false;
	}
	if(document.getElementById('PODate').value==''){
	alert('Please enter PO Date');
	document.getElementById('PODate').focus();
	return false;
	}
	if(document.getElementById('cat').value=='0'){
	alert('Please choose a category');
	document.getElementById('cat').focus();
	return false;
	}		
	if(document.getElementById('basicAmount').value==''){
	alert('Basic Amount cannot be empty');
	document.getElementById('basicAmount').focus();
	return false;
	}
	if(document.getElementById('taxableAmount').value==''){
	alert('Taxable AMount cannot be empty');
	document.getElementById('taxableAmount').focus();
	return false;
	}
	if(document.getElementById('grandTotal').value==''){
	alert('Grand Total cannot be empty');
	document.getElementById('grandTotal').focus();
	return false;
	}
	return true;
}	




function getContactName(str)
{
	if(str.length==0)
	{
	document.getElementById("ContactName").innerHTML="";
	return;
	}
	if(window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	
	document.getElementById("ContactName").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","getContact.php?Client="+str,true);
	xmlhttp.send();	
} 



function getPhoneNo(str)
{
	if(str.length==0)
	{
	document.getElementById("PhoneNo").innerHTML="";
	return;
	}
	if(window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("PhoneNo").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","getPhone.php?Contact="+str,true);
	xmlhttp.send();	
} 



function openPopupProfile2()
{
	window.open("TelephonicItems.php?modid=<?php echo $_REQUEST['modid']?>&frmid=<?php echo $_REQUEST['frmid']?>");
}





function calculateTotalAmt(val,id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
	var qty=document.getElementById("qty_"+i).value;
	var tot_amt=qty*val;
	document.getElementById("totalamt_"+i).value=tot_amt.toFixed(2);
	}
	else
	{
	var qty=document.getElementById("qty").value;
	var tot_amt=qty*val;
	document.getElementById("totalamt").value=tot_amt.toFixed(2);
	}
}




function calassprice(val,id)
{
	var id_brk=id.split('_');
	var i=id_brk[2];
	if(id_brk.length>1)
	{
	
	var tot_amt=(70*val)/100;
	document.getElementById("ass_price_"+i).value=tot_amt.toFixed(2);
	}
	else
	{
	
	var tot_amt=(70*val)/100;
	document.getElementById("ass_price").value=tot_amt.toFixed(2);
	}
}




function calass_amount(id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{ 
	var qty=document.getElementById("qty_"+i).value;
	var ass_value=document.getElementById("ass_price_"+i).value;
	var tot_amt=ass_value*qty;
	document.getElementById("totalassamt_"+i).value=tot_amt.toFixed(2);
	}
	else
	{
	var qty=document.getElementById("qty").value;
	var ass_value=document.getElementById("ass_price").value;
	var tot_amt=ass_value*qty;
	document.getElementById("totalassamt").value=tot_amt.toFixed(2);
	}
}



function calculateEDAmt(i)
{
	var EDRate = document.getElementById("EDRate_"+i).value;
	alert("EDRate");
	if(EDRate=='0')
	{
	//var stock_price = document.getElementById("stock_qty_"+i).value;
	//alert(stock_price);
	document.getElementById("EDAmt_"+i).value='0.00';
	}
	else
	{
	var stock_price = document.getElementById("stock_qty_"+i).value;
	var EDAmt=((parseFloat(EDRate)*parseFloat(stock_price) )/100);
	document.getElementById("EDAmt_"+i).value=EDAmt.toFixed(2);
	}
}


function calculateBasic()
{
	var totalBasic=0;
	//var first_row=document.getElementById("totalamt").value;
	//if(first_row==''){first_row=0;}
	var cnt=document.getElementById("hiditemcount1").value;
	//var newcount=parseInt(cnt)+1;
	for(var i=0;i<cnt;i++)
	{
	var totalBasic1=document.getElementById("totalamt_"+i).value;
	var totalBasic=(parseFloat(totalBasic)+parseFloat(totalBasic1)).toFixed(2);
	}
	document.getElementById("basicAmount").value=parseFloat(totalBasic);
}



function calculateDiscounted()
{
	var totalDiscounted=0;
	var cnt=document.getElementById("hiditemcount").value;
	for(var i=0;i<cnt;i++)
	{
	var totalDiscounted1=document.getElementById("EDAmt_"+i).value;
	
	var totalDiscounted=(parseFloat(totalDiscounted)+parseFloat(totalDiscounted1)).toFixed(2);
	}
	if(totalDiscounted1!=='0')
	{
	document.getElementById("totalDiscountedPrice").value=totalDiscounted;
	}
	else{
	var total=document.getElementById("basicAmount").value;
	
	var Edrate=document.getElementById("EDRate_"+i).value;
	var discountEdrate=((parseFloat(Edrate)*parseFloat(total) )/100);
	document.getElementById("totalDiscountedPrice").value=discountEdrate.toFixed(2);
	}
}

function calculateECess()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").value;
	var ECessPercentage=document.getElementById("ECessPercentage").value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue").value=total.toFixed(2);
}

function calculateSAHCess()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage").value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue").value=total.toFixed(2);
}
function calculateTaxable()

{
	var Basic=document.getElementById("basicAmount").value;
	var totalDiscountedPrice=document.getElementById("totalDiscountedPrice").value;
	var ECessValue=document.getElementById("ECessValue").value;
	var SAHCessValue=document.getElementById("SAHCessValue").value;
	if(totalDiscountedPrice==''){totalDiscountedPrice=0;}
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	var TOTAL=parseFloat(totalDiscountedPrice)+parseFloat(ECessValue)+parseFloat(SAHCessValue)+parseFloat(Basic);
	document.getElementById("taxableAmount").value=TOTAL.toFixed(2);
}




function calculateVATCST(str)
{
	if (str.length==0)
	{
	document.getElementById("vat_rate").value="";
	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("vat_rate").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?salesId1="+str,true);
	xmlhttp.send();
}




function GetContactDetails(str)
{
	if (str.length==0)
	{
	document.getElementById("Client").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)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("AGNQUT").innerHTML=data[0];
	document.getElementById("ADD1").innerHTML=data[1];
	document.getElementById("ADD2").innerHTML=data[2];
	document.getElementById("ADD3").innerHTML=data[3];
	document.getElementById("ADD4").innerHTML=data[4];
	document.getElementById("ADD5").innerHTML=data[5];
	//alert(data);
	}
	}
        var brnch=document.getElementById("Site").value;
	xmlhttp.open("GET","GetContactDetals.php?CLIENTID="+str+"&branch="+brnch,true);
	xmlhttp.send();
}




function GetQuotesItems(str)
{
	if (str.length==0)
	{
	document.getElementById("against_quots").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)
	{
	
	var data=xmlhttp.responseText.split("__");
	document.getElementById("order_type").value=data[0];
	document.getElementById("showdata").innerHTML=data[1];
	document.getElementById("BASICAM").innerHTML=data[2];
	document.getElementById("EDF").innerHTML=data[3];
	document.getElementById("ECESSID").innerHTML=data[4];
	document.getElementById("SHEID").innerHTML=data[5];
	document.getElementById("TAXABLID").innerHTML=data[6];
	document.getElementById("VATCSID").innerHTML=data[7];
	document.getElementById("GRANDID").innerHTML=data[8];
	//alert(data);
	}
	}
	xmlhttp.open("GET","GetQuotesItems.php?QuotesId="+str,true);
	xmlhttp.send();
}






function calculateGrand()
{
	var a=document.getElementById("totalDiscountedPrice").value;
	var b=document.getElementById("taxableAmount").value;
	var c=document.getElementById("VatCstValue").value;
	if(b==''){b=0;}
	if(c==''){c=0;}
	var GRAND=parseFloat(b)+parseFloat(c);
	document.getElementById("grandTotal").value=GRAND.toFixed(2);
}
</script>
<blockquote>&nbsp;</blockquote>
<div class="body_contain">
<h1><?php echo $title; ?></h1>
<form action="" method="post"  >
<div class="insideclass">
<div style="z-index:-1000em;">
  <div class="demo">
    <div id="tabs">
 <div id="tabs-1">
<div class="tab_div">

<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td class="tabledata1">Branch</td>
    	<td><select name="Site" id="Site" style="width:160px;">
<!--        	<option value="0">Select Branch</option>-->
            	<?php $SQL="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')";
					$Res=DB_query($SQL,$db);
					while($Row=DB_fetch_array($Res)){?>
             <option value="<?php echo $Row['loccode']?>"<?php echo($_SESSION['Site']==$Row['loccode'] ? 'selected':'');?> ><?php echo $Row['locationname']?></option>
                                <?php  } ?>
         </select></td>
		 <td><span class="tabledata1">SOP No
		     <label><font color="#FF0000">*</font></label>
		 </span></td>
		 <td><input type="text" name="orderNo" id="orderNo" value="Auto Generated" readonly="" style="width:160px;" /></td>
		 <td class="tabledata1"><label>Cost Center </label></td>
         <td><input type="text" name="cost_center" id="cost_center" value="Auto Generated" style="width:160px;" readonly="" /></td>
		 </tr>
<tr class="row1">
       <td class="tabledata1">Client</td>
      <td><?php $ClientSQL="Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' order by c_name ASC"  ;?>
        <select style="width:160px;" name="Client" id="Client" onchange="GetContactDetails(this.value);">
          <option value="0">--Select--</option>
          <?php $ClientRes=DB_query($ClientSQL,$db);
					while($ClientRow=DB_fetch_array($ClientRes)){?>
          <option value="<?php echo $ClientRow['id']?>" <?php echo($_SESSION['Client']==$ClientRow['id']?'selected':'')?>  ><?php echo $ClientRow['c_name']?></option>
          <?php  } ?>
        </select></td>
      <td><span class="tabledata1">Contact Person</span></td>
      <td id="ADD2"><?php $SQL="Select * from contact_information_master where master_code='".$_SESSION['Client']."'";?>
        <select style="width:160px;" name="ContactPerson" onchange="getPhoneNo(this.value)">
          <option value="0">--Select--</option>
          <?php $Res=DB_query($SQL,$db);
								  while($Row=DB_fetch_array($Res)){?>
          <option value="<?php echo $Row['id']?>" <?php echo($_SESSION['ContactPerson']==$Row['id']?'selected':'')?>><?php echo $Row['person']?></option>
          <?php  } ?>
        </select></td>
      <td  class="tabledata1">Date<label><font color="#FF0000">*</font></label></td>
     <td><input type="text" name="TelephonicDate" id="TelephonicDate" value="<?php echo date('d/m/Y');?>"  class="datepicker" style="width:160px;"></td>
     </tr>
<tr  class="row1"><td class="tabledata1">Against Quotes<font color="#FF0000">*</font></td>
          <td id="AGNQUT"><select name="against_quots" id="against_quots" style="width:160px;">
            <option value="0">Select Quotes No</option>
          </select></td>
          <td><span class="tabledata1">Phone No</span></td>
		  <td id="ADD4"><div id="PhoneNo"><input type="text" style="width:160px;" name="Telephone" id="Telephone" value="<?php echo $_SESSION['Telephone']?>"  >
                        </div></td>
        
          <td class="tabledata1"><label>Delivery Date</label></td>
          <td ><input type="text" name="DelieveryDate" id="DelieveryDate" style="width:160px;" class="datepicker" value="<?php echo $_SESSION['DelieveryDate']?>" /></td>
      </tr>
<tr  class="row1">
          <td class="tabledata1">Address</td>
          <td id="ADD1"><input type="text"  style="width:160px;" name="Address1"  value="<?php echo $_SESSION['Address1']?>"/></td>
          <td id="ADD1"><span class="tabledata1">Client P.O. No.
              <label><font color="#FF0000">*</font></label>
          </span></td>
          <td id="ADD1"><input type="text" name="PONo" id="po_no" style="width:160px;"  value="<?php echo $_REQUEST['PONo']?>" /></td>
          <td class="tabledata1">P.O. Date
            <label><font color="#FF0000">*</font></label></td>
          <td ><input type="text" name="PODate" id="PODate" style="width:160px;" class="datepicker"  value="<?php echo $_SESSION['PODate']?>" /></td>
      </tr>
<tr class="row1">
		  <td>&nbsp;</td>
          <td id="ADD3"><input type="text" name="Address2" id="Address2" style="width:160px;" value="<?php echo $_SESSION['Address2']?>"  ></td>
          <td id="ADD3"><span class="tabledata1">Transport</span></td>
          <td id="ADD3"><select style="width:160px;" name="Transport">
            <option value="0">--Select--</option>
            <?php $SQL="Select * from transport_master where CompanyId='".$_SESSION['ACGCompanyId']."'";
								$Res=DB_query($SQL,$db);
								while($Row=DB_fetch_array($Res)){?>
            <option value="<?php echo $Row['id']?>" <?php echo($_SESSION['Transport']==$Row['id']?'selected':'' );?>  ><?php echo $Row['TransportName']?></option>
            <?php  } ?>
          </select></td>
          <td class="tabledata1">Road Permit</td>
		  <td id="ADD5"><input name="RoadPermit" type="text"   style="width:160px;"   value="<?php echo $_SESSION['RoadPermit']?>"  /></td>
       </tr>
<tr class="row1">
	   		<td>&nbsp;</td>
            <td id="ADD5"><input type="text" name="Address3" id="Address3" style="width:160px;" value="<?php echo $_SESSION['Address3']?>"  ></td>
            <td id="ADD5"><span class="tabledata1">Status</span></td>
            <td id="ADD5"><select style="width:160px;" name="Status">
              <option id="Pending">Created</option>
            </select></td>
            <td id="ADD5"><span class="tabledata1">Freight Type</span></td>
            <td id="ADD5"><select style="width:160px;" name="freight">
              <option value="0">Select</option>
              <option value="Paid">Paid</option>
              <option value="topay">To Pay</option>
              <option value="Nill">Nill</option>
            </select></td>
</tr>
<tr class="row1">
         <td class="tabledata1"><label>Category</label></td>
         <td><select name="cate" id="cat" style="width:160px;">
           <option value="0">Select</option>
           <option value="Urgent"<?php if($_SESSION['cate']=='Urgent'){ ?> selected="selected" <?php } ?> >Urgent</option>
           <option value="Normal" <?php if($_SESSION['cate']=='Normal'){ ?> selected="selected" <?php } ?>>Normal</option>
         </select></td>
         <td><span class="tabledata1">Order Type</span></td>
         <td><select name="order_type" id="order_type" style="width:160px;"   onchange="getorder(this.value)">
           <option value="item_wise">TBI</option>
          
         </select></td>
         <td class="tabledata1"><label>Sales Key Executive <font color='red'>*</font></label></td>
         <td><?php 
	
		//echo "select * from www_users where companyid='".$_SESSION['ACGCompanyId']."' and department in('".$Dept_id."')";
		$Sale_key_Exe=DB_query("select * from salesman_master where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);
	
	?>
           <select name="Sale_Key_Exec" id="Sale_Key_Exec" style="width:160px;">
             <option value="">Select</option>
             <?php while($Sale_keyRow=DB_fetch_array($Sale_key_Exe))
	{
	?>
             <option value="<?php echo $Sale_keyRow['id'] ?>"  ><?php echo $Sale_keyRow['sales_name']; ?></option>
             <?php } ?>
           </select></td>
     </tr>

<tr class="row1">
          <td class="tabledata1">Pending Payments (if any)</td>
          <td colspan="5"><textarea name="PendingPayment" id="PendingPayment" style="width:679px; height:73px;"><?php echo $_SESSION['PendingPayment'];?></textarea></td>
     </tr>

</table>
<br />
<div id="showdata">

</div>

<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td valign="top" width="50%">
	<!--<table width="100%" border="0" cellspacing="0" cellpadding="3" align="left" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
	<tr class="row1">
	<td colspan="2" class="tabledata1" style="text-align:center;"><strong>Terms And Conditions</strong></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1" width="19%" scope="row">Pkg &amp; Forwarding</td>
	<td class="tabledata1" width="28%" nowrap="nowrap">
	<select name="pack_forward" id="menu1" style="width:150px;" onChange="checkApplicable(this.value)">
	<option value="AS">As per calculation</option>
	<option value="NA">N/A</option>
	</select><input type="text" name="PFRemarks" id="remarks1" value="" style="width:auto;" />
	</td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Freight</td>
	<td><select name="freight" id="menu2"
	style="width:150px;;" onChange="checkApplicable(this.value)">
	<option value="AS">As per calculation</option>
	<option value="NA">N/A</option>
	</select><input type="text" name="freightRemarks" id="remarks2" value="" style="width:auto;" /></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Payment Terms</td>
	<td><select name="payTerms" style="width:150px;">
	<?php 
	$payment_sql=DB_query("Select * from paymentterms",$db);
	while($payment_row=DB_fetch_array($payment_sql))
	{?>
	<option value="<?php echo $payment_row['termsindicator'];?>"><?php echo $payment_row['terms'];?></option>
	<?php 	
	}
	?>
	</select></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Sales Tax</td>
	<td><select name="salesTax" id="menu3" style="width:150px;" onChange="checkApplicable(this.value)">
	<option value="AS">As per calculation</option>
	<option value="NA">N/A</option>
	</select><input type="text" name="salesRemarks" id="remarks3" value="" style="width:auto;"/></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Excise</td>
	<td><select name="Excise" id="" style="width:150px;" onChange="checkApplicable(this.value)">
	<option value="AS">As per calculation</option>
	<option value="NA">N/A</option>
	</select><input type="text" name="exciseRemarks" id="" value="" style="width:auto;" /></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1" nowrap="nowrap">Insurance</td>
	<td><select name="insurance" id="menu4" style="width:150px;" onChange="checkApplicable(this.value)">
	<option value="AS">As per calculation</option>
	<option value="NA">N/A</option>
	</select><input type="text" name="insRemarks" id="remarks4" value="" style="width:auto;"/></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Delivery</td>
	<td colspan="2"><input type="text" name="delivery" id="delivery" style="width:215px;" /></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Validity</td>
	<td colspan="2"><input type="text" name="validity" id="validity" style="width:215px;" /></td>
	</tr>
	</table>	-->
	</td>
	<td valign="top" width="50%">
	<table width="100%" border="0" cellspacing="0" cellpadding="3" bgcolor="#e7e7e7">
	<tr class="row1">
	<td class="tabledata1" colspan="2"><center><h1 style="border-width: 0 0 0 0px;">Amount And Taxes</h1></center></td>
	</tr>
	<tr class="row1">
	
	<td class="tabledata1">Value Of Goods
	<label><font color="#FF0000">*</font></label></td>
	<td id="BASICAM"><input name="basicAmount" type="text"  style="width:150px;" onfocus="calculateBasic()" id="basicAmount"/></td>
	</tr>
	<tr class="row1">
	
	<td class="tabledata1">Excise Duty</td>
	<td id="EDF"><select name="EDBillRate" id="EDRate" style="width:107px" onchange="calculateBillExcise(this.value)"  >
	<option value="0">--Select--</option>
	<?php
	$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'" ;
	$ServiceRes=DB_query($ServiceSql,$db);
	while($ServiceRow=DB_fetch_array($ServiceRes))
	{
	?>
	<option value="<?php echo $ServiceRow['id']?>"><?php echo $ServiceRow['caption']?></option>
	<?php	
	}
	
	?>
	</select>
	<input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text"  style="width:107px;" onfocus="calculateTotalExcise()"/>
	</td>
	</tr>
	<tr class="row1">
	
	<td class="tabledata1">E-Cess</td>
	<td id="ECESSID"><?php  $SQl=DB_query("SELECT * FROM excise_tax WHERE caption LIKE '%Edu Cess%'",$db);
	$RESULT=DB_fetch_array($SQl);
	
	
	?>
	<input type="hidden" name="ECessID" value="<?php echo $RESULT['id']?>" style="width:150px;">
	<input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $RESULT['def_rate'];?>"  readonly style="width:107px" />
	<input name="ECessValue" id="ECessValue" type="text"   readonly onfocus="calculateECess()" style="width:107px"/></td>
	</tr>
	<tr class="row1">
	
	<td class="tabledata1">SHE Cess </td>
	<?php  $SQl=DB_query("SELECT * FROM excise_tax WHERE caption LIKE '%SHE Cess%'",$db);
	$RESULT=DB_fetch_array($SQl);
	
	
	?>
	<td id="SHEID"><input type="hidden" name="SHECessId" value="<?php echo $RESULT['id']?>" style="width:150px;">
	<input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $RESULT['def_rate'];?>" style="width:107px;" readonly/>
	<input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $SAHCessValue?>" style="width:107px;" readonly onfocus="calculateSAHCess()"/></td>
	</tr>
	<tr class="row1">
	
	<td class="tabledata1">Taxable Amount
	<label><font color="#FF0000">*</font></label></td>
	<td id="TAXABLID"><input name="taxableAmount" id="taxableAmount" type="text" style="width:150px;" onfocus="calculateTaxable()"/></td>
	</tr>
	<tr class="row1">
	
	<td class="tabledata1">VAT/CST</td>
	<td id="VATCSID"><select name="VatCst" id="value3" onchange="calculateVATCST(this.value)" style="width:150px;">
	<option value="" >Select</option>
	<?php 
	$salesSql=DB_query("Select * from sales_tax_master",$db);
	while($salesRow=DB_fetch_array($salesSql))
	{?>
	<option value="<?php echo $salesRow['salestax_id'];?>" <?php echo $VatCst==$salesRow['salestax_id']?'selected':''?>><?php echo $salesRow['tax_code'];?></option>
	<?php 	
	}
	?>
	</select>
	<div id="VATId">
	<input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $VatCstValue?>" style="width:150px;" readonly  onfocus="calculateEditVATCST()" />
	</div>
	<input type="hidden" name="" id="vat_rate" value="<?php echo $rate;?>" />
	</td>
	</tr>
	<tr class="row1">
	
	<td class="tabledata1"><strong>Grand Total</strong>
	<label><font color="#FF0000">*</font></label></td>
	<td id="GRANDID"><input name="grandTotal" id="grandTotal" type="text"  style="width:150px;" onfocus="calculateGrand()" readonly="readonly"  /></td>
	</tr>
	</table>
	</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td class="tabledata1">
		<p align="center">
			<input type="submit" name="Save" value="Save" class="search" onclick="return validation();"/>
			<a href="index.php?route=CRM/ViewSalesOrder&modid=12&frmid=322" onclick="return confirm('Are you sure?');">
			<input type="button" name="Cancel" value="Cancel" class="search"  />
			</a>
		</p>
	</td>
</tr>
</table>
 </div>
 </div>
    </div>
  </div>
    </div>
  </div>
    </form><!-- inside div close -->
</div>
<!-- Main div close -->
<script language="javascript" type="text/javascript">
function addRow(tableID) 
{
	if(document)
		var table = document.getElementById(tableID);
		var rowCount = table.rows.length;
		var row = table.insertRow(rowCount);
		document.getElementById("hiditemcount").value=rowCount;
		var colCount = table.rows[0].cells.length;
		for(var i=0; i<colCount; i++) {	 
            
			var newcell = row.insertCell(i);
           	//newcell.style.background='#e7e7e7';
			  newcell.className='tabledata';
			   newcell.innerHTML = table.rows[0].cells[i].innerHTML;
				switch(newcell.childNodes[0].type) 
				{
				case "text":
					newcell.childNodes[0].value = "";
					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
					
					
				break;

				case "hidden":

					newcell.childNodes[0].value = "";

					var nod_id_hidden = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "button":

					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "checkbox":

				newcell.childNodes[0].checked = false;
				var nod_id_chk = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				

				break;

				case "select-one":
				
				newcell.childNodes[0].selectedIndex = 0;
				var nod_id = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				break;	
			}
		}
	}
function deleteRowOrder(tableID) 
{
	try 
	{
		var table = document.getElementById(tableID);
		//alert(table);
		var rowCount = table.rows.length;
		//alert(rowCount);
		for(var i=0; i<rowCount; i++) 
			{
				var row = table.rows[i];
				var chkbox = row.cells[0].childNodes[0];
				if(null != chkbox && true == chkbox.checked) 
				{
					if(rowCount <= 1) 
					{
						alert("Cannot delete all the rows.");
						break;
					}
				table.deleteRow(i);
				rowCount--;
				i--;
				}
				
			}
	document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
		alert(e);
	}

}
	
	
function open_items()
{
if(document.getElementById("order_type").value=='')
{
alert("Must Select Order Type First");	
}
else
{	
	window.open("TelephonicItems.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>","itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");}}
function calculateExcise(str,id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
		divid="excisevalue_"+i;
		var amount=document.getElementById("totalamt_"+i).value;
	}
	else
	{
		divid="excisevalue";
		var amount=document.getElementById("totalamt").value;
	}
	if(str.length==0)
	{
		document.getElementById(divid).value="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById(divid).value=xmlhttp.responseText;
		
	}
	
}
xmlhttp.open("GET","calculateExcise.php?type=TELORD&amount="+amount+"&q="+str,true);
xmlhttp.send();	
	} 
	
function calculateExcise1(str,id)	
{
var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
		divid="excisevalue_"+i;
		var amount=document.getElementById("totalassamt_"+i).value;
	}
	else
	{
		divid="excisevalue";
		var amount=document.getElementById("totalassamt").value;
	}
	if(str.length==0)
	{
		document.getElementById(divid).value="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById(divid).value=xmlhttp.responseText;
		
	}
	
}
xmlhttp.open("GET","calculateExcise.php?type=TELORD&amount="+amount+"&q="+str,true);
xmlhttp.send();	
	} 	
	
function calculateBillExcise(str)
{
	var value=document.getElementById("basicAmount").value;
	if(str.length==0)
	{
		document.getElementById("totalDiscountedPrice").innerHTML="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById("totalDiscountedPrice").value=xmlhttp.responseText;
 	}
 }
xmlhttp.open("GET","calculateExcise.php?type=bill&id="+str+"&value="+value,true);
xmlhttp.send();	}
function calculateTotalExcise()
{
	var EDRate=document.getElementById("EDRate").value;
	if(EDRate==0){
	var totalExcise=0;
	//var first_row=document.getElementById("excisevalue").value;
	//if(first_row==''){first_row=0;}
	var cnt=document.getElementById("hiditemcount1").value;
	//var newcount=parseInt(cnt)+1;
	for(var i=0;i<cnt;i++)
	{
	 	var totalExcise1=document.getElementById("excisevalue_"+i).value;
	 	var totalExcise=(parseFloat(totalExcise)+parseFloat(totalExcise1)).toFixed(2);
	}
	  document.getElementById("totalDiscountedPrice").value=parseFloat(totalExcise);
	}
	else{return false;}
}

function calculateEditVATCST()
{
	var rate=document.getElementById("vat_rate").value;
	var taxableAmount=document.getElementById("taxableAmount").value;
	var vat_cst=taxableAmount*(rate/100);
	document.getElementById("VatCstValue").value=vat_cst.toFixed(2);
}

/*function validate()
{
	if(document.getElementById("Site").value=='0')
	{alert('Please choose a branch before saving'); document.getElementById("Site").focus();  return false;}
	
	if(document.getElementById("orderNo").value=='')
	{alert('SOP No. cannot be empty'); document.getElementById("orderNo").focus(); return false;}
	
	if(document.getElementById("Client").value=='0')
	{alert('Please choose a client before saving'); document.getElementById("Client").focus(); return false;}
	
	if(document.getElementById("PONo").value=='')
	{alert('Client PO No. cannot be empty'); document.getElementById("PONo").focus(); return false;}
		
	return false;
}*/

function getorder(str)
{
	if(str!='Consolidate')
	document.getElementById("EDRate").setAttribute('disabled',true);
	else
	document.getElementById("EDRate").removeAttribute('disabled');
if(str.length==0)
	{
		document.getElementById("showdata").innerHTML="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById("showdata").innerHTML=xmlhttp.responseText;
 	}
 }
xmlhttp.open("GET","gettelephonicdata.php?id="+str,true);
xmlhttp.send();
	
	
	
	
	
}


</script>
