<link rel="stylesheet" href="css/new_mxerp.css">
<link rel="stylesheet" href="/css/jquery.ui.all.css">
<!--<script src="js1/jquery-1.7.2.js"></script>
<script src="js1/jquery.ui.widget.js"></script>
<script src="js1/jquery.ui.tabs.js"></script>
<script>
	$(function() {
		$( "#tabs" ).tabs();
	});
	</script>-->
<?php
$PageSecurity = 1;
$tabindex=0;
include('includes/DefinePaymentClass.php');
$title = _('Trouble Ticket Edit');
include('includes/SQL_CommonFunctions.inc');
if($_REQUEST['act']=='delitem' && $_REQUEST['id']!='')
{
	$update_del_status=DB_query("update trouble_ticket_creation_details set edit_status='1' where id='".$_REQUEST['id']."'",$db);
	echo "<script>location.href='index.php?route=service/ttEdit&action=Edit&ttid=".$_REQUEST['ttid']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_REQUEST['act']=='reset')
{
	$update_del_status=DB_query("update trouble_ticket_creation_details set edit_status='0' where tt_id='".$_REQUEST['ttid']."' and edit_status='1'",$db);
	echo "<script>location.href='index.php?route=service/ttEdit&action=Edit&ttid=".$_REQUEST['ttid']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}

if($_REQUEST['Save']){

	 $updatett = "UPDATE trouble_ticket_creation SET
				 	branch='".$_REQUEST['branch']."', 
					part_name='".$_REQUEST['part_name']."', 
					product_name='".$_REQUEST['product_name']."',
					invoiceNo='".$_REQUEST['invoiceNo']."',
					invoice_date='".$_REQUEST['invoice_date']."',
					expire_date='".$_REQUEST['expire_date']."',
					closer_date='".FormatDateForSQL($_REQUEST['closer_date'])."',
					prority='".$_REQUEST['prority']."',  
					category='".$_REQUEST['category']."',  
					scope_compaint='".$_REQUEST['scope_compaint']."',  
					mode_compaint='".$_REQUEST['mode_compaint']."',
					mode_contract='".$_REQUEST['mode_compaint']."',
					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']."',
					createdBy='".$_SESSION['UserID']."',
					CompanyId='".$_SESSION['ACGCompanyId']."',
					comt       = '".$_REQUEST['comt']."'
					WHERE id = '".$_REQUEST['ttid']."'";
					
					$tt_update = DB_query($updatett,$db);
					
			$delete_qry = DB_query("DELETE FROM trouble_ticket_creation_details WHERE tt_id = '".$_REQUEST['ttid']."'",$db);
			
			
			for($i=0;$i<count($_REQUEST['itemname']);$i++)
			{
				if($_REQUEST['itemname'][$i]!='')
				{
					$data_arr['tt_id']=$_REQUEST['ttid'];
					$data_arr['itemname']=$_REQUEST['itemname'][$i];
					$data_arr['rqty']=$_REQUEST['rqty'][$i];
					$data_arr['price']=$_REQUEST['price'][$i];
					$data_arr['amt']=$_REQUEST['amt'][$i];
					
					
					$rowinsert= $s->RecordInsert('trouble_ticket_creation_details', $data_arr);
					if(!$rowinsert)
					{
					   die('Error'.DB_error());
					}
				}
				
			}
			
			
			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', $data3, $cond3);
			}
	
	
			$count2=$_REQUEST['hiditemcount1']+1;
			for($t=0;$t<$count2;$t++)
			{
				if($_REQUEST['service'][$t]!=''){
				$data4['tt_id']=$_REQUEST['ttid'];
				$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', $data4);
				}
			}
			
$_SESSION['session_msg']="Trouble Ticket Update successfully";
echo "<script>location.href='index.php?route=service/view_trouble_ticket_creation&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
	



unset($_POST);
?>
<script type="text/javascript">
function getInvoice(str)
{
	var clientId=document.getElementById("partyId").value;
	var prodId = str;
	if (clientId.length==0)
	{
		alert("Please select party Name.");
		return;
	}
	window.open("getInvoice.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>&clientID="+clientId+"&itemId="+prodId,"itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}

function showInvoiceDetails(str)
{
	
	var invoiceId = str;
	window.open("getInvoiceDetail.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>&invoiceId="+invoiceId,"itempopup_window", "height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");

}

function getInvoiceNumber(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("invoiceNo").innerHTML=data[0];
	document.getElementById("productId").innerHTML=data[1];
    }
  }
xmlhttp.open("GET","getInvoiceList.php?partyid="+str,true);
xmlhttp.send();
}


