
	<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
$PageSecurity = 1;
$tabindex=0;
include('includes/DefinePaymentClass.php');
$title = _('Telephonic Order Memo');
include('includes/SQL_CommonFunctions.inc');
if($_REQUEST['act']=='delitem' && $_REQUEST['id']!='')
{
	$update_del_status=DB_query("update salesorder_details set del_status='1' where id='".$_REQUEST['id']."'",$db);
	echo "<script>location.href='index.php?route=CRM/viewsalesorderTelephonicEdit&action=Edit&SOrderId=".$_REQUEST['SOrderId']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}

if($_REQUEST['act']=='delkititem' && $_REQUEST['id']!='')
{
	$update_del_status=DB_query("update salesorder_kit_details set del_status='1' where id='".$_REQUEST['id']."'",$db);
	echo "<script>location.href='index.php?route=CRM/viewsalesorderTelephonicEdit&action=Edit&SOrderId=".$_REQUEST['SOrderId']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}

if($_REQUEST['act']=='reset1')
{
	$update_del_status=DB_query("update salesorder_kit_details set del_status='0' where masterId='".$_REQUEST['SOrderId']."' and del_status='1'",$db);
	echo "<script>location.href='index.php?route=CRM/viewsalesorderTelephonicEdit&action=Edit&SOrderId=".$_REQUEST['SOrderId']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}



if($_REQUEST['act']=='reset')
{
	$update_del_status=DB_query("update salesorder_details set del_status='0' where masterId='".$_REQUEST['SOrderId']."' and del_status='1'",$db);
	echo "<script>location.href='index.php?route=CRM/viewsalesorderTelephonicEdit&action=Edit&SOrderId=".$_REQUEST['SOrderId']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_REQUEST['action']=='Edit' )
{

  $getlead=DB_query( "select * from salesorder where id='".$_REQUEST['SOrderId']."'",$db);
	 while($row_lead=DB_fetch_array($getlead))
	 {
	    $Site=$row_lead['branch'];
		$orderNo=$row_lead['orderNo'];
  	    $TelephonicDate=ConvertSQLDate($row_lead['orderDate']);
		$PORefNo=$row_lead['PORefNo'];
		$customerDate=ConvertSQLDate($row_lead['customerPODate']);
		$Client=$row_lead['client'];
		$Sale_Key_Exec=$row_lead['Sale_Key_Exec'];
		$SalesId=$row_lead['id'];
		$DelieveryDate=ConvertSQLDate($row_lead['DeliveryDate']) ;
		$RoadPermit=$row_lead['RoadPermit'];
	    $Transport=$row_lead['Transport'];
		$freight=$row_lead['freight'];
		$TelStatus=$row_lead['TelStatus'];
		$PendingPayment=$row_lead['PendingPayment'];	
		$Address=DB_query("select * from clientmaster where id='".$Client."'",$db);
		$AddressRow=DB_fetch_array($Address);
		$Address1=$AddressRow['pre_address1'];
		$add21=DB_query("select * from city_master where id='".$AddressRow['pre_city']."'",$db);
		$add22=DB_fetch_array($add21);
		$Address2=$add22['city'];
		$add23=DB_query("select * from state_master where id='".$AddressRow['pre_state']."'",$db);
		$add24=DB_fetch_array($add23);
		$Address3=$add24['state'];
		$cate=$row_lead['cate'];
		$order_type=$row_lead['order_type'];
		$sparekit=$row_lead['sparekit'];
		$Telephone=DB_query( "select * from contact_information_master where master_code='".$Client."'",$db);
		$TelephoneRow=DB_fetch_array($Telephone);
		$ContactPerson=$TelephoneRow['ContactPerson'];
		$id=$TelephoneRow['id'];
		$TelePhoneNo=$TelephoneRow['phone'];
		$PONo=$row_lead['PORefNo'] ;
 	    $PODate=ConvertSQLDate($row_lead['customerPODate']) ;
 	
	
		
		
		
		$exciseDuty=$row_lead['exciseDuty'];
 		$basicAmount=$row_lead['basicAmount'];
		$exciseValue=$row_lead['TotalExciseValue'];
		$ECessPercentage=$row_lead['ECessPercentage'];
		$ECessValue=$row_lead['ECessValue'];
		$SAHCessPercentage=$row_lead['SAHCessPercentage'];
		$SAHCessValue=$row_lead['SAHCessValue'];
		$ser_per=$row_lead['ser_per'];
		$service_amt=$row_lead['service_amt'];
		$train_chages=$row_lead['train_chages'];
		$dsl_charges=$row_lead['dsl_charges'];
		$install_charges=$row_lead['install_charges'];
		$insurance_charges=$row_lead['insurance_charges'];
		$frieght_charges=$row_lead['frieght_charges'];
		$frd_charges=$row_lead['frd_charges'];
		$pkg_charges=$row_lead['pkg_charges'];	
		
		
		$taxableAmount=$row_lead['taxableAmount'];
		$VatCst=$row_lead['VatCst'];
		$VatCstValue=$row_lead['VatCstValue'];
		$grandTotal=$row_lead['grandTotal'];
 	 }}
