
<?php session_name('CAKEPHP'); session_start();	
$PageSecurity = 1;
$tabindex=0;
include('includes/DefinePaymentClass.php');
$title = _('Telephonic Order Memo');
include('includes/SQL_CommonFunctions.inc');
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<style>
#showdata {
	display: block;
	background: url(Default.png) no-repeat;
	top: 0px;
	left: 0px;
	width: 300px;
	min-height: 60px;
	z-index:0;
}
#back {
	display: none;
	top: 0px;
	left: 0px;
	width: 300px;
	min-height: 60px;
	z-index:0;
}
</style>
<?php 
if(($_REQUEST['Save']))
{
	$prefix_sql=DB_query("Select prefix from locations where loccode='".$_REQUEST['branch']."' ",$db);
    $prefix_row=DB_fetch_array($prefix_sql);
    $branchPrefix=$prefix_row['prefix'];

    $orderNo_sql="Select id,requirement_id from trouble_ticket_jobcard_material where branch='".$_REQUEST['branch']."' order by id desc limit 1";
   $orderResult=DB_query($orderNo_sql,$db);

   if(DB_num_rows($orderResult)>0)
    {
	$orderNo_row=DB_fetch_array($orderResult);	
 	$OrderNo=$orderNo_row['requirement_id'];
	$OrderNo_brk1=substr($OrderNo,0,7);
	$OrderNo_brk2=substr($OrderNo,-4);
	$next=$OrderNo_brk2+1;
	$sql_orderNo=$OrderNo_brk1.str_pad($next,4,"0",STR_PAD_LEFT);
	
  }
  else
  {
	$sql_orderNo=$branchPrefix."/RQ/00001";
  }	
 	$sql1="Insert into trouble_ticket_jobcard_material set
			branch='".$_REQUEST['branch']."', 
			requirement_id='".$sql_orderNo."',
			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']."',
			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']."'";
					
	$result1=DB_query($sql1,$db);
	$TicketId=DB_Last_Insert_ID($db,'trouble_ticket_jobcard_material','id');

if(isset($TicketId))
{
	for($i=0;$i<count($_REQUEST['itemname']);$i++)
	{
		if($_REQUEST['itemname'][$i]!='')
		{
			$data_arr['req_id']=$TicketId;
			$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());
			}
		}
	}
}




echo "<script>location.href='index.php?route=service/view_job_card_material&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
prnMsg( _('Material Order inserted successfully'),'success');}


unset($_POST);
?>
<script language="JavaScript">
function addRow(tableID) 
{
//alert(tableID);
	if(document)
		//document.getElementById("back").style.display = "none";
    	//document.getElementById("showdata").style.display = "block";
		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 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+'_'+rowCount;
					
					
				break;

				case "hidden":

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

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

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

				break;

				case "button":

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

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

				break;

				case "checkbox":

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

				break;

				case "select-one":
				
				newcell.childNodes[0].selectedIndex = 0;
				var nod_id = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				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=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}
	