/*function validation(form)
{
	

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

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

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

if(document.getElementById('grandTotal').value==''){
alert('Taxable Amt should not be empty');
document.getElementById('grandTotal').focus();
return false;
}
return true;
}	
*/


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


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

function calculateTotalAmt(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");
}
 </script>
<div class="body_contain">
  <h1><?php echo $title; ?></h1>
  <?php $tt="SELECT * FROM trouble_ticket_creation WHERE id= '".$_REQUEST['ttid']."'";
	  $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="troubleTicket">
              <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)){
							$p='';
							$p='selected'
					  ?>
                      <option Value="<?php echo $loc['loccode']?>" <?php echo $p?>><?php echo  $loc['locationname']?></option>
                      <?php }
					?>
                    </select>
                  </td>
                  <td class="tabledata1">Ticket No.<label><font color="#FF0000"> *</font></label></td>
                  <td><input type="text" style="width:150px;" name="ticket_number" readonly="readonly" value="<?php echo $fetch_tt_qry['ticket_number']?>" />
                  </td>
                </tr>
                <tr class="row1">
                  <td class="tabledata1">Party Name<label><font color="#FF0000"> *</font></label></td>
                  <td><?php 
	  					$ClientSQL="Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and  Site in('".$_SESSION['AssignedBranch']."') and Zone in(".$_SESSION['AssignedSites'].")";
						$Client_Name = DB_query($ClientSQL,$db);
					?>
                    <select name="part_name" id="partyId" style="width:150px;"  onchange="getInvoiceNumber(this.value)">
                      <option selected Value="">Select your option</option>
                      <?php 
					  	while($Client = DB_fetch_array($Client_Name)){
							$p = '';
							if($fetch_tt_qry['part_name']==$Client['id'])
							$p='selected';
					  ?>
                      <option Value="<?php echo $Client['id']?>" <?php echo $p;?>><?php echo $Client['c_name']?></option>
                      <?php } ?>
                    </select>
                  </td>
                  <td class="tabledata1">Product Name<label><font color="#FF0000"> *</font></label></td>
                  <td><?php $item = DB_query("SELECT id,item_name FROM item_master",$db);?>
                    <select name="product_name" id="productId" style="width:150px;" onchange="getInvoice(this.value)">
                      <option selected Value="">Selection your option</option>
                      <?php 
					  	while($Item_name = DB_fetch_array($item)){
							$p='';
							if($fetch_tt_qry['product_name']==$Item_name['id'])
							$p='selected';
					  ?>
                      <option Value="<?php echo $Item_name['id']?>" <?php echo $p?>><?php echo $Item_name['item_name']?></option>
                      <?php } ?>
                    </select>
                  </td>
                </tr>
				<tr class="row1">
          <td class="tabledata1">Invoice No<label><font color="#FF0000"> *</font></label></td>
          <td><?php 
	  	$InvoiceSQL="Select invoice_id,invoiceNo from invoice";
		$Invoice_No = DB_query($InvoiceSQL,$db);
	?>
            <select name="invoiceNo" id="invoiceNo" style="width:150px;" onchange="showInvoiceDetails(this.value)">
              <option Value="">Select your option</option>
              <?php 
			  	
			  	while($Invoice = DB_fetch_array($Invoice_No)){
			  		$p='';
					if($fetch_tt_qry['invoiceNo']==$Invoice['invoice_id'])
					$p='selected';
			  ?>
			  
			  
              <option Value="<?php echo $Invoice['invoice_id']?>" <?php echo $p; ?>><?php echo $Invoice['invoiceNo']?></option>
              <?php } ?>
            </select>          </td>
          <td class="tabledata1">Invoice Date<label><font color="#FF0000"> *</font></label></td>
          <td><input name="invoice_date" id="invoiceDate" value="<?php echo $fetch_tt_qry['invoice_date'];?>" readonly="readonly" style="width:150px;" /></td>
        </tr>
		<tr class="row1">
			<td class="tabledata1">Warrantee Expire Date<label><font color="#FF0000"> *</font></label></td>
			<td><input name="expire_date" id="expireDate" value="<?php echo $fetch_tt_qry['expire_date'];?>" readonly="readonly" style="width:150px;" /></td>
			<td class="tabledata1">Expected Closer Date<label><font color="#FF0000"> *</font></label></td>
			<td><input name="closer_date" id="closerDate" value="<?php echo ConvertSQLDate($fetch_tt_qry['closer_date']);?>" readonly="readonly" class="datepicker" style="width:150px;" /></td>
		</tr>
                <tr class="row1">
                  <td class="tabledata1">Priority<label><font color="#FF0000"> *</font></label></td>
                  <td><select name="prority" style="width:150px;" id="prority">
                      <option Value="1"<?php if($prority=='1'){?> selected="selected"<?php } ?>>Low</option>
                      <option Value="2"<?php if($prority=='2'){?> selected="selected" <?php }?>>High</option>
                      <option Value="3"<?php if($prority=='3'){?> selected="selected" <?php } ?>>Urgent</option>
                    </select>
                  </td>
                  <td class="tabledata1">Category</td>
                  <td><select name="category" style="width:150px;">
                      <option Value="1"<?php if($category == '1'){?> selected="selected"<?php }?>>Big Problem</option>
                      <option Value="2"<?php if($category=='2'){?> selected="selected"<?php }?>>Small Problem</option>
                      <option Value="3" <?php if($category=='3'){ ?> selected="selected"<?php }?>>Other Problem</option>
                    </select>
                  </td>
                </tr>
                <tr class="row1">
                  <td class="tabledata1">Scope of service<label><font color="#FF0000"> *</font></label></td>
                  <td><select name="scope_compaint" style="width:150px;">
                      <option value="1"<?php if($scope_compaint == '1'){?> selected="selected"<?php }?>>Complaint</option>
                      <option value="2"<?php if($scope_compaint == '2'){?> selected="selected"<?php }?>>Installation</option>
                      <option value="3"<?php if($scope_compaint == '3'){?> selected="selected"<?php }?>>De-Installation</option>
                      <option value="4"<?php if($scope_compaint == '4'){?> selected="selected"<?php }?>>Re-Installation</option>
                      <option value="5"<?php if($scope_compaint == '5'){?> selected="selected"<?php }?>>Preventive</option>
                      <option value="6"<?php if($scope_compaint == '6'){?> selected="selected"<?php }?>>Service</option>
                      <option value="7"<?php if($scope_compaint == '7'){?> selected="selected"<?php }?>>Site Survey</option>
                    </select></td>
                  <td class="tabledata1">Mode of complaint</td>
                  <td><select name="mode_compaint" style="width:150px;">
                      <option Value="1"<?php if($mode_compaint == '1'){?> selected="selected"<?php }?>>By Call</option>
                      <option Value="2"<?php if($mode_compaint == '2'){?> selected="selected"<?php }?>>By Mail</option>
                      <option Value="3"<?php if($mode_compaint == '3'){?> selected="selected"<?php }?>>Internal Mail Request</option>
                      <option Value="4"<?php if($mode_compaint == '4'){?> selected="selected"<?php }?>>Internal Request</option>
                    </select>
                  </td>
                </tr>
                <tr class="row1">
                  <td class="tabledata1">Mode of Contract<label><font color="#FF0000"> *</font></label></td>
                  <td colspan="3"><select name="mode_contract" style="width:150px;">
                      <option Value="1"<?php if($mode_contract == '1'){?> selected="selected"<?php }?>>Lease</option>
                      <option Value="2"<?php if($mode_contract == '2'){?> selected="selected"<?php }?>>NA</option'>
                      <option Value="3"<?php if($mode_contract == '3'){?> selected="selected"<?php }?>>Sold</option>
                    </select>
                  </td>
                </tr>
                <tr class="row1">
                  <td class="tabledata1" scope="row">Problem Desc.<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>

              <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" />
                </p>
                <div style="width:auto; overflow:auto;">
                  <div id="showdata">
                    <table width="100%" border="0" cellspacing="0" cellpadding="3">
                      <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_creation_details where tt_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/ttEdit&action=Edit&ttid=<?php echo $_REQUEST['ttid'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act=delitem&id=<?php echo $item_row1['id'];?>"><img src="images/delete.gif" /></a>
                          <?php //echo $i+1;?></td>
                        <td class="tabledata"><input type="hidden" name="row_id[]" id="row_id" value="<?php echo $item_row1['id']?>" /></td>
                        <td  class="tabledata"><input type="hidden" name="itemid[]" value="<?php echo $item_row['id'];?>" />
                          <input type="hidden" name="itemname[]" id="item_code_<?php echo $i;?>" value="<?php echo $item_row1['itemname'];?>" readonly  size="6">
                          <?php echo $item_row1['itemname'];?>
                          <input type="hidden" value="<?php echo $item_row['StockID'];?>" tabindex=""  readonly="" id="washing_profile" name="itemcode[]"   />
                          <input type="hidden" name="salesdetailid[<?php echo $i;?>]" value="<?php echo $item_row1['id'];?>"  />
                          <input type="hidden" name="itemid[<?php echo $i;?>]" value="<?php echo $item_row['id'];?>" />
                        </td>
                        <td class="tabledata"><?php echo $item_row['item_name'];?> </td>
                        <td class="tabledata" ><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="item_code[]" id="itemid" size="40"/></td>
                          <td><input type="text" name="itemname[]"  id="itemname" size="40"/></td>
                          <td>&nbsp;</td>
                          <td><input type="text" name="rqty[]"  id="rqty" size="40"/>
                          </td>
                          <td><input type="text" name="price[]" id="price" size="40" />
                          </td>
                          <td><input type="text" name="amt[]" id="amt" size="40" onkeyup="calculateTotalAmt(this.id)"/></td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                </div>
                <a href="index.php?route=service/ttEdit&action=Edit&ttid=<?php echo $_REQUEST['ttid'];?>&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 where tt_id='".$_REQUEST['ttid']."'",$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">&nbsp;</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/ttEdit&action=Edit&ttid1=<?php echo $_REQUEST['ttid1'];?>&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'];?>" 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="0" cellspacing="0" cellpadding="3" style="border:#999999 solid 1px;">
                    <tr class="row1">
                      <td class="tabledata" style="width:120px;">Material 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:150px;" 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:150px;" 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:150px;" 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_tt()"/>
                <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 calculateBillExcise(str)
{
	var value=document.getElementById("basicAmount").value;
	if(str.length==0)
	{
		document.getElementById("totalDiscountedPrice").innerHTML="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById("totalDiscountedPrice").value=xmlhttp.responseText;
 	}
 }
xmlhttp.open("GET","calculateExcise.php?type=bill&id="+str+"&value="+value,true);
xmlhttp.send();	}