if($_REQUEST['editdata']==1)
{
$Site=	$_SESSION['Site'];
$orderNo=$_SESSION['orderNo'];	
$TelephonicDate=$_SESSION['TelephonicDate'];
$Client1=$_SESSION['Client'];
//$Sale_Key_Exec=
$Address1=$_SESSION['Address1'];
//$id=
$Address2=$_SESSION['Address2'];
$TelePhoneNo=$_SESSION['Telephone'];
$Address3=$_SESSION['Address3'];
$customerDate=$_SESSION['PODate'];
$DelieveryDate=$_SESSION['DelieveryDate'];
$RoadPermit=$_SESSION['RoadPermit'];
$Transport=$_SESSION['Transport'];
$PendingPayment=$_SESSION['PendingPayment'];
$cate=$_SESSION['cate'];	}
if(($_REQUEST['Save']) && $_REQUEST['action']=='Edit' )
{
$delete1=DB_query("delete from  salesorder_kit_details where masterId ='".$_REQUEST['SOrderId']."' ",$db);

// $_REQUEST['SOrderId'];
 	  $sql1="update salesorder set
					branch='".$_REQUEST['Site']."', 
					orderDate='".FormatDateForSQL($_REQUEST['TelephonicDate'])."',
					orderNo='".$_REQUEST['orderNo']."', 
					client='".$_REQUEST['Client']."',
					Sale_Key_Exec='".$_REQUEST['Sale_Key_Exec']."',  
			        PORefNo='".$_REQUEST['PONo']."',  
					customerPODate='".FormatDateForSQL($_REQUEST['PODate'])."',  
			         SalesOrderType='Tel',
					 DeliveryDate='".FormatDateForSQL($_REQUEST['DelieveryDate'])."',
					 RoadPermit='".$_REQUEST['RoadPermit']."',
					 Transport='".$_REQUEST['Transport']."',
					 freight='".$_REQUEST['freight']."',
					 PendingPayment='".$_REQUEST['PendingPayment']."', 
					 TelStatus= '".$_REQUEST['Status']."',
					 ContactPerson='".$_REQUEST['ContactPerson']."',
					 basicAmount='".$_REQUEST['basicAmount']."',
					 exciseDuty='".$_REQUEST['EDBillRate']."', 
					TotalExciseValue='".$_REQUEST['totalDiscountedPrice']."',
					taxableAmount='".$_REQUEST['taxableAmount']."',
					ECessPercentage='".$_REQUEST['ECessPercentage']."',
					ECessId='".$_REQUEST['ECessID']."',
					ECessValue='".$_REQUEST['ECessValue']."',
					SHECessId='".$_REQUEST['SHECessId']."',
					VatCst='".$_REQUEST['VatCst']."',
					VatCstValue='".$_REQUEST['VatCstValue']."',
 			        SAHCessPercentage='".$_REQUEST['SAHCessPercentage']."',  
					SAHCessValue='".$_REQUEST['SAHCessValue']."', 
					grandTotal='".$_REQUEST['grandTotal']."',
					pkg_charges='".$_REQUEST['packchrg']."',
					frd_charges='".$_REQUEST['forwordchrg']."',
					frieght_charges='".$_REQUEST['frieghttodest']."',
					insurance_charges='".$_REQUEST['inschrg']."',
					install_charges='".$_REQUEST['ins_com_chrg']."',
					dsl_charges='".$_REQUEST['chrg_dsl']."',
					train_chages='".$_REQUEST['train_chsl']."',
					ser_per='".$_REQUEST['chrg_dsl']."',
					service_amt='".$_REQUEST['ser_tax']."',	 
					modifyBy='".$_SESSION['UserID']."',
					sparekit='".$_REQUEST['kitidfication']."',
				    order_type='".$_REQUEST['order_type']."',
					cate='".$_REQUEST['cate']."',
 				    CompanyId='".$_SESSION['ACGCompanyId']."' where id='".$_REQUEST['SOrderId']."'";
					
	$result1=DB_query($sql1,$db);
	
for($i=0;$i<count($_REQUEST['row_id']);$i++)
{
	$update1="Update salesorder_details set 
						Quantity='".$_REQUEST['Qty'][$i]."',
						Rate='".$_REQUEST['price'][$i]."',
						Amount='".$_REQUEST['stock_qty'][$i]."',
						EDRate='".$_REQUEST['EDRate'][$i]."',
						EDAmt='".$_REQUEST['EDAmt'][$i]."',
						remarks='".$_REQUEST['remarks'][$i]."',
						mrp_unit='".$_REQUEST['mrp_per'][$i]."',
						ass_price='".$_REQUEST['ass_price'][$i]."',
						total_ass_price='".$_REQUEST['total_ass_price'][$i]."'
						where id='".$_REQUEST['row_id'][$i]."'
						";
	$update_res1=DB_query($update1,$db);
}

for($j=0;$j<count($_REQUEST['item_code1']);$j++)
{
	if($_REQUEST['item_code1'][$j]!='')
	{
		$data_arr['masterId']=$_REQUEST['SOrderId'];
		$data_arr['ItemCode']=$_REQUEST['item_code1'][$j];
		$data_arr['Quantity']=$_REQUEST['Qty1'][$j];
		$data_arr['Rate']=$_REQUEST['price1'][$j];
		$data_arr['pricePer']=1;
		$data_arr['Amount']=$_REQUEST['stock_qty1'][$j];
		$data_arr['EDRate']=$_REQUEST['EDRate1'][$j];
		$data_arr['EDAmt']=$_REQUEST['EDAmt1'][$j];
		$data_arr['remarks']=$_REQUEST['remarks1'][$j];
		$data_arr['mrp_unit']=$_REQUEST['mrp_per1'][$j];
	    $data_arr['ass_price']=$_REQUEST['ass_price1'][$j];
	    $data_arr['total_ass_price']=$_REQUEST['total_ass_price1'][$j];
		$data_arr['ApprovalStatus']=$_REQUEST['ApprovalStatus1'][$j];
		$rowinsert= $s->RecordInsert('salesorder_details', $data_arr);
	}
}



for($k=0;$k<count($_REQUEST['kitid']);$k++)
{
	if($_REQUEST['kitid'][$k]!='')
	{
	$data_arr1['masterId']=$_REQUEST['SOrderId'];
	$data_arr1['kitid']=$_REQUEST['kitid'][$k];
	$data_arr1['Quantity']=$_REQUEST['kitQty'][$k];
	$data_arr1['Rate']=$_REQUEST['kitprice'][$k];
	$data_arr1['Amount']=$_REQUEST['stockkitqty'][$k];
	$rowinsert1= $s->RecordInsert('salesorder_kit_details', $data_arr1);
	}
 	
}



$delete=DB_query("delete from  salesorder_details where masterId = '".$_REQUEST['SOrderId']."' and del_status='1'",$db);

echo "<script>location.href='index.php?route=CRM/ViewSalesOrdMgnt&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";

prnMsg( _('Sales Order inserted successfully'),'success');
}
if(($_REQUEST['SaveComment']) && $_REQUEST['action']=='Edit' )
{
$comt_edit="insert into salesorder_comments set
			sopno='".$_REQUEST['SOrderId']."',
			user='".$_SESSION['UserID']."',
			comment='".$_REQUEST['comt']."',
			posted_date=now()";
			if($_REQUEST['comt']!=='')
			{
$rs_edit=DB_query($comt_edit,$db);
} 
echo "<script>location.href='index.php?route=CRM/ViewSalesOrder&modid=12&frmid=322'</script>";
//$s->pageLocation($target."&action=Edit&SOrderId=".$_REQUEST['SOrderId']."#tabs-2");

}
unset($_POST);
?>
<script type="text/javascript">

