<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 = _('Job Card Material Edit');
include('includes/SQL_CommonFunctions.inc');
if($_REQUEST['act']=='delitem' && $_REQUEST['id']!='')
{
	$update_del_status=DB_query("update trouble_ticket_jobcard_material set edit_status='1' where id='".$_REQUEST['id']."'",$db);
	echo "<script>location.href='index.php?route=service/reqEdit&action=Edit&reqid=".$_REQUEST['reqid']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_REQUEST['act']=='reset')
{
	$update_del_status=DB_query("update trouble_ticket_jobcard_material_details set edit_status='0' where req_id='".$_REQUEST['reqid']."' and edit_status='1'",$db);
	echo "<script>location.href='index.php?route=service/reqEdit&action=Edit&reqid=".$_REQUEST['reqid']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}

if($_REQUEST['Save']){
	 $updatejc = "UPDATE trouble_ticket_jobcard_material SET
				 	branch='".$_REQUEST['branch']."',
					requirement_id='".$_REQUEST['requirement_id']."',
					job_card_number='".$_REQUEST['jc_no']."', 
					tt_no='".$_REQUEST['tt_no']."',
					technician_id='".$_REQUEST['technician_name']."',
					party_name='".$_REQUEST['part_name']."', 
					product_name='".$_REQUEST['product_name']."',
					serial_number='".$_REQUEST['serial_no']."',
					prob_desc='".$_REQUEST['prob_desc']."',
					basicAmount='".$_REQUEST['basicAmount']."',
					EDBillRate='".$_REQUEST['EDBillRate']."',
					ECessRate='".$_REQUEST['ECessPercentage']."',
					ECessValue='".$_REQUEST['ECessValue']."',
					SAHCessPercentage='".$_REQUEST['SAHCessPercentage']."',
					SAHCessValue='".$_REQUEST['SAHCessValue']."',
					taxableAmount='".$_REQUEST['taxableAmount']."',
					VatCst='".$_REQUEST['VatCst']."',
					VatCstValue='".$_REQUEST['VatCstValue']."',
					grandTotal='".$_REQUEST['grandTotal']."',
					createdBy='".$_SESSION['UserID']."',
					CompanyId='".$_SESSION['ACGCompanyId']."',
					totalDiscountedPrice = '".$_REQUEST['totalDiscountedPrice']."',
					exciseDuty = '".$_REQUEST['exciseDuty']."'
					WHERE id = '".$_REQUEST['reqid']."'";
					
					$jc_update = DB_query($updatejc,$db);
					
			$delete_qry = DB_query("DELETE FROM trouble_ticket_jobcard_material_details WHERE req_id = '".$_REQUEST['reqid']."'",$db);
			
			
			for($i=0;$i<count($_REQUEST['itemname']);$i++)
			{
				if($_REQUEST['itemname'][$i]!='')
				{
					$data_arr['req_id']=$_REQUEST['reqid'];
					$data_arr['jc_id']=$_REQUEST['jc_no'];
					$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_jobcard_material_details', $data_arr);
					if(!$rowinsert)
					{
					   die('Error'.DB_error());
					}
				}
				
			}?>
				<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 calculateEDAmt(i)
{

    
 		
	var EDRate = document.getElementById("EDRate_"+i).value;
	
	if(EDRate=='0')
	{
		
		document.getElementById("EDAmt_"+i).value='0.00';
		
	}
	else{
		
	
	 
 	var stock_price = document.getElementById("stock_qty_"+i).value;
 
	var EDAmt=((parseFloat(EDRate)*parseFloat(stock_price) )/100);
 	 document.getElementById("EDAmt_"+i).value=EDAmt.toFixed(2);
 	}
	 
 
}


function calculateBasic()
{
	var totalBasic=0;
	var 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("basicAmount").value=parseFloat(totalBasic)+parseFloat(first_row);
}

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 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 calculateGrand()
{
	var a=document.getElementById("totalDiscountedPrice").value;
	var b=document.getElementById("taxableAmount").value;
	var c=document.getElementById("VatCstValue").value;
	if(b==''){b=0;}
	if(c==''){c=0;}
	
	var GRAND=parseFloat(b)+parseFloat(c);
	document.getElementById("grandTotal").value=GRAND.toFixed(2);
}
function calculateEditVATCST()
{
	var rate=document.getElementById("rate").value;
	var taxableAmount=document.getElementById("taxableAmount").value;
	var vat_cst=taxableAmount*(rate/100);
	document.getElementById("VatCstValue").value=vat_cst.toFixed(2);
}
function 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 getJCdetail(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("ttNo").value=data[7];
	document.getElementById("ttNo1").value=data[6];
	document.getElementById("serialNo").value=data[8];
	document.getElementById("prob_desc").value=data[9];
    }
  }