function calculateTotalExcise()
{	
	var totalExcise=0;
	var EDRate=document.getElementById("EDRate").value;
	if(EDRate==0)
	{
		var first_row=document.getElementById("excisevalue").value;
		if(first_row==''){first_row=0;}else{first_row=first_row;}
		var cnt=document.getElementById("hiditemcount").value;
		if(cnt==''){cnt=0;}
		var edit_cnt=document.getElementById("edit_cnt").value;
		var new_count=parseInt(edit_cnt)+parseInt(cnt); 
	for(var i=0;i<new_count;i++)
	{
	 	var totalExcise1=document.getElementById("excisevalue_"+i).value;
	 	var totalExcise=(parseFloat(totalExcise)+parseFloat(totalExcise1)).toFixed(2);
	}
	  document.getElementById("totalDiscountedPrice").value=parseFloat(totalExcise)+parseFloat(first_row);
	}
	else{return false;}
}

function calculateExcise1(str,id)	
{
var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
		divid="excisevalue_"+i;
		var amount=document.getElementById("totalassamt_"+i).value;
	}
	else
	{
		divid="excisevalue";
		var amount=document.getElementById("totalassamt").value;
	}
	if(str.length==0)
	{
		document.getElementById(divid).value="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById(divid).value=xmlhttp.responseText;
		
	}
	
}
xmlhttp.open("GET","calculateExcise.php?type=TELORD&amount="+amount+"&q="+str,true);
xmlhttp.send();	
	} 
	
	function calassprice(val,id)
{
	
		var id_brk=id.split('_');
		var i=id_brk[1];
		if(id_brk.length>1)
		{
			
			var tot_amt=(70*val)/100;
			document.getElementById("ass_price_"+i).value=tot_amt.toFixed(2);
		}
		else
		{
			
			var tot_amt=(70*val)/100;
			document.getElementById("ass_price").value=tot_amt.toFixed(2);
		}
}

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

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