function validation(form)
{
	

if(document.getElementById('Site').value=='0')
{alert('Please Select the Branch');
document.getElementById('Site').focus();
return false;
}
	
if(document.getElementById('PONo').value==''){
alert('PO No should not be empty');
document.getElementById('PONo').focus();
return false;
}
	

if(document.getElementById('Client').value=='0'){
alert('Client should not be empty');
document.getElementById('Client').focus();
return false;}
	

if(document.getElementById('PODate').value==''){
alert('PO Date should not be empty');
document.getElementById('PODate').focus();
return false;
}
	
if(document.getElementById('basicAmount').value==''){
alert('Basic Amt should not be empty');
document.getElementById('basicAmount').focus();
return false;
}
	
if(document.getElementById('taxableAmount').value==''){
alert('Taxable Amt should not be empty');
document.getElementById('taxableAmount').focus();
return false;
}

if(document.getElementById('grandTotal').value==''){
alert('Taxable Amt should not 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 openPopupProfile1()
{
	window.open("clientname.php");
}
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 calculateEDAmt(i)
{

    
 		
	var EDRate = document.getElementById("EDRate_"+i).value;
	
	if(EDRate=='0')
	{
		
		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 totalBasic3=0;
	var first_row1=0;
	var first_row=document.getElementById("totalamt").value;
	if(first_row==''){first_row=0;}
	var cnt=document.getElementById("hiditemcount").value;
	if(cnt==''){cnt=0;}
	var edit_cnt=document.getElementById("edit_cnt").value;
	var new_count=parseInt(edit_cnt)+parseInt(cnt); 
	for(var i=0;i<new_count;i++)
	{
	   if(document.getElementById("totalamt_"+i).value!='')
	 	var totalBasic1=document.getElementById("totalamt_"+i).value;
		else
		var totalBasic1=0;
		//alert(totalBasic1);
	 	var totalBasic=(parseFloat(totalBasic)+parseFloat(totalBasic1)).toFixed(2);
	}
 
   if(document.getElementById("kitidfication").checked == true)
	{
	
	if(document.getElementById("totalkitamt").value!='')
    var first_row1=document.getElementById("totalkitamt").value;
	else
	var first_row1=0;
	if(document.getElementById("hiditemcount1").value!='')
	var cnt1=document.getElementById("hiditemcount1").value
	else
	var cnt1=0;
	var edit_cnt2=document.getElementById("edit_cnt1").value;
	var new_count2=parseInt(edit_cnt2)+parseInt(cnt1); 
	var newcount1=parseInt(new_count2);
	for(var t=0;t<newcount1;t++)
	{	
	if(document.getElementById("totalkitamt_"+t).value!='')
	var totalBasic2=document.getElementById("totalkitamt_"+t).value;
	var totalBasic3=(parseFloat(totalBasic3)+parseFloat(totalBasic2)).toFixed(2);
	}	
	}
	else if(document.getElementById("kitidfication1").checked == true)
	{
	var totalBasic3=0;
	var first_row1=0;
	}
	
	
	  document.getElementById("basicAmount").value=parseFloat(totalBasic)+parseFloat(first_row)+parseFloat(totalBasic3)+parseFloat(first_row1);
}

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);
 
 	 }
	
	
	document.getElementById("totalDiscountedPrice").value=totalDiscounted;
}

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("rate").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("rate").value=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","calculateExcise.php?salesId="+str,true);
		xmlhttp.send();
}

function calculateVATCST(str)
{	
     var amt=document.getElementById("basicAmount").value;
	
	  if (str.length==0)
  		{
  			document.getElementById("VATId").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("VATId").innerHTML=xmlhttp.responseText;
    		}
  		}
	    xmlhttp.open("GET","calexciseamount.php?salesId="+str+"&amt="+amt,true);
		xmlhttp.send();
}

function calculateservice(str)
{	
     var amt=document.getElementById("train_chsl").value;
	
	  if (str.length==0)
  		{
  			document.getElementById("saledid").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("saledid").innerHTML=xmlhttp.responseText;
    		}
  		}
	    xmlhttp.open("GET","calexciseamount.php?exiceid="+str+"&amt="+amt,true);
		xmlhttp.send();
}


function calculateGrand()
{
	
	
	var a=document.getElementById("basicAmount").value;
	var b=document.getElementById("packchrg").value;
	var c=document.getElementById("forwordchrg").value;
	var d=document.getElementById("frieghttodest").value;
	var e=document.getElementById("inschrg").value;
	var f=document.getElementById("ins_com_chrg").value;
	var g=document.getElementById("chrg_dsl").value;
	var h=document.getElementById("train_chsl").value;
	var i=document.getElementById("VatCstValue").value;
	var j=document.getElementById("ser_tax").value;
	
	
	
	if(a==''){a=0;}
	if(b==''){b=0;}
	if(c==''){c=0;}
	if(d==''){e=0;}
	if(e==''){e=0;}
	if(f==''){f=0;}
	if(g==''){g=0;}
	if(h==''){h=0;}
	if(i==''){i=0;}
	if(j==''){j=0;}
	
	var GRAND=parseFloat(a)+parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e)+parseFloat(f)+parseFloat(g)+parseFloat(h)+parseFloat(i)+parseFloat(j);
	
	document.getElementById("grandTotal").value=GRAND.toFixed(2);
	
}

