<?php 
$url_index= "index.php?route=ToolPlants/Transaction/fixed_asset_sale_entry_index".$rurl;
$url_add= "index.php?route=ToolPlants/Transaction/fixed_asset_sale_entry".$rurl;

if($_REQUEST['Submit'] !='' and $_REQUEST['action'] == 'addNew'){
$sql="select invoice_no from tpl_fixed_assetsales_entry where site='".$_REQUEST['site']."' ORDER BY id desc limit 1";
	$qyprefix=DB_query("Select prefix from locations Where loccode ='".$_REQUEST['site']."'",$db);
	$row_prefix=DB_fetch_array($qyprefix);
	$projectprefix=$row_prefix['prefix'];
	$result = DB_query($sql,$db);
	$numrows = DB_num_rows($result);
	if($numrows>0)
	{
	$IsuuNo=DB_fetch_array($result);
	$Explo=explode("/",$IsuuNo['invoice_no']);
	$maxval=$Explo[2];
	$strFinal = $maxval+1;
	$strBothFinal = $projectprefix."/"."FASI".'/'.str_pad($strFinal,4,"0",STR_PAD_LEFT);
	}
	else
	{
	$strBothFinal= $projectprefix."/"."FASI".'/'.'0001';
	}

	$data['invoice_no'] = $strBothFinal;
	$data['site'] = $_REQUEST['site'];
	$data['invoice_date'] = FormatDateForSQL($_REQUEST['invoice_date']);
	$data['invoice_time'] = $_REQUEST['invoice_time'];
	$data['removal_date'] = FormatDateForSQL($_REQUEST['removal_date']);
	$data['removal_time'] = $_REQUEST['removal_time'];
	$data['document_type'] = $_REQUEST['document_type'];
	$data['document_no'] = $_REQUEST['document_no'];
	$data['partyname'] = $_REQUEST['partyname'];
	$data['party_address'] = $_REQUEST['party_address'];
	$data['party_PO_no'] = $_REQUEST['party_PO_no'];
	$data['PO_date'] = FormatDateForSQL($_REQUEST['PO_date']);
	$data['dispatch_through'] = $_REQUEST['dispatch_through'];
	$data['payment_terms'] = $_REQUEST['payment_terms'];
	$data['payment_mode'] = $_REQUEST['payment_mode'];
	$data['mode_of_transport'] = $_REQUEST['mode_of_transport'];
	$data['asset_type'] = $_REQUEST['asset_type'];
	$data['basic_amount'] = $_REQUEST['basic_amount'];
	$data['excise'] = $_REQUEST['excise'];
	$data['exciseValue'] = $_REQUEST['exciseValue'];
	$data['ecessValue'] = $_REQUEST['ecessValue'];
	$data['shecessValue'] = $_REQUEST['shecessValue'];
	$data['taxable_amount'] = $_REQUEST['taxable_amount'];
	$data['VatCst'] = $_REQUEST['VatCst'];
	$data['VatCstValue'] = $_REQUEST['VatCstValue'];
	$data['other_charges'] = $_REQUEST['other_charges'];
	$data['total_sale_value'] = $_REQUEST['total_sale_value'];
	$data['deprecation_amount'] = $_REQUEST['deprecation_amount'];
	$data['created'] = date('Y-m-d');
	$data['created_by'] = $_SESSION['UserID'];
	$data['CompanyId'] = $_SESSION['ACGCompanyId'];
	
	$s->RecordInsert('tpl_fixed_assetsales_entry',$data);
//die;
	$last_id=DB_Last_Insert_Id($db,"tpl_fixed_assetsales_entry","id");
	
	if($last_id !=''){
	
		for($i=0;$i<count($_REQUEST['sale_qty']);$i++){
			if($_REQUEST['sale_qty'][$i] !=''){
				$data1['sale_id'] = $last_id;
				$data1['asset_id'] = $_REQUEST['asset_code'][$i];
				$data1['sale_qty'] = $_REQUEST['sale_qty'][$i];
				$data1['sale_price'] = $_REQUEST['sale_price'][$i];
				$data1['sale_value'] = $_REQUEST['sale_value'][$i];
				$s->RecordInsert('tpl_fixed_assetsales_entry_details',$data1);
			}		
		}	
	}
	
	$_SESSION['success_msg']="Saved Successfully";
	echo "<script>location.href='$url_index'</script>";	
}