function validate_tt()
 	{
		if(document.troubleTicket.branch.value=='')
			{
				alert("Please Select Branch First");
				return false;
			}
			else if(document.troubleTicket.ticket_number.value=='')
			{
				alert("Please Select Ticket Number");
				return false;
			}
			else if(document.troubleTicket.part_name.value=='')
			{
				alert("Please Select Party Name");
				return false;
			}
			else if(document.troubleTicket.product_name.value=='')
			{
				alert("Please Select Product Name");
				return false;
			}
			else if(document.troubleTicket.invoiceNo.value=='')
			{
				alert("Please Select Invoice No.");
				return false;
			}
			else if(document.troubleTicket.invoice_date.value=='')
			{
				alert("Please Enter The Invoice Date");
				return false;
			}
			else if(document.troubleTicket.expire_date.value=='')
			{
				alert("Please Enter The Warrantee Expiry Date");
				return false;
			}
			else if(document.troubleTicket.closer_date.value=='')
			{
				alert("Please Enter The Expected Closing Date");
				return false;
			}
			else if(document.troubleTicket.prority.value=='')
			{
				alert("Please Select The Prority");
				return false;
			}
			else if(document.troubleTicket.scope_compaint.value=='')
			{
				alert("Please Select The Scope of Service");
				return false;
			}
			else if(document.troubleTicket.mode_contract.value=='')
			{
				alert("Please Select The Mode of Contract");
				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>