function open_items()
{
	window.open("TelephonicItems.php?action=<?php echo $_REQUEST['action']?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=Edit&SOrderId=<?php echo $_REQUEST['SOrderId'] ?>","item_popup_window","height=500,width=900,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}
 </script>
<div class="body_contain">
<h1><?php echo $title; ?></h1>
<div class="insideclass">
<div style="z-index:-1000em;">
<div class="demo">
<div id="tabs">
	<ul>
		<li><a href="#tabs-1">Order Details</a></li>
		<li><a href="#tabs-2">More Information</a></li>
	</ul>
<div id="tabs-1">
<div class="tab_div">
<form action="" method="post"  >
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php if(count($msgErr)>0){?>
   <tr>
   <td colspan="4"><?php
   for($i=0;$i<count($msgErr);$i++)
   {
     echo "<div class='error'>".$msgErr[$i].'</div>';
   }
    ?></td>
   </tr>
   <?php } ?>
</table>	
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td class="tabledata1">Branch</td>
	<td ><input type="hidden" name="salid" id="salid" value="<?php echo $_REQUEST['SOrderId']; ?>" />
		<select style="width:150px;" name="Site" id="Site" onchange="showstore(this.value)">
			<option value="0">Select Branch</option>
			<?php $SQL="Select * from locations where mst_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($Site==$Row['loccode'] ? 'selected':'');?> ><?php echo $Row['locationname']?></option>
					<?php  } ?>
					</select>
	</td>
	<td>Store</td>
	<td><div id="dealer1"><select name="dealer" id="dealer" style="width:150px;">
<?php  
$sql=DB_query("select * from storetype where Store_Site='".$Site."'",$db);
while($row=DB_fetch_array($sql))
{
?>
<option value="<?php echo $row['id'] ?>"><?php echo $row['StoreName']; ?></option>
<?php } ?>
	
</select></div></td>
</tr>
<tr class="row1">
	<td class="tabledata1">SOP No<label><font color="#FF0000">*</font></label></td>
	<td><div id="orderid"><input type="text" name="orderNo" id="orderNo" value="<?php echo $orderNo;?>" style="width:150px;">
                    </div></td>
	<td class="tabledata1">Date<label><font color="#FF0000">*</font></label></td>
	<td><input type="text" name="TelephonicDate" id="TelephonicDate" value="<?php echo $TelephonicDate;?>" class="datepicker" style="width:150px;"></td>
</tr>
<tr class="row1">
	<td class="tabledata1">Client</td>
	<td><select style="width:150px;" name="Client" onchange="ShowDiv(this.value,'ContactName','getContact.php')">
			<option value="0">--Select--</option>
			<?php $ClientSQL="Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and  Site in('".$_SESSION['AssignedBranch']."') and Zone in(".$_SESSION['AssignedSites'].") order by c_name ASC"  ;
				$ClientRes=DB_query($ClientSQL,$db);
				while($ClientRow=DB_fetch_array($ClientRes)){?>
			<option value="<?php echo $ClientRow['id']?>" <?php echo($Client==$ClientRow['id']?'selected':'')?>  ><?php echo $ClientRow['c_name']?></option>
					<?php  } ?>
 					</select>
	</td>
	<td class="tabledata1">Sales Key Executive</td>
	<td><?php $Sale_key_Exe=DB_query("select * from www_users where companyid='".$_SESSION['ACGCompanyId']."'",$db);?>
		<select name="Sale_Key_Exec" style="width:150px;">
			<option value="0">Select</option>
			<?php while($Sale_keyRow=DB_fetch_array($Sale_key_Exe)){?>
			<option value="<?php echo $Sale_keyRow['id'] ?>"<?php echo ($Sale_Key_Exec==$Sale_keyRow['id']?'selected':'')?>><?php echo $Sale_keyRow['userid']; ?></option>
			<?php } ?>
		</select>
	</td>
</tr>
<tr class="row1">
	<td colspan="4">
		<table id="ContactName"width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td class="tabledata1">Address</td>
	<td><input type="text"  style="width:150px;" name="Address1"  value="<?php echo  $Address1;?>"/></td>
	<td class="tabledata1">Contact Person</td>
	<td><?php $SQL="Select * from contact_information_master where master_code='".$Client."'";?>
			<select style="width:150px;" 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($id==$Row['id']?'selected':'')?>><?php echo $Row['person']?></option>
<?php  } ?>
					
		</select>
	</td>
</tr>
<tr class="row1">
	<td>&nbsp;</td>
	<td><input type="text" name="Address2" id="Address2" style="width:150px;" value="<?php echo $Address2; ?>"  ></td>
	<td class="tabledata1">Phone No</td>
	<td><div id="PhoneNo" style="width:100px;"><input type="text" style="width:150px;" name="Telephone" id="Telephone" value="<?php echo $TelePhoneNo?>"  ></div></td>
</tr>
<tr  class="row1">
	<td align="left">&nbsp;</td>
	<td><input type="text" name="Address3" id="Address3" style="width:150px;" value="<?php echo $Address3;?>"  > </td>
	<td align="left">&nbsp;</td>
	<td>&nbsp;</td>
</tr>
</table>
	</td>
</tr>
<tr class="row1">
	<td class="tabledata1">Client P.O. No.<label><font color="#FF0000">*</font></label></td>
    <td><input type="text" name="PONo" id="PONo " style="width:150px;"  value="<?php echo $PORefNo; ?>"   ></td>
    <td class="tabledata1">P.O. Date<label><font color="#FF0000">*</font></label></td>
    <td><input type="text" name="PODate" id="PODate " style="width:150px;" class="datepicker"  value="<?php echo $customerDate;?>"  ></td>
</tr>
<tr class="row1">
	<td class="tabledata1">Delivery Date</td>
    <td ><input type="text" name="DelieveryDate" id="DelieveryDate" style="width:150px;" class="datepicker" value="<?php echo $DelieveryDate;?>"   ></td>
    <td class="tabledata1">Road Permit</td>
    <td><input name="RoadPermit" type="text" style="width:150px;"   value="<?php echo $RoadPermit; ?>"  /></td>
</tr>
<tr class="row1">
	<td class="tabledata1">Transport</td>
    <td><select style="width:150px;" name="Transport">
			<option value="0">--Select--</option>
			<?php echo	$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($Transport==$Row['id']?'selected':'' );?>  ><?php echo $Row['TransportName']?></option>
					<?php  } ?>
					</select></td>
	<td class="tabledata1">Freight Type</td>
    <td><select style="width:150px;" name="freight">
            <option value="0">Select</option>
			<option value="Paid"<?php echo($freight=='Paid'?'selected':''); ?>>Paid</option>
			<option value="topay"<?php echo($freight=='topay'?'selected':''); ?>>To Pay</option>
			<option value="Nill"<?php echo($freight=='Nill'?'selected':''); ?>>Nill</option>
        </select></td>