if($_REQUEST['Submit'] !='' and $_REQUEST['action'] == 'edit'){

	$data['site'] = $_REQUEST['site'];
	$data['invoice_date'] = FormatDateForSQL($_REQUEST['invoice_date']);
	$data['invoice_time'] = $_REQUEST['invoice_time'];
	$data['removal_date'] = FormatDateForSQL($_REQUEST['removal_date']);
	$data['removal_time'] = $_REQUEST['removal_time'];
	$data['document_type'] = $_REQUEST['document_type'];
	$data['document_no'] = $_REQUEST['document_no'];
	$data['partyname'] = $_REQUEST['partyname'];
	$data['party_address'] = $_REQUEST['party_address'];
	$data['party_PO_no'] = $_REQUEST['party_PO_no'];
	$data['PO_date'] = FormatDateForSQL($_REQUEST['PO_date']);
	$data['dispatch_through'] = $_REQUEST['dispatch_through'];
	$data['payment_terms'] = $_REQUEST['payment_terms'];
	$data['payment_mode'] = $_REQUEST['payment_mode'];
	$data['mode_of_transport'] = $_REQUEST['mode_of_transport'];
	$data['asset_type'] = $_REQUEST['asset_type'];
	$data['basic_amount'] = $_REQUEST['basic_amount'];
	$data['excise'] = $_REQUEST['excise'];
	$data['exciseValue'] = $_REQUEST['exciseValue'];
	$data['ecessValue'] = $_REQUEST['ecessValue'];
	$data['shecessValue'] = $_REQUEST['shecessValue'];
	$data['taxable_amount'] = $_REQUEST['taxable_amount'];
	$data['VatCst'] = $_REQUEST['VatCst'];
	$data['VatCstValue'] = $_REQUEST['VatCstValue'];
	$data['other_charges'] = $_REQUEST['other_charges'];
	$data['total_sale_value'] = $_REQUEST['total_sale_value'];
	$data['deprecation_amount'] = $_REQUEST['deprecation_amount'];
	
	$s->RecordEdit('tpl_fixed_assetsales_entry',$data,"id='".$_REQUEST['id']."'");
	
	for($i=0;$i<count($_REQUEST['sale_qty']);$i++){
	if($_REQUEST['sale_qty'][$i] !=''){
		$data1['sale_id'] = $last_id;
		$data1['asset_id'] = $_REQUEST['asset_code'][$i];
		$data1['sale_qty'] = $_REQUEST['sale_qty'][$i];
		$data1['sale_price'] = $_REQUEST['sale_price'][$i];
		$data1['sale_value'] = $_REQUEST['sale_value'][$i];
		$s->RecordEdit('tpl_fixed_assetsales_entry_details',$data1,"id='".$_REQUEST['assetRowId'][$i]."'");
	}
}	
	$_SESSION['success_msg']="Saved Successfully";
	echo "<script>location.href='$url_index'</script>";	
}

if($_REQUEST['action']=='edit' and $_REQUEST['act']=='delAssets')
{
	$condition="id='".$_REQUEST['aid']."'";
	$s->DeleteRecord('tpl_fixed_assetsales_entry_details',  $condition);	
}

if($_REQUEST['id'] !=''){

$sql = "SELECT S.*, C.c_name,C.pre_address1, P.terms 
		FROM tpl_fixed_assetsales_entry S 
		INNER JOIN clientmaster C ON C.id=S.partyname
		LEFT JOIN paymentterms P ON P.termsindicator=C.payment_terms
		WHERE S.id='".$_REQUEST['id']."'";
$result = DB_query($sql,$db);
$row = DB_fetch_array($result);

extract($row);
}

