<?php 
//**********************DELETE ITEMS FROM  THE ITEM LIST*************AS************15-11-2012**********START HERE*************
if($_REQUEST['act_amit']=='DelItem')
{	
	$condition="id='".$_REQUEST['ITMId']."' and parant_id='".$_REQUEST['TVID1']."'";
	$s->DeleteRecord('technician_visit_entry_details',  $condition);// DELETE ITEM
	
	$requistion_id = $s->GetFieldValue('technician_visit_entry', 'id="'.$_REQUEST['TVID1'].'"', 'requsitionno');
	if($requistion_id!=''){
		$condition="product_id='".$_REQUEST['itmName']."' and requsitionno='".$requistion_id."'";
		$s->DeleteRecord('requisitionorderdetails',  $condition);
	}	
}

//**********************DELETE ITEMS FROM  THE ITEM LIST*************AS************15-11-2012****************END HERE*******




//**********************DELETE SERVICE *************AS************15-11-2012**********START HERE*************

if($_REQUEST['act_singh']=='DelServ')
{	
	$condition1="id='".$_REQUEST['Sid']."' and parant_id='".$_REQUEST['TVID1']."'";
	$s->DeleteRecord('technician_service_visit',  $condition1);// DELETE ITEM
}
//**********************DELETE SERVICE *************AS************15-11-2012**********END HERE*************