</tr>
<tr class="row1">
	<td class="tabledata1">Status</td>
	<td><select style="width:150px;" name="Status">
			<option id="Pending">Created</option>
		</select></td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
</tr>
<tr class="row1">
	<td class="tabledata1">Category</td>
	<td ><select name="cate" id="cat" style="width:150px;">
               	<option value="">Select</option>
               	<option value="Urgent"<?php if($cate=='Urgent'){ ?> selected="selected" <?php } ?> >Urgent</option>
               	<option value="Normal" <?php if($cate=='Normal'){ ?> selected="selected" <?php } ?>>Normal</option>
               </select></td>	
	<td class="tabledata1">Order Type</td>
	<td><select name="order_type" id="order_type" style="width:150px;"   >        	
                 <option value="<?php echo $order_type; ?>" <?php if($order_type=='MRP_Item'){ ?>selected="selected" <?php } ?> ><?php if($order_type=='MRP_Item'){ ?>MRP Item Wise<?php } else {?>TBI<?php } ?> </option>	
                </select></td>
</tr>
<tr class="row1">
	<td class="tabledata1">Pending Pay. (if any)</td>
    <td colspan="3"><textarea name="PendingPayment" id="PendingPayment"  style="width:610px; height:40px;"><?php echo $PendingPayment;?></textarea></td>
</tr>
<tr class="row1">
	<td colspan="4" ><p align="left"><input type="button" onclick="addRow('dataTable')" value="Add Rows" class="search" />&nbsp;&nbsp; <input type="button" class="search"   onclick="deleteRowOrder('dataTable')" value="Delete Rows"/>&nbsp;&nbsp; <input type="button" name="profile_popup" value="Pick Items" id="profile_popup"  onclick="open_items()" class="search" />
	</p></td>
</tr>
<tr class="row1"><!-- c6c6c6 -->
	<td colspan="4">
 			<div id="showdata">
 			<table width="100%" border="1" cellspacing="0" cellpadding="3">
              <tr class="row1">
                <td class="tabledata">S.No</td>
				<td class="tabledata"></td>
				<td class="tabledata">Item Code</td>
				<td class="tabledata">Shade/Item Name. </td>
				<td class="tabledata">Item Desc. </td>
                <td class="tabledata">Qty</td>
                <td class="tabledata">Price</td>
                <td class="tabledata">Total Amt</td>
               
                 <td class="tabledata">Remarks</td>
              </tr>
		<!-------------Add ITEMS IN THE ITEM LIST AT TIME OF EDIT----------------------->
<?php 
 $i=0;
// echo "Select * from salesorder_details where masterId='".$SalesId."' and del_status='0'";
  $ItemSQL=DB_query("Select * from salesorder_details where masterId='".$SalesId."' and del_status='0'",$db);
  while($item_row1=DB_fetch_array($ItemSQL))
  {
 
	//echo "select * from item_master where id='".$item_row1[ItemCode]."'";
	 $itemquery=DB_query("select * from item_master where id='".$item_row1[ItemCode]."'" , $db);
	$item_row=DB_fetch_array($itemquery);
	 //echo "select StockID,item_name,unit, make ,grade, color from item_master where StockID='".$itemlist[$i]."'" ;
	
		if($i%2==0)
		{$bg="#CCCCCC";}
		else
		$bg="#C8BECB";
	
	?>
	
	<tr bgcolor="<?php //echo $bg;?>"  class="row1">
	<td class="tabledata"><a href="index.php?route=CRM/viewsalesorderTelephonicEdit&action=Edit&SOrderId=<?php echo $_REQUEST['SOrderId'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act=delitem&id=<?php echo $item_row1['id'];?>"><img src="images/delete.gif" /></a>
	<?php //echo $i+1;?></td>
	<td class="tabledata"><input type="hidden" name="row_id[<?php echo $i; ?>]" id="row_id" value="<?php echo $item_row1['id']?>" /></td>	
	<td  class="tabledata">
	<input type="hidden" name="itemid[<?php echo $i; ?>]" value="<?php echo $item_row['id'];?>" />
	<input type="hidden" name="item_code[<?php echo $i;?>]" id="item_code_<?php echo $i;?>" value="<?php echo $item_row['StockID'];?>" readonly  size="6">	
	<?php echo $item_row['StockID'];?>
				
   <input type="hidden" value="<?php echo $item_row['StockID'];?>" tabindex=""  readonly="" id="washing_profile" name="itemcode[]"   />
   <input type="hidden" name="salesdetailid[<?php echo $i;?>]" value="<?php echo $item_row1['id'];?>"  />
   <input type="hidden" name="itemid[<?php echo $i;?>]" value="<?php echo $item_row['id'];?>" />
	</td>	
   <td class="tabledata">
				<?php echo $item_row['item_name'];?>
                </td>
   <td class="tabledata" ><?php echo $item_row['item_desc'];?></td>
   
   <td class="tabledata" ><input type="text" style="width:50" name="Qty[<?php echo $i;?>]" id="qty_<?php echo $i;?>" value="<?php echo $item_row1['Quantity']?>"/></td>
   
   <td class="tabledata" ><input type="text" name="price[<?php echo $i;?>]" id="price_<?php echo $i;?>" value="<?php echo $item_row1['Rate']?>" size="6" onkeyup="calculateTotalAmt(this.value,this.id)" /></td>
   
   <td class="tabledata" ><input type="text" name="stock_qty[<?php echo $i;?>]" id="totalamt_<?php echo $i;?>" style="width:70px;" value="<?php echo $item_row1['Amount']?>" readonly="true"  />
   
   <?php $item_row1['EDRate']; ?>
   </td>
     
   <td class="tabledata"><textarea name="remarks[<?php echo $i; ?>]"><?php echo $item_row1['remarks']; ?></textarea></td>
    	
  </tr>
  <?php  $i++;
   }  ?>	
  <input type="hidden" name="" value="<?php echo $i;?>" id="edit_cnt" /> 
  <?php 
  {
  ?>
<!------Add Extra Items--------->	
<tbody id="dataTable">
<tr class="row1">
<td style="white-space:nowrap;" class="tabledata"><input name="delitem[]" type="checkbox" value="<?php echo $item_row['id'];?>" /></td>
<td class="tabledata"><input type="hidden" name="item_code1[]" id="itemid" /></td>	
<td class="tabledata"><input type="text" name="" value="" id="itemcode" size="6" /></td>
<td class="tabledata" style="white-space:nowrap"><input type="text" name="" size="12" value="" id="itemname" /></td>
<td class="tabledata"><input type="text" name="" value="" id="itemdesc" size="25"/></td>
<td class="tabledata"><input type="text" name="Qty1[]" value="" id="qty" size="6"/></td>
<td class="tabledata"><input type="text" name="price1[]" value="" id="price" onkeyup="calculateTotalAmt(this.value,this.id)" size="6"/></td>
<td class="tabledata"><input type="text" name="stock_qty1[]" value="" id="totalamt" readonly="true" size="9"/></td>

   <td class="tabledata"><textarea  name="remarks1[]" id="excisevalue" ></textarea></td>
   <input type="hidden" name="ApprovalStatus1[]" value="Pending">
  
  </tr>
  				</tbody>
<?php } ?>
  
 <!------Add Extra Items--------->	 
  
