<?php 
//******************DELETE ITEMS FROM JC TABLE********START HERE**********AS***********10-11-2012***************************
if($_REQUEST['action']=='DelItem')
{	
	$condition="id='".$_REQUEST['JCID']."'";
	$s->DeleteRecord('trouble_ticket_jobcard_details',  $condition);// ITEMS DELETED
}
//******************DELETE ITEMS FROM JC TABLE********END HERE**********AS***********10-11-2012***************************




//******************DELETE SERVICES FROM JC TABLE********START HERE**********AS***********10-11-2012***************************
if($_REQUEST['action']=='DelService')
{
	$condition1="id='".$_REQUEST['JCID']."'";
	$s->DeleteRecord('add_service_jobcard',  $condition1);// SERVICES DELETED
}
//******************DELETE ITEMS FROM JC TABLE********END HERE**********AS***********10-11-2012***************************



//******************INSERT THE DATA INTO TABLE********START HERE**********AS***********10-11-2012***************************
if($_REQUEST['save'])
{
	$Branch=$_REQUEST['branch_name'];
	$prefix=$s->GetFieldValue('locations',"loccode='".$Branch."'",'prefix');
	$rec=DB_query("select * from technician_visit_entry where branch_name='".$Branch."'",$db);
	$NoRows=DB_num_rows($rec);
	if($NoRows>0)
	{
	$MAXID=DB_query("Select max(visit_no) as VISNO from technician_visit_entry where branch_name='".$Branch."'",$db);
	$MAXROW=DB_fetch_array($MAXID);
	$SUBMAX=substr($MAXROW['VISNO'],-2);
	$MAX_ID=$SUBMAX+1;
	$FinalCode=$prefix."/".'VN'."/".str_pad($MAX_ID,4,"0",STR_PAD_LEFT);// AUTO GENERATE CODE
	}
	else
	{
	$FinalCode=$prefix."/".'VN'."/".'0001';// AUTO GENERATE CODE AT FIRST TIME
	}
	$data['branch_name']=$Branch;
	$data['visit_no']=$FinalCode;
	$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'];
	$Insert=$s->RecordInsert('technician_visit_entry', $data);// INSERT IN PARANT TABLE
	$LastId=DB_Last_Insert_ID($db,'technician_visit_entry','id');
	
	$count23=count($_REQUEST['itemid1']);
	for($i=0;$i<$count23;$i++)
	{
	$data12['parant_id']=$LastId;
	$data12['item_name']=$_REQUEST['itemid1'][$i];
	$data12['req_qty']=$_REQUEST['rqty1'][$i];
	$data12['price']=$_REQUEST['price1'][$i];
	$data12['tptal_amt']=$_REQUEST['amt1'][$i];
	$Insert1=$s->RecordInsert('technician_visit_entry_details', $data12);//INSERT IN CHILED(ITEMS) TABLE
	}
	
	$count=$_REQUEST['hiditemcount']+1;
	for($i=0;$i<$count;$i++)
	{
	if($_REQUEST['itemid'][$i]!=''){
	$data1['parant_id']=$LastId;
	$data1['item_name']=$_REQUEST['itemid'][$i];
	$data1['req_qty']=$_REQUEST['rqty'][$i];
	$data1['price']=$_REQUEST['price'][$i];
	$data1['tptal_amt']=$_REQUEST['amt'][$i];
	$Insert1=$s->RecordInsert('technician_visit_entry_details', $data1);//INSERT IN CHILED(ITEMS) TABLE
	}
	}
	
	################## Requisition ################################################################################
	$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='".$Branch."' 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."/".$Branch."/".$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='".$Branch."',
					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<$count23;$i++)
		{
			$itemname1 = $s->GetFieldValue('item_master', 'id="'.$_REQUEST['itemid1'][$i].'"', 'item_name');
			$material_details_sql="insert into requisitionorderdetails set
											id='',
											requsitionno='".$last_id."',
											product_id='".$_REQUEST['itemid1'][$i]."',
											product_description='".$itemname1."',
											totalreceivetilldate = '', 
											req_quantity='".$_REQUEST['rqty1'][$i]."'"; 
			
			$details_res=DB_query($material_details_sql,$db);
		}
		for($i=0;$i<$count;$i++)
		{
			$itemname2 = $s->GetFieldValue('item_master', 'id="'.$_REQUEST['itemid'][$i].'"', 'item_name');
			if($_REQUEST['itemid'][$i]!=''){
				$material_details_sql="insert into requisitionorderdetails set
											id='',
											requsitionno='".$last_id."',
											product_id='".$_REQUEST['itemid'][$i]."',
											product_description='".$itemname2."',
											totalreceivetilldate = '', 
											req_quantity='".$_REQUEST['rqty'][$i]."'"; 
			
				$details_res=DB_query($material_details_sql,$db);
			}
		}
		
		$update_req_tech = "UPDATE technician_visit_entry SET requsitionno='".$last_id."' WHERE id='".$LastId."'"; 
		$details_update_req = DB_query($update_req_tech,$db);
	}
	
	####################################   END  ######################################################################### 
	
	
	$count143=count($_REQUEST['service_type1']);
	for($j=0;$j<$count143;$j++)
	{
	$data23['parant_id']=$LastId;
	$data23['service_name']=$_REQUEST['service1'][$j];
	$data23['service_type']=$_REQUEST['service_type1'][$j];
	$data23['service_description']=$_REQUEST['service_desc1'][$j];
	$data23['billable']=$_REQUEST['billable1'][$j];
	$data23['service_amt']=$_REQUEST['service_amt1'][$j];
	$Insert1=$s->RecordInsert('technician_service_visit', $data23);//INSERT IN CHILED(SERVICES) TABLE
	}
	
	$count1=$_REQUEST['hiditemcount1']+1;
	for($j=0;$j<$count1;$j++)
	{
	if($_REQUEST['service_type'][$j]!=''){
	$data2['parant_id']=$LastId;
	$data2['service_name']=$_REQUEST['service'][$j];
	$data2['service_type']=$_REQUEST['service_type'][$j];
	$data2['service_description']=$_REQUEST['service_desc'][$j];
	$data2['billable']=$_REQUEST['billable'][$j];
	$data2['service_amt']=$_REQUEST['service_amt'][$j];
	$Insert1=$s->RecordInsert('technician_service_visit', $data2);//INSERT IN CHILED(SERVICES) TABLE
	}
	}
	$s->pageLocation("index.php?route=service/view_technician_visit_entry".$rurl);//PAGE REDIRECTION
}
//******************INSERT THE DATA INTO TABLE********END HERE**********AS***********10-11-2012***************************
?>
<style>
#showdata {
	display: block;
	background: url(Default.png) no-repeat;
	top: 0px;
	left: 0px;
	width: auto;
	min-height: 60px;
	z-index:0;
}
#back {
	display:none;
	top: 0px;
	left: 0px;
	width: auto;
	min-height: 60px;
	z-index:0;
}
</style>
<!-------------------------JS AND AJAX FILES INCLUDED HERE------------STRAT 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("MATARIALAMT").innerHTML=data[8];
	document.getElementById("VATCSTNO").innerHTML=data[9];
	document.getElementById("TOTALSERVICEAMT").innerHTML=data[10];
	document.getElementById("SERVICETAX").innerHTML=data[11];
	document.getElementById("OTHERAMT").innerHTML=data[12];
	document.getElementById("GRANDTOTALAMT").innerHTML=data[13];
	document.getElementById("ITEMDETAIL").innerHTML=data[14];
	document.getElementById("edit_cnt").value=data[15];
	document.getElementById("back").style.display=data[16];
	document.getElementById("SERVICEDETAILS").innerHTML=data[17];
	document.getElementById("edit_cnt1").value=data[18];
	}
	}
	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) 
{
	//alert(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;
	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.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);
	var val=parseFloat(document.getElementById("price_"+i).value);
	var tot_amt=qty*val;
	document.getElementById("amt_"+i).value=tot_amt.toFixed(2);
	}
	else
	{
	var qty=parseFloat(document.getElementById("rqty").value);
	var val=parseFloat(document.getElementById("price").value);
	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 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 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 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 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 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>
<!-------------------------JS AND AJAX FILES INCLUDED HERE------------STRAT HERE-------------------------------------->



<!-------------------------VALIDATION -------------------------------STRAT HERE-------------------------------------->

<script type="text/javascript" language="javascript">
function validate()
{
	if(document.getElementById("branch_name").value=='0')
	{
	alert("Please Select The Branch First");
	return false;
	}
	if(document.getElementById("visit_date").value=='')
	{
	alert("Please Select The Visit Date First");
	return false;
	}
	if(document.getElementById("job_card_no").value=='0')
	{
	alert("Please Select The Job Card No First");
	return false;
	}
	if(document.getElementById("party_name1").value=='')
	{
	alert("Please Enter The Party Name First");
	return false;
	}
	if(document.getElementById("product_name1").value=='')
	{
	alert("Please Enter The Product Name First");
	return false;
	}
	if(document.getElementById("tt_no1").value=='')
	{
	alert("Please Enter The TT No First");
	return false;
	}
	if(document.getElementById("invoice_no").value=='')
	{
	alert("Please Enter The Invoice No First");
	return false;
	}
	if(document.getElementById("serial_no").value=='')
	{
	alert("Please Enter The Serial No First");
	return false;
	}
	if(document.getElementById("technician1").value=='')
	{
	alert("Please Enter The Technician Name First");
	return false;
	}
	if(document.getElementById("service_scope_no1").value=='')
	{
	alert("Please Enter The Scope Of Services First");
	return false;
	}
	if(document.getElementById("service_scope_no").value=='')
	{
	alert("Please Enter The Scope Of Services First");
	return false;
	}
	if(document.getElementById("status").value=='0')
	{
	alert("Please Select The Status First");
	return false;
	}
	if(document.getElementById("fault_details").value=='')
	{
	alert("Please Enter The fault Details First");
	return false;
	}
	if(document.getElementById("current_status").value=='')
	{
	alert("Please Enter The Current Status First");
	return false;
	}
	if(document.getElementById("problem_remark").value=='')
	{
	alert("Please Enter The Problem Remark First");
	return false;
	}
	if(document.getElementById("client_remark").value=='')
	{
	alert("Please Enter The Client Remark First");
	return false;
	}
	if(document.getElementById("remark_by_technician").value=='')
	{
	alert("Please Enter The Remark By Technician First");
	return false;
	}
}
</script>

<!-------------------------VALIDATION -------------------------------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" action="">
<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<label><font color="#FF0000"> *</font></label></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)){?>
	<option value="<?php echo $site_row['loccode']?>"><?php echo $site_row['locationname']?></option>
	<?php } ?>
	</select>
	</td>
	<td class="tabledata1">Visit Date<label><font color="#FF0000"> *</font></label></td>
