<link rel="stylesheet" href="css/new_mxerp.css">

<?php
$PageSecurity = 1;
$tabindex=0;
include('includes/DefinePaymentClass.php');
$title = _('Job Card Creation');
include('includes/SQL_CommonFunctions.inc');
if($_REQUEST['act']=='delitem' && $_REQUEST['id']!='')
{
	$update_del_status=DB_query("update trouble_ticket_jobcard_details set edit_status='1' where id='".$_REQUEST['id']."'",$db);
	echo "<script>location.href='index.php?route=service/jcEdit&action=Edit&jcid=".$_REQUEST['jcid']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_REQUEST['act']=='DelServ' && $_REQUEST['sid']!='')
{

	$condition1="id='".$_REQUEST['sid']."' and jc_id='".$_REQUEST['jcid1']."'";
	$s->DeleteRecord('add_service_jobcard',  $condition1);// DELETE ITEM
	echo "<script>location.href='index.php?route=service/jcEdit&action=Edit&jcid=".$_REQUEST['jcid1']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}

if($_REQUEST['act']=='reset')
{
	$update_del_status=DB_query("update trouble_ticket_jobcard_details set edit_status='0' where jc_id='".$_REQUEST['jcid']."' and edit_status='1'",$db);
	echo "<script>location.href='index.php?route=service/jcEdit&action=Edit&jcid=".$_REQUEST['jcid']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}

if($_REQUEST['Save']){
	 $updatejc = "UPDATE trouble_ticket_jobcard SET
				 	branch='".$_REQUEST['branch']."',
					job_card_number='".$_REQUEST['jobcard_number']."', 
					job_card_date='".$_REQUEST['jobcard_date']."',
					job_card_time='".$_REQUEST['jobcard_time']."',
					ticket_number='".$_REQUEST['tt_no']."',
					party_name='".$_REQUEST['part_name']."', 
					product_name='".$_REQUEST['product_name']."',
					serial_number='".$_REQUEST['serial_no']."',
					technician='".$_REQUEST['technician_name']."',
					scope_compaint='".$_REQUEST['scope_compaint']."',  
					mode_compaint='".$_REQUEST['service_typem']."',
					mode_contract='".$_REQUEST['mode_contract']."',
					closing_date='".$_REQUEST['closer_date']."',
					status='".$_REQUEST['status']."',
					prob_desc='".$_REQUEST['prob_desc']."',
					materialAmount='".$_REQUEST['materialAmount']."',
					VatCst='".$_REQUEST['VatCst']."',
					VatCstValue='".$_REQUEST['VatCstValue']."',
					serviceAmount='".$_REQUEST['serviceAmount']."',
					serviceTax='".$_REQUEST['serviceTax']."',
					serviceTaxValue='".$_REQUEST['serviceTaxValue']."',
					otherAmount='".$_REQUEST['otherAmount']."',
					grandTotal='".$_REQUEST['grandTotal']."',
					pending_amount='".$_REQUEST['grandTotal']."',
					createdBy='".$_SESSION['UserID']."',
					CompanyId='".$_SESSION['ACGCompanyId']."'
					WHERE id = '".$_REQUEST['jcid']."'";
					
					$jc_update = DB_query($updatejc,$db);
					
			//$delete_qry = DB_query("DELETE FROM trouble_ticket_jobcard_details WHERE jc_id = '".$_REQUEST['jcid']."'",$db);
			
			
			
			
			$count1=$_REQUEST['hiditemcount']+1;
			for($i=0;$i<count($_REQUEST['row_id']);$i++)
			{
				$data1['rqty']=$_REQUEST['rqty'][$i];
				$data1['price']=$_REQUEST['price'][$i];
				$data1['amt']=$_REQUEST['amt'][$i];
				$cond1="id='".$_REQUEST['row_id'][$i]."'";
				$s->RecordEdit('trouble_ticket_jobcard_details', $data1, $cond1);//UPDATION IN FETCHED ITEMS
			}

	
			for($j=0;$j<$count1;$j++)
			{
				if($_REQUEST['itemid1'][$j]!=''){
				$data2['jc_id']=$_REQUEST['jcid'];
				$data2['itemname']=$_REQUEST['itemid1'][$j];
				$data2['rqty']=$_REQUEST['rqty1'][$j];
				$data2['price']=$_REQUEST['price1'][$j];
				$data2['amt']=$_REQUEST['amt1'][$j];
				$Insert1=$s->RecordInsert('trouble_ticket_jobcard_details', $data2);// INSERT NEW ITEMS
				}
			}
			
			
			
			
			
			for($k=0;$k<count($_REQUEST['row_aks']);$k++)
			{
				$data3['service']=$_REQUEST['service1'][$k];
				$data3['service_type']=$_REQUEST['service_type1'][$k];
				$data3['service_desc']=$_REQUEST['service_desc1'][$k];
				$data3['service_amt']=$_REQUEST['service_amt1'][$k];
				$data3['billable']=$_REQUEST['billable1'][$k];
				$cond3="id='".$_REQUEST['row_aks'][$k]."'";
				$s->RecordEdit('add_service_jobcard', $data3, $cond3);
			}
	
	
			$count2=$_REQUEST['hiditemcount1']+1;
			for($t=0;$t<$count2;$t++)
			{
				if($_REQUEST['service'][$t]!=''){
				$data4['jc_id']=$_REQUEST['jcid'];
				$data4['service']=$_REQUEST['service'][$t];
				$data4['service_type']=$_REQUEST['service_type'][$t];
				$data4['service_desc']=$_REQUEST['service_desc'][$t];
				$data4['service_amt']=$_REQUEST['service_amt'][$t];
				$data4['billable']=$_REQUEST['billable'][$t];
				$Insert1=$s->RecordInsert('add_service_jobcard', $data4);
				}
			}

			
		$_SESSION['session_msg']="Job Card Update successfully";
	
			echo "<script>location.href='index.php?route=service/view_job_card&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
 			?>
			
				<script type="text/javascript">alert("Sucessfully Updated");</script>
			<?php
			
	}