</table>
			</div>
 <input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
      </td>
</tr>

<?php if($sparekit=='yes') { ?>
<tr class="row1">
	<td colspan="4" ><p align="left"><input type="button" onclick="addRow1('dataTable1')" value="Add Rows" class="search" />&nbsp;&nbsp; <input type="button" class="search"   onclick="deleteRowOrder1('dataTable1')" value="Delete Rows"/>&nbsp;&nbsp; <input type="button" name="profile_popup" value="Pick Items" id="profile_popup"  onclick="open_items1()" class="search" />
	<input type="radio" class="search" id="kitidfication" name="kitidfication" value="yes"  <?php if($sparekit=='yes') { ?>  
 checked="checked" <?php } ?>  onclick="calculateBasic()"/><strong>Include Spare Kit</strong>
	<input type="radio" class="search" id="kitidfication1"  name="kitidfication" value="no" <?php if($sparekit=='no') { ?>checked="checked" <?php } ?> onclick="calculateBasic()" /><strong>Not Include Spare Kit</strong></p></td>
</tr>
<tr class="row1">
	<td colspan="4"><strong>Spare part Kit details</strong>
 			<div id="showdata">
 			<table width="100%" border="1" cellspacing="0" cellpadding="3">
              <tr class="row1">
                <td class="tabledata">S.No</td>
				<td class="tabledata"></td>
				<td class="tabledata">Kit  Code</td>
				<td class="tabledata">Kit Name. </td>
				<td class="tabledata">Kit Desc. </td>
                <td class="tabledata">Qty</td>
                <td class="tabledata">Price</td>
                <td class="tabledata">Total Amt</td>
               
               
              </tr>
		<!-------------Add ITEMS IN THE ITEM LIST AT TIME OF EDIT----------------------->
<?php 
 $i=0;
// echo "Select * from salesorder_details where masterId='".$SalesId."' and del_status='0'";
  $ItemSQL1=DB_query("Select * from salesorder_kit_details where masterId='".$SalesId."' and del_status='0'",$db);
  while($item_row2=DB_fetch_array($ItemSQL1))
  {
 
	//echo "select * from item_master where id='".$item_row1[ItemCode]."'";
	 $itemquery=DB_query("select * from spare_part_kits where id='".$item_row2['kitid']."'" , $db);
	$item_row4=DB_fetch_array($itemquery);
	 //echo "select StockID,item_name,unit, make ,grade, color from item_master where StockID='".$itemlist[$i]."'" ;
	
		if($i%2==0)
		{$bg="#CCCCCC";}
		else
		$bg="#C8BECB";
		
	
	?>
	
	<tr bgcolor="<?php //echo $bg;?>"  class="row1">
	<td class="tabledata"><a href="index.php?route=CRM/viewsalesorderTelephonicEdit&action=Edit1&SOrderId=<?php echo $_REQUEST['SOrderId'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act=delkititem&id=<?php echo $item_row2['id'];?>"><img src="images/delete.gif" /></a>
	<?php //echo $i+1;?></td>
	<td class="tabledata"><input type="hidden" name="kitrow_id[]" id="row_id" value="<?php echo $item_row2['id']?>" /></td>	
	<td  class="tabledata">
	<input type="hidden" name="kitid[]" id="kitid_<?php echo $i; ?>" value="<?php echo $item_row4['id'];?>" />
			<?php echo $item_row4['kit_code'];?>	
	</td>	
   <td class="tabledata"> <input type="text" name="" size="12" id="kitname_<?php echo $i;?>" 
   value="<?php echo $item_row4['kit_name'];?>" /> </td>
   <td class="tabledata" ><input type="text" name=""  id="kitdesc_<?php echo $i;?>" size="25"
    value="<?php echo $item_row4['kit_desc'];?>" ></td>
   
   <td class="tabledata" ><input type="text" style="width:50" name="kitQty[]" id="kitqty_<?php echo $i;?>" value="<?php echo $item_row2['Quantity']?>"/></td>
   
   <td class="tabledata" ><input type="text" name="kitprice[]" id="kitprice_<?php echo $i;?>" value="<?php echo $item_row2['Rate']?>" size="6" onkeyup="calculateTotalAmt(this.value,this.id)" /></td>
   
   <td class="tabledata" ><input type="text" name="stockkitqty[]" id="totalkitamt_<?php echo $i;?>" style="width:70px;" value="<?php echo $item_row2['Amount']?>" readonly="true"  />
   
  
   </td>  
 
  </tr>
  <?php  $i++;
   }  ?>	
  <input type="hidden" name="" value="<?php echo $i;?>" id="edit_cnt1" /> 
 
<!------Add Extra Items--------->	
<tbody id="dataTable1">
<tr class="row1">
	<td style="white-space:nowrap;" class="tabledata"><input name="delitem1[]" type="checkbox" value="<?php echo $item_row['id'];?>" />
	</td>
	<td class="tabledata"><input type="hidden" name="kitid[]" id="kitid" /></td>
	<td class="tabledata"><input type="text" name="" value="" id="kitcode" size="6" /></td>
	<td class="tabledata" style="white-space:nowrap"><input type="text" name="" size="12" value="" id="kitname" /></td>
	<td class="tabledata"><input type="text" name="" value="" id="kitdesc" size="25"/></td>
	<td class="tabledata"><input type="text" name="kitQty[]" value="" id="kitqty" size="6" /></td>
	<td class="tabledata"><input type="text" name="kitprice[]" value="" id="kitprice" onkeyup="calculateTotalkitAmt(this.value,this.id)" size="6"/></td>
	<td class="tabledata"><input type="text" name="stockkitqty[]" value="" id="totalkitamt"  size="9"/></td>
	
</tbody>

  
 <!------Add Extra Items--------->	 
  
</table>
			</div>
 <input type="hidden" name="hiditemcount1" id="hiditemcount1" value="" />
      </td>
</tr>
<?php } ?>