//**********************UPADATE THE RECORD*************AS************15-11-2012**********START HERE*************
if($_REQUEST['update'])
{
	$data['branch_name']=$_REQUEST['branch_name'];
	$data['visit_date']=FormatDateForSQL($_REQUEST['visit_date']);
	$data['party_name']=$_REQUEST['party_name'];
	$data['job_card_no']=$_REQUEST['job_card_no'];
	$data['tt_no']=$_REQUEST['tt_no'];
	$data['product_name']=$_REQUEST['product_name'];
	$data['serial_no']=$_REQUEST['serial_no'];
	$data['invoice_no']=$_REQUEST['invoice_no'];
	$data['scope_of_services']=$_REQUEST['service_scope_no'];
	$data['technician']=$_REQUEST['technician'];
	$data['status']=$_REQUEST['status'];
	$data['fault_details']=$_REQUEST['fault_details'];
	$data['current_status']=$_REQUEST['current_status'];
	$data['problem_remark']=$_REQUEST['problem_remark'];
	$data['Total_material_Amt']=$_REQUEST['Total_material_Amt'];
	$data['vat_cst']=$_REQUEST['VatCst'];
	$data['VatCstValue']=$_REQUEST['VatCstValue'];
	$data['service_total_amt']=$_REQUEST['service_total_amt'];
	$data['service_tax']=$_REQUEST['service_tax'];
	$data['service_tax_value']=$_REQUEST['service_tax_value'];
	$data['other_charges']=$_REQUEST['other_amt'];
	$data['grand_total']=$_REQUEST['grandTotal'];
	$data['client_remark']=$_REQUEST['client_remark'];
	$data['remark_by_technician']=$_REQUEST['remark_by_technician'];
	$cond="id='".$_REQUEST['TVID1']."'";
	$s->RecordEdit('technician_visit_entry', $data, $cond);// UPDATE IN PARANT TABLE
 	$count1=$_REQUEST['hiditemcount']+1;
	for($i=0;$i<count($_REQUEST['row_id']);$i++)
	{
		$data1['req_qty']=$_REQUEST['rqty'][$i];
		$data1['price']=$_REQUEST['price'][$i];
		$data1['tptal_amt']=$_REQUEST['amt'][$i];
		$cond1="id='".$_REQUEST['row_id'][$i]."'";
		$s->RecordEdit('technician_visit_entry_details', $data1, $cond1);//UPDATION IN FETCHED ITEMS
	}

	
	for($j=0;$j<$count1;$j++)
	{
		if($_REQUEST['itemid1'][$j]!=''){
		$data2['parant_id']=$_REQUEST['TVID1'];
		$data2['item_name']=$_REQUEST['itemid1'][$j];
		$data2['req_qty']=$_REQUEST['rqty1'][$j];
		$data2['price']=$_REQUEST['price1'][$j];
		$data2['tptal_amt']=$_REQUEST['amt1'][$j];
		$Insert1=$s->RecordInsert('technician_visit_entry_details', $data2);// INSERT NEW ITEMS
		}
	}
	
	
	##########################  Requistion Entry Start ################################################################
	$requistion_id = $s->GetFieldValue('technician_visit_entry', 'id="'.$_REQUEST['TVID1'].'"', 'requsitionno');
	if($requistion_id!=''){
		for($i=0;$i<count($_REQUEST['row_id']);$i++)
		{
			$itemname1 = $s->GetFieldValue('item_master', 'id="'.$_REQUEST['itemid'][$i].'"', 'item_name');
			$datareq['product_id']=$_REQUEST['itemid'][$i];
			$datareq['product_description']=$itemname1;
			$datareq['req_quantity']=$_REQUEST['rqty'][$i];
			$cond1="product_id='".$_REQUEST['itemid'][$i]."' AND requsitionno='".$requistion_id."'";
			$s->RecordEdit('requisitionorderdetails', $datareq, $cond1);
		}
		
		for($j=0;$j<$count1;$j++)
		{
			$itemname2 = $s->GetFieldValue('item_master', 'id="'.$_REQUEST['itemid1'][$j].'"', 'item_name');
			if($_REQUEST['itemid1'][$j]!=''){
				echo$material_details_sql="insert into requisitionorderdetails set
											id='',
											requsitionno='".$last_id."',
											product_id='".$_REQUEST['itemid1'][$j]."',
											product_description='".$itemname2."',
											totalreceivetilldate = '', 
											req_quantity='".$_REQUEST['rqty1'][$j]."'"; 
				
				$details_res=DB_query($material_details_sql,$db);
			}
		}
	}else{
		$PageIdno = 'Purchase Requisition';
		$year=date('y');
		$year_after=$year+1;
			
		$prefix_sql=DB_query("Select * from prefix_tbl where prefix_name='".$PageIdno."'",$db);
		$prefix_row=DB_fetch_array($prefix_sql);
		$prefix=$prefix_row['prefix_code'];
			
		$sql="Select Reqno from materialrequisitions where sitecode='".$_REQUEST['branch_name']."' order by Reqno desc limit 1";
		$result=DB_query($sql,$db);
		$myrow=DB_fetch_array($result);
			
		if(DB_num_rows($result)>0)
		{
			$Reqno=$myrow['Reqno'];
			$req_part1=substr($Reqno,-4);
			$req_final=$req_part1+1;
		}
		else
		{
			$req_final="1";
		}
			
		$string=$prefix."/".$_REQUEST['branch_name']."/".$year."-".$year_after."/";
		$final_string=$string.str_pad($req_final,4,"0",STR_PAD_LEFT);
		
		
		$requisition_sql="Insert into materialrequisitions set
						requisitionno='',
						comments='',
						prdate='".FormatDateForSQL($_REQUEST['visit_date'])."',
						initiator='".$_SESSION['UserID']."',
						sitecode='".$_REQUEST['branch_name']."',
						Reqno='".$final_string."',
						CompanyId='".$_SESSION['ACGCompanyId']."'";
										
		$requisition_res=DB_query($requisition_sql,$db);
		$last_id=DB_Last_Insert_ID($db,'materialrequisitions','id');
		
		if($last_id!='')
		{
			for($i=0;$i<count($_REQUEST['row_id']);$i++)
			{
				$itemname1 = $s->GetFieldValue('item_master', 'id="'.$_REQUEST['itemid'][$i].'"', 'item_name');
				$material_details_sql="insert into requisitionorderdetails set
												id='',
												requsitionno='".$last_id."',
												product_id='".$_REQUEST['itemid'][$i]."',
												product_description='".$itemname1."',
												totalreceivetilldate = '', 
												req_quantity='".$_REQUEST['rqty'][$i]."'"; 
				
				$details_res=DB_query($material_details_sql,$db);
			}
			for($j=0;$j<$count1;$j++)
			{
				$itemname2 = $s->GetFieldValue('item_master', 'id="'.$_REQUEST['itemid1'][$j].'"', 'item_name');
				if($_REQUEST['itemid1'][$j]!=''){
					echo$material_details_sql="insert into requisitionorderdetails set
												id='',
												requsitionno='".$last_id."',
												product_id='".$_REQUEST['itemid1'][$j]."',
												product_description='".$itemname2."',
												totalreceivetilldate = '', 
												req_quantity='".$_REQUEST['rqty1'][$j]."'"; 
				
					$details_res=DB_query($material_details_sql,$db);
				}
			}
			
			$update_req_tech = "UPDATE technician_visit_entry SET requsitionno='".$last_id."' WHERE id='".$_REQUEST['TVID1']."'"; 
			$details_update_req = DB_query($update_req_tech,$db);
		}
	}
	##########################  Requistion Entry End ################################################################
	
	for($k=0;$k<count($_REQUEST['row_aks']);$k++)
	{
		$data3['service_name']=$_REQUEST['service1'][$k];
		$data3['service_type']=$_REQUEST['service_type1'][$k];
		$data3['service_description']=$_REQUEST['service_desc1'][$k];
		$data3['billable']=$_REQUEST['billable1'][$k];
		$data3['service_amt']=$_REQUEST['service_amt1'][$k];
		$cond3="id='".$_REQUEST['row_aks'][$k]."'";
		$s->RecordEdit('technician_service_visit', $data3, $cond3);//UPDATION IN FETCHED SERICES
	}
	
	$count2=$_REQUEST['hiditemcount1']+1;
	for($t=0;$t<$count2;$t++)
	{
		if($_REQUEST['service'][$t]!=''){
		$data4['parant_id']=$_REQUEST['TVID1'];
		$data4['service_name']=$_REQUEST['service'][$t];
		$data4['service_type']=$_REQUEST['service_type'][$t];
		$data4['service_description']=$_REQUEST['service_desc'][$t];
		$data4['billable']=$_REQUEST['billable'][$k];
		$data4['service_amt']=$_REQUEST['service_amt'][$t];
		$Insert1=$s->RecordInsert('technician_service_visit', $data4);//INSERT NEW SERVICES
		}
	}
	$s->pageLocation("index.php?route=service/view_technician_visit_entry".$rurl);// PAGE REDIRECTION
}