unset($_POST);
?>
<script type="text/javascript">

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(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 calculateMaterial()
{
	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("materialAmount").value=parseFloat(totalBasic)+parseFloat(first_row);
}


function calculateService()
{
	var totalBasic=0;
	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;}
	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("serviceAmount").value=parseFloat(service_amt)+parseFloat(service_amt2);
}


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("materialAmount").value;
	var vat_cst=taxableAmount*(rate/100);
	document.getElementById("VatCstValue").value=vat_cst.toFixed(2);
}

function calculateServiceTax(str)
{
	
	if (str.length==0)
  		{
  			document.getElementById("servicerate").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("servicerate").value=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","calculateExcise.php?servicesId="+str,true);
		xmlhttp.send();
}
function calculateEditServiceTax()
{
	var rate=document.getElementById("servicerate").value;
	var taxableAmount=document.getElementById("serviceAmount").value;
	var vat_cst=taxableAmount*(rate/100);
	document.getElementById("serviceTaxValue").value=vat_cst.toFixed(2);
}


function calculateGrand()
{
	var a=document.getElementById("materialAmount").value;
	var b=document.getElementById("VatCstValue").value;
	var c=document.getElementById("serviceAmount").value;
	var d=document.getElementById("serviceTaxValue").value;
	var e=document.getElementById("otherAmount").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);
}

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=600,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 getTTdetail(str)
{

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)
    {
	data = xmlhttp.responseText.split("__");
    document.getElementById("partyId").value=data[1];
	document.getElementById("partyId1").value=data[0];
	document.getElementById("productId").value=data[3];
	document.getElementById("productId1").value=data[2];
	document.getElementById("technicianName").value=data[5];
	document.getElementById("technicianName1").value=data[4];
	document.getElementById("scopeCompaint").value=data[7];
	document.getElementById("scopeCompaint1").value=data[6];
	document.getElementById("serviceType").value=data[9];
	document.getElementById("serviceType1").value=data[8];
	document.getElementById("modeContract").value=data[11];
	document.getElementById("modeContract1").value=data[10];
	document.getElementById("closerDate").value=data[12];
	document.getElementById("prob_desc").value=data[13];
    }
  }
xmlhttp.open("GET","getTTdetails.php?ttid="+str,true);
xmlhttp.send();
}

 </script>
