// JavaScript Document

//page- add salary : getdetails on change staff
function getStaffData() {	
	var staff_id = $('#staff').val();
	var year = $('#year').val();
	var month = $('#month').val();	
	$.ajax({url:"./ajax/ajax.php?staff_id="+staff_id+"&year="+year+"&month="+month+"&action=get_staff_data",success:function(result){
		//alert(result);	
		var staffdata = result.split('-|-');
		$('#salary').val(staffdata[0]);
		$('#advances').val(staffdata[1]);		
		$('#tot_leaves').val(staffdata[3]);
		$('#msg-leaves').html(staffdata[6]);
		$('#msg-leaves2').html(staffdata[7]);
		var totDeduction = parseInt(staffdata[4])+parseInt(staffdata[5]);
		$('#insentives').val('0');
		$('#deductions').val(totDeduction);
		if(totDeduction>0){
			$('#net_amount').val(parseInt(staffdata[2])-parseInt(totDeduction));
		} else {
			$('#net_amount').val(staffdata[2]);
		}
	}});
}

//page- add salary : change net amout on changing incentive/deduction
function changeNetAmount() {		
	var result = insentives = deductions = net_amount = 0;		
	insentives = parseInt(document.getElementById("insentives").value);
    deductions = parseInt(document.getElementById("deductions").value); 
    advance_return = parseInt(document.getElementById("advance_return").value); 
    if(isNaN(insentives) || insentives== 'undefined'){
    	 insentives = 0;
    } 
    if (isNaN(deductions) || deductions== 'undefined'){
    	deductions = 0;
    }     	
    if (isNaN(advance_return) || advance_return== 'undefined'){
    	advance_return = 0;
    } 
    net_amount = parseInt(document.getElementById("net_amount2").value);                
    result = ((net_amount+insentives) - deductions)-advance_return;    
	$('#net_amount').val(result);
}

function set_cat_type(cat_id, type) {
	$.ajax({url:"./ajax/ajax.php?cat_id="+cat_id+"&cat_type="+type+"&action=change_cat_type",success:function(result){
		
	}});
}