function calculateExtraItemSubTotal(){
	
	var rowCount=parseInt($('#rowCount_e').val());
	var service_sub_tot=0;
	var error=false;
	for(i=1; i<=rowCount; i++){
		
		
		price_fld='#price_'+i;
		var price=($(price_fld).val());
		
		//check is numaric
		if($.isNumeric(price)){
			service_sub_tot+=parseFloat(price);
		}
		else {

		}	
	}	
	
	$('#service_sub_tot').val(service_sub_tot);
	$('#service_sub_tot_dis').text(convertToAmount(service_sub_tot));
	
}

function calculateExtraItemGrandTotal(){
	
	
	//alert();
	calculateExtraItemSubTotal();
	calculateTechnicianSubTotal();
	
	calculateTotal();
	
	//set parts sub total 
	var parts_sub_tot=$('#parts_sub_tot').val();
	$('#Subtotal').text(convertToAmount(parts_sub_tot));
	
	
	
	var service_sub_tot=parseFloat($('#service_sub_tot').val());	
	var technician_sub_tot=parseFloat($('#technician_sub_tot').val());	
	var parts_sub_tot=parseFloat($('#parts_sub_tot').val());
	
	var grand_total_sub_tot=service_sub_tot+technician_sub_tot+parts_sub_tot;
	
	
	
	
	

	//set val
	$('#service_sub_tot_footer_dis').text(convertToAmount(service_sub_tot));
	$('#service_sub_tot_summ_dis').text(convertToAmount(service_sub_tot));
	
	$('#technician_sub_tot_footer_dis').text(convertToAmount(technician_sub_tot));
	$('#technician_sub_tot_summ_dis').text(convertToAmount(technician_sub_tot));
	
	$('#parts_sub_tot_footer_dis').text(convertToAmount(parts_sub_tot));
	$('#parts_sub_tot_summ_dis').text(convertToAmount(parts_sub_tot));
	
	$('#grand_total_sub_tot_footer_dis').text(convertToAmount(grand_total_sub_tot));
	$('#grand_total_sub_tot_summ_dis').text(convertToAmount(grand_total_sub_tot));
	$('#grand_total').val((grand_total_sub_tot));
	
	
	
	//alert(service_sub_tot);
	
}


	jQuery(document).ready(function() {
		
		FormValidator.init();
		
		//hide error box
		$('.alert-danger').hide();
	});
	
	jQuery(document).ready(function() {
		
		
		
		
	//conirm
	$( "#conirm" ).click(function() {
		var sel_id=$('#sel_id').val(); 
		var popup_type=$('#popup_type').val();
		var page=$('#page').val();
		var row_id=sel_id;
		
if(page=='vehicle_service'){
	if(popup_type=='delete'){
		var tmp='#row_sr_'+row_id;
		$(tmp).remove();
		displayNotice('page','ExtraItem item has been deleted successfully!');
		calculateTotal(); 
	}
} //end page check
	
	});
	

});		

function deleteExtraItemItem(row_id){
	$("#myModal4").modal();
	$('#sel_id').val(row_id); 
	$('#popup_type').val('delete');
	$('#page').val('vehicle_service');
	$("#label").text("Are you sure you want to delete this service item?");
}

function clearForm(){
	
	$('#qtyTotal').text(convertToAmount(0));
	//('#sale_datetime').text('');
	$('#sale_datetime').css("borderColor","#d5d5d5");
	$('#warehouse_id').css("borderColor","#d5d5d5");
	$('#customer_id').css("borderColor","#d5d5d5");
	//$('#tax_rate_id').css("borderColor","#d5d5d5");
	//$('#warehouse_id').val("");
	$('#customer_id').val("");

	$('#balance_dis').text(convertToAmount(0));
	$('#Subtotal').text(convertToAmount(0));
	//set ref no
	getNextRefNo();
}





function addExtraItemToListByID(item_id,item_code,item_name,item_price,unit_code){
	//alert('item_id:'+item_id);
	var customer_id=$('#customer_id').val();
	error=false;
	
	if(customer_id==''){
		//error=true;	
	}
	if(error){
		 bootbox.alert('Please select Customer before adding any service', function () {
            $('#add_extra_item_tab').focus();
         });
	}else {
	var rowCount_e=$('#rowCount_e').val();
	var nxtCount=parseInt(rowCount_e)+1;
	$('#rowCount_e').val(nxtCount);
	//alert(product_price);
	var vcl_srvs_price=vcl_srvs_price;
	var vcl_srvs_price_dis=convertToAmount(vcl_srvs_price);
	var sub_total_item=convertToAmount(vcl_srvs_price*1); //when add qty=1
	var discount_val=0;
	var discount_val_tot=0;
	var sub_tot=0;
	sub_tot=item_price*1;
	var sub_tot_dis=convertToAmount(sub_tot);
	//unit_code='kg';
	//var product_part_no_txt='';
	//var product_oem_part_number_txt='';
	//if(product_part_no) product_part_no_txt=', Part No.:'+product_part_no;
	//if(product_oem_part_number) product_oem_part_number_txt=', OEM Part No.:'+product_oem_part_number;
	//alert(rowCount);
$('#ExtraItemTable tbody').prepend('<tr class="child" id="row_e_'+nxtCount+'"><td>'+item_name+' ('+item_code+') '+'<input type="hidden" name="row_e['+nxtCount+'][extra_item][]" value="Extra" id="extra_item_'+nxtCount+'"><input type="hidden" class="form-control text-center rquantity" name="row_e['+nxtCount+'][item_id][]" value="'+item_id+'" id="item_id_'+nxtCount+'"></td><td><input style="width:100%; text-align:right" type="text" name="row_e['+nxtCount+'][bkng_itm_note][]" id="bkng_itm_note_'+nxtCount+'" value="">'+'</td><td class="text-right"><input style="width:100%; text-align:right" type="text" name="row_e['+nxtCount+'][price][]" id="price_e_'+nxtCount+'" value="'+item_price+'">'+'</td><td class="text-right"><input style="width:100px; text-align:right" type="text" name="row_e['+nxtCount+'][itm_qty][]" id="itm_qty_'+nxtCount+'" onclick="this.select(); setTmpVal(this.value);" onchange="extra_item_qty_change('+nxtCount+');" value="'+1+'"> ('+unit_code+') </td><td class="text-right"><input style="width:100px; text-align:right" type="text" name="row_e['+nxtCount+'][sub_tot][]" id="sub_tot_'+nxtCount+'" value="'+sub_tot+'"></td><td><a onclick="deleteServiceItem('+nxtCount+')"><i class="fa fa-times tip podel" id="1446800197032" title="Remove" style="cursor:pointer;"></i></a></td></tr>');
	calculateTotal();
} //end error check
}








//************** end reset function ***
  