?>
<link rel="stylesheet" href="css/new_mxerp.css">
<style type="text/css">
#amc-tab{}
  #amc-tab table{border:none; }
  #amc-tab table tr td{border-right:#808080 1px solid; border-bottom:#808080 1px solid;}
  #amc-tab table tr td:last-child{border-right:none;}
  #amc-tab table tr:last-child td{border-bottom:none;}
  #amc-tab table tr td > table tr td{border-right:#808080 1px solid; border-bottom:#808080 1px solid;}
  #amc-tab table tr td > table tr td:last-child{border-right:none;}
  #amc-tab table tr td > table tr:last-child td{border-bottom:none;}
</style>
<div class="body_contain">
<div class="tab_div">
<h1>Fixed Asset Sale Entry</h1>
<script src="ui/jquery.ui.timepicker.js"></script>
<form action="" name="frm_sale_entry" method="post">	
<h3><strong>General Details</strong></h3>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
  <tr class="row1">
    <td width="13%" style="text-align:right;">Site</td>
    <td width="20%"><select name="site" id="site" style="width:98%;">
    <option value="0">-Select -</option>
     <?php 
		echo $site_sql = "Select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_result = DB_query($site_sql,$db);
		while($site_row = DB_fetch_array($site_result))
		{
		?>
         <option value="<?php echo $site_row['loccode']; ?>" <?php echo ($site_row['loccode']==$site) ? "selected" : "";?> ><?php echo $site_row['locationname']; ?></option>
            <?php } ?>
    </select></td>
    <td width="13%" style="text-align:right;"><strong>Invoice No.</strong></td>
    <td width="20%"><input name="" id="" type="text" class="" style="width:98%;" value="<?php echo ($invoice_no !='') ? $invoice_no: "Auto Generate";?>" readonly=""/></td>
    <td width="13%" style="text-align:right;"><strong>Invoice Date &amp; Time</strong></td>
    <td><input name="invoice_date" id="invoice_date" value="<?php echo ($invoice_date !='') ? ConvertSQLDate($invoice_date) : "";?>" type="text" class="cap datepicker" style="width:74%; float:left; margin-right:3px;"/><input type="text" name="invoice_time" id="invoice_time" class="timepicker" style="width:23%; float:left;" value='<?php if($invoice_time!=''){ echo $invoice_time; } ?>'>   
	</td>
  </tr>
  <tr class="row1">
  	<td style="text-align:right;"><strong>Removal Date &amp; Time </strong></td>
    <td><input name="removal_date" id="removal_date" value="<?php echo ($removal_date !='') ? ConvertSQLDate($removal_date) : "";?>" type="text" class="cap datepicker" style="width:74%; float:left; margin-right:3px;"/><input type="text" name="removal_time" id="removal_time" class="timepicker" style="width:23%; float:left;" value='<?php if($removal_time!=''){ echo $removal_time; } ?>'></td>
    <td style="text-align:right;"><strong>Document Type</strong></td>
    <td><select style="width:98%;" name="document_type" id="document_type">
      <option>--Select--</option>
      <option value="Bill" <?php echo ($document_type=='Bill') ? "selected" : "";?>>Bill</option>
    </select></td>
	<td style="text-align:right;"><strong>Document No.</strong></td>
    <td><input name="document_no" id="document_no" type="text" class="" value="<?php echo $document_no;?>" style="width:98%;" /></td>
  </tr>
  <tr class="row1">
  	<td style="text-align:right;"><strong>Party Name</strong></td>
    <td><select style="width:98%;" name="partyname" id="partyname" onchange="GetPartyAddress(this.value);">
      		<option>--Select--</option>
      	<?php
			$sqlparty = "SELECT * FROM clientmaster WHERE CompanyId ='".$_SESSION['ACGCompanyId']."'";
			$result = DB_query($sqlparty,$db);
			while($partyRow=DB_fetch_array($result)){	
		?>
			<option value="<?php echo $partyRow['id'];?>" <?php echo ($partyRow['id']==$partyname) ? "selected" : "";?>>
				<?php echo $partyRow['c_name'];?>
			</option>
			
		<?php }?>
    </select></td>
    <td style="text-align:right;"><strong>Party PO No.</strong></td>
    <td><input name="party_PO_no" id="party_PO_no" type="text" class="" style="width:98%;" value="<?php echo $party_PO_no;?>" /></td>
    <td style="text-align:right;"><strong>Party PO Date</strong></td>
    <td><input name="PO_date" id="PO_date" type="text" class="cap datepicker" value="<?php echo ($PO_date !='')? ConvertSQLDate($PO_date) : "";?>" style="width:98%;" readonly="true" /></td>
  </tr>
  <tr class="row1">
  	<td style="text-align:right;"><strong>Address</strong></td>
    <td id="client_address"><textarea name="party_address" style="width:98%" id="party_address"><?php echo $party_address;?></textarea></td>
    <td style="text-align:right;"><strong>Dispatch Through</strong></td>
    <td><select style="width:98%;" name="dispatch_through" id="dispatch_through">
      <option value="Road" <?php echo ($dispatch_through == 'Road') ? "selected" : "";?>>Road</option>
      <option value="Air" <?php echo ($dispatch_through == 'Air') ? "selected" : "";?>>Air</option>
      <option value="Train" <?php echo ($dispatch_through == 'Train') ? "selected" : "";?>>Train</option>
      <option value="Sea" <?php echo ($dispatch_through == 'Sea') ? "selected" : "";?>>Sea</option>
    </select></td>
    <td style="text-align:right;"><strong>Payment Terms</strong></td>
    <td id="client_payment">	
	<select style="width:98%;" name="payment_terms" id="payment_terms">
	<?php if($_REQUEST['id'] !=''){?>
		<option value="<?php echo $payment_terms;?>"><?php echo $terms;?></option>
	<?php }else{?>
      <option>--Select--</option>
	  <?php }?>
    </select>	
	</td>
  </tr>
  <tr class="row1">
  	<td style="text-align:right;"><strong>Payment Mode</strong></td>
    <td><select style="width:98%;" name="payment_mode" id="payment_mode">
      <option value="Cheque" <?php echo ($payment_mode == 'Cheque') ? "selected" : "";?>>Cheque</option>
      <option value="Cash" <?php echo ($payment_mode == 'Cash') ? "selected" : "";?>>Cash</option>
      <option value="RTGS" <?php echo ($payment_mode == 'RTGS') ? "selected" : "";?>>RTGS</option>
      <option value="Other" <?php echo ($payment_mode == 'Other') ? "selected" : "";?>>Other</option>
    </select></td>
    <td style="text-align:right;"><strong>Mode of Transport</strong></td>
    <td><input name="mode_of_transport" id="mode_of_transport" type="text" class="" style="width:98%;" value="<?php echo $mode_of_transport;?>" /></td>
    <td colspan="2">&nbsp;</td>
  </tr>