<tr class="row1">
	<td colspan="4">
		<p align="left"><a href="index.php?route=CRM/viewsalesorderTelephonicEdit&action=Edit&SOrderId=<?php echo $_REQUEST['SOrderId'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act=reset"><input type="button" name="profile_popup" value="Undo Item Deletion" id="profile_popup" class="search" /></a>
		&nbsp; <a href="index.php?route=CRM/viewsalesorderTelephonicEdit&action=Edit&SOrderId=<?php echo $_REQUEST['SOrderId'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act=reset1"><input type="button" name="profile_popup" value="Undo Spare Item Deletion" id="profile_popup" class="search" /></a>
		</p>
	</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td width="57%" align="left" style="width:50%"></td>
	<td width="43%" align="right" style="width:50%">
		<table width="100%" border="0" cellspacing="0" cellpadding="3">
		<tr class="row1">
		<td class="tabledata1" colspan="2"><h1 style="border-width: 0 0 0 0px;">Amount And Taxes</h1></td>
		</tr>
		<tr class="row1">
		<td width="72%" class="tabledata1">TOTAL EX- WORK COST
		<label><font color="#FF0000">*</font></label></td>
		<td width="28%"><input name="basicAmount" type="text"   style="width:107px;" onfocus="calculateBasic()" id="basicAmount"
		 value="<?php echo $basicAmount; ?>"
		/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">PACKING CHARGES</td>
		<td><input type="text" name="packchrg" id="packchrg" style="width:107px;"  value="<?php echo $pkg_charges; ?>"></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">FORWARDING CHARGES</td>
		<td><input type="text" name="forwordchrg" id="forwordchrg" style="width:107px;"  value="<?php echo $frd_charges; ?>"></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">FREIGHT TO DESTINATION</td>
		<td><input type="text" name="frieghttodest" id="frieghttodest" style="width:107px;"  value="<?php echo $frieght_charges; ?>"></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">INSURANCE CHARGES</td>
		<td><input type="text" name="inschrg" id="inschrg" style="width:107px;"  value="<?php echo $insurance_charges; ?>"></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">INSTALLATION & COMMISSIONG CHARGES FOR CRANE</td>
		<td><input name="ins_com_chrg" id="ins_com_chrg" type="text" style="width:107px;"  value="<?php echo $install_charges; ?>"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">CHARGES FOR DSL</td>
		<td><input type="text" name="chrg_dsl" id="chrg_dsl" style="width:107px;"  value="<?php echo $dsl_charges; ?>"></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">TRAINING CHARGES</td>
		<td><input type="text" name="train_chsl" id="train_chsl" style="width:107px;"  value="<?php echo $train_chages; ?>"></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">VAT/CST</td>
		<td><select name="VatCst" id="value3" style="width:107px;" onchange="calculateVATCST(this.value)">
		<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:107px;" readonly 
		onfocus="calvattotal()"		  />
		</div>
		<?php $vatcal=DB_query("select taxrate from sales_tax_master where salestax_id='".$VatCst."'",$db);
		      $vatcal1=DB_fetch_array($vatcal); 
		
		$vatcal12=$vatcal1['taxrate'];  ?>
		<input type="hidden" name="rate4" id="rate4" value="<?php echo $vatcal12; ?>" />
		<!--<input type="hidden" name="rate" id="rate" value="<?php //echo $rate;?>" />-->
		</td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">SERVICE TAX</td>
		<td>
		<?php 
		$SerSQL=DB_query("select * from service_tax_master",$db);
		?>
		<select name="chrg_dsl" id="chrg_dsl" style="width:107px;" onchange="calculateservice(this.value)">
			
			<?php while($Service=DB_fetch_array($SerSQL)) {?>
			<option value="<?php echo  $Service['id']?>" <?php echo $ser_per==$Service['salestax_id']?'selected':''?>><?php echo  $Service['tax_code']?></option>
			<?php } ?>
		</select>
		<div id="saledid">
		<input name="ser_tax" id="ser_tax" type="text"  style="width:107px;" readonly  value="<?php echo $service_amt; ?>" 
		onfocus="calamountcheck()"		/>
		</div>
		<?php $sal1=DB_query("select taxrate from service_tax_master where id='".$ser_per."'",$db);
		      $sal2=DB_fetch_array($sal1); 
		
		$sal=$sal2['taxrate'];  ?>
		<input type="hidden" name="rate3" id="rate3" value="<?php echo $sal; ?>" />

		</td>
		</tr>
		<tr class="row1">
		<td class="tabledata1"><strong>Grand Total</strong>
		<label><font color="#FF0000">*</font></label></td>
		<td><input name="grandTotal" id="grandTotal" type="text"  style="width:107px;" onfocus="calculateGrand()" readonly="readonly"  value="<?php echo $basicAmount; ?>" /></td>
		</tr>
		</table>
	</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td colspan="11">
		<p align="center">
			<input type="submit" name="Save" value="Save" class="search"   />
<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>
</form>
	</div>
</div><!-- Tab 1 Close -->
<div id="tabs-2">
	<form action="" method="post"  >		