//**********************UPADATE THE RECORD*************AS************15-11-2012**********END HERE*************


if($_REQUEST['action']=='Edit')
{
	$condition="id='".$_REQUEST['TVID1']."'";
	$GetRec=$s->GetRecordById('technician_visit_entry',  $condition);
	$GetRow=DB_fetch_array($GetRec);
	extract($GetRow);
}

?>
<!-----------------INCLUDE AJAX FILES--------------------------------START HERE------------------------------------->
<script type="text/javascript" language="javascript">
function getjobcardno(str)
{
	//alert(str);
	if(str.length==0)
	{
	document.getElementById("JOBCARDNO").innerHTML="";
	}
	if(window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	document.getElementById("JOBCARDNO").innerHTML=xmlhttp.responseText;
	}
	xmlhttp.open("GET","Getjobcardno.php?Site="+str,true);
	xmlhttp.send();
}


function GetAllDetails(str)
{
	if(str.length==0)
	{
	document.getElementById("JOBCARDNO").innerHTML="";
	}
	if(window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("PARTY").innerHTML=data[0];
	document.getElementById("TTNO").innerHTML=data[1];
	document.getElementById("PRODUCTNAME").innerHTML=data[2];
	document.getElementById("SERIALNO").innerHTML=data[3];
	document.getElementById("INVOICENO").innerHTML=data[4];
	document.getElementById("SCOPEOFSER").innerHTML=data[5];
	document.getElementById("TECHNICIAN").innerHTML=data[6];
	document.getElementById("FAULT").innerHTML=data[7];
	document.getElementById("BASICAMT").innerHTML=data[8];
	document.getElementById("EXCISEDUTY").innerHTML=data[9];
	document.getElementById("ECESS").innerHTML=data[10];
	document.getElementById("SHECESS").innerHTML=data[11];
	document.getElementById("TAXABLEAMT").innerHTML=data[12];
	document.getElementById("VATCSTNO").innerHTML=data[13];
	document.getElementById("GRANDTOTALAMT").innerHTML=data[14];
	//document.getElementById("ITEMDETAIL").innerHTML=data[15];
	//document.getElementById("edit_cnt").value=data[16];
	}
	}
	var modid=document.getElementById("modid").value;
	var frmid=document.getElementById("frmid").value;
	xmlhttp.open("GET","GetAllDetails.php?JCARDNO="+str+"&modid="+modid+"&frmid="+frmid,true);
	xmlhttp.send();
}


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("open_item.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 GoToBack(serviceID)
{
	if(document.getElementById("back").style.display != 'block') {
	document.getElementById("back").style.display = "block";
	}else{
	if(document)
	var edit_cnt1=document.getElementById("edit_cnt1").value;
	var table = document.getElementById(serviceID);
	var rowCount = table.rows.length;
	//alert(rowCount);
	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 newCount=parseInt(rowCount)+parseInt(edit_cnt1)-1;
	var newcell = row.insertCell(i);
	//newcell.style.background='#e7e7e7';
	// newcell.className='tabledata';
	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;
	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 deleteRowService(serviceID) 
{
	try 
	{
	var table = document.getElementById(serviceID);
	//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 calculateTotalAmt(val,id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
	var qty=parseFloat(document.getElementById("rqty_"+i).value);
	if(qty==''){qty=0;}
	var val=parseFloat(document.getElementById("price_"+i).value);
	if(val==''){val=0;}
	var tot_amt=qty*val;
	document.getElementById("amt_"+i).value=tot_amt.toFixed(2);
	}
	else
	{
	var qty=document.getElementById("rqty").value;
	if(qty==''){qty=0;}
	var val=document.getElementById("price").value;
	if(val==''){val=0;}
	var tot_amt=qty*val;
	document.getElementById("amt").value=tot_amt.toFixed(2);
	}
}







function calculatematerialamt()
{
	var totalBasic=0;
	var first_row=document.getElementById("amt").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++)
	{
	 	var totalBasic1=document.getElementById("amt_"+i).value;
	 	var totalBasic=(parseFloat(totalBasic)+parseFloat(totalBasic1)).toFixed(2);
	}
	  document.getElementById("Total_material_Amt").value=parseFloat(totalBasic)+parseFloat(first_row);
}





function calculateserviceamt()
{
	var service_amt2=0;
	var cnt1=document.getElementById("hiditemcount1").value;
	if(cnt1==''){cnt1=0;}
	var edit_cnt1=document.getElementById("edit_cnt1").value;
	var new_count1=parseInt(edit_cnt1)+parseInt(cnt1); 
	var service_amt=document.getElementById("service_amt").value;
	if(service_amt==''){service_amt=0;}
	var newcount1=parseInt(cnt1)+1;
		for(var i=0;i<new_count1;i++)
	{
		var service_amt1=document.getElementById("service_amt_"+i).value;
	 	var service_amt2=(parseFloat(service_amt2)+parseFloat(service_amt1)).toFixed(2);
	}
	  document.getElementById("service_total_amt").value=parseFloat(service_amt)+parseFloat(service_amt2);
}



function calculateservice(str)
	{
	//alert(str);
	if (str.length==0)
	{
	document.getElementById("service_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("service_rate").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateserviceamt.php?serviceId="+str,true);
	xmlhttp.send();
}


function calculateserv()
{
	var ser_rate=document.getElementById("service_rate").value;
	var serviceAmount=document.getElementById("service_total_amt").value;
	var serv_value=serviceAmount*(ser_rate/100);
	document.getElementById("service_tax_value").value=serv_value.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 calculateEditVATCST()
{
	var rate=document.getElementById("rate").value;
	var taxableAmount=document.getElementById("Total_material_Amt").value;
	var vat_cst=taxableAmount*(rate/100);
	document.getElementById("VatCstValue").value=vat_cst.toFixed(2);
}


function calculateGrand()
{
	var a=document.getElementById("Total_material_Amt").value;
	var b=document.getElementById("VatCstValue").value;
	var c=document.getElementById("service_total_amt").value;
	var d=document.getElementById("service_tax_value").value;
	var e=document.getElementById("other_amt").value;
	if(a==''){a=0;}
	if(b==''){b=0;}
	if(c==''){c=0;}
	if(d==''){d=0;}
	if(e==''){e=0;}
	var GRAND=parseFloat(a)+parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e);
	document.getElementById("grandTotal").value=GRAND.toFixed(2);
}

</script>

<!-----------------INCLUDE AJAX FILES--------------------------------END HERE------------------------------------->

<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Technician Visit entry</h1>
<form name="myform" method="post">
<input type="hidden" name="modid" id="modid" value="<?php echo $_REQUEST['modid'] ?>" />
<input type="hidden" name="frmid" id="frmid" value="<?php echo $_REQUEST['frmid'] ?>" />
<h3 align="center">General Details</h3>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
<tr class="row1">
<td class="tabledata1">Branch</td>
<td>
<select name="branch_name" id="branch_name" style="width:150px;"  onchange="getjobcardno(this.value)">
	<option value="0">Select</option>
	<?php $site_sql=DB_query("Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
	while($site_row=DB_fetch_array($site_sql)){
	$sel1='';
	if($branch_name==$site_row['loccode'])
	$sel1='selected';?>
	<option value="<?php echo $site_row['loccode']?>"<?php echo $sel1; ?>><?php echo $site_row['locationname']?></option>
	<?php } ?>
	</select>
	</td>
	<td class="tabledata1">Visit Date</td>
<td><input type="text" name="visit_date" value="<?php echo ConvertSQLDate($visit_date); ?>" class="datepicker" style="width:150px;" /></td>
</tr>
<tr class="row1">
<td class="tabledata1">Visit No.</td>
<td><input type="text" name="invoiceNo" value="<?php echo $visit_no; ?>" readonly="" style="width:150px;" /></td>
<td class="tabledata1">Party Name</td>
<td id="PARTY"><input type="hidden" name="party_name" id="party_name" value="<?php echo $party_name; ?>" style="width:100%" />
<input type="text" name="party_name1" id="party_name1" value="<?php echo $s->GetFieldValue('clientmaster',"id='".$party_name."'",'c_name'); ?>" style="width:150px;" />
</td>
</tr>
<tr class="row1">
<td class="tabledata1">Job Card No</td>
<td id="JOBCARDNO"><?php $JCN=DB_query("select * from trouble_ticket_jobcard where branch='".$branch_name."'",$db); ?>
<select name="job_card_no" id="job_card_no" style="width:150px;" tabindex="1"  >
	<option value="0">Select</option>
	<?php while($JCNRow=DB_fetch_array($JCN)) {
		$sel2='';
		if($job_card_no==$JCNRow['id'])
		$sel2='selected';?>
	<option value="<?php echo $JCNRow['id']; ?>"<?php echo $sel2; ?>><?php echo $JCNRow['job_card_number'] ?></option>
	<?php } ?>
</select></td>
<td class="tabledata1">Product name</td>
<td id="PRODUCTNAME"><input type="hidden" name="product_name" id="product_name" value="<?php echo $product_name;?>" style="width:50px;">
<input type="text" name="product_name1" id="product_name1" value="<?php echo $s->GetFieldValue('item_master',"id='".$product_name."'",'item_name');?>" style="width:150px;">
</td>
</tr>
<tr class="row1">
<td class="tabledata1">TT No.</td>
<td id="TTNO"><input type="hidden" name="tt_no" value="<?php echo $tt_no; ?>" style="width:50px;" />
<input type="text" name="tt_no1" value="<?php echo $s->GetFieldValue('trouble_ticket_creation',"id='".$tt_no."'",'ticket_number'); ?>" style="width:150px;" />
</td>
<td class="tabledata1">Invoice No.</td>
<td id="INVOICENO"><input type="text" name="invoice_no" value="<?php echo $invoice_no; ?>" style="width:150px;" /></td>
</tr>
<tr class="row1">
<td class="tabledata1">Serial No</td>
<td id="SERIALNO"><input type="text" name="serial_no" value="<?php echo $serial_no; ?>" style="width:150px;" /></td>
<td class="tabledata1">Technician</td>
<td id="TECHNICIAN"><input type="hidden" name="technician" value="<?php echo $technician; ?>" style="width:50px;" />
<input type="text" name="technician1" value="<?php echo $s->GetFieldValue('technicians',"id='".$technician."'",'technician'); ?>"  style="width:150px;" />
</td>
</tr>
<tr class="row1">
<td class="tabledata1">Scope of Service</td>
<td id="SCOPEOFSER">
<input type="hidden" name="service_scope_no" value="<?php echo $scope_of_services; ?>" style="width:50px;" />
<input type="text" name="service_scope_no1" value="<?php if($scope_of_services==1){echo 'Complaint';}
						  if($scope_of_services==2){echo 'Installation';}
						  if($scope_of_services==3){echo 'De-Installation';}
						  if($scope_of_services==4){echo 'Re-Installation';}
						  if($scope_of_services==5){echo 'Preventive';}
						  if($scope_of_services==6){echo 'Service';}
						  if($scope_of_services==7){echo 'Site Survey';} ?>" style="width:150px;" /></td>
<td class="tabledata">Status</td>
<td id="COMPLAINT">
<input name="status1" id="status" style="width:150px;" value="In Process" readonly="readonly" /><br />
<input name="status" id="status1" value="2" style="visibility:hidden; height:1px;" readonly="readonly" />
</td>
</tr>
</table>
<h3 align="center">Fault Descriptions</h3>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
<tr>
<td class="tabledata1" style="width:146px;">Fault Details</td>
<td colspan="3" id="FAULT"><input type="text" name="fault_details" value="<?php echo $fault_details; ?>" style="width:80%; height:50px;" /></td>
</tr>
<tr>
<td class="tabledata11">Current Status</td>
<td colspan="3"><input type="text" name="current_status" value="<?php echo $current_status; ?>" style="width:80%; height:50px;" /></td>
</tr>
<tr>
<td class="tabledata1">Problem Remarks</td>
<td colspan="3"><input type="text" name="problem_remark" value="<?php echo $problem_remark; ?>" style="width:80%; height:50px;" /></td>
</tr>
</table>
<h3 align="center">Spare Parts & services Details</h3>
<div style="width:auto; overflow:auto; border:#006699 solid 2px;">
        <p align="left" style="padding-top:5px; padding-bottom:5px;">
          <input type="button" onClick="addRow('dataTable')" value="Add Rows for Spare Part" class="search" />
          &nbsp;&nbsp;
          <input type="button" class="search"   onclick="deleteRowOrder('dataTable')" value="Delete" />
          &nbsp;&nbsp;
          <input type="button" name="profile_popup" value="Add Spare Part" id="profile_popup"  onclick="open_items()" class="search" />
		  &nbsp;&nbsp;
		  <input type="button"  value="Add Service" name="add_service" class="search" onClick="GoToBack('serviceID');" />
          <input name="button" type="button" class="search"   onclick="deleteRowService('serviceID')" value="Delete" />
        </p>
        <!-- <p style="padding-left:0px; margin:0; text-align:left;">
          <input type="button" value="Add Spare Part" name="item_popup" class="heading_button"  onclick="open_items(this.id)">
          &nbsp;&nbsp;
          <input type="button" value="Add Service" class="heading_button" />
        </p>-->
        <div style="width:auto; overflow:auto;">
          <div id="showdata">
            <table width="100%" border="1" cellspacing="0" cellpadding="3">
              <tr>
                <td class="tabledata">S. No.</td>
                <td class="tabledata">Item Name</td>
				<td class="tabledata"></td>
               <!-- <td class="tabledata">Qty in Stock </td>-->
                <td class="tabledata">Req. Qty.</td>
                <td class="tabledata">Price</td>
                <td class="tabledata">Total amount</td>
              </tr>
			 <!-- <tr>
				<td colspan="6" id="ITEMDETAIL"></td>
				</tr>-->
	<?php $i=0; $ItemSQL=DB_query("select * from technician_visit_entry_details where parant_id='".$_REQUEST['TVID1']."'",$db); 
		while($ItemRow=DB_fetch_array($ItemSQL)){?>
				<tr class="row1">
					<td class="tabledata"><a href="index.php?route=service/technician_visit_entry_Edit&action=Edit&TVID1=<?php echo $_REQUEST['TVID1'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act_amit=DelItem&ITMId=<?php echo $ItemRow['id'];?>&itmName=<?php echo $ItemRow['item_name'];?>"><img src="images/delete.gif" /></a></td>
				<td class="tabledata">
				<?php echo $s->GetFieldValue('item_master',"id='".$ItemRow['item_name']."'",'item_name'); ?>
					<input type="hidden" name="row_id[<?php echo $i; ?>]" id="row_id" value="<?php echo $ItemRow['id']?>" />
				  </td>
							<td class="tabledata">
							<input type="hidden" name="itemid[<?php echo $i; ?>]" id="itemid1_<?php echo $i; ?>" value="<?php echo $ItemRow['item_name'] ?>" size="40"/></td>
					<td class="tabledata"><input type="text" name="rqty[<?php echo $i; ?>]" value="<?php echo $ItemRow['req_qty']; ?>"  id="rqty_<?php echo $i; ?>" size="20"/></td>
					<td class="tabledata"><input type="text" name="price[<?php echo $i; ?>]" id="price_<?php echo $i; ?>" value="<?php echo $ItemRow['price']; ?>" size="20" /></td>
					<td class="tabledata"><input type="text" name="amt[<?php echo $i; ?>]" id="amt_<?php echo $i; ?>" value="<?php echo $ItemRow['tptal_amt']; ?>" size="20" onKeyUp="calculateTotalAmt(this.value,this.id)"/></td>
				</tr>	  
				<?php $i++;} ?>
				<input type="hidden" name="" value="<?php echo $i;?>" id="edit_cnt" /> 
              <tbody id="dataTable">
                <tr bgcolor="#c1c1c1">
                  <td><input name="delitem[]" type="checkbox" value="<?php echo $item_row['id'];?>" /></td>
                  <td><input type="text" name="itemname1[]"  id="itemname" size="40"/></td>
				   <td><input type="hidden" name="itemid1[]" id="itemid" size="40" > </td>
                <!--  <td>&nbsp;</td>-->
                  <td><input type="text" name="rqty1[]"  id="rqty" size="20"/>                  </td>
                  <td><input type="text" name="price1[]" id="price" size="20" />                  </td>
                  <td><input type="text" name="amt1[]" id="amt" size="20" onKeyUp="calculateTotalAmt(this.value,this.id)"/></td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
		 <input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
     <!--<input type="hidden" name=""  id="edit_cnt" />-->
<?php $ServiceSql = DB_query("Select * from technician_service_visit where parant_id='".$_REQUEST['TVID1']."'",$db);?>
<style>
#showdata {
	display: block;
	background: url(Default.png) no-repeat;
	top: 0px;
	left: 0px;
	width: auto;
	min-height: 60px;
	z-index:0;
}
<?php if(DB_num_rows($ServiceSql)>0) {?>
#back {
	display:block;
	top: 0px;
	left: 0px;
	width: auto;
	min-height: 60px;
	z-index:0;
}
<?php }else {  ?>
#back {
	display:none;
	top: 0px;
	left: 0px;
	width: auto;
	min-height: 60px;
	z-index:0;
}
<?php } ?>
</style>
		<div style="width:auto; overflow:auto;">
			<div id="back">
				<table width="100%" border="1" cellspacing="0" cellpadding="0" style="border:#666666 solid 1px;">
               <tr>
                <td width="76" class="tabledata">S. No.</td>
				<td class="tabledata">Service</td>
                <td width="229" class="tabledata">Service Type</td>
                <td width="251" class="tabledata">Service Description</td>
				<td width="151" class="tabledata">Billable</td>
                <td width="240" class="tabledata">Service Amount</td>
              </tr>
			  <?php $j=0; while($ServiceRow=DB_fetch_array($ServiceSql)) {?>
			  <tr>
			  	<td class="tabledata"><a href="index.php?route=service/technician_visit_entry_Edit&action=Edit&TVID1=<?php echo $_REQUEST['TVID1'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act_singh=DelServ&Sid=<?php echo $ServiceRow['id'];?>"><img src="images/delete.gif" /></a></td>
				<td class="tabledata">
				<input type="hidden" name="row_aks[<?php echo $j; ?>]" value="<?php echo $ServiceRow['id']; ?>">
				<input type="text" name="service1[<?php echo $j; ?>]" value="<?php echo $ServiceRow['service_name'];?>" id="service_<?php echo $j; ?>" size="40"/></td>
				<td class="tabledata"><?php $serv= DB_query("SELECT * FROM services_type",$db);?>
				  	<select name="service_type1[<?php echo $j; ?>]" style="width:130px;" id="service_type">
						<option value="">--Select--</option>
						<?php 
							   while($getServe_type= DB_fetch_array($serv)){
							   $serv1='';
							   if($ServiceRow['service_type']==$getServe_type['id'])
							   $serv1='selected';?>
	<option value="<?php echo $getServe_type['id']?>"<?php echo $serv1; ?>><?php echo $getServe_type['service_type']?></option>
							   <?php } ?>
					</select>
			    </td>
				   <td class="tabledata">
				  	<?php $stype= DB_query("SELECT * FROM services_description",$db);?>
				  	<select name="service_desc1[<?php echo $j; ?>]" id="service_desc_<?php echo $j; ?>" style="width:130px;">
						<option value="">--Select--</option>
						<?php 
						   while($getStype= DB_fetch_array($stype)){
						   $desc123='';
						   if($ServiceRow['service_description']==$getStype['id'])
						   $desc123='selected';
						   ?>
							<option value="<?php echo $getStype['id']?>"<?php echo $desc123; ?>><?php echo $getStype['service_description']?></option>
						   <?php } ?>
					</select>
				  </td>
				   <td>
				  	<select name="billable1[]" id="billable" style="width:140px;">
						<option value="Y"<?php echo($ServiceRow['billable']=='Y'?'selected':''); ?>>YES</option>
						<option value="N"<?php echo($ServiceRow['billable']=='N'?'selected':''); ?>>NO</option>
					</select>
				  </td>
				  <td class="tabledata"><input type="text" name="service_amt1[<?php echo $j; ?>]" id="service_amt_<?php echo $j; ?>" value="<?php echo $ServiceRow['service_amt']; ?>" size="20"/></td>
			  </tr>
			  <?php $j++;} ?>
			   <input type="hidden" name="" value="<?php echo $j; ?>" id="edit_cnt1" />
			   <tbody id="serviceID">
				<tr bgcolor="#c1c1c1">
                  <td><input name="delitem[]" type="checkbox" value="<?php echo $item_row['id'];?>" /></td>
				  <td><input type="text" name="service[]" id="service" size="40"/></td>
                  <td><?php $serv=DB_query("SELECT * FROM services_type",$db);?>
				  	<select name="service_type[]" style="width:130px;" id="service_type">
						<option value="">--Select--</option>
						<?php  while($getServe_type=DB_fetch_array($serv)){?>
						<option value="<?php echo $getServe_type['id']?>"><?php echo $getServe_type['service_type']?></option>
						<?php } ?>
					</select>
				  </td>
                  <td><?php $stype=DB_query("SELECT * FROM services_description",$db);?>
				  	<select name="service_desc[]" id="service_desc" style="width:130px;">
						<option value="">--Select--</option>
						<?php while($getStype=DB_fetch_array($stype)){?>
						<option value="<?php echo $getStype['id']?>"><?php echo $getStype['service_description']?></option>
						<?php }?>
					</select>
				  </td>
				   <td>
				  	<select name="billable[]" id="billable" style="width:140px;">
						<option value="Y">YES</option>
						<option value="N">NO</option>
					</select>
				  </td>
                  <td><input type="text" name="service_amt[]" id="service_amt" size="20" value=""/></td>
                </tr>
  		</tbody>
	</table>
			</div>
		</div>
        <input type="hidden" name="hiditemcount1" id="hiditemcount1" value="" />
        <div style="width:32%; float:right;">
          <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#999999 solid 1px;">
            <tr class="row1">
              <td class="tabledata" style="width:120px;">Material Total Amt.</td>
              <td id="MATARIALAMT"><input name="Total_material_Amt" type="text"  style="width:150px;" value="<?php echo $Total_material_Amt; ?>" onFocus="calculatematerialamt()" id="Total_material_Amt" readonly=""/></td>
            </tr>
            <tr class="row1">
              <td class="tabledata">Vat/Cst</td>
              <td id="VATCSTNO"><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))
					{
					$sel_A='';
					if($vat_cst==$salesRow['salestax_id'])
					$sel_A='selected';
					?>
          <option value="<?php echo $salesRow['salestax_id'];?>"<?php echo $sel_A; ?>><?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;"   onfocus="calculateEditVATCST()"/>
                </div>
                <input type="hidden" name="" id="rate" value="<?php echo $rate;?>" />
              </td>
            </tr>
            <tr class="row1">
              <td class="tabledata">Service Total Amt</td>
              <td id="TOTALSERVICEAMT"><input type="text" name="service_total_amt" id="service_total_amt" style="width:150px;" onfocus="calculateserviceamt()" value="<?php echo $service_total_amt; ?>" readonly="" /></td>
            </tr>
			<tr class="row1">
              <td class="tabledata">Service Tax</td>
              <td id="SERVICETAX"><?php $servSql=DB_query("select * from service_tax_master",$db);
			  					while($servRow=DB_fetch_array($servSql)){
								$sel23='';
								if($service_tax==$servRow['id'])
								$sel23='selected';?>
			<select name="service_tax" id="service_tax" style="width:150px;" onchange="calculateservice(this.value)">
				<option value="0">Select</option>
				<option value="<?php echo $servRow['id'] ?>"<?php echo $sel23; ?>><?php echo $servRow['tax_code'] ?></option>
			</select>
								  <?php } ?>
		<input name="service_tax_value" id="service_tax_value" type="text" value="<?php echo $service_tax_value?>" style="width:150px;"   onfocus="calculateserv()" readonly="" />
					<input type="hidden" name="" id="service_rate" value="<?php echo $rate;?>" />
								  </td>
            </tr>
			<tr class="row1">
              <td class="tabledata">Other Amt</td>
              <td id="OTHERAMT"><input name="other_amt" id="other_amt" type="text" value="<?php echo $other_charges; ?>" style="width:150px;" onfocus=""/></td>
            </tr>
            <tr>
              <td class="tabledata">Grand Total</td>
              <td id="GRANDTOTALAMT"><input name="grandTotal" id="grandTotal" type="text" value="<?php echo $grand_total; ?>"  style="width:150px;" onFocus="calculateGrand()" readonly="readonly"  /></td>
            </tr>
          </table>
        </div>
        <div class="cl"></div>
      </div>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
<tr>
<td class="tabledata" style="width:146px;">Client Remarks</td>
<td colspan="3"><textarea name="client_remark"  style="width:100%; 50px;"><?php echo $client_remark ?></textarea></td>
</tr>
<tr>
<td class="tabledata">Remarks by Technician</td>
<td colspan="3"><textarea name="remark_by_technician"  style="width:100%; 50px;"><?php echo $remark_by_technician ?></textarea></td>
</tr>
</table>
<p align="center"><input type="submit" name="update" value="Update" /></p>
</form>
</div></div>