</table>

<br />
<h3><strong>Add Assets</strong></h3>
<p align="left">
	<input type="button" onClick="addRow('dataTable')" value="Add Row" accesskey="A" class="search" />&nbsp;
	<input type="button" value="Delete Row" name="item_popup" class="search"  onclick="deleteRow('dataTable');">
	<input type="button" name="profile_popup" value="Pick Asset" id="profile_popup"  onclick="open_items()" accesskey="I" class="search" />
	</p>
<!--<h3><strong></strong></h3>-->
<table width="100%" align="center" border="1" cellpadding="3" cellspacing="0" style="border:#808080 1px solid; border-collapse:collapse; background:#ffffff;">
  <tr>
    <th width="3%">&nbsp;</th>
    <th width="3%">&nbsp;</th>
    <th width="8%">Asset Code</th>
    <th>Asset name</th>
    <th width="8%">Serial No</th>
    <th width="8%">Model No.</th>
    <th width="9%">Vehicle No.</th>
    <th width="9%">Purchase Date</th>
    <th width="12%">Purchase Amount</th>
    <th width="11%">Sale Qty</th>
    <th width="8%">Sale Price</th>
    <th width="9%">Sale Value</th>
  </tr>
  <?php 
  	if($_REQUEST['id'] !=''){
	$sqlAst = "SELECT S.asset_id, S.sale_qty, S.sale_value, S.sale_price, A.asset_name, A.asset_code_prefix, A.serial_no, 	
						   A.model_no, A.vehicle_no, A.purchase_date, A.asset_amount, U.unitname 
						   FROM tpl_fixed_assetsales_entry_details S
						   INNER JOIN tpl_fixed_asset_definition A on A.id=S.asset_id
						   LEFT JOIN unitsofmeasure U on U.unitid=A.unit_of_measurement
						   where S.sale_id='".$_REQUEST['id']."'";
						   
	$res = DB_query($sqlAst,$db);
	$i=0;
	while($assetRow = DB_fetch_array($res)){?>
	 <tr bgcolor="#ffffff">
		<td><a href="<?php echo $url_add;?>&action=edit&id=<?php echo $_REQUEST['id'];?>&act=delAssets&aid=<?php echo $assetRow['id'];?>"><img src="images/delete.gif" /></a></td>
		<td style="width:1%"><input type="hidden" name="asset_code[]" id="asset_code_<?php echo $i;?>" value="<?php echo $assetRow['asset_id'];?>" /><input type="hidden" name="assetRowId[]" id="assetRowId_<?php echo $i;?>" value="<?php echo $assetRow['id'];?>" /></td>
		<td><?php echo $assetRow['asset_code_prefix'];?></td>
		<td><?php echo $assetRow['asset_name'];?></td>
		<td><?php echo $assetRow['serial_no'];?></td>
		<td><?php echo $assetRow['model_no'];?></td>
		<td><?php echo $assetRow['vehicle_no'];?></td>
		<td><?php echo $assetRow['purchase_date'];?></td>
		<td><?php echo $assetRow['asset_amount'];?><input type="hidden" name="purchage_amount[]" id="purchage_amount_<?php echo $i;?>" value="<?php echo $assetRow['asset_amount'];?>" /></td>
		<td><input type="text" name="sale_qty[]" id="sale_qty_<?php echo $i;?>" style="width:98%;" value="<?php echo $assetRow['sale_qty'];?>" /></td>
		<td><input type="text" name="sale_price[]" id="sale_price_<?php echo $i;?>" style="width:98%;" value="<?php echo $assetRow['sale_price'];?>" /></td>
		<td><input type="text" name="sale_value[]" id="sale_value_<?php echo $i;?>" style="width:98%;" value="<?php echo $assetRow['sale_value'];?>" onfocus="calSaleValue(this.id,sale_price);" /></td>
  </tr>
	<?php $i++;} 
	$editcount = $i; 
	}
	?>
  
 <tbody id="dataTable">
  <tr bgcolor="#ffffff">
	<td><input type="checkbox" name="select[]" id="select" onchange="checkdata(<?php echo $i; ?>)"></td>
	<td style="width:1%"><input type="hidden" name="asset_code[]" id="asset_code" /></td>
	<td><input type="text" name="" id="assetcode" value="" style="width:98%;" /></td>
	<td><input type="text" name="asset_name[]" id="assetname" value="" style="width:98%;" /></td>
	<td><input type="text" name="serial_no[]"  id="serial_no" value="" style="width:98%;"></td>
	<td><input type="text" name="model_no[]" id="model_no" value="" style="width:98%;"/></td>
	<td><input type="text" name="vehicle_no[]" id="vehicle_no" style="width:98%;" /></td>
	<td><input type="text" name="purchage_date[]" id="purchage_date" style="width:98%;" /></td>
	<td><input type="text" name="purchage_amount[]" id="purchage_amount" style="width:98%;" /></td>
	<td><input type="text" name="sale_qty[]" id="sale_qty" style="width:98%;" value="" /></td>
	<td><input type="text" name="sale_price[]" id="sale_price" style="width:98%;" value="" /></td>
	<td><input type="text" name="sale_value[]" id="sale_value" style="width:98%;" value="" onfocus="calSaleValue(this.id,sale_price);" /></td>
  </tr>
 </tbody>