<?php 
$comment_edit="select * from salesorder_comments where sopno='".$_REQUEST['SOrderId']."'";
$comment_edit1=DB_query($comment_edit,$db);
$i=0;
while($comment_editRow=DB_fetch_array($comment_edit1))
{
?>
			<div style="width:auto;">
			<p style="margin:0px; padding:0px; text-align:left; font-weight:bold">Comment</p>
			<p style="margin:0px; padding:0px; text-align:left;"><textarea readonly="readonly" name="comt" style="width:700px;" ><?php echo $comment_editRow['comment']; ?></textarea></p>
			<p style="margin:0px; padding:0px; text-align:left; color:#003366"><?php echo 'By '.$s->GetFieldValue('www_users',"id='".$comment_editRow['user']."'",'realname'); ?>&nbsp;&nbsp;<?php echo ConvertSQLDate($comment_editRow['posted_date']); ?></p>
			 </div>
			<!--	<table width="100%" border="0">
		  <tr class="row1">
			<td rowspan="2" width="10%"><img src="images/langmanager.png"  width="30px" height="30px" /> </td>
			<td width="90%"><?php echo $comment_editRow['comment']; ?><br />
			
			
			
			</td>
		  </tr><tr class="row1"><td colspan="2"  height="20px"></td></tr>
		  
		</table>-->

				 
			 
		<?php $i++;} ?>
		 
		
		<div style="width:auto;">
				<p style="margin:0px; padding:0px; text-align:left; font-weight:bold"><?php if($_REQUEST['action']=='Edit'){echo 'Add New Comment';} ?></p>
				<p style="margin:0px; padding:0px; text-align:left;"><textarea name="comt" style="width:700px;" ></textarea></p>				
			<p style="margin:0px; padding:0px; text-align:left; color:#003366"><?php if($_REQUEST['action']=='Edit'){echo 'By User';} ?></p>
			
			<input type="submit" name="SaveComment" value="Save"  class="search" />

			</div>
		
</form>


	</div><!-- Tab 2 Close -->
</div>
</div>
</div>
</div><!-- inside div close -->
</div><!-- Main div close -->
<script language="javascript" type="text/javascript">
function addRow(tableID) 
{
	if(document)
	var edit_cnt=document.getElementById("edit_cnt").value;
	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 newCount=parseInt(rowCount)+parseInt(edit_cnt)-1;
	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+'_'+newCount;
	newcell.childNodes[0].name = newcell.childNodes[0].name+'_'+newCount;
	break;
	
	case "hidden":
	
	newcell.childNodes[0].value = "";
	
	var nod_id_hidden = newcell.childNodes[0].id;
	
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	
	break;
	
	case "button":
	
	var nod_id = newcell.childNodes[0].id;
	
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	
	break;
	
	case "checkbox":
	
	newcell.childNodes[0].checked = false;
	var nod_id_chk = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	
	
	break;
	
	case "select-one":
	
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	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()
{
	window.open("TelephonicItemsodmang.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>","itempopup_window","height=500,width=900,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;
	}
	
	//alert(divid);
	
	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 totalExcise=0;
	var EDRate=document.getElementById("EDRate").value;
	if(EDRate==0)
	{
		var first_row=document.getElementById("excisevalue").value;
		if(first_row==''){first_row=0;}else{first_row=first_row;}
		var cnt=document.getElementById("hiditemcount").value;
		if(cnt==''){cnt=0;}
		var edit_cnt=document.getElementById("edit_cnt").value;
		var new_count=parseInt(edit_cnt)+parseInt(cnt); 
	for(var i=0;i<new_count;i++)
	{
	 	var totalExcise1=document.getElementById("excisevalue_"+i).value;
	 	var totalExcise=(parseFloat(totalExcise)+parseFloat(totalExcise1)).toFixed(2);
	}
	  document.getElementById("totalDiscountedPrice").value=parseFloat(totalExcise)+parseFloat(first_row);
	}
	else{return false;}
}

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

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 calassprice(val,id)
{
	
		var id_brk=id.split('_');
		var i=id_brk[1];
		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 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;
 	}
 }
 var sales=document.getElementById("salid").value;
xmlhttp.open("GET","gettelephoniceditdata.php?id="+str+"&SalesId="+sales,true);
xmlhttp.send();
	
	
	
	
	
}

function calamountcheck()
{
var rate=document.getElementById("rate3").value;
var amount=document.getElementById("train_chsl").value;

var amount1=parseFloat(amount)*parseFloat(rate);
var totalamt=parseFloat(amount1)/100;
document.getElementById("ser_tax").value=totalamt.toFixed(2);

}

function calvattotal()
{
var rate=document.getElementById("rate4").value;
var amount=document.getElementById("basicAmount").value;

var amount1=parseFloat(amount)*parseFloat(rate);
var totalamt=parseFloat(amount1)/100;
document.getElementById("VatCstValue").value=totalamt.toFixed(2);

}


function addRow1(tableID) 
{
	if(document)
		var table = document.getElementById(tableID);
		var rowCount = table.rows.length;
		var row = table.insertRow(rowCount);
		document.getElementById("hiditemcount1").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 deleteRowOrder1(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("hiditemcount1").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
		alert(e);
	}

}

function open_items1()
{
if(document.getElementById("Site").value=='0')
{
alert("Must Select Site First");	
}
else if(document.getElementById("TelephonicDate").value=='')
{
alert("Must Select Date First");	
}
else if(document.getElementById("dealer1").value='')
{
alert("Must Select Store First");
}
else
{	
 var site=document.getElementById("Site").value;
  var store=document.getElementById("dealer").value;
   var date=document.getElementById("TelephonicDate").value;
	window.open("Telephonickititem.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>&site="+site+"&store="+store+"&date="+date,"itempopup_window","height=500,width=900,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");}	
}	


function showstore(str)
{

if(str.length==0)
  		{
  			document.getElementById("dealer1").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("dealer1").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","dealercode.php?salesId="+str,true);
		xmlhttp.send();



}


function calculateTotalkitAmt(str,id)
{
var i=id.split("_");
if(i[1]==undefined)
{
if(document.getElementById("kitqty").value!='')
var qty=document.getElementById("kitqty").value;
else
var qty=0;
if(document.getElementById("kitprice").value!='')
var rate=document.getElementById("kitprice").value;
else
var rate=0;
amount=parseFloat(qty)*parseFloat(rate);
document.getElementById("totalkitamt").value=amount;
}
else
{
var k=i[1];
if(document.getElementById("kitqty_"+k).value!='')
var qty=document.getElementById("kitqty_"+k).value;
else
var qty=0;
if(document.getElementById("kitprice_"+k).value!='')
var rate=document.getElementById("kitprice_"+k).value;
else
var rate=0;
amount=parseFloat(qty)*parseFloat(rate);
document.getElementById("totalkitamt_"+k).value=amount;

}

}

</script>