<td><input type="text" name="visit_date" id="visit_date" value="" class="datepicker" style="width:150px;" /></td>
</tr>
<tr class="row1">
<td class="tabledata1">Visit No.</td>
<td><input type="text" name="invoiceNo" value="Auto Generated" readonly="" style="width:150px;" /></td>
<td class="tabledata1">Party Name<font color="#FF0000">*</font></td>
<td id="PARTY"><input type="text" name="party_name" id="party_name" style="width:150px;" /></td>
</tr>


<tr class="row1">
<td class="tabledata1">Job Card No.<label><font color="#FF0000"> *</font></label></td>
<td id="JOBCARDNO"><select name="job_card_no" id="job_card_no" style="width:150px;" tabindex="1" >
	<option value="0">Select</option>
	<option value="0"></option>
</select></td>
<td class="tabledata1">Product name<font color="#FF0000">*</font></td>
<td id="PRODUCTNAME"><input type="text" name="product_name" id="product_name" style="width:150px;"></td>
</tr>

<tr class="row1">
<td class="tabledata1">TT No.<font color="#FF0000">*</font></td>
<td id="TTNO"><input type="text" name="tt_no" id="tt_no" value="" style="width:150px;" /></td>
<td class="tabledata1">Invoice No<font color="#FF0000">*</font></td>
<td id="INVOICENO"><input type="text" name="invoice_no" id="invoice_no" value="" style="width:150px;" /></td>
</tr>