/*function open_items()
{
window.open("open_item.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>","item_popup_window","height=500,width=700,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}
function open_items(i)
{ 
	window.open("open_item.php?rowcount="+i,"profiles_popup_window","height=425,width=640,toolbar=no,menubar=no,dependent=yes,resizable=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("techId").value=data[5];
	document.getElementById("techId1").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">
  <div class="tab_div">
    <form action="" method="post">
      <h1>Job Card Material Creation</h1>
      <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 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 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  if($_REQUEST['requirement_id']=='') echo 'Auto Generated'; else $_REQUEST['requirement_id'] ;?>" />          </td>
          <td class="tabledata1">Technician Name</td>
          <td colspan="2">
            <input name="technician_name1" id="techId" style="width:100%" value="" />
			<input name="technician_name" id="techId1" style="visibility:hidden; height:1px;" value="" />	
		</td>
         
        </tr>
		
        <tr>
			<td class="tabledata1">TT No.</td>
          <td colspan="2">
            <input name="tt_no1" id="ttNo" style="width:100%" value="" />
			<input name="tt_no" id="ttNo1" style="visibility:hidden; height:1px;" value="" />	
		</td>
          <td class="tabledata1">Party Name</td>
          <td colspan="2">
            <input name="part_name1" id="partyId" style="width:100%" value="" />
			<input name="part_name" id="partyId1" style="visibility:hidden; height:1px;" value="" />	
		</td>
        </tr>
		<tr>
			<td class="tabledata1">Product Name</td>
          <td colspan="2">
		    <input name="product_name1" id="productId" style="width:100%" value="" />
			<input name="product_name" id="productId1" style="visibility:hidden; height:1px;" value="" />
         </td>
          <td class="tabledata1">Serial No.</td>
          <td colspan="2"><input name="serial_no" id="serialNo" value=""  /></td>
        </tr>
        <tr>
          <td class="tabledata1" scope="row">Fault Details.</td>
          <td colspan="5"><input name="prob_desc" type="text" id="prob_desc" value="" 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="Add Spare Part" id="profile_popup"  onclick="open_items()" class="search" />
        </p>
        <!-- <p style="padding-left:0px; margin:0; text-align:left;">
          <input type="button" value="Add Spare Part" name="item_popup" class="heading_button"  onclick="open_items(this.id)">
          &nbsp;&nbsp;
          <input type="button" value="Add Service" class="heading_button" />
        </p>-->
		
        <div style="width:806px; overflow:auto;">
          <div id="showdata">
            <table width="806" border="1" cellspacing="0" cellpadding="3">
              <tr>
                <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>
              <!--<tr bgcolor="#c1c1c1">
              <tbody id="dataTable">
                <tr bgcolor="#c1c1c1">
                  <td><input name="delitem[]" type="checkbox" value="<?php echo $item_row['id'];?>" />
				  <input type="hidden" name="item_code[]" id="item_code" 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="20"/>                  </td>
                  <td><input type="text" name="price[]" id="price" size="20" />                  </td>
                  <td><input type="text" name="amt[]" id="amt" size="20" onkeyup="calculateTotalAmt(this.id)"/></td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
		<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
        <input type="hidden" name="" value="" id="edit_cnt" />
		
		<?php 
			 $basic = DB_query("Select * from trouble_ticket_creation",$db);
 			$basicAmount=DB_fetch_array($basic);
		?>
		<div style="width:806px; overflow:auto;">
			<div id="back">
				<table width="806" 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="240" class="tabledata">Service Amount</td>
              </tr>
			   <tbody id="serviceID">
				<tr bgcolor="#c1c1c1">
                  <td><input name="delitem[]" type="checkbox" value="<?php echo $item_row['id'];?>" />
				  </td>
				  <td> <input type="text" name="service[]" id="service" size="40"/></td>
                  <td><?php $serv= DB_query("SELECT * FROM services_type",$db);?>
				  	<select name="service_type[]" style="width:50%" 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:50%">
						<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><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="" />
        <input type="hidden" name="" value="" id="edit_cnt1" />
        <p style="padding-left:5px;padding-top:5px; margin:0; text-align:left;">
          <input type="button" value="Add" class="submit_button" />
          &nbsp;&nbsp;
          <input type="button" value="Delete" class="submit_button" />
        </p>
        <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"/></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 echo $ServiceRow['caption']?></option>
                  <?php	
					}
					
					?>
                </select>
                <input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text"  style="width:107px;" onfocus="calculateTotalExcise()"/>
              </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" value="<?php echo $RESULT['def_rate'];?>"  readonly style="width:107px" />
                <input name="ECessValue" id="ECessValue" type="text"   readonly onfocus="calculateECess()" style="width:107px"/>
              </td>
            </tr>
            <tr>
              <td class="tabledata">She-cess</td>
              <td>
			  <?php  $SQl1=DB_query("SELECT * FROM excise_tax WHERE caption LIKE '%SHE Cess%'",$db);
				$RESULT1=DB_fetch_array($SQl1);
				
				
				  ?>
			  <input type="hidden" name="SHECessId" value="<?php echo $RESULT['id']?>" style="width:107px;">
                <input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $RESULT1['def_rate'];?>" style="width:107px;" readonly/>
                <input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $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()"/></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 $VatCst==$salesRow['salestax_id']?'selected':''?>><?php echo $salesRow['tax_code'];?></option>
                  <?php 	
					}
					?>
                </select>
                <div id="VATId">
                  <input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $VatCstValue?>" style="width:107px;" readonly  onfocus="calculateEditVATCST()" />
                </div>
                <input type="hidden" name="" id="rate" value="<?php echo $rate;?>" />
              </td>
            </tr>
            <!--<tr>
              <td class="tabledata">Other Charges</td>
              <td>&nbsp;</td>
            </tr>-->
            <tr>
              <td class="tabledata">Grand Total</td>
              <td><input name="grandTotal" id="grandTotal" type="text"  style="width:107px;" onfocus="calculateGrand()" readonly="readonly"  /></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>
</div>
<script>
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;
 	}
 }
xmlhttp.open("GET","getservicedata.php?id="+str,true);
xmlhttp.send();
}

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 calculateBasic()
{
	var totalBasic=0;
	var first_row=document.getElementById("amt").value;
	if(first_row==''){first_row=0;}
	var cnt=document.getElementById("hiditemcount").value;
	var newcount=parseInt(cnt)+1;
	for(var i=1;i<newcount;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 calculateTotalExcise()
{
	var EDRate=document.getElementById("EDRate").value;
	if(EDRate==0){
	var totalExcise=0;
	var first_row=document.getElementById("excisevalue").value;
	//if(first_row==''){first_row=0;}
	var cnt=document.getElementById("hiditemcount").value;
	var newcount=parseInt(cnt)+1;
	for(var i=1;i<newcount;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 calculateTotalExcise()
{
	var EDRate=document.getElementById("EDRate").value;
	if(EDRate==0){
	var totalExcise=0;
	var first_row=document.getElementById("excisevalue").value;
	//if(first_row==''){first_row=0;}
	var cnt=document.getElementById("hiditemcount").value;
	var newcount=parseInt(cnt)+1;
	for(var i=1;i<newcount;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 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);
}
</script>