<div class="body_contain">
  <h1><?php echo $title; ?></h1>
  <?php $tt="SELECT * FROM trouble_ticket_jobcard WHERE id= '".$_REQUEST['jcid']."'";
	  $tt_qry = DB_query($tt,$db);
	  $fetch_tt_qry = DB_fetch_array($tt_qry);
	  extract($fetch_tt_qry);
	?>
  <div class="insideclass">
    <div style="z-index:-1000em;">
      <div class="demo">
        <div id="tabs">
          <div id="tabs-1">
            <form action="" method="post" name="jobCard">
              <table width="100%" border="0" cellspacing="0" cellpadding="3" style="border:#999999 solid 1px;">
        <tr class="row1">
          <td class="tabledata1">Branch<label><font color="#FF0000"> *</font></label></td>
          <td><?php $location = DB_query("SELECT * FROM locations where CompanyId = '".$_SESSION['ACGCompanyId']."'",$db);
		  
		  ?>
            <select name="branch" style="width:150px;">
              <option selected Value="">Select your option</option>
              <?php while($loc = DB_fetch_array($location)){?>
              <option Value="<?php echo $loc['loccode']?>" <?php if($loc['loccode']==$fetch_tt_qry['branch']) {echo "selected";}?>><?php echo  $loc['locationname']?></option>
              <?php }
			?>
            </select>          </td>
			<td colspan="2"></td>		

        </tr>
		<tr class="row1">
           <td class="tabledata1">Job Card No.<label><font color="#FF0000"> *</font></label></td>
          <td><input type="text" style="width:150px;" name="jobcard_number" readonly="readonly" value="<?php echo  $fetch_tt_qry['job_card_number'];?>" />          </td>
          <td class="tabledata1">Job Card Date & Time<label><font color="#FF0000"> *</font></label></td>
          <td><input type="text" style="width:150px;" name="jobcard_date" readonly="readonly" class="datepicker" value="<?php echo $fetch_tt_qry['job_card_date'];?>" />
		  <?php 
		  $timezone = "Asia/Calcutta";
			if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
			  $t=date("G:i", time());  ?>
		  <input type="text" style="width:60px;" name="jobcard_time" readonly="readonly" value="<?php  if($_REQUEST['jobcard_time']!='') { echo $_REQUEST['jobcard_time'];}else{echo $t; }?>" /></td>
        </tr>
		
        <tr class="row1">
			<td class="tabledata1">TT No.<label><font color="#FF0000"> *</font></label></td>
          <td><?php 
	  $TTSQL="Select * from trouble_ticket_creation";
		$tt_No = DB_query($TTSQL,$db);
	?>
            <select name="tt_no" id="ttId" style="width:150px;" onchange="getTTdetail(this.value)">
              <option selected Value="">Select your option</option>
              <?php while($tt = DB_fetch_array($tt_No)){?>
              <option Value="<?php echo $tt['id']?>" <?php if($tt['id']==$fetch_tt_qry['ticket_number']) {echo "selected";}?>><?php echo $tt['ticket_number']?></option>
              <?php } ?>
            </select>          </td>
          <td class="tabledata1">Party Name<label><font color="#FF0000"> *</font></label></td>
          <td>
		  <?php $ClientSQL= $s->GetFieldValue('clientmaster', 'id="'.$fetch_tt_qry['party_name'].'"','c_name');?>
            <input name="part_name1" id="partyId" style="width:150px" value="<?php echo $ClientSQL; ?>" />
			<input name="part_name" id="partyId1" style="visibility:hidden; height:1px;" value="<?php echo $fetch_tt_qry['party_name']; ?>" />
		</td>
        </tr>
		<tr class="row1">
			<td class="tabledata1">Product Name<label><font color="#FF0000"> *</font></label></td>
          <td>
		  <?php $ProductSQL= $s->GetFieldValue('item_master', 'id="'.$fetch_tt_qry['product_name'].'"','item_name');?>
		    <input name="product_name1" id="productId" style="width:150px" value="<?php echo $ProductSQL; ?>" />
			<input name="product_name" id="productId1" style="visibility:hidden; height:1px;" value="<?php echo $fetch_tt_qry['product_name']; ?>" />
         </td>
          <td class="tabledata1">Serial No.</td>
          <td><input name="serial_no" id="serialNo" value="<?php echo $fetch_tt_qry['serial_number']; ?>" style="width:150px"  /></td>
        </tr>
		<tr class="row1">
			<td class="tabledata1">Technician Name<label><font color="#FF0000"> *</font></label></td>
			<?php $TechnicianSQL= $s->GetFieldValue('technicians', 'id="'.$fetch_tt_qry['technician'].'"','technician');?>
			<td><input name="technician_name1" id="technicianName" value="<?php echo $TechnicianSQL; ?>" readonly="readonly" style="width:150px;" />
			<input name="technician_name" id="technicianName1" style="visibility:hidden; height:1px;" value="<?php echo $fetch_tt_qry['technician'];?>" />
			</td>
			<td class="tabledata1">Scope of Service<label><font color="#FF0000"> *</font></label></td>
			<td>
			<?php 
			if($fetch_tt_qry['scope_compaint']=='1'){$ttscope="Complaint";}
			else if($fetch_tt_qry['scope_compaint']=='2'){$ttscope="Installation";}
			else if($fetch_tt_qry['scope_compaint']=='3'){$ttscope="De-Installation";}
			else if($fetch_tt_qry['scope_compaint']=='4'){$ttscope="Re-Installation";}
			else if($fetch_tt_qry['scope_compaint']=='5'){$ttscope="Preventive";}
			else if($fetch_tt_qry['scope_compaint']=='6'){$ttscope="Service";}
			else if($fetch_tt_qry['scope_compaint']=='7'){$ttscope="Site Survey";}
			else {$ttscope="";}
			?>
			<input name="scope_compaint1" id="scopeCompaint" value="<?php echo $ttscope; ?>" readonly="readonly" style="width:150px" />
			<input name="scope_compaint" id="scopeCompaint1" style="visibility:hidden; height:1px;" value="<?php echo $fetch_tt_qry['scope_compaint']; ?>" readonly="readonly" />
			</td>
		</tr>
         <tr class="row1">
			<td class="tabledata1">Mode of Complaint<label><font color="#FF0000"> *</font></label></td>
			<td>
			<?php 
			if($fetch_tt_qry['mode_compaint']==1){$ttmode="By Call";}
			else if($fetch_tt_qry['mode_compaint']==2){$ttmode="By Mail";}
			else if($fetch_tt_qry['mode_compaint']==3){$ttmode="Internal Mail Request";}
			else if($fetch_tt_qry['mode_compaint']==4){$ttmode="Internal Request";}
			else {$ttmode="";}
			?>
			<input name="service_typem1" id="serviceType" value="<?php echo $ttmode;?>" readonly="readonly" style="width:150px" />
			<input name="service_typem" id="serviceType1" style="visibility:hidden; height:1px;" value="<?php echo $fetch_tt_qry['mode_compaint'];?>" />
			</td>
			<td class="tabledata1">Mode of Contract<label><font color="#FF0000"> *</font></label></td>
			<?php 
			if($fetch_tt_qry['mode_contract']==1){$ttcontract="Lease";}
			else if($fetch_tt_qry['mode_contract']==2){$ttcontract="NA";}
			else if($fetch_tt_qry['mode_contract']==3){$ttcontract="Sold";}
			else {$ttcontract="";}
			?>
			<td><input name="mode_contract1" id="modeContract" value="<?php echo $ttcontract; ?>" readonly="readonly" style="width:150px" />
			<input name="mode_contract" id="modeContract1" style="visibility:hidden; height:1px;" value="<?php echo $fetch_tt_qry['mode_contract']; ?>" />
			</td>
		</tr>
        <tr class="row1">
          <td class="tabledata1">Expected closing date<label><font color="#FF0000"> *</font></label></td>
          <td><input name="closer_date" id="closerDate" value="<?php echo $fetch_tt_qry['closing_date']; ?>" readonly="readonly" style="width:150px" />
			</td>
          <td class="tabledata1">Job Card Status</td>
          <td>
		   <input type="text" name="status1" value="<?php if($fetch_tt_qry['status']=='1') {echo "Open";}?>" readonly="readonly" style="width:150px;" />		  <input type="text" name="status" value="1" style="visibility:hidden; height:1px;" readonly="readonly" />
		         </td>
        </tr>
        <tr class="row1">
          <td class="tabledata1" scope="row">Fault Details.<label><font color="#FF0000"> *</font></label></td>
          <td colspan="3"><input name="prob_desc" type="text" id="prob_desc" value="<?php echo $fetch_tt_qry['prob_desc']; ?>" style="width:80%; height:50px;"></td>
        </tr>
        
      </table>
              <br />
              <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="Pick Items" 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>
                <div style="width:auto; overflow:auto;">
                  <div id="showdata">
                    <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse;">
                      <tr>
                        <td class="tabledata">S. No.</td>
                        <td class="tabledata"></td>
                        <td class="tabledata">Item Name</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>
                      <?php 
		 $i=0;
		
		  $ItemSQL=DB_query("Select * from trouble_ticket_jobcard_details where jc_id='".$fetch_tt_qry['id']."' AND edit_status = '0'",$db);
		  while($item_row1=DB_fetch_array($ItemSQL))
		  {
			 //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=service/jcEdit&action=Edit&jcid=<?php echo $_REQUEST['jcid'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act=delitem&id=<?php echo $item_row1['id'];?>"><img src="images/delete.gif" /></a></td>
                        <td class="tabledata">
                        <input type="hidden" name="itemid[]" style="width:50px;" id="itemid1_<?php echo $i;?>" value="<?php echo $item_row1['itemname'];?>" readonly >
						<input type="hidden" name="row_id[<?php echo $i; ?>]" id="row_id" value="<?php echo $ItemRow['id']?>" />
						</td>
                        <td  class="tabledata">
                          
                          <?php echo $itemname = $s->GetFieldValue('item_master', 'id="'.$item_row1['itemname'].'"', 'item_name');?>
                          <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'];?>"  />
                        <td class="tabledata"><?php echo $item_row['item_name'];?> </td>
                        <td class="tabledata" ><input type="text"  value="<?php echo $item_row1['rqty'];?>" id="rqty_<?php echo $i;?>" name="rqty[]" /></td>
                        <td class="tabledata" ><input type="text" style="width:50" name="price[]" id="price_<?php echo $i;?>" value="<?php echo $item_row1['price']?>"/></td>
                        <td class="tabledata" ><input type="text" name="amt[]" id="amt_<?php echo $i;?>" value="<?php echo $item_row1['amt']?>" size="6" onkeyup="calculateTotalAmt(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_row1['id'];?>" /></td>
                          <td><input type="hidden" name="itemid1[]" id="itemid"  /></td>
                          <td><input type="text" name="itemname1[]"  id="itemname" style="width:100%;" /></td>
                          <td>&nbsp;</td>
                          <td><input type="text" name="rqty1[]"  id="rqty" style="width:100%;"/>                          </td>
                          <td><input type="text" name="price1[]" id="price" style="width:100%;" />                          </td>
                          <td><input type="text" name="amt1[]" id="amt" style="width:100%;" onkeyup="calculateTotalAmt(this.id)"/></td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                </div>
                <a href="index.php?route=service/jcEdit&action=Edit&jcid=<?php echo $_REQUEST['jcid'];?>&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>
                <input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
				
				
<?php $ServiceSql = DB_query("Select * from add_service_jobcard where jc_id='".$_REQUEST['jcid']."'",$db);?>
<style>
#showdata {
	display: block;
	background: url(Default.png) no-repeat;
	top: 0px;
	left: 0px;
	width: 100%;
	min-height: 60px;
	z-index:0;
}
<?php if(DB_num_rows($ServiceSql)>0) {?>
#back {
	display:block;
	top: 0px;
	left: 0px;
	width: 100%;
	min-height: 60px;
	z-index:0;
}
<?php }else {  ?>

#back {
	display:none;
	top: 0px;
	left: 0px;
	width: 100%;
	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="251" 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/jcEdit&action=Edit&jcid1=<?php echo $_REQUEST['jcid'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act=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'];?>" id="service_<?php echo $j; ?>" size="40"/></td>
				<td><?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>
				  	<?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_desc']==$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">
				  	<option value="Y" <?php if($ServiceRow['billable']=='Y') {echo "selected";}?>>Yes</option>
					<option value="N" <?php if($ServiceRow['billable']=='N') {echo "selected";}?>>No</option>
				  </select>
				  </td>
				  <td><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="billable1[]" id="billable">
				  	<option value="Y" <?php if($ServiceRow['billable']=='Y') {echo "selected";}?>>Yes</option>
					<option value="N" <?php if($ServiceRow['billable']=='N') {echo "selected";}?>>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;">Materials Total Amt.</td>
                      <td><input name="materialAmount" type="text"  style="width:150px;" onfocus="calculateMaterial()" id="materialAmount" value="<?php echo $fetch_tt_qry['materialAmount']?>" readonly="readonly"/></td>
                    </tr>
					<tr class="row1">
                      <td class="tabledata">Vat/Cst</td>
                      <td><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 $fetch_tt_qry['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 $fetch_tt_qry['VatCstValue']?>" style="width:107px;" readonly  onfocus="calculateEditVATCST()" />
                        </div>
                        <input type="hidden" name="" id="rate" value="<?php echo $rate;?>" />
                      </td>
                    </tr>
					<tr class="row1">
                      <td class="tabledata" style="width:150px;">Service Total Amt.</td>
                      <td><input name="serviceAmount" type="text"  style="width:120px;" onfocus="calculateService()" id="serviceAmount" value="<?php echo $fetch_tt_qry['serviceAmount']?>"  readonly="readonly"/></td>
                    </tr>
					<tr class="row1">
                      <td class="tabledata">Service Tax</td>
                      <td><select name="serviceTax" id="value3" onchange="calculateServiceTax(this.value)" style="width:150px;">
                          <option value="" >Select</option>
                          <?php 
					$salesSql=DB_query("Select * from service_tax_master",$db);
					while($salesRow=DB_fetch_array($salesSql))
					{?>
                          <option value="<?php echo $salesRow['id'];?>"<?php echo $fetch_tt_qry['serviceTax']==$salesRow['id']?'selected':''?>><?php echo $salesRow['tax_code'];?></option>
                          <?php 	
					}
					?>
                        </select>
                        <div id="VATId">
                          <input name="serviceTaxValue" id="serviceTaxValue" type="text" value="<?php echo $fetch_tt_qry['serviceTaxValue']?>" style="width:107px;" readonly  onfocus="calculateEditServiceTax()" />
                        </div>
                        <input type="hidden" name="" id="servicerate" value="<?php echo $servicerate;?>" />
                      </td>
                    </tr>
					
                    
                    <tr class="row1">
                      <td class="tabledata">Other Amount</td>
                      <td><input name="otherAmount" id="otherAmount" type="text" style="width:150px;" value="<?php echo $fetch_tt_qry['otherAmount']?>"/></td>
                    </tr>
                    
                    <tr class="row1">
                      <td class="tabledata">Grand Total</td>
                      <td><input name="grandTotal" id="grandTotal" type="text"  style="width:150px;" onfocus="calculateGrand()" readonly="readonly" value="<?php echo $fetch_tt_qry['grandTotal']?>"  /></td>
                    </tr>
                  </table>
                </div>
                <div class="cl"></div>
              </div>
              <p align="center">
                <input type="submit" name="Save" value="Save" onclick="return validate_jc()"/>
                <input type="submit" name="cancel" value="Cancel" />
              </p>
            </form>
          </div>
          <!-- Tab 1 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("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 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 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 validate_jc()
 	{
		if(document.jobCard.branch.value=='')
			{
				alert("Please Select Branch First");
				return false;
			}
			else if(document.jobCard.jobcard_number.value=='')
			{
				alert("Please Enter Job Card Number");
				return false;
			}
			else if(document.jobCard.jobcard_date.value=='')
			{
				alert("Please Enter Job Card Date");
				return false;
			}
			else if(document.jobCard.jobcard_time.value=='')
			{
				alert("Please Enter Job Card Time");
				return false;
			}
			else if(document.jobCard.tt_no.value=='')
			{
				alert("Please Select TT Number");
				return false;
			}
			else if(document.jobCard.part_name.value=='')
			{
				alert("Please Enter Party Name");
				return false;
			}
			else if(document.jobCard.product_name.value=='')
			{
				alert("Please Enter Product Name");
				return false;
			}
			//else if(document.jobCard.serial_no.value=='')
			//{
			//	alert("Please Enter Serial No.");
			//	return false;
			//}
			else if(document.jobCard.technician_name.value=='')
			{
				alert("Please Enter The Technician Name");
				return false;
			}
			else if(document.jobCard.scope_compaint.value=='')
			{
				alert("Please Enter The Scope of Service");
				return false;
			}
			else if(document.jobCard.service_typem.value=='')
			{
				alert("Please Enter The Mode of compaint");
				return false;
			}
			else if(document.jobCard.mode_contract.value=='')
			{
				alert("Please Select The Mode of Contract");
				return false;
			}
			else if(document.jobCard.closer_date.value=='')
			{
				alert("Please Enter The Expected Closing Date");
				return false;
			}
			else if(document.troubleTicket.prob_desc.value=='')
			{
				alert("Please Enter The Problem Description");
				return false;
			}
			var counter=document.getElementById("rowcount").value;
			for(var x=0;x<counter;x++)
				{
					  if(document.getElementById("itemname").value=='')
						{
							alert("Please Enter The Item Name");
							return false;
						}
					 else if(document.getElementById("rqty").value=='')
						{
							alert("Please Enter The Quantity");
							return false;
						}	
					 else if(document.getElementById("itemname_"+x).value=='')
						{
							alert("Please Enter The Item Name");
							return false;
						}
						else if(document.getElementById("rqty_"+x).value=='')
						{
							alert("Please Enter The Quantity");
							return false;
						}
				}
}



</script>