xmlhttp.open("GET","getJCdetails.php?jcid="+str,true);
xmlhttp.send();
}


 </script>
<div class="body_contain">
  <h1><?php echo $title; ?></h1>
  <?php $tt="SELECT * FROM trouble_ticket_jobcard_material WHERE id= '".$_REQUEST['reqid']."'";
	  $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">
              <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#999999 solid 1px;">
        <tr>
          <td class="tabledata1">Branch</td>
          <td colspan="2"><?php $location = DB_query("SELECT * FROM locations where CompanyId = '".$_SESSION['ACGCompanyId']."'",$db)?>
            <select name="branch" style="width:100%">
              <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 class="tabledata1">Job Card No.</td>
			 <td colspan="2"><?php 
	  		$JCSQL="Select * from trouble_ticket_jobcard";
			$jc_No = DB_query($JCSQL,$db);
	?>
            <select name="jc_no" id="jcId" style="width:100%" onchange="getJCdetail(this.value)">
              <option selected Value="">Select your option</option>
              <?php while($jc = DB_fetch_array($jc_No)){?>
              <option Value="<?php echo $jc['id']?>" <?php if($jc['id']==$fetch_tt_qry['job_card_number']) {echo "selected";}?>><?php echo $jc['job_card_number']?></option>
              <?php } ?>
            </select></td>
        </tr>
		
		<tr>
           <td class="tabledata1">Requirement No.</td>
          <td colspan="2"><input type="text" style="width:100%" name="requirement_id" readonly="readonly" value="<?php  echo $fetch_tt_qry['requirement_id'];?>" />          </td>
          <td class="tabledata1">Technician Name</td>
			<?php $TechnicianSQL= $s->GetFieldValue('technicians', 'id="'.$fetch_tt_qry['technician_id'].'"','technician');?>
			<td colspan="2"><input name="technician_name1" id="technicianName" value="<?php echo $TechnicianSQL; ?>" readonly="readonly" />
			<input name="technician_name" id="technicianName1" style="visibility:hidden; height:1px;" value="<?php echo $fetch_tt_qry['technician'];?>" />
			</td>
         
        </tr>
		
        <tr>
			<td class="tabledata1">TT No.</td>
          <td colspan="2">
		  <?php $TTSQL= $s->GetFieldValue('trouble_ticket_creation', 'id="'.$fetch_tt_qry['tt_no'].'"','ticket_number');?>
            <input name="tt_no1" id="ttNo" style="width:100%" value="<?php echo $TTSQL; ?>" />
			<input name="tt_no" id="ttNo1" style="visibility:hidden; height:1px;" value="<?php echo $fetch_tt_qry['tt_no']; ?>" />	
		</td>
		  <td class="tabledata1">Party Name</td>
          <td colspan="2">
		  <?php $ClientSQL= $s->GetFieldValue('clientmaster', 'id="'.$fetch_tt_qry['party_name'].'"','c_name');?>
            <input name="part_name1" id="partyId" style="width:100%" 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>
			<td class="tabledata1">Product Name</td>
          <td colspan="2">
		  <?php $ProductSQL= $s->GetFieldValue('item_master', 'id="'.$fetch_tt_qry['product_name'].'"','item_name');?>
		    <input name="product_name1" id="productId" style="width:100%" 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 colspan="2"><input name="serial_no" id="serialNo" value="<?php echo $fetch_tt_qry['serial_number']; ?>"  /></td>
        </tr>
        <tr>
          <td class="tabledata1" scope="row">Fault Details.</td>
          <td colspan="5"><input name="prob_desc" type="text" id="prob_desc" value="<?php echo $fetch_tt_qry['prob_desc']; ?>" style="width:100%; height:50px;"></td>
        </tr>
        <tr>
          <td class="tabledata1" scope="row">&nbsp;</td>
          <td colspan="5">
		  	<!--<select name="z" id="order_type" style="width:206px;"   onchange="getorder(this.value)">
			  <option value="Consolidate">Spare Parts</option>
			  <option value="MRP_Item">Add Service</option>
			</select>-->
		  </td>
        </tr>
      </table>
              <br />
              <div style="width:810px; 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:806px; overflow:auto;">
                  <div id="showdata">
                    <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse;">
                      <tr>
                        <td class="tabledata"></td>
                        <td class="tabledata">S. No.</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_material_details where req_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/reqEdit&action=Edit&reqid=<?php echo $_REQUEST['reqid'];?>&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"><?php echo $i+1;?>
                        <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[]" style="width:50px;" id="item_code_<?php echo $i;?>" value="<?php echo $item_row1['itemname'];?>" readonly >
                          <?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"  /></td>
                          <td><input type="text" name="itemname[]"  id="itemname" style="width:100%;" /></td>
                          <td>&nbsp;</td>
                          <td><input type="text" name="rqty[]"  id="rqty" style="width:100%;"/>                          </td>
                          <td><input type="text" name="price[]" id="price" style="width:100%;" />                          </td>
                          <td><input type="text" name="amt[]" 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="" />
                <div style="width:32%; float:right;">
                  <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#999999 solid 1px;">
                    <tr>
                      <td class="tabledata" style="width:120px;">Basic Amt.</td>
                      <td><input name="basicAmount" type="text"  style="width:107px;" onfocus="calculateBasic()" id="basicAmount" value="<?php echo $fetch_tt_qry['basicAmount']?>"/></td>
                    </tr>
                    <tr>
                      <td class="tabledata">Excise Duty</td>
                      <td><select name="EDBillRate" id="EDRate" style="width:107px" onchange="calculateBillExcise(this.value)" >
                          <option value="0">--Select--</option>
                          <?php
    		$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'" ;
			$ServiceRes=DB_query($ServiceSql,$db);
			while($ServiceRow=DB_fetch_array($ServiceRes))
			{
				
			?>
                          <option value="<?php echo $ServiceRow['id']?>" <?php if($fetch_tt_qry['EDBillRate']==$ServiceRow['id']) echo "selected";?>><?php echo $ServiceRow['caption']?></option>
                          <?php	
			}
    		
    		?>
                        </select>
                        <input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text"  style="width:107px;" onfocus="calculateTotalExcise()" value="<?php echo $fetch_tt_qry['totalDiscountedPrice'];?>"/>
                      </td>
                    </tr>
                    <tr>
                      <td class="tabledata">E-cess</td>
                      <td><?php  $SQl=DB_query("SELECT * FROM excise_tax WHERE caption LIKE '%Edu Cess%'",$db);
				$RESULT=DB_fetch_array($SQl);
				
				
				  ?>
                        <input type="hidden" name="ECessID" value="<?php echo $RESULT['id']?>" style="width:107px;">
                        <input name="ECessPercentage" id="ECessPercentage" type="text"   readonly style="width:107px" value="<?php echo $fetch_tt_qry['SAHCessPercentage']?>" />
                        <input name="ECessValue" id="ECessValue" type="text"   readonly onfocus="calculateECess()" style="width:107px" value="<?php echo $fetch_tt_qry['ECessValue']?>"/>
                      </td>
                    </tr>
                    <tr>
                      <td class="tabledata">She-cess</td>
                      <td><input type="hidden" name="SHECessId" value="<?php echo $fetch_tt_qry['id']?>" style="width:107px;">
                        <input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $fetch_tt_qry['SAHCessPercentage'];?>" style="width:107px;" readonly/>
                        <input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $fetch_tt_qry['SAHCessValue']?>" style="width:107px;" readonly onfocus="calculateSAHCess()"/>
                      </td>
                    </tr>
                    <tr>
                      <td class="tabledata">Total Taxable</td>
                      <td><input name="taxableAmount" id="taxableAmount" type="text" style="width:107px;" onfocus="calculateTaxable()" value="<?php echo $fetch_tt_qry['taxableAmount']?>"/></td>
                    </tr>
                    <tr>
                      <td class="tabledata">Vat/Cst</td>
                      <td><select name="VatCst" id="value3" onchange="calculateVATCST(this.value)" style="width:107px;">
                          <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>
                      <td class="tabledata">Grand Total</td>
                      <td><input name="grandTotal" id="grandTotal" type="text"  style="width:107px;" 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 check_po()"/>
                <input type="submit" name="cancel" value="Cancel" />
              </p>
            </form>
          </div>
          <!-- Tab 1 Close -->
          <div id="tabs-2">
            <form action="" method="post"  >
              <?php 
			$comment_edit="select * from salesorder_comments where sopno='".$_REQUEST['jcid']."'";
			$comment_edit1=DB_query($comment_edit,$db);
			$i=0;
			while($comment_editRow=DB_fetch_array($comment_edit1))
			{
			?>
              <div style="width:auto;">
                <p style="margin:0px; padding:0px; text-align:left; font-weight:bold">Comment</p>
                <p style="margin:0px; padding:0px; text-align:left;">
                  <textarea readonly="readonly" name="comt" style="width:700px;" ><?php echo $fetch_tt_qry['comt']?>;</textarea>
                </p>
                <p style="margin:0px; padding:0px; text-align:left; color:#003366"><?php echo 'By '.$s->GetFieldValue('www_users',"id='".$comment_editRow['user']."'",'realname'); ?>&nbsp;&nbsp;<?php echo ConvertSQLDate($comment_editRow['posted_date']); ?></p>
              </div>
              <?php $i++;} ?>
              <div style="width:auto;">
                <p style="margin:0px; padding:0px; text-align:left; font-weight:bold">
                  <?php if($_REQUEST['action']=='Edit'){echo 'Add New Comment';} ?>
                </p>
                <p style="margin:0px; padding:0px; text-align:left;">
                  <textarea name="comt" style="width:700px;" ></textarea>
                </p>
                <p style="margin:0px; padding:0px; text-align:left; color:#003366">
                  <?php if($_REQUEST['action']=='Edit'){echo 'By User';} ?>
                </p>
                <input type="submit" name="SaveComment" value="Save"  class="search" />
              </div>
            </form>
          </div>
          <!-- Tab 2 Close -->
        </div>
      </div>
    </div>
  </div>
  <!-- inside div close -->