<tr class="row1">
<td class="tabledata1">Serial No.<font color="#FF0000">*</font></td>
<td id="SERIALNO"><input type="text" name="serial_no" id="serial_no" value="" style="width:150px;" /></td>
<td class="tabledata1">Technician<font color="#FF0000">*</font></td>
<td id="TECHNICIAN"><input type="text" name="technician" id="technician" value="" style="width:150px;" /></td>
</tr>

<tr class="row1">
<td class="tabledata1">Scope of Service<font color="#FF0000">*</font></td>
<td id="SCOPEOFSER"><input type="text" name="service_scope_no" id="service_scope_no" value="" style="width:150px;" /></td>
<td class="tabledata1">Status<label><font color="#FF0000"> *</font></label></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">Fault Details<font color="#FF0000">*</font></td>
<td colspan="3" id="FAULT"><input type="text" name="fault_details" id="fault_details" value="" style="width:80%; height:50px;" /></td>
</tr>
<tr>
<td class="tabledata1">Current Status<font color="#FF0000">*</font></td>
<td colspan="3"><input type="text" name="current_status" id="current_status" value="" style="width:80%; height:50px;" /></td>
</tr>
<tr>
<td class="tabledata1">Problem Remarks<font color="#FF0000">*</font></td>
<td colspan="3"><input type="text" name="problem_remark" id="problem_remark" value="" 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"></td>
                <td class="tabledata">Item Name</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>
              <tbody id="dataTable">
                <tr bgcolor="#c1c1c1">
                  <td><input name="delitem[]" type="checkbox" value="<?php echo $item_row['id'];?>" />
                 </td>
				 <td><input type="hidden" name="itemid[]" id="itemid" ></td>
                  <td><input type="text" name="itemname[]"  id="itemname" size="40"/></td>
                  <td><input type="text" name="rqty[]"  id="rqty" size="20"/>                  </td>
                  <td><input type="text" name="price[]" id="price" size="20" />                  </td>
                  <td><input type="text" name="amt[]" 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" />
		<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="55" class="tabledata">S. No.</td>
				<td width="132" class="tabledata">&nbsp;</td>
                <td width="143" class="tabledata">Service Type</td>
                <td width="156" class="tabledata">Service Description</td>
				<td width="151" class="tabledata">Billable</td>
                <td width="155" class="tabledata">Service Amount</td>
              </tr>
			<tr>
				<td colspan="6" id="SERVICEDETAILS"></td>
			</tr>
			   <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" style="width:120px;"/></td>
                  <td><?php $serv= DB_query("SELECT * FROM services_type",$db);?>
				  	<select name="service_type[]" style="width:140px;" 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:140px;">
						<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" style="width:140px;" value=""/></td>
                </tr>
  </tbody>