</table>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
<input type="hidden" name="" value="<?php echo $editcount;?>" id="edit_cnt" />

<br />
<!--<h3><strong></strong></h3>-->

<table width="40%" align="right" border="1" cellpadding="3" cellspacing="0" style="border:#808080 1px solid; border-collapse:collapse; background:#ffffff;">
  <tr>
    <td widtd="40%" align="left"><strong>Basic Amount</strong></td>
    <td><input name="basic_amount" id="basic_amount" type="text" class="" style="width:100%;" value="<?php echo $basic_amount;?>" onfocus="calBasic();"/></td>
  </tr>
  <tr>
    <td align="left"><strong>Excise</strong></td>
    <td>
		<select style="width:98%;" name="excise" id="excise" onchange="calculateExcise(this.value);">
      		<option>--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['id'] ==$excise ) ? "selected" : "";?>><?php echo $ServiceRow['caption']?></option>
			<?php	
			}
			
			?>
	    </select>
	</td>
  </tr>
  <tr>
  	<td><strong>Excise Value</strong></td>
	<td><input name="exciseValue" id="exciseValue" type="text" value="<?php echo $exciseValue;?>" size="25" style="width:98%;" readonly />
</td>
  </tr>
  <tr>
    <td align="left"><strong>E-Cess</strong></td>
    <td><input name="ecessValue" id="ecessValue" value="<?php echo $ecessValue;?>" type="text" class="" style="width:98%;"  /></td>
  </tr>
  <tr>
    <td align="left"><strong>She-Cess</strong></td>
    <td><input name="shecessValue" id="shecessValue" value="<?php echo $shecessValue;?>" type="text" class="" style="width:98%;"/></td>
  </tr>
  <tr>
    <td align="left"><strong>Taxable Amount</strong></td>
    <td><input name="taxable_amount" id="taxable_amount" type="text" class="" style="width:98%;" value="<?php echo $taxable_amount;?>" onfocus="calTaxable();"/></td>
  </tr>
  <tr>
    <td align="left"><strong>VAT/CST</strong></td>
    <td>
		<select name="VatCst" id="VatCst" onchange="calculateVATCST(this.value)" style="width:98%;">
		<option value="">Select</option>
		<?php 
		$salesSql=DB_query("Select salestax_id, tax_code 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>
	</td>
  </tr>
  <tr>
  <td><strong>VAT/CST Amount</strong></td>
  <td><input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $VatCstValue?>" style="width:98%;" readonly  onfocus="calculateEditVATCST()" /></td>
  </tr>
  <tr>
    <td align="left"><strong>Other Charges</strong></td>
    <td><input name="other_charges" id="other_charges" type="text" class="" style="width:98%;" value="<?php echo $other_charges;?>"/></td>
  </tr>
  <tr>
    <td align="left"><strong>Total Sale Value</strong></td>
    <td><input name="total_sale_value" id="total_sale_value" type="text" class="" style="width:98%;" value="<?php echo $total_sale_value;?>" onfocus="calTotal();"/></td>
  </tr>
  <tr>
    <td align="left"><strong>Deprecation Amount</strong></td>
    <td><input name="deprecation_amount" id="deprecation_amount" type="text" class="" style="width:98%;" value="<?php echo $deprecation_amount;?>" onfocus="calDeprecation();"/></td>
  </tr>
</table>

<h3><strong>Add Assets</strong></h3>

<table width="100%" align="center" border="1" cellpadding="3" cellspacing="0" style="border:#808080 1px solid; border-collapse:collapse; background:#fff;">
<tr class="row1">
	<td class="tabledata1" style="text-align:center;" colspan="4">
	<input type="submit" name="Submit" value="Save" class="search" id="Submit" onclick="return validate();" />
	</td>
</tr>

</table>

</form>
<script type="text/javascript">

function GetPartyAddress(str){

if (str.length==0)
{
	  document.getElementById("client_info").innerHTML='<textarea name="tpl_fixed_assetsales_entry[party_address]" rows="3" cols="15" style="width:220px;" ></textarea>';
	return;
}
if (window.XMLHttpRequest)
{
 xmlhttp=new XMLHttpRequest();
}else{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var data = xmlhttp.responseText.split("__");
			document.getElementById("client_address").innerHTML=data[0];
			document.getElementById("client_payment").innerHTML=data[1];
		}
	}
	
	xmlhttp.open("GET","get_client_info.php?site="+str,true);
	xmlhttp.send();


}