</div>
<!-- Main div close -->
<script language="javascript" type="text/javascript">
function addRow(tableID) 
{
	
		if(document)
		var edit_cnt=document.getElementById("edit_cnt").value;
		var table = document.getElementById(tableID);
		var rowCount = table.rows.length;
		var row = table.insertRow(rowCount);
		document.getElementById("hiditemcount").value=rowCount;
		var colCount = table.rows[0].cells.length;
		for(var i=0; i<colCount; i++) 
		{	 
            var newCount=parseInt(rowCount)+parseInt(edit_cnt)-1;
			var newcell = row.insertCell(i);
           		//	 newcell.style.background='#e7e7e7';
			 newcell.className='tabledata';
			   newcell.innerHTML = table.rows[0].cells[i].innerHTML;
				switch(newcell.childNodes[0].type) 
				{
				case "text":
					newcell.childNodes[0].value = "";
					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
					newcell.childNodes[0].name = newcell.childNodes[0].name+'_'+newCount;
				break;

				case "hidden":

					newcell.childNodes[0].value = "";

					var nod_id_hidden = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;

				break;

				case "button":

					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;

				break;

				case "checkbox":

				newcell.childNodes[0].checked = false;
				var nod_id_chk = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
				

				break;

				case "select-one":
				
				newcell.childNodes[0].selectedIndex = 0;
				var nod_id = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
				break;	
			}
		}
	}
	
function deleteRowOrder(tableID) 
{
		try 
		{
			var table = document.getElementById(tableID);
			//alert(table);
			var rowCount = table.rows.length;
			//alert(rowCount);
			for(var i=0; i<rowCount; i++) 
				{
					var row = table.rows[i];
					var chkbox = row.cells[0].childNodes[0];
					if(null != chkbox && true == chkbox.checked) 
					{
						if(rowCount <= 1) 
						{
							alert("Cannot delete all the rows.");
							break;
						}
					table.deleteRow(i);
					rowCount--;
					i--;
					}
					
				}
		document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
		}
		catch(e) 
		{
			alert(e);
		}

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

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

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

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



</script>