</table>
			</div>
		</div>
        <input type="hidden" name="hiditemcount1" id="hiditemcount1" value="" />
        <input type="hidden" name="" value="" id="edit_cnt1" />
        <p style="padding-left:5px;padding-top:5px; margin:0; text-align:left;">
          
        </p>
        <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;" 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))
					{?>
                  <option value="<?php echo $salesRow['salestax_id'];?>" <?php echo $VatCst==$salesRow['salestax_id']?'selected':''?>><?php echo $salesRow['tax_code'];?></option>
                  <?php 	
					}
					?>
                </select>
                <div id="VATId">
                  <input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $VatCstValue?>" style="width:150px;"   onfocus="calculateEditVATCST()" readonly="" />
                </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()" 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)){?>
								<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 $servRow['tax_code'] ?></option>
								</select>
								  <?php } ?>
								<input name="service_tax_value" id="service_tax_value" type="text" value="<?php echo $VatCstValue?>" 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" style="width:150px;" onfocus=""/></td>
            </tr>
            <tr class="row1">
              <td class="tabledata">Grand Total</td>
              <td id="GRANDTOTALAMT"><input name="grandTotal" id="grandTotal" type="text"  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="tabledata1">Client Remarks<font color="#FF0000">*</font></td>
<td colspan="3"><textarea name="client_remark" id="client_remark"  style="width:80%; 50px;"></textarea></td>
</tr>
<tr>
<td class="tabledata1">Remarks by Technician<font color="#FF0000">*</font></td>
<td colspan="3"><textarea name="remark_by_technician" id="remark_by_technician" style="width:80%; 50px;"></textarea></td>
</tr>
</table>
<p align="center">
	<input type="submit" name="save" value="Save" onclick="return validate()" />
	<input type="submit" name="cancel" value="Cancel" />
</p>
</form>
</div></div>