function calculateExcise(str){

if (str.length==0)
{
	document.getElementById("exciseValue").value='0';
	document.getElementById("ecessValue").value='0';
	document.getElementById("shecessValue").value='0';
	return;
}
if (window.XMLHttpRequest)
{
 xmlhttp=new XMLHttpRequest();
}else{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var data = xmlhttp.responseText.split("__");
			document.getElementById("exciseValue").value=data[0];
			document.getElementById("ecessValue").value=data[1];
			document.getElementById("shecessValue").value=data[2];

		}
	}
	var amt = document.getElementById("basic_amount").value;
	xmlhttp.open("GET","calculateExciseNew.php?taxId="+str+"&discounted="+amt,true);
	xmlhttp.send();
}

function calculateVATCST(str)
{
	if (str.length==0)
	{
	document.getElementById("VatCstValue").value="";
	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("VatCstValue").value=xmlhttp.responseText;
	}
	}
	var amt = document.getElementById("taxable_amount").value;
	
	xmlhttp.open("GET","calculateExciseNew.php?salesId="+str+"&taxable="+amt,true);
	xmlhttp.send();
}

function open_items()
{
if(document.getElementById("site").value != 0)
{
var site= document.getElementById("site").value;
	window.open("pick_fixed_assets_sale.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&reid=<?php echo $_REQUEST['rid']; ?>&action1=<?php echo $_REQUEST['action']; ?>&project="+site,"item_popup_window","height=500,width=700,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}else{
	alert("Select Branch First");
}
}
	

function validate()
{
	if(document.getElementById("site").value=='0')
	{
		alert("Please Select The Site");
		return false;
	}
	if(document.getElementById("invoice_date").value=='')
	{
		alert("Please Select The Invoice");
		return false;
	}
	
	if(document.getElementById("invoice_time").value=='')
	{
		alert("Please Enter Invoice Time");
		return false;
	}
	
	if(document.getElementById("removal_date").value=='')
	{
		alert("Please Select Removal Date");
		return false;
	}
	
	if(document.getElementById("removal_time").value=='')
	{
		alert("Please Enter Removal Time");
		return false;
	}
	if(document.getElementById("partyname").value =='')
	{
		alert("Plaese Select Party Name");
	}
	
	var assets = document.getElementsByName("asset_code[]");
	if(assets[0].value =='')
	{
		alert("Select at least 1 Asset");
		return false;
	}
	
}

function addRow(tableID) 
{
	if(document)
	if(document.getElementById("edit_cnt").value!='')
	{
		var edit_cnt=parseInt(document.getElementById("edit_cnt").value);
	}
	else
	{
	edit_cnt=1;
	}
	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='row1';
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	break;
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id_hidden = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id_chk = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	break;	
	}
	}
}


function calSaleValue(id){

var ids = id.split("_");
var sale_amt = 0;
if(ids.length>2){
	var qty = parseFloat(document.getElementById("sale_qty_"+ids[2]).value);
	var price = parseFloat(document.getElementById("sale_price_"+ids[2]).value);
	if(qty !='' && price !='')
	{
		sale_amt = qty*price;
	}
	
	document.getElementById("sale_value_"+ids[2]).value = parseFloat(sale_amt);


}else{

	var qty = parseFloat(document.getElementById("sale_qty").value);
	var price = parseFloat(document.getElementById("sale_price").value);
	
	
	if(!isNaN(qty) && !isNaN(price))
	{
		sale_amt = qty*price;
		
	}
	
	document.getElementById("sale_value").value = parseFloat(sale_amt);
  }
}

function calBasic(){

	var basic = 0;
	var basic1 = parseFloat(document.getElementById("sale_value").value);
	var basic2 = 0;
	var count1 = 0;
	var count2 = 0;;
	if(document.getElementById("hiditemcount").value !='')
		count1 = parseInt(document.getElementById("hiditemcount").value);
	if(document.getElementById("edit_cnt").value !='')	
		count2 = parseInt(document.getElementById("edit_cnt").value);
	
	var count = count1+count2;
	if(count>0){
		var i = '<?php if($_REQUEST['action']=='edit') echo 0; else echo 1;?>';
		'<?php if($_REQUEST['action']=='addNew') {?>'; count = count+1; '<?php }?>';

		for(i; i<count; i++){
			basic2 += parseFloat(document.getElementById("sale_value_"+i).value);
		}
	}
	basic = basic1+basic2;
	document.getElementById("basic_amount").value = parseFloat(basic);

}

function calTaxable(){

	var basic = 0;
	var exciseVal = 0;
	var ecessVal = 0;
	var shecess = 0;  
	var taxable = 0; 

	if(!isNaN(document.getElementById("basic_amount").value))
		basic = parseInt(document.getElementById("basic_amount").value);
		
	if(!isNaN(document.getElementById("exciseValue").value))
		exciseVal = parseInt(document.getElementById("exciseValue").value);
		
	if(!isNaN(document.getElementById("ecessValue").value))
		ecessVal = parseInt(document.getElementById("ecessValue").value);	
	
	if(!isNaN(document.getElementById("shecessValue").value))
		shecess = parseInt(document.getElementById("shecessValue").value);	

	taxable = basic+exciseVal+ecessVal+shecess;
	document.getElementById("taxable_amount").value = parseFloat(taxable);

}

function calTotal(){
	
	var basic = 0;
	var exciseVal = 0;
	var ecessVal = 0;
	var shecess = 0;  
	var vat = 0; 
	var others =0;
	var total = 0;

	if(!isNaN(document.getElementById("basic_amount").value))
		basic = parseFloat(document.getElementById("basic_amount").value);
		
	if(!isNaN(document.getElementById("exciseValue").value))
		exciseVal = parseFloat(document.getElementById("exciseValue").value);
		
	if(!isNaN(document.getElementById("ecessValue").value))
		ecessVal = parseFloat(document.getElementById("ecessValue").value);	
	
	if(!isNaN(document.getElementById("shecessValue").value))
		shecess = parseFloat(document.getElementById("shecessValue").value);
			
	if(!isNaN(document.getElementById("VatCstValue").value))
		vat = parseFloat(document.getElementById("VatCstValue").value);
		 		
	if(!isNaN(document.getElementById("other_charges").value))
		others = parseFloat(document.getElementById("other_charges").value);	
			
	total = basic+exciseVal+ecessVal+shecess+vat+others;
	
	document.getElementById("total_sale_value").value = parseFloat(total);

}

function calDeprecation(){

	var purchase = 0;
	var purchase1= parseFloat(document.getElementById("purchage_amount").value);
	var purchase2 = 0;
	var count1 = 0;
	var count2 = 0;
	var total_amount = 0;
	var deprecation_amount = 0;
	
	if(document.getElementById("hiditemcount").value !='')
		count1 = parseInt(document.getElementById("hiditemcount").value);
	if(document.getElementById("edit_cnt").value !='')	
		count2 = parseInt(document.getElementById("edit_cnt").value);
	
	var count = count1+count2;
	if(count>0){
		for(var i=1;i<=count; i++){
			purchase2 += parseFloat(document.getElementById("purchage_amount_"+i).value);
		}
	}
	
	if(!isNaN(document.getElementById("total_sale_value").value))	
		total_amount = parseFloat(document.getElementById("total_sale_value").value);

	purchase = purchase1+purchase2;
	deprecation_amount = purchase-total_amount;
	document.getElementById("deprecation_amount").value = parseFloat(deprecation_amount);

}

$('.timepicker').timepicker();


</script>
