/*****************************/
/*     Created By Jithin     */
/*          19-11-2013       */
/*****************************/

var hrURL =localStorage['serviceURLHR'];
var editIcon = "images/edit.png";
var removeIcon = "images/delete.png";
var currentPage;

/////////////////////////////////////////  Page management and URL Tracking Functions  //////////////////////////////////////
$('.payroll-menu li').live('click',function(){
	$this = $(this);
	window.location.hash = $this.attr('data-page');
	
});
/////////////////////////////////////////  URL TRACKING /////////////////////////////////////////////////////////////////////

var itemCount=0;
var k=1;
var pageLimit = 15;

$(window).load(function(){
   	locationHashChanged();	
	

});
			
//jQuery(window).hashchange( locationHashChanged );													
window.onhashchange = locationHashChanged;		 	

function locationHashChanged() {	

	hash=window.location.href.split('#')[1]	

	if(hash){
		
		$('.menu-selected').removeClass('menu-selected');			
		//var menuList = $('.payroll-menu');	
		
		if($('li[data-page="'+hash+'"]').length){
			
			//$('#light-pagination').pagination('updateItems',15);
			$('li[data-page="'+hash+'"]').addClass('menu-selected');		
			
			
			
			setTimeout(window[hash],500); // call current function	
			currentPage =hash; 
			
			
			
			$("#light-pagination").jui_pagination({
				currentPage: 1,
				visiblePageLinks: 5,
				totalPages: 1,
				onChangePage:window[hash],
			});
			$('.newpersonalLeaveApplicationForm').hide('blind',500,function(){$(this).remove();});
			//$('#newpersonalLeaveApplicationFormss').hide('blind',500,function(){$(this).remove();});
		}else{
			$('li[data-page="'+currentPage+'"]').addClass('menu-selected');
			if(hash){
				//window.location.hash =	currentPage;currentPage =hash; 
			}
			
			//currentPage =currentPage;
			
		}
	}else{ 
		window.location.hash = "leaveRequests";
	}
}
$('#prdaddate').live('click',function(){
		 $(this).datepicker({dateFormat:"dd-mm-yy"}).focus();	
	});

$('#prd_addate').live('click',function(){
		 $(this).datepicker({dateFormat:"dd-mm-yy"}).focus();	
	});

$('#toaddate').live('click',function(){
		 $(this).datepicker({dateFormat:"dd-mm-yy"}).focus();	
	});

$('.my_date').live('click',function(){
		 var to_date = $('#day_to').val();
		// $(this).datepicker({dateFormat:"dd-mm-yy", minDate: 0,maxDate:to_date}).focus();	
		
		$(this).datepicker({
							dateFormat:"dd-mm-yy",
							yearRange: "1950:2020",
							changeMonth: true, 
							changeYear: true
							})
		 		.focus();
	});

$('.my_date_to').live('click',function(){
		 var from_date = $('#day_from').val();	
		 
		 $(this).datepicker({
							dateFormat:"dd-mm-yy",
							yearRange: "1950:2020",
							changeMonth: true, 
							changeYear: true
							})
		 		.focus();	
	});

function timesheet_edit(){
	window.location="timesheet-adjustable-form.php";
	//location.reload();
}
function timesheet_approval(){
	window.location="timesheet-adjustable-form.php#timesheet_approval";
	
}
function timesheet_view(){
	window.location="timesheet-adjustable-form.php#timesheet_view";
	
}
jQuery('.registerwages').live('click',registerwages);
function registerwages(){
	window.location="register-wages.php#registerwages";
}

jQuery('.leave_Requests').live('click',leave_Requests);
function leave_Requests(){            
	window.location="leave-request.php#leaveRequests";	
}

jQuery('.personal_leave').live('click',personal_leave);
function personal_leave(){
	window.location="leave-request.php#personalleave";	
}
jQuery('.leaveList').live('change',leave_atach);



function getregister_wages(e,pageno){
	
	
	if(!pageno)
	pageno =1;
	var totbasicpay = 0;
	var totdeduction = 0;
	var totbenefit = 0;
	var totcontribution = 0;
	var totpayable = 0;

	var searchString = $('.pdtSearchForm').serialize(); 
	if(pageno == 1 ){
			k=1; 
		 }else{
			k= ((pageno-1) * pageLimit)+1;
		 }
		 var tot = 0;
	
	$('.header').show('blind',500);
	removeCurrentPage();
	
	
	
	
	$('.getregister_wages').append('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-employees">'+
							 ' <tr>'+
								'<td width="20%" height="17"><translate>Name</translate></td>'+
								'<td width="10%"><translate>Father Name</translate></td>'+
								'<td width="12%"><translate>Desgination</translate></td>'+
								'<td width="11%"><translate>Basic</translate></td>'+
								'<td width="11%"><translate>DA</translate></td>'+
								'<td width="16%"><translate>Tot Att</translate></td>'+
								'<td width="11%"><translate>Total Payable</translate></td>'+
								'<td width="9%"><translate>Pay Slip</translate></td>'+
								'<td width="9%"><translate>Payment Status</translate></td>'+
								'</tr>'+
								 
							'</table>');
	
	
	
	$.getJSON(hrURL+"manageSalary.php?act=getwages&page="+pageno+"&"+searchString,function(data){
		var salaryDetails = data.salaryDetails;
		
		$.each(salaryDetails,function(index,salaryDetails){
									  
		var status;
		if(salaryDetails.paymentStatus == 1){
			status ="Paid"; //'<img src="images/1388406658_ok-green.png" width="20"/> ';		
		}else{
			status ="Not Paid"; //'<img src="images/1388407735_delete_64.png" width="20"/> ';	
		}
			totbasicpay = parseInt(parseFloat(totbasicpay) + parseFloat(salaryDetails.basic_pay));
			totdeduction = parseInt(parseFloat(totdeduction) + parseFloat(salaryDetails.deduction));
			totbenefit = parseInt(parseFloat(totbenefit) + parseFloat(salaryDetails.benefit));
			totcontribution = parseInt(parseFloat(totcontribution) + parseFloat(salaryDetails.contribution));
			
		
			var total = (parseFloat(salaryDetails.basic_pay)+parseFloat(salaryDetails.benefit)-parseFloat(salaryDetails.deduction)).toFixed(2)	;		
			totpayable = parseFloat(totpayable) + parseFloat(total);
			$('.list-employees').append(' <tr>'+
											'<td width="20%" height="17">'+salaryDetails.name+'</td>'+
											'<td width="10%" height="17">'+salaryDetails.branch_name+'</td>'+
											'<td width="12%">'+parseFloat(salaryDetails.basic_pay).toFixed(2)+'</td>'+
											'<td width="11%">'+parseFloat(salaryDetails.deduction).toFixed(2)+'</td>'+
											'<td width="11%">'+parseFloat(salaryDetails.benefit).toFixed(2)+'</td>'+
											'<td width="16%">'+parseFloat(salaryDetails.contribution).toFixed(2)+'</td>'+
											'<td width="11%">'+total+'</td>'+
											'<td width="9%"><a class="payslip showPaySlip" style="cursor:pointer" data-id="'+salaryDetails.employee_id+'">Pay Slip</a></td>'+
											'<td width="11%" align="center">'+status+'</td>'+
											'</tr>');
			
			itemCount = salaryDetails.totalrows;
			
				k++;
		});
		
		
			
		$('.list-employees').show('blind',500);
		
		 $('#light-pagination').pagination('updateItems',itemCount);
			
	});
	
	
	
}

function  download_register_wages(pagenum)
{
	var empid = $('#employees').val();
	window.location = serviceURLHR+"download_register_wages.php?employees="+empid;
/*	alert(pagenum);
	$.ajax({
			type: "POST",
			url:serviceURLHR+"download.php",
			data: 'pagenum='+pagenum,
			success:function(msg){ 
			//$("#subject_div").html(msg);alert()
			//alert(msg);
				window.open('data:application/vnd.ms-excel,' + $('#dvData').html(msg));		
					}
			});*/
}


jQuery('.searchPdt').live('click',function(){ leaveRequests('1','1') });
jQuery('.searchpersonalPdt').live('click',function(){ personalleave('1','') });
jQuery('.searchPF').live('click',function(){ pfRequests('1','') });

jQuery('.leaveList').live('change',function(){ balanceleave() });
jQuery('.searchesi').live('click',function(){ esiRequests('1','') });

jQuery('#day_from').live('change',function(){ checkbalanceleave() });
jQuery('#day_to').live('change',function(){ checkbalanceleave() });
function change(page){
location.href=page;
}
function removeCurrentPage(){

$('.paymentMethod').remove();
$('#tablelist table').hide('blind',500,function(){ $(this).remove(); })	
}


function checkbalanceleave()
{ 

	var leavetype=$('.leaveList').val();
	if(leavetype!='')
	{
		balanceleave();
	}
	
}
function balanceleave()
{
	
	
	var userid=$('#employeesList').val();
	var leavetype=$('.leaveList').val();
	var day_from=$('#day_from').val();
	var day_to=$('#day_to').val();
		
		

	$.getJSON(hrURL + "balanceLeave.php?userid="+userid+"&leavetype="+leavetype+"&day_from="+day_from+"&day_to="+day_to,function(data){
																						
						
						var leaves = data.leaves;	
						
						if(leaves!='general')
						{
							if(leaves >=0)
							var leavebalance=leaves+' leave is available';
							else
							var leavebalance='Leave Not Available';
						$('.leavebalance').html(leavebalance);
							if(parseInt(leaves)<0)
							{
							
							$(".applypersonalLeave").css("display", "none");
							
							}
							else
							{
							
							$(".applypersonalLeave").css("display", "block");
							}
						}
						else
						{
							var leavebalance='';
							$('.leavebalance').html(leavebalance);
							$(".applypersonalLeave").css("display", "block");
						}
						//$('.categories').append(data.leaves);
						
	});
}

function leave_atach()
{
	
	var userid=$('#employeesList').val();
	var leavetype=$('.leaveList').val();
	var day_from=$('#day_from').val();
	var day_to=$('#day_to').val();
		
		

	$.getJSON(hrURL + "branch.php?action=atch&userid="+userid+"&leavetype="+leavetype+"&day_from="+day_from+"&day_to="+day_to,function(data){
																						
						
						var leaves = data.leavatch;	
						$.each(leaves, function(index, leaves) 
			            {
							
							if(leaves.title=='SL')
							{
							$(".leaveats").css('display', 'block');
							//document.getElementById("leaveath").style.visibility="visible";
							}
							else
							{
								$(".leaveats").css('display', 'none');
								//document.getElementById("leaveath").style.visibility="hidden";
							}
				        });
						/*if(leaves!='general')
						{
							if(leaves >=0)
							var leavebalance=leaves+' leave is available';
							else
							var leavebalance='Leave Not Available';
						$('.leavebalance').html(leavebalance);
							if(parseInt(leaves)<0)
							{
							
							$(".applypersonalLeave").css("display", "none");
							
							}
							else
							{
							
							$(".applypersonalLeave").css("display", "block");
							}
						}
						else
						{
							var leavebalance='';
							$('.leavebalance').html(leavebalance);
							$(".applypersonalLeave").css("display", "block");
						}*/
						//$('.categories').append(data.leaves);
						
	});
}
/////////////////////////////////////////////////////////////////////////////// Deduction management //////////////////////////////////////////////////////
/*function deductionManagement(){
	removeCurrentPage();
	$('.header').show('blind',500);
	$.getJSON(hrURL + "manageDeduction.php?act=list",function(data){
		var deduction = data.deductions;
			$('#tablelist').append('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-deduction">'+
										  '<tr>'+
											'<td width="23%">Title</td>'+
											'<td width="45%">Description</td>'+
											'<td width="12%">Type</td>'+
											'<td width="9%">Value</td>'+
											//'<td width="6%">&nbsp;</td>'+
											'<td width="5%"><img src="images/icon-add.png" class="addNewDeduction" width="20" height="20" /></td>'+
										 '</tr>'+
										'</table>')	

			$.each(deduction, function(index,deductions){
				var ded_unit='';
				var type='';
				switch(deductions.unit){
					case "1":ded_unit="Rs";break;
					case "2":ded_unit = "%";break;
				}
				switch (deductions.deduction_benefit){
					case "1":type = "Deduction";break;
					case "2":type = "Earnings";break;
					case "3":type = "Employer's Contribution";break;
				}
				
					$('.list-deduction').append( '<tr>'+
														'<td width="23%">'+deductions.name+'</td>'+
														'<td width="45%">'+deductions.description+'</td>'+
														'<td width="12%">'+type+'</td>'+
														'<td width="9%">'+deductions.amount+" ("+ded_unit+')</td>'+
														//'<td width="6%"><img data-id="'+deductions.id+'" src="'+editIcon+'" class="editDeduction"/></td>'+
														'<td width="5%"><img data-id="'+deductions.id+'" src="'+removeIcon+'" class="removeDeduction"/></td>'+
													 '</tr>');				
			});
			$('.list-deduction').show('blind',500);
		
	});
}*/

function addnewDeduction(){
	//alert('asd');
	//alert($('.newDeductionform').length);
	if($('.newDeductionform').length){
		
	}else{
	$('.list-deduction').before('<form class="newDeductionform"><table width="50%" border="0" style="display:none" cellspacing="0" cellpadding="0" class="newDeduction">'+
								  '<tr>'+
									'<td width="47%">&nbsp;</td>'+
									'<td width="53%">&nbsp;</td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Title</translate></td>'+
									'<td><input type="text" name="deductionTitle" id="deductionTitle" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Description</translate></td>'+
									'<td><textarea name="deductionDescription" id="deductionDescription" cols="45" rows="4"></textarea></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Type</translate></td>'+
									'<td><select name="type" id="type">'+
									  '<option value="1">Deduction</option>'+
									  '<option value="2">Benefit</option>'+
									  '<option value="3">Employer\'s Contribution</option>'+
									'</select>'+
									'</td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Amount / Persentage</translate></td>'+
									'<td><input type="text" name="amount" id="amount" />'+
									  '<select name="unit" id="unit">'+
										'<option value="1">Rs</option>'+
										'<option value="2">%</option>'+
									  '</select>'+
									  '</td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button saveDeduction" id="button" value="Submit" />'+
									'<input type="button" name="button" class="color-button cancelDeduction" id="button" value="Cancel" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td>&nbsp;</td>'+
								  '</tr>'+
								'</table></form>');
	$('.newDeduction').show('blind',500);
	}
}

function saveNewDeduction(){	
	dataString = $('.newDeductionform').serialize();
	$.post(hrURL + "manageDeduction.php?act=insert",dataString,function(data){
		var deductions = data.deduction
		switch(deductions.unit){
					case "1":ded_unit="Rs";break;
					case "2":ded_unit = "%";break;
				}
				switch (deductions.deduction_benefit){
					case "1":type = "Deduction";break;
					case "2":type = "Earnings";break;
					case "3":type = "Employer's Contribution";break;
				}
		$('.list-deduction').append( '<tr>'+
							'<td width="23%">'+deductions.name+'</td>'+
							'<td width="45%">'+deductions.description+'</td>'+
							'<td width="12%">'+type+'</td>'+
							'<td width="9%">'+deductions.amount+" ("+ded_unit+')</td>'+
							'<td width="5%"><img data-id="'+deductions.id+'" src="'+removeIcon+'" class="removeDeduction"/></td>'+
							'</tr>');	
		
		$('.newDeductionform').hide('blind',500,function(){ $(this).remove(); });
		
	},'json');
}


function removeDeduction(){
	var did = $(this).attr('data-id');
	$this = $(this);
	$.get(hrURL + "manageDeduction.php?act=remove&did="+did,function(){
		$this.parent().parent().remove();															 
	});
}




//////////////////////////////////////////////////////////////////////// Salary Management ////////////////////////////////////////////////////////////////
/*function paySalary(){
	$('.header').show('blind',500);
	removeCurrentPage();

	$('#tablelist').append('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-employees">'+
							 ' <tr>'+
								'<td width="30%" height="17">Name</td>'+
								'<td width="12%">Basic Pay</td>'+
								'<td width="11%">Deductions</td>'+
								'<td width="11%">Earnings</td>'+
								'<td width="16%">Employer Contributions</td>'+
								'<td width="11%">Total Payable</td>'+
								'<td width="9%">Pay Slip</td>'+
								'<td width="9%">Payment Status</td>'+
								'</tr>'+
							'</table>');	
	
	$.getJSON(hrURL+"manageSalary.php?act=lastms",function(data){
		var salaryDetails = data.salaryDetails;
		
		$.each(salaryDetails,function(index,salaryDetails){
									  
		var status;
		if(salaryDetails.paymentStatus == 1){
			status ="Paid"; //'<img src="images/1388406658_ok-green.png" width="20"/> ';		
		}else{
			status ="Not Paid"; //'<img src="images/1388407735_delete_64.png" width="20"/> ';	
		}
		
		
			var total = (parseFloat(salaryDetails.basic_pay)+parseFloat(salaryDetails.benefit)-parseFloat(salaryDetails.deduction)).toFixed(2)	;					  
			$('.list-employees').append(' <tr>'+
											'<td width="30%" height="17">'+salaryDetails.name+'</td>'+
											'<td width="12%">'+parseFloat(salaryDetails.basic_pay).toFixed(2)+'</td>'+
											'<td width="11%">'+parseFloat(salaryDetails.deduction).toFixed(2)+'</td>'+
											'<td width="11%">'+parseFloat(salaryDetails.benefit).toFixed(2)+'</td>'+
											'<td width="16%">'+parseFloat(salaryDetails.contribution).toFixed(2)+'</td>'+
											'<td width="11%">'+total+'</td>'+
											'<td width="9%"><a class="payslip showPaySlip" style="cursor:pointer" data-id="'+salaryDetails.employee_id+'">Pay Slip</a></td>'+
											'<td width="11%" align="center">'+status+'</td>'+
											'</tr>');											  
		});
		
		$('.list-employees').show('blind',500);	
	});
	
	
}*/


//$('.showPaySlip').live('click',function(){
	//window.location.hash = $(this).attr('data-id');	
//	History.pushState({state:1}, "State 1", "?state=1");
//});


function preloadPaySlip(){
//	removeCurrentPage();

	$this = $(this);	
	var  paymentmonth = $('.paymentmonth').val();
	var  paymentyear  = $('.paymentyear').val();
paySlip($this,paymentmonth,paymentyear) ;
}

function paySlip($this,paymentmonth,paymentyear){
	//alert(paymentmonth);
removeCurrentPage();
	var employeeid =$this.attr('data-id'); 
	$('.header').hide('blind',500);

	
	if(paymentmonth == null){
		var d = new Date();
		var paymentmonth =d.getMonth() +1; 

	}else{
		if(parseInt(paymentmonth) < 10){
		paymentmonth = 0+paymentmonth;	
		}
	}
	
	if(paymentyear==null){
			 var dt = new Date();
			dt.setDate(1);
			//dt.setMonth(dt.getMonth() - 1);
			var paymentyear =dt.getFullYear(); 
		//	alert(dt);
	}
	//$('#busy').show();
	//$('#tablelist form').hide('blind',200);

	firstdateofmth = "01/"+paymentmonth+"/"+paymentyear;

	var lastDay = new Date(paymentyear,paymentmonth, 0);
	var lastdateofmth = new Date(lastDay).format("mm-dd-yyyy");
	localStorage['lastdateofmth']=lastdateofmth;

	var month=new Array();
	month[1]="January";
	month[2]="February";
	month[3]="March";
	month[4]="April";
	month[5]="May";
	month[6]="June";
	month[7]="July";
	month[8]="August";
	month[9]="September";
	month[10]="October";
	month[11]="November";
	month[12]="December";
	
	
	if(paymentmonth < 10 && paymentmonth.length > 1){
		paymentmonth = paymentmonth[1];	
	}

	var n = month[paymentmonth];
	var joindate;
	
	
	$.getJSON(hrURL+"manageSalary.php?act=single&emp_id="+employeeid+"&month="+paymentmonth+"&year="+paymentyear,function(data){
		var earnings = data.salaryDetails;
		//$('#busy').hide();
		//$('#tablelist').html('');
		
		$('#tablelist').append('<form class="paySlipForm"><table width="100%" border="0" cellspacing="0" cellpadding="0">'+
								  '<tr>'+
									'<td width="38%">'+
									'<input type="button" class="color-button gobacktolist" value="Back To List"/>'+
									'Change Pay Period</td>'+
									'<td width="6%">'+
									
									
									'<select name="year" class="paymentyear" data-id="'+employeeid+'">'+
									'</select></td>'+
									'<td width="8%">'+
									
									'<select name="month"  class="paymentmonth" data-id="'+employeeid+'">'+
									'</select></td>'+
									
									'<td width="48%">&nbsp;</td>'+
								  '</tr>'+
								'</table>'+
							   
							   '<table width="100%" style="display:none" height="224" class="paySlip" border="0" cellpadding="0" cellspacing="0">'+
							  '<tr>'+
								'<td height="80" align="center">'+
								//'<div class="pay-slip-title-res-name" style="height:50px;"></div>'+
								'<div class="pay-slip-title">Pay Slip for the period of  '+ n +" "+ paymentyear +'</div></td>'+
								'</tr>'+
							 ' <tr>'+
								'<td height="122" valign="top"><table class="employee-details" width="100%" height="121" border="0" cellpadding="0" cellspacing="0">'+
								 ' <tr>'+
									'<td width="13%"><translate>Employee ID</translate></td>'+
									'<td width="37%" class="empid">&nbsp;</td>'+
									'<td width="14%"><translate>Employee Name</translate></td>'+
									'<td width="36%" class="empname">&nbsp;</td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Joining Date</translate></td>'+
									'<td class="joiningdate">&nbsp;</td>'+
									'<td><translate>Designation</translate></td>'+
									'<td class="designation">&nbsp;</td>'+
								 ' </tr>'+
								 ' <tr>'+
									'<td><translate>Days Worked</translate></td>'+
									'<td class="workeddays">&nbsp;</td>'+
									'<td><translate>Payment Method</translate></td>'+
									'<td class="paymentMethods">&nbsp;</td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Earned Leaves</translate></td>'+
									'<td class="leaves">&nbsp;</td>'+
									'<td><translate>Loss of pay</translate></td>'+
									'<td class="lossofpayLeaves">&nbsp;</td>'+
								  '</tr>'+
								'</table></td>'+
							  '</tr>'+
							  '<tr>'+
								'<td height="122" valign="top">'+
								
								'<table width="100%" class="earnings-deduction" border="0" cellpadding="0" cellspacing="0">'+
								  '<tr>'+
									'<td width="50%" height="30"><translate>Earning</translate></td>'+
									'<td width="50%"><translate>Deductions</translate></td>'+
								  '</tr>'+
								  '<tr><td valign="top" class="totalEarnings">'+
								 ' <span class="basicPay" style="width:80%; height:25px; float:left;"><translate>Basic Pay</translate></span>'+
									'<span class="basicPayAmt" style="float:right; width:20%; text-align:right;"></span>'+

								  
								  '</td><td valign="top" class="totalDeductions">'+
								  

								  
								  '</td></tr>'+
								  '<tr class="total-earnings">'+
									'<td  height="30"><span class="earnings" style="width:80%; height:25px; float:left;"><translate>Total Earnings</translate></span>'+
									'<span class="totalEarningsAmount" style="float:right; width:20%; text-align:right;"></span></td>'+
									'<td><span class="earnings" style="width:80%; height:25px; float:left;"><translate>Total Deduction</translate></span>'+
									'<span class="totalDeductionAmount" style="float:right; width:20%; text-align:right;"></span></td>'+
								  '</tr>'+
								'</table></td>'+
								'</tr>'+
							  '<tr>'+
								'<td>'+
								
								'<table width="100%" border="0" cellspacing="0" cellpadding="0" class="paymentSummery">'+
                                  '<tr>'+
                                    '<td width="50%"><span class="earnings" style="width:80%; height:25px; float:left;"><translate>Employer Contribution</translate></span>'+
									'<span class="totalContribution" style="float:right; width:20%; text-align:right;"></span></td>'+
									
                                    '<td><span class="earnings" style="width:80%; height:25px; float:left;"><translate>Net Payable</translate></span>'+
									'<span class="netPayable" style="float:right; width:20%; text-align:right;"></span></td>'+
                                  '</tr>'+

                                '</table>'+
								
								'</td>'+
							 ' </tr>'+
							  '<tr>'+
								'<td>'+
								'<input type="button" class="color-button payCurrentSalary" style="float:left" value="Pay Salary">'+
								'<input type="button" class="color-button printPaySlip" style="display:none" value="Print PaySlip">'+
								'</td>'+
								'</tr>'+
							'</table></form>');
		var totalEarnings = 0;
		var totalDeduction = 0;
		var totalContribution = 0;
		
		$.each(earnings, function(index,earnings){
		
		$('.basicPayAmt').html(parseFloat(earnings.emp_basic_pay).toFixed(2));
		$('.empid').html(': '+earnings.e_id);
		
		
		
		$('.empname').html(': '+earnings.e_fname);
		$('.designation').html(': '+earnings.e_post);
		$('.workeddays').html(': '+earnings.lastMonthDays);
		$('.leaves').html(': '+earnings.earnesLeaves);
		$('.lossofpayLeaves').html(': '+earnings.lossofpay);
		
		$('.leaves').append('<input type="hidden" value='+earnings.earnesLeaves+' name="earned_leaves">');
		$('.basicPayAmt').append('<input type="hidden" value='+parseFloat(earnings.emp_basic_pay).toFixed(2)+' name="basicPayAmt">');
		$('.empid').append('<input type="hidden" value='+earnings.e_id+' name="userid">');
		$('.lossofpayLeaves').append('<input type="hidden" value='+earnings.lossofpay+' name="lossofpay_leaves">');
		
		
		
		if(earnings.paymentMethod){
			$('.paymentMethods').html(': '+earnings.paymentMethod + "("+ earnings.referances + ")");
		}else{
			$('.paymentMethods').html(': ');	
		}
		
		
		
		
		var paymentPerDay = parseFloat(earnings.emp_basic_pay)/parseFloat(earnings.totalDays);
		var deductionLeaves = paymentPerDay*parseFloat(earnings.lossofpay);
		
			joindate = new Date(earnings.e_dstart).format('dd-mm-yyyy');
			$('.joiningdate').html(': '+joindate);
			
			joindate = new Date(earnings.e_dstart).format('mm-dd-yyyy');
			
			
		
		
		if(earnings.deduction_benefit == "1"){
			$('.totalDeductions').append('<span class="earnings" style="width:80%; height:25px; float:left;">'+earnings.name+'</span>'+
									'<span class="deductionAmt" style="float:right; width:20%; text-align:right;">'+parseFloat(earnings.totalamount).toFixed(2)+'</span>');	
			
			$('.totalDeductions').append('<input type="hidden" value='+parseFloat(earnings.totalamount).toFixed(2)+' name="deductionAmt[]">');
			$('.totalDeductions').append('<input type="hidden" value='+parseFloat(earnings.amount).toFixed(2)+' name="deductionPrice[]">');
			$('.totalDeductions').append('<input type="hidden" value='+earnings.unit+' name="deductionUnit[]">');
			$('.totalDeductions').append('<input type="hidden" value='+earnings.deduction_id+' name="deductionId[]">');
			
			totalDeduction +=parseFloat(earnings.totalamount);
		}else if(earnings.deduction_benefit == "2"){
			$('.totalEarnings').append('<span class="earnings" style="width:80%; height:25px; float:left;">'+earnings.name+'</span>'+
									'<span class="earningAmt" style="float:right; width:20%; text-align:right;">'+parseFloat(earnings.totalamount).toFixed(2)+'</span>');
			
			$('.totalEarnings').append('<input type="hidden" value='+parseFloat(earnings.totalamount).toFixed(2)+' name="deductionAmt[]">');
			$('.totalEarnings').append('<input type="hidden" value='+parseFloat(earnings.amount).toFixed(2)+' name="deductionPrice[]">');
			$('.totalEarnings').append('<input type="hidden" value='+earnings.unit+' name="deductionUnit[]">');
			$('.totalEarnings').append('<input type="hidden" value='+earnings.deduction_id+' name="deductionId[]">');
			
			
			totalEarnings +=parseFloat(earnings.totalamount);
			
		}else{
			
			if(earnings.totalamount !==null){
				totalContribution +=parseFloat(earnings.totalamount);
			}
			
			$('.totalEarnings').append('<input type="hidden" value='+parseFloat(earnings.totalamount).toFixed(2)+' name="deductionAmt[]">');
			$('.totalEarnings').append('<input type="hidden" value='+parseFloat(earnings.amount).toFixed(2)+' name="deductionPrice[]">');
			$('.totalEarnings').append('<input type="hidden" value='+earnings.unit+' name="deductionUnit[]">');
			$('.totalEarnings').append('<input type="hidden" value='+earnings.deduction_id+' name="deductionId[]">');
		}
		
		if(earnings.lossofpay > 0){
			$('.totalDeductions').append('<span class="earnings" style="width:80%; height:25px; float:left;">Leave</span>'+
									'<span class="deductionAmt" style="float:right; width:20%; text-align:right;">'+parseFloat(deductionLeaves).toFixed(2)+'</span>');
			
			$('.totalDeductions').append('<input type="hidden" value='+parseFloat(deductionLeaves).toFixed(2)+' name="leave_deduction">');
			
			
		totalDeduction +=parseFloat(deductionLeaves);
		}
		
		
			$('.totalEarningsAmount').html((parseFloat(totalEarnings)+parseFloat(earnings.emp_basic_pay)).toFixed(2));
			$('.totalDeductionAmount').html(totalDeduction.toFixed(2));
			$('.totalContribution').html(totalContribution.toFixed(2));
			
		$('.netPayable').html((parseFloat(totalEarnings)+parseFloat(earnings.emp_basic_pay)-totalDeduction).toFixed(2));
		$('.netPayable').append('<input type="hidden" value='+(parseFloat(totalEarnings)+parseFloat(earnings.emp_basic_pay)-totalDeduction).toFixed(2)+' name="total_payable">');
		
		
		if(earnings.status == 'paid'){
			$('.payCurrentSalary').val('Salary Paid');
			$('.payCurrentSalary').removeClass('payCurrentSalary');	
			$('.printPaySlip').css({"display":"block","float":"left"});
		}
		
//	}
		});
		//alert("Slow ?");
		
		
		     var joindate = new Date(joindate);
			 var lastdateofmth = new Date(lastDay);

			if(joindate > lastdateofmth){
	
				$('.payCurrentSalary').val('Employee Joined Date is Grater');
				$('.payCurrentSalary').attr('class','color-button');
			}
		
		
		
		
		$('.paySlip').show('blind',500,function(){
			if($('.paySlipForm').length > 1){
				$('.paySlipForm:first').remove();
			}										
		});
		
		$('.paymentmonth').getmonths(paymentmonth);
		$('.paymentyear').getYears(paymentyear);
	});
}

//////////////////////////////////////////////////////////// Leave Management /////////////////////////////////////////////////////////////////////

/*function leaveManagement(){
	$('.header').show('blind',500);
	removeCurrentPage();
	$.getJSON(hrURL + "manageLeaves.php?act=list",function(data){
		var leaves = data.leaves;
			$('#tablelist').append('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leaves">'+
										  '<tr>'+
											'<td width="23%">Title</td>'+
											'<td width="45%">Description</td>'+
											'<td width="9%">Days</td>'+
											//'<td width="6%">&nbsp;</td>'+
											'<td width="5%"><img src="images/icon-add.png" class="addNewLeaves" width="20" height="20" /></td>'+
										 '</tr>'+
										'</table>')	

			$.each(leaves, function(index,leaves){
				
				var based_on='';
				switch(leaves.based_on){
					case "1":based_on="Month";break;
					case "2":based_on = "Year";break;
				}
				
					$('.list-leaves').append( '<tr>'+
														'<td width="23%">'+leaves.title+'</td>'+
														'<td width="45%">'+leaves.description+'</td>'+
														'<td width="9%">'+leaves.number_of_days+' Days / '+based_on+'</td>'+
														//'<td width="6%"><img data-id="'+leaves.lid+'" src="'+editIcon+'" class="editLeave"/></td>'+
														'<td width="5%"><img data-id="'+leaves.lid+'" src="'+removeIcon+'" class="removeLeave"/></td>'+
													 '</tr>');				
			});
			$('.list-leaves').show('blind',500);
		
	});	
}*/

function addNewLeaves(){
	//alert('asd');
	$('.list-leaves').before('<form class="newLeaveform"><table width="50%" border="0" style="display:none" cellspacing="0" cellpadding="0" class="newLeave">'+
								  '<tr>'+
									'<td width="47%">&nbsp;</td>'+
									'<td width="53%">&nbsp;</td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Title</translate></td>'+
									'<td><input type="text" name="leaveTitle" id="leaveTitle" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Description</translate></td>'+
									'<td><textarea name="leaveDescription" id="leaveDescription" cols="45" rows="4"></textarea></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Days</translate></td>'+
									'<td><input type="text" name="days" id="days" placeholder="Days" /> /'+
									  '<select name="based_on" id="based_on"> '+
										'<option value="1">Month</option>'+
										'<option value="2">Year</option>'+
									  '</select>'+
									  '</td>'+
								  '</tr>'+

								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button saveLeave" id="button" value="Submit" />'+
									'<input type="button" name="button" class="color-button cancelNewLeave" id="button" value="Cancel" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td>&nbsp;</td>'+
								  '</tr>'+
								'</table></form>');
	$('.newLeave').show('blind',500);
}
function saveLeave(){	
	
	
	dataString = $('.newLeaveform').serialize();
	$.post( hrURL+ "manageLeaves.php?act=insert",dataString,function(data){
		var leaves = data.leaves
		var based_on='';
				switch(leaves.based_on){
					case "1":based_on="Month";break;
					case "2":based_on = "Year";break;
				}
				
			$('.list-leaves').append( '<tr>'+
									'<td width="23%">'+leaves.title+'</td>'+
									'<td width="45%">'+leaves.description+'</td>'+
									'<td width="9%">'+leaves.number_of_days+' Days / '+based_on+'</td>'+
									'<td width="5%"><img data-id="'+leaves.id+'" src="'+removeIcon+'" class="removeLeave"/></td>'+
									'</tr>');	
			$('.newLeaveform').hide('blind',500,function(){ $(this).remove(); });
		
	},'json');
}


function removeLeaveType(){
	$this = $(this);
	var lid = $(this).attr('data-id');
	$.get(hrURL +"manageLeaves.php?act=remove&lid="+lid,function(){
		$this.parent().parent().remove();															 
	});
	
}


function personalleave(e,pageno){
	lastPage =1;
	if(!pageno)
	pageno =1;
	$(".searchpersonalPdt").css("display", "block");
	if(pageno == 1 ){
			k=1; 
		 }else{
			k= ((pageno-1) * pageLimit)+1;
		 }
	 var tot = 0;
	
	$(".leave_search").css("display", "block");
	$(".pdtSearchForm").css("display", "block");
	$(".searchPdt").css("display", "none");
	$(".designation").css("display", "none");
	$(".branch").css("display", "none");
	$(".imdatesupervisor").css("display", "none");
	var searchString = $('.pdtSearchForm').serialize(); 
	var userid=$('.userid').val();
	var depart_id=$('.depart_id').val();
	var lastPage;
	var todaysdate = new Date().format("yyyy-mm-dd");
	$('.header').show('blind',500);
	removeCurrentPage();
	$('#t_leave_list').html('');
	$('#tablelist').append('<table width="100%" border="0" cellspacing="0" style="display:block" cellpadding="0" class="list-leaverequests">'+
										  '<tr>'+
											
											'<td width="10%"><translate>Sl No</translate></td>'+
											'<td width="10%"><translate>Leave From</translate></td>'+
											'<td width="10%"><translate>Leave To</translate></td>'+
											'<td width="12%"><translate>Leave Type</translate></td>'+
											'<td width="28%"><translate>Reason</translate></td>'+
											'<td width="15%"><translate>Status</translate></td>'+
											'<td width="8%"><translate>Cancel Leave</translate></td>'+
										 '</tr>'+
										'</table>')	;
	$.getJSON(hrURL + "manageLeaves.php?act=loadpersonalRequests&userid="+userid+"&page="+pageno+"&"+searchString,function(data){
		var leaves = data.leaves;
		
		
		$('.list-leaverequests').append('');
		
		$.each(leaves,function(index,leaves){
			
			
		
		/*if(leaves.imd_status == 1)
		{
			viewstatus ='<img src="images/1388406658_ok-green.png" style="cursor:pointer" data-status="0" requestid="'+leaves.id+'"  title="Approved" class="approvedLeave" width="20" height="20" />';
			
		}else{
			viewstatus ='<img src="images/1388407735_delete_64.png" style="cursor:pointer" data-status="1" requestid="'+leaves.id+'"  title="Pending" class="approvedLeave" width="20" height="20" />';
			
		}*/	
		//alert(todaysdate);
		if(todaysdate<=leaves.day_to)
		{
		var cancel_leav_class='Cancellleave';
		
		}
		else
		{
		
		var cancel_leav_class='Cancelledleave';
		}
		
		
		
		if(leaves.imd_status == 0)
		{
			viewstatus ='Applied';
			
		}
		if(leaves.imd_status == 1)
		{
			viewstatus ='Approved';
			
		}
		
		if(leaves.blocked==1){
			viewstatus ='Declined';
		}
		
		if(leaves.is_cancelled == 1)
		{
			/*viewcancel ='<img src="images/1388406658_ok-green.png" style="cursor:pointer" data-status="0" requestid="'+leaves.id+'"  title="Cancelled" class="'+cancel_leav_class+'" width="20" height="20" />';*/
			viewcancel = 'Yes'
			
		}else{
			/*viewcancel ='<img src="images/1388407735_delete_64.png" style="cursor:pointer" data-status="1" requestid="'+leaves.id+'"  title="Not Cancelled" class="'+cancel_leav_class+'"  width="20" height="20" />';*/
			viewcancel = 'No'
			
		}
		
							   
	
		var leavedetails='<tr>'+
												
												'<td width="15%">'+k+'</td>'+
												'<td width="10%">'+moment(leaves.day_from).format('DD-MM-YYYY')+'</td>'+
												'<td width="10%">'+moment(leaves.day_to).format('DD-MM-YYYY')+'</td>'+
												'<td width="12%">'+leaves.title+'</td>'+
												'<td width="28%">'+leaves.reason+'</td>'+
												'<td width="14%">'+viewstatus+'</td>'+
												'<td width="20%"><a href="#" id="'+leaves.id+'" class="cancelpersonelleave">Yes</a></td>'+
											 '</tr>';
	if(leaves.e_fname)
	{
				$('.list-leaverequests').append(leavedetails);
				itemCount =leaves.totalrows;
				lastPage  = leaves.lastPage;
	}
	else
	{
		$('.list-leaverequests').append('');	
	}
				
				
				k++;
			});
		
		
		
			
		/*	$("#light-pagination").jui_pagination({
				totalPages: lastPage,
			});*/
			
			
			//$("#light-pagination").jui_pagination('destroy');
		//console.log(lastPage+"-"+pageno);
		$("#light-pagination").hide();
		if(lastPage){ 
			$(".pagination-holder").show();
			$("#light-pagination").show();
			$('.list-leaverequests').show('blind');
			$("#light-pagination").jui_pagination({
				totalPages: lastPage,
				onChangePage:personalleave,
				 currentPage: pageno,
			});
			//console.log(lastPage);
		}
			
	});
	
	
	
}
function cancelpersonelleave()
{
	var id = $(this).attr('id');	
	dataString = 'id='+id;
	$.post( hrURL+ "manageLeaves.php?act=cancelpersonalleave",dataString,function(data){});
	personalleave();
	return false;
}

function employeeoption()
{
	
	$.post( hrURL+ "manageEmployees.php?action=empname",function(data){$('#employeesList').html(data);$('#leaveList').loadLeaves();});
	
}

function addNewpersonalLeaveRequest(){
	//alert();
	//console.log('12');
	$(".leave_search").css("display", "none");
	$(".pdtSearchForm").css("display", "none");
	$(".searchpersonalPdt").css("display", "none");
	$(".searchPdt").css("display", "none");
	$(".Cancellleave").each(function(){
		 $(this).attr('class', 'cantcancel');
	});
	
	//$('.newpersonalLeaveApplicationForm').remove();	
	//if($('.newpersonalLeaveApplicationForm').length){
		
		//}else{	
			var userid=$('.userid').val();var user_name=$('.user_name').val();var depart_id=$('.depart_id').val();
			
				$.getJSON(serviceURLHR + "manageempstatus.php?action=lev_track",function(data){
		var timing = data.timing; 
		//console.log(data);
		$('#tablelist').html('<div class="newpersonalLeaveApplicationWindow mainbody" style="display:none; width:auto;">'+
						 '<form class="newpersonalLeaveApplicationForm" id="newpersonalLeaveApplicationFormss" enctype="multipart/form-data" method="post" ><table width="90%" height="" border="0" cellpadding="0" cellspacing="0">'+
						  '<tr>'+
							'<td width="25%">&nbsp;</td>'+
							'<td width="65%"></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td class="categories" height="35"><translate>Employee</translate></td>'+
							'<td height="35">'+
							'<select name="employeesList" id="employeesList"><option value="">-Select-</option>'+
							'</select>'+
							'<input type="hidden" name="depart_id" id="depart_id" value="'+depart_id+'" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td class="categories" height="35"><translate>Leave From</translate></td>'+
							'<td height="35"><input type="text" name="day_from" id="day_from" class="my_date" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td class="categories" height="35"><translate>Leave To</translate></td>'+
							'<td height="35"><input type="text" name="day_to" id="day_to" class="my_date_to" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td class="categories" height="35"><translate>Leave Type</translate></td>'+
							'<td height="35"><select name="leave_id" id="leaveList" class="leaveList"><option value="">--Select Any--</option>'+
							'</select><span class="leavebalance"></span>    </td>'+
						  '</tr>'+
						  '<tr >'+
						  '<td>&nbsp;</td>'+
							'<td height="35" class="categories leaveats" id="leaveath" style="display:none;" ><span style=" font-size:13px!important;"><translate>Choose Supporting Document</translate></span><input type="file" name="atachss" id="atachss" style="border:none;"></td>'+
							
						  '</tr>'+
						  
							 /* '<tr>'+
							'<td class="categories">Employee Status</td>'+
							'<td><select name="empstat" id="empstat" class="leavestat"><option value="">--Select Any--</option>'+
							
							'</select>   </td>'+
							
						  '</tr>'+*/
						  '<tr>'+
							'<td height="35" class="categories"><translate>Reason</translate></td>'+
							'<td height="35"><textarea name="reason" id="reason" cols="45" rows="5"></textarea></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="35" class="categories"><translate>Day</translate></td>'+
							'<td height="35"><table><tr><td><translate>Half Day <input name="day_type" type="radio" value="1" id="level" class="levelss" /></td><td style="padding:0 10px; color:#ddd;"> | </td><td>Full Day <input name="day_type" type="radio" value="2" id="level"  class="levelss" /></td></tr></table></td>'+
							'</tr>'+
						  '<tr>'+
							'<td height="35" class="categories">&nbsp;</td>'+
							'<td height="35"><input type="button" name="button" id="applyLeave" class="color-button2 applypersonalLeave" value="Submit" style="padding:5px 10px; visibility:visible1;" />'+
							'<input type="button" name="button" id="cencelApplication" class="color-button2 cancelpersonalApplication" value="Cancel" style="padding:5px 10px;" /></td>'+
						  '</tr>'+
						'</table></form></div>');
		
		$('.newpersonalLeaveApplicationWindow').show('fade',500);
		
		   				if(timing.user_id!=1)
				{ 
					/* if(timing.add_right==1)
					 {
						 $('.applypersonalLeave').css( 'visibility','visible' );
					 }
					 else
					 {
						 $('.applypersonalLeave').css( 'visibility','hidden' );
					 }*/
				}
				employeeoption();
		});
			//employeeoption();
			
	
				
				$('.pagination-holder').hide();
				//$('.newpersonalLeaveApplicationWindow').show('bind',500);
				//$('#leaveList').loadLeaves();
		//}
	
	
	
	balanceLeaveTable();
}
function balanceLeaveTable(){
	/*balance leave*/
	var hiddenuser_type = $('#hiddenuser_type').val();
	if(hiddenuser_type=='Superadmin')
	var userid=$('#employeesList').val();
	else
	var userid=$('#userhid').val(); 
	
	$('#t_leave_list').html('');
	$('#l_list').empty('');
	$.getJSON(serviceURLHR+"balanceLeaveList.php?userid="+userid,function(data){
		select_list = data.leaves;
		$('#t_leave_list').html('<table width="100%" style="border:3px solid #ddd; margin-top:15px;" height="" border="0" cellpadding="8" cellspacing="8" id="l_list">'+
					  '<tr>'+
						'<td width="25%" style="padding:5px 10px; border-bottom:1px solid #ddd;"><strong><translate>Leave Type</translate></strong></td>'+
						'<td width="25%" style="padding:5px 10px; border-bottom:1px solid #ddd;"><strong><translate>Total Leaves Alloted</translate></strong></td>'+
						'<td width="25%" style="padding:5px 10px; border-bottom:1px solid #ddd;"><strong><translate>Total Leaves Availied</translate></strong></td>'+
						'<td width="25%" style="padding:5px 10px; border-bottom:1px solid #ddd;"><strong><translate>Balance Leave</translate></strong></td>'+
					  '</tr>'+
					  '</table>');
					  
		$.each(select_list, function(index, select_list) { 
									
					 
			 $('#l_list').append(
					  '<tr>'+
						'<td width="25%" style="padding:5px 10px; border-bottom:1px solid #ddd;">'+select_list.description+'</td>'+
						'<td width="25%" style="padding:5px 10px; border-bottom:1px solid #ddd;">'+select_list.total_leave+'</td>'+
						'<td width="25%" style="padding:5px 10px; border-bottom:1px solid #ddd;">'+select_list.leave_taken+'</td>'+
						'<td width="25%" style="padding:5px 10px; border-bottom:1px solid #ddd;">'+select_list.balance_leave+'</td>'+
					  '</tr>');
			  
		});	
		 
	});
}

function savepersonalLeaveRequest(){
	var hiddenuser_type = $('#hiddenuser_type').val();
	var day_from = $('#day_from').val();
	var day_to = $('#day_to').val();
	var reason = $('#reason').val();
	
	if(day_from == ''){
		alert('Leave From is required')	;
	}else if(day_to == ''){
		alert('Leave To is required')	;
	}else if(reason == ''){
		alert('Reason is required')	;
	}else if ($(".levelss:checked").length == 0){
		
		alert('Please choose Day');
	}else{
		var $this = $(this);
		var employeeid =$('#employeesList').val();
		var employeeName = $('.employeeName').html();
		var leavetype = $('#leaveList').val();
		var depart_id = $('#depart_id').val();
		var dataString = $('.newpersonalLeaveApplicationForm').serialize(); //alert(dataString);
		
		$.post(serviceURLHR + "manageLeaves.php?act=newRequest&emp_id="+employeeid,dataString,function(data){
			
			var leaves = data.leaves;
			 //
			$.each(leaves,function(index,leaves){
			
			if(leaves.imd_status == 1)
			{
				viewstatus ='<img src="images/1388406658_ok-green.png" style="cursor:pointer" data-status="0" requestid="'+leaves.id+'"  title="Approved" class="approvedLeave" width="20" height="20" />';
				
			}else{
				viewstatus ='<img src="images/1388407735_delete_64.png" style="cursor:pointer" data-status="1" requestid="'+leaves.id+'"  title="Pending" class="approvedLeave" width="20" height="20" />';
				
			}	
			
			
			
			$('.list-leaverequests').append( '<tr>'+
													'<td width="15%">'+leaves.e_fname+'</td>'+
													'<td width="15%">'+leaves.desig_name+'</td>'+
													'<td width="10%">'+moment(leaves.day_from).format('DD-MM-YYYY')+'</td>'+
													'<td width="10%">'+moment(leaves.day_to).format('DD-MM-YYYY')+'</td>'+
													'<td width="12%">'+leaves.title+'</td>'+
													'<td width="28%">'+leaves.reason+'</td>'+
													'<td width="14%">'+viewstatus+'</td>'+
													
													'<td width="6%"><img src="images/icon-add.png" class="addNewDeduction" width="20" height="20" /></td>'+
												 '</tr>');	
			
			//location.reload();
			});
			//$('.newpersonalLeaveApplicationWindow').hide('blind',300,function(){ $(this).remove()});
			if(hiddenuser_type=='Superadmin')
			window.location ="leave-request.php#leaveRequests";
			else
			window.location ="leave-request.php#personalleave";
		},'json');
		
		//location.reload();
		if(hiddenuser_type=='Superadmin')
			window.location ="leave-request.php#leaveRequests";
			else
			window.location ="leave-request.php#personalleave";
	}
}
///////////////////////////////////////////// Leave request management //////////////////////////////////////////////
//;

function leaveRequests(e,pageno){
lastPage =1;
	if(!pageno)
	pageno =1;
	
	
	var searchString = $('.pdtSearchForm').serialize(); 
	if(pageno == 1 ){
			k=1; 
		 }else{
			k= ((pageno-1) * pageLimit)+1;
		 }
		 var tot = 0;
	$(".leave_search").css("display", "block");	
	$(".pdtSearchForm").css("display", "block");
	$(".searchpersonalPdt").css("display", "none");
	$(".searchPdt").css("display", "block");
	$(".designation").css("display", "block");
	$(".branch").css("display", "block");
	$(".imdatesupervisor").css("display", "block");
	$('.pagination-holder').show();
	var userid=$('.userid').val();
	var depart_id=$('.depart_id').val();
	$('.header').show('blind',500);
	removeCurrentPage();
	$('#t_leave_list').html('');
	var userid=$('.userid').val();var user_name=$('.user_name').val();var depart_id=$('.depart_id').val();
	
	
	var lastPage;

	$('#tablelist').append('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leaverequests">'+
										  '<tr>'+
											'<td width="15%"><translate>Sl No</translate></td>'+
											'<td width="15%"><translate>Employee Name</translate></td>'+
											'<td width="15%"><translate>Designation</translate></td>'+
											'<td width="10%"><translate>Leave From</translate></td>'+
											'<td width="10%"><translate>Leave To</translate></td>'+
											'<td width="12%"><translate>Leave Type</translate></td>'+
											'<td width="28%"><translate>Reason</translate></td>'+
											
											'<td width="14%" colspan="2"><translate>Action</td>'+
											
										 '</tr>'+
										'</table>')	;
	/*'<td width="14%">Imm.Supervisor</td>'+*/
	$.getJSON(hrURL + "manageLeaves.php?act=loadRequests&userid="+userid+"&page="+pageno+"&depart_id="+depart_id+"&"+searchString,function(data){
		var leaves = data.leaves; 
		
		
		if(leaves){
		$.each(leaves,function(index,leaves){
			
			
				  var ap_stat	=  leaves.imd_status == 1?"selected":"";
				  var ap_de	= leaves.blocked == 1?"selected":"";
		
		if(leaves.imd_status == 1)
		{
			viewstatus ='<img src="images/1388406658_ok-green.png" style="cursor:pointer" data-status="0" requestid="'+leaves.id+'"  title="Approved" class="approveLeave" width="20" height="20" />';
			
		}else{
			viewstatus ='<img src="images/1388407735_delete_64.png" style="cursor:pointer" data-status="1" requestid="'+leaves.id+'"  title="Pending" class="approveLeave" width="20" height="20" />';
			
		}	
		
		
		if(depart_id==3)
		{
		var cancel_leav_class='Cancellleave';
			
			if(leaves.imd_supervisor_id!=userid)
			{
			if(leaves.imd_status == 1)
			{
				viewstatus ='<img src="images/1388406658_ok-green.png" style="cursor:pointer" data-status="0"  title="Approved" requestid="'+leaves.id+'" class="noapproveLeave" width="20" height="20" />';
				
			}else{
				viewstatus ='<img src="images/1388407735_delete_64.png" style="cursor:pointer" data-status="1"  title="Pending" requestid="'+leaves.id+'" class="noapproveLeave" width="20" height="20" />';
				
			}
			}
		}
		else
		{
		
		var cancel_leav_class='Cancelledleave';
		}
		
		
		
		
		if(leaves.is_cancelled == 1)
		{
			viewcancel ='<img src="images/1388406658_ok-green.png" style="cursor:pointer" data-status="0" requestid="'+leaves.id+'"  title="Cancelled" class="'+cancel_leav_class+'" width="20" height="20" />';
			
		}else{
			viewcancel ='<img src="images/1388407735_delete_64.png" style="cursor:pointer" data-status="1" requestid="'+leaves.id+'"  title="Not Cancelled" class="'+cancel_leav_class+'" width="20" height="20" />';
			
		}
		
	
		var leavedetails='<tr>'+
						'<td width="15%">'+k+'</td>'+
						'<td width="15%">'+leaves.e_fname+'</td>'+
						'<td width="15%">'+leaves.desig_name+'</td>'+
						'<td width="10%">'+moment(leaves.day_from).format('DD-MM-YYYY')+'</td>'+
						'<td width="10%">'+moment(leaves.day_to).format('DD-MM-YYYY')+'</td>'+
						'<td width="12%">'+leaves.title+'</td>'+
												'<td width="28%">'+leaves.reason+'</td>'+
												
												'<td width="14%"><select name="approveleave" id="approveleave" onchange="approveLeaves('+leaves.id+',this.value);">'+
												'<option value="">Select Status</option>'+
												'<option value="1" '+ap_stat+'>Approve</option>'+
												'<option value="0" '+ap_de+'>Decline</option>'+
												'</select></td>'+
												
											 '</tr>';

				itemCount = leaves.totalrows;				
				lastPage  = leaves.lastPage;
		if(leaves.e_fname){
				$('.list-leaverequests').append(leavedetails);	
		}else{
				$('.list-leaverequests').append('<tr><td colspan="8"> No data found.</td></tr>');	
				$('.list-leaverequests').show('blind');
		}
				
				k++;

			}); 
		}else{
			
		$('.list-leaverequests').append('<tr><td colspan="8"> No data found.</td></tr>');		
		
		}
		
		$("#light-pagination").jui_pagination('destroy');
		//console.log(lastPage+"-"+pageno);
		$("#light-pagination").hide();
		if(lastPage){
			$("#light-pagination").show();
			$('.list-leaverequests').show('blind');
			$("#light-pagination").jui_pagination({
				totalPages: lastPage,
				onChangePage:leaveRequests,
				 currentPage: pageno,
			});
			//console.log(lastPage);
		}
			
	});
	
	
	
}
function approveLeaves(id,val)
{	
	var dataString='id='+id+'&status='+val;
	$.post( hrURL+ "manageLeaves.php?act=approveleave",dataString,function(data){});
	leaveRequests();
}
function newLeaveRequest(){

if($('.newLeaveApplicationForm').length){
		
	}else{
$('.list-leaverequests').before('<div class="newLeaveApplicationWindow" style="display:none">'+
					 '<form class="newLeaveApplicationForm"><table width="500" height="200" border="0" cellpadding="0" cellspacing="0">'+
					  '<tr>'+
						'<td width="217">&nbsp;</td>'+
						'<td width="304"></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td class="categories"><translate>Employee</translate></td>'+
						'<td><select name="employeesList" id="employeesList">'+
						'</select> </td>'+
					  '</tr>'+
					  '<tr>'+
						'<td class="categories"><translate>Leave From</translate></td>'+
						'<td><input type="text" name="day_from" id="day_from" class="my_date" /></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td class="categories"><translate>Leave To</translate></td>'+
						'<td><input type="text" name="day_to" id="day_to" class="my_date" /></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td class="categories"><translate>Leave Type</translate></td>'+
						'<td><select name="leave_id" id="leaveList">'+
						'</select>    </td>'+
					  '</tr>'+
					  '<tr>'+
						'<td class="categories"><translate>Reason</translate></td>'+
						'<td><textarea name="reason" id="reason" cols="45" rows="5"></textarea></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td class="categories">&nbsp;</td>'+
						'<td><input type="button" name="button" id="applyLeave" class="color-button2 applyLeave" value="Submit" />'+
						'<input type="button" name="button" id="cencelApplication" class="color-button2 cencelApplication" value="Cancel" /></td>'+
					  '</tr>'+
					'</table></form></div>');
			$('#employeesList').getEmployees();
			
				console.log('tset');
			
$('.newLeaveApplicationWindow').show('blind',500);
	}
}

function saveLeaveRequest(){ 
	var $this = $(this);
	
	$this.attr('class','applyLeave1');
	
	var employeeid =$('#employeesList').val();
	var dataString = $('.newLeaveApplicationForm').serialize();
	
	$.post(serviceURLHR + "manageLeaves.php?act=newRequest&emp_id="+employeeid,dataString,function(){
		$('.newLeaveApplicationWindow').hide('blind',300,function(){ $(this).remove()});
		
	});
	$this.attr('class','applyLeave');
}


function changeRequestStatus(){
		var $this = $(this);
		var newStatus	 = $this.attr('data-status');
		var requestid	= $this.attr('requestid');
		$.get(hrURL + "manageLeaves.php?act=changeStatus&reqid="+requestid+"&set="+newStatus,function(){
				
				if(newStatus == 1){
					$this.attr({'src':'images/1388406658_ok-green.png','title':'Approved','data-status':'0'});
				}else{
					$this.attr({'src':'images/1388407735_delete_64.png','title':'Pending','data-status':'1'});
				}
				
				
				
		});
		
	
}
function HRchangeRequestStatus(){
		var $this = $(this);
		var newStatus	 = $this.attr('data-status');
		var requestid	= $this.attr('requestid');
		
		
		$.get(hrURL + "manageLeaves.php?act=HRchangeStatus&reqid="+requestid+"&set="+newStatus,function(){
				
				if(newStatus == 1){
					$this.attr({'src':'images/1388406658_ok-green.png','title':'Approved','data-status':'0'});
				}else{
					$this.attr({'src':'images/1388407735_delete_64.png','title':'Pending','data-status':'1'});
				}
				
				
				
		});
		
	
}

function Cancellleave(){
	
		var $this = $(this);
		var newStatus	 = $this.attr('data-status');
		var requestid	= $this.attr('requestid');
		
		$.get(hrURL + "manageLeaves.php?act=cancelStatus&reqid="+requestid+"&set="+newStatus,function(){
				
				if(newStatus == 1){
					$this.attr({'src':'images/1388406658_ok-green.png','title':'Cancelled','data-status':'0'});
				}else{
					$this.attr({'src':'images/1388407735_delete_64.png','title':'Not Cancelled','data-status':'1'});
				}
				
				
				
		});
		
	
}
////////////////////////////////////////////////  PAY SALARY ////////////////////////////////////////////

function salaryPayment(){

if($('.paymentMethod').length){
	
}else{
	$(".paySlipForm").append('<div class="paymentMethod" style="display:none">'+
					 '<table width="500" height="200" border="0" cellpadding="0" cellspacing="0">'+
					  '<tr>'+
						'<td width="217">&nbsp;</td>'+
						'<td width="304">&nbsp;</td>'+
					  '</tr>'+
					  '<tr>'+
						'<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
					  '</tr>'+
					  '<tr>'+
						'<td class="paymentmethod"><translate>Payment Method</translate></td>'+
						'<td>'+
						'<select name="paymentThrough" class="paymentThrough">'+
						'</select'+
						'</td>'+
					  '</tr>'+
					  '<tr>'+
						'<td class="referance_label"><translate>Referance</translate></td>'+
						'<td><input type="text" name="referance" id="referance" class="referance" /></td>'+
					  '</tr>'+

					  '<tr>'+
						'<td class="categories">&nbsp;</td>'+
						'<td><input type="button" name="button" id="submitSalary" class="color-button2" value="Submit" />'+
						'<input type="button" name="button" id="cancelPayment" class="color-button2" value="Cancel" /></td>'+
					  '</tr>'+
					'</table></div>');
	$('.paymentMethod').center();
	$('.paymentThrough').paymentMethods();
	
	$('.paymentMethod').show('fade',300);
}
	
}

function submitSalary(){
	var $this = $(this);
	var dataString = $('.paySlipForm').serialize();
	$.post(serviceURLHR + "manageSalary.php?act=paySal",dataString,function(){
																			
		$('.payCurrentSalary').val('Salary Paid');
		$('.payCurrentSalary').removeClass('payCurrentSalary');
		$('.printPaySlip').css({"display":"block","float":"left"});
		
		$('.paymentMethod').hide('fade',300,function(){ $(this).remove(); })
	});
}


loadimediatesupervisor();

function loadimediatesupervisor(){
	$.getJSON(serviceURLHR + 'immediatesupervisor.php?action=load',function(data){
		imdsupervisor = data.imdsupervisor;
		
		$.each(imdsupervisor, function(index, imdsupervisor) {
									 
				$('#imdatesupervisor').append('<option value="'+imdsupervisor.e_id+'">'+imdsupervisor.e_fname	+'</option>');
							
		});	
	});
}


loadBranch();

function loadBranch(){
	$.getJSON(serviceURLHR + 'branch.php?action=load',function(data){
		branch = data.branch;
		
		$.each(branch, function(index, branch) {
									 
							$('#branch').append('<option value="'+branch.branch_id+'">'+branch.branch_name	+'</option>');
							
		});	
	});
}

loadDesignation();

function loadDesignation(){
	
	$.getJSON(serviceURLHR + 'designations.php?action=load',function(data){
		designation = data.designation;
		
		$.each(designation, function(index, designation) {
									 
							$('#designation').append('<option value="'+designation.desig_id+'">'+designation.desig_name+'</option>');
							
		});	
	});
}


function printPaySlip(){
	
	$('.paymentSummery').append(  '<tr class="setHt">'+
                                    '<td width="50%" height="250"></td>'+
                                    '<td></td>'+
                                  '</tr>'+
								  
								  '<tr class="signature">'+
                                    '<td width="50%" height="150"><translate>Employer\'s Signature</translate></td>'+
                                    '<td align="right"><translate>Employee\'s Signature</translate></td>'+
                                  '</tr>');
	
	$('.color-button').css('display','none');

	$('.paySlip').print();
	$('.color-button').css('display','block');
	$('.signature').remove();
	$('.setHt').remove();
	
};





///////////////////////// getLeaveList to ListBox ///////////////////////////////////////////////////

jQuery.fn.loadLeaves = function getLeaveList(){
	selected =this;
	$('#leaveList').html('');
	var employeeid = $('#employeesList').val();
	$.getJSON(	serviceURLHR +"manageLeaves.php?act=getLeaves&emp_id="+employeeid,function(data){
		var leaves = data.leaves;
		$.each(leaves,function(index,leaves){ 
			selected.append('<option value='+leaves.lid+'>'+leaves.title+'</option>');
		});
	});
	loadLeavestat();
}


function loadLeavestat(){ 
	
	$.getJSON(serviceURLHR + 'branch.php?action=loadstst',function(data){
		 branch = data.branch;
		$.each(branch, function(index, branch) {
									 
							$('#empstat').append('<option value="'+branch.id+'">'+branch.emply_stat+'</option>'); 
							
		});	
	});
}

/////////////////////// getEmployeeList ListBox//////////////////////////////////////////////////////
jQuery.fn.getEmployees = function getEmployeesList(){
	$this = $(this);
	
	$.getJSON(	serviceURLHR +"manageEmployees.php?action=employeeslist",function(data){
		var employees = data.employees;
		$.each(employees,function(index,employees){
			$this.append('<option value='+employees.e_id+'>'+employees.e_fname+'</option>');
		});
		$('#leaveList').loadLeaves();
	});
}



/////////////////////// Load PaymentMethods list to select box //////////////////////////////////////
jQuery.fn.paymentMethods = function getPaymentMethodList(){
	$this = this;
	$.getJSON(	serviceURLHR +"paymentMethods.php?act=list",function(data){
		var methods = data.methods;
		$.each(methods,function(index,methods){
			$this.append('<option value='+methods.id+'>'+methods.title+'</option>');
		});
	});
}


////////////////////////////// Months list //////////////////////////////
jQuery.fn.getmonths = function setAllMunths(paymentmonth){
	$this = this;

	
	var currentMonth =paymentmonth;
	$this.html('');

var months = ["January", "February", "March", "April", "May", "June",
                  "July", "August", "September", "October", "November", "December"];

	$.each(months,function(index,months){
		if( (parseInt(index)+1) == currentMonth){
			$this.append('<option selected="selected" value="'+ (parseInt(index)+1) +'">'+months+'</option>');	
		}else{
			$this.append('<option value="'+ (parseInt(index)+1) +'">'+months+'</option>');	
		}
		
	});


}

////////////////////////////// Year list //////////////////////////////
jQuery.fn.getYears = function setAllYears(paymentyear){
	$this = this;
	var currentYear =paymentyear; 
	$this.html('');


    var dt = new Date();
	var thisyear =dt.getFullYear(); 
	
	
	
	for ( i = 2013; i < (parseInt(thisyear)+1); i += 1 ) {  
		if( i == currentYear){
			$this.append('<option selected="selected" value="'+ i +'">'+i+'</option>');	
		}else{
			$this.append('<option value="'+ i +'">'+i+'</option>');	
		}
	}



}
/////////////////////////////////////////// Holiday Calendar ////////////////////////////////////////
/*function holidayCalendar(){
	removeCurrentPage();
	$("#tablelist").append('<table class="calendarHolder" style="display:none"><tr></td><div id="calendar"></div></td></tr></table>');
		var calendar = $('#calendar').fullCalendar({
		
		//	editable: true,
			
			eventSources: [ {url:hrURL + "holidatManagement.php?act=list"}],
			
			eventDrop: function(event, delta) {
			//	alert(event.title + ' was moved ' + delta + ' days\n' +
					//'(should probably update your database)');
				date = new Date(event.start).format("yyyy-mm-dd");
				$.get(hrURL + "holidatManagement.php?act=update&title"+event.title+"&start="+date+"&id="+event.id);
				
			},
			selectable: true,
			selectHelper: true,
			select: function(start, end, allDay) {
				var title = prompt('Event Title:');
				if (title) {
					date = new Date(start).format("yyyy-mm-dd");
					$.get(hrURL + "holidatManagement.php?act=addNew&title="+title+"&start="+date,function(){
					
					calendar.fullCalendar('renderEvent',{
							title: title,
							start: start,
							end: end,
							allDay: allDay
						},true );
					 });
				}
				calendar.fullCalendar('unselect');
			},
			eventClick: function (calEvent, jsEvent, view) {       
				 if(confirm('Are you sure from removing the event?')){
					 $.get(hrURL + "holidatManagement.php?act=remove&id="+calEvent._id)
						$('#calendar').fullCalendar('removeEvents', calEvent._id);
				 }
			},
			
			loading: function(bool) {
				if (bool) $('#loading').show();
				else $('#loading').hide();
			}
			
		});
	$('.calendarHolder').show('blind',500);
	//calendar.fullCalendar()
	
}
*/
////////////////////////////////////////////////////////////////////  REPORTS  //////////////////////////////////////////////////////
function paymentHistory(){
	

	var selectedMth = $('.paymentHistorypaymentmonth').val();
	var selectedYear = $('.paymentHistorypaymentyear').val();
	
	if(!selectedMth){
		selectedMth = 1;
		selectedYear =2014;
	}
	
	removeCurrentPage();
	$('.header').show('blind',500);

	$("#tablelist").append('<table class="report-holder" style="display:none;">'+
						   '<tr><td>'+
						   '<select name="year" class="paymentHistorypaymentyear" data-id="">'+
									'</select>'+
									
									'<select name="month"  class="paymentHistorypaymentmonth" data-id="">'+
									'</select>'+
						   
						   '</td></tr>'+
						   '<tr><td><ul class="grandTotals">'+
							'<li class="salaryTotal"></li>'+
							'<li class="deductionTotal"></li>'+
							'<li class="earningsTotal"></li>'+
							'</ul>'+
							'<ul class="earnings">'+
							'<li class="earningsList"></li>'+
							'<li class="earningsList"></li>'+
							'<li class="earningsList"></li>'+
							'</ul>'+
'</td></tr></table>');
	
	$.getJSON(hrURL + "paymentReports.php?act=dashboard&month="+selectedMth+"&year="+selectedYear,function(data){
		
		
	if(data.dashboard.earningsList !== true)	{

	$('.salaryTotal').html('Paid Salary : '+data.dashboard.totalPaidAmt); 
	
	
	var totalDeductions=0;
	var totalEarnings=0;
	
	var deductionAndEarningsList=data.dashboard.earningsList;
	$('.earnings').html('');
		$.each(deductionAndEarningsList,function(index,deductionAndEarningsList){
				if(deductionAndEarningsList.deduction_benefit =="1"){
					$('.grandTotals').append('<li class="earningsList">'+deductionAndEarningsList.name+' : '+deductionAndEarningsList.totalDeduction+'</li>');	
					
					totalDeductions += parseFloat(deductionAndEarningsList.totalDeduction);
					
				}else if(deductionAndEarningsList.deduction_benefit =="2"){
					$('.grandTotals').append('<li class="earningsList">'+deductionAndEarningsList.name+' : '+deductionAndEarningsList.totalDeduction+'</li>');	
					totalEarnings += parseFloat(deductionAndEarningsList.totalDeduction);
					
				}else{
					$('.grandTotals').append('<li class="earningsList">'+deductionAndEarningsList.name+' : '+deductionAndEarningsList.totalDeduction+'</li>');	
				}
				
				
	
				
				
		});
		$('.report-holder').show('blind',500);
		$('.deductionTotal').html('Total Deduction : '+parseFloat(totalDeductions).toFixed(2)); 	
		$('.earningsTotal').html('Total Earnings : '+parseFloat(totalEarnings).toFixed(2)); 
	
	
	}else{
		$("#tablelist").html('<table class="report-holder" style="display:none;">'+
						   '<tr><td>'+
						   '<select name="year" class="paymentHistorypaymentyear" data-id="">'+
									'</select>'+
									
									'<select name="month"  class="paymentHistorypaymentmonth" data-id="">'+
									'</select>'+
						   
						   '</td></tr>'+
						   '<tr><td>No Data found ! '+
						'</td></tr></table>');
		
		$('.report-holder').show('blind',500);
		$('.paymentHistorypaymentmonth').getmonths(selectedMth);
		$('.paymentHistorypaymentyear').getYears(selectedYear);
		
	}
	
	

		
	
		
		
	})
	
		$('.paymentHistorypaymentmonth').getmonths(selectedMth);
	$('.paymentHistorypaymentyear').getYears(selectedYear);
	
}



function paidSalaryReport(){
	
	
}

function deductionAndEarningsReport(){
	
	
}
function deductionManagement()
{
	window.location="payroll-management.php#deductionManagement";
}
function leaveManagement()
{
	window.location="payroll-management.php#leaveManagement";
}
function holidayCalendar()
{
	window.location="payroll-management.php#holidayCalendar";
}
function paySalary()
{
	window.location="payroll-management.php#paySalary";
}
function pfRequests(e,pageno){
	window.location="pf_listing.php#pfRequests";
	if(!pageno)
	pageno =1;
	
	
	var searchString = $('.pFSearchForm').serialize(); 
	
	//alert(searchString);
	if(pageno == 1 ){
			k=1; 
		 }else{
			k= ((pageno-1) * pageLimit)+1;
		 }
		 var tot = 0;
		 
		 $(".searchesi").css("display", "none");
		 $(".searchPF").css("display", "block");
		 $(".pf_esisearchform").css("display", "block");
		 $(".ded_searchform").css("display", "none");
	/*$(".searchpersonalPdt").css("display", "none");
	$(".searchPdt").css("display", "block");
	$(".designation").css("display", "block");
	$(".branch").css("display", "block");
	$(".imdatesupervisor").css("display", "block");
	var userid=$('.userid').val();
	var depart_id=$('.depart_id').val();
	$('.header').show('blind',500);
	removeCurrentPage();
	var userid=$('.userid').val();var user_name=$('.user_name').val();var depart_id=$('.depart_id').val();
	*/
	removeCurrentPage();
	var lastPage;

	$('#tablelist').append('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leaverequests">'+
										  '<tr>'+
											'<td width="15%"><translate>Sl No</translate></td>'+
											'<td width="15%"><translate>Employee</translate></td>'+
											'<td width="10%"><translate>Month</translate></td>'+
											'<td width="10%"><translate>Year</translate></td>'+
											'<td width="10%"><translate>Employee PF</translate></td>'+
											'<td width="12%"><translate>Company Contribution PF</translate></td>'+
													
										 '</tr>'+
										'</table>')	;
		//$.getJSON(hrURL + "manageLeaves.php?act=loadRequests&userid="+userid+"&page="+pageno+"&depart_id="+depart_id+"&"+searchString,function(data){

	$.getJSON(hrURL + "manageLeaves.php?act=PFRequests&page="+pageno+"&"+searchString,function(data){
		var pfdetails = data.get_pfdetails;
		
		$.each(pfdetails,function(index,pfdetails){
		
		var dates = pfdetails.pay_period;
		var mnt = new Date(dates).format("mmmm");
		var year = new Date(dates).format("yyyy");
		
		var pf_viewdetails='<tr>'+
						'<td width="15%">'+k+'</td>'+
						'<td width="15%">'+pfdetails.e_fname+'</td>'+
						'<td width="15%">'+mnt+'</td>'+
						'<td width="15%">'+year+'</td>'+
						'<td width="15%">'+pfdetails.cmp_pf+'</td>'+
						'<td width="28%">'+pfdetails.emp_pf+'</td>'+
						'</tr>';	

				$('.list-leaverequests').append(pf_viewdetails);	
				itemCount = pfdetails.totalrows;
				lastPage  = pfdetails.lastPage;
								
				k++;
			});
			$('.list-leaverequests').show('blind');
			$("#light-pagination").jui_pagination({
				totalPages: lastPage,
			});
			
			
			
	});
	
	
	
}


function esiRequests(e,pageno){
	window.location="pf_listing.php#esiRequests";
	if(!pageno)
	pageno =1;
	
	
	var searchString = $('.pFSearchForm').serialize(); 
	
	//alert(searchString);
	if(pageno == 1 ){
			k=1; 
		 }else{
			k= ((pageno-1) * pageLimit)+1;
		 }
		 var tot = 0;
		 $(".searchesi").css("display", "block");
		 $(".searchPF").css("display", "none");
	/*$(".searchpersonalPdt").css("display", "none");
	$(".searchPdt").css("display", "block");
	$(".designation").css("display", "block");
	$(".branch").css("display", "block");
	$(".imdatesupervisor").css("display", "block");
	var userid=$('.userid').val();
	var depart_id=$('.depart_id').val();
	$('.header').show('blind',500);
	removeCurrentPage();
	var userid=$('.userid').val();var user_name=$('.user_name').val();var depart_id=$('.depart_id').val();
	*/
	removeCurrentPage();
	var lastPage;

	$('#tablelist').append('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leaverequests">'+
										  '<tr>'+
											'<td width="15%"><translate>Sl No</translate></td>'+
											'<td width="15%"><translate>Employee</translate></td>'+
											'<td width="10%"><translate>Month</translate></td>'+
											'<td width="10%"><translate>Year</translate></td>'+
											'<td width="10%"><translate>Employee ESI</translate></td>'+
											'<td width="12%"><translate>Company Contribution PF</translate></td>'+
													
										 '</tr>'+
										'</table>')	;
		//$.getJSON(hrURL + "manageLeaves.php?act=loadRequests&userid="+userid+"&page="+pageno+"&depart_id="+depart_id+"&"+searchString,function(data){

	$.getJSON(hrURL + "manageLeaves.php?act=esiRequests&page="+pageno+"&"+searchString,function(data){
		var esidetails = data.get_esidetails;
		
		$.each(esidetails,function(index,esidetails){
		
		var dates = esidetails.pay_period;
		var mnt = new Date(dates).format("mmmm");
		var year = new Date(dates).format("yyyy");
		
		var esi_viewdetails='<tr>'+
						'<td width="15%">'+k+'</td>'+
						'<td width="15%">'+esidetails.e_fname+'</td>'+
						'<td width="15%">'+mnt+'</td>'+
						'<td width="15%">'+year+'</td>'+
						'<td width="15%">'+esidetails.cmp_esi+'</td>'+
						'<td width="28%">'+esidetails.emp_esi+'</td>'+
						'</tr>';	

				$('.list-leaverequests').append(esi_viewdetails);	
				itemCount = esidetails.totalrows;
				lastPage  = esidetails.lastPage;
								
				k++;
			});
			$('.list-leaverequests').show('blind');
			$("#light-pagination").jui_pagination({
				totalPages: lastPage,
			});
			
			
			
	});
	
	
	
}

function employeewageregister(){
	var $this = $(this);
	var dataString = $('.pdtWageSearchForm').serialize();
	var pagenum=1;
	var URLHR = 'http://192.168.1.6:8081/HRMK/';
	$('#busy').show();
	$.get(URLHR + "register-wages.php?act=wageRequests&"+dataString,function(data){
																			
			$("body").html(data);
	});
	
}







///////////////////////////////////////////////EVENT MANAGEMENT//////////////////////////////////////////
jQuery('.payCurrentSalary').live('click',salaryPayment);
jQuery('.addNewLeaves').live('click',addNewLeaves);
jQuery('.saveLeave').live('click',saveLeave);
jQuery('.addNewDeduction').live('click',addnewDeduction);
jQuery('.saveDeduction').live('click',saveNewDeduction);
jQuery('.payslip').live('click',preloadPaySlip);
jQuery('#cancelPayment').live('click',function(){ $('.paymentMethod').hide('fade',300,function(){ $(this).remove(); }) });
jQuery('#submitSalary').live('click',submitSalary);
jQuery('.paymentmonth').live('change',preloadPaySlip);
jQuery('.paymentyear').live('change',preloadPaySlip);
jQuery('.removeDeduction').live('click',removeDeduction);
jQuery('.removeLeave').live('click',removeLeaveType);
jQuery('.printPaySlip').live('click',printPaySlip);
jQuery('.gobacktolist').live('click',paySalary);
jQuery('.approveLeave').live('click',changeRequestStatus);
jQuery('.HRapproveLeave').live('click',HRchangeRequestStatus);
jQuery('.Cancellleave').live('click',Cancellleave);
jQuery('.cancelDeduction').live('click',function(){ $('.newDeductionform').hide('blind',500,function(){ $(this).remove(); }) });
jQuery('.cancelNewLeave').live('click',function(){ $('.newLeaveform').hide('blind',500,function(){ $(this).remove(); }); });
jQuery('.addNewLeaveRequest').live('click',newLeaveRequest);
jQuery('.addNewpersonalLeaveRequest').live('click',addNewpersonalLeaveRequest);
/*jQuery('.addNewpersonalLeaveRequestss').live('click',newpersonalLeaveRequest);*/

jQuery('#employeesList').live('change',function(){ $('#leaveList').loadLeaves(); balanceLeaveTable();});
jQuery('.applyLeave').live('click',saveLeaveRequest);
jQuery('.cencelApplication').live('click',function(){ $('.newLeaveApplicationWindow').hide('blind',300,function(){ $(this).remove()}); });
jQuery('.applypersonalLeave').live('click',savepersonalLeaveRequest);
jQuery('.cancelpersonalApplication').live('click',function(){ $('.newpersonalLeaveApplicationWindow').hide('blind',300,function(){ $(this).remove()});
																																				  $(".cantcancel").each(function(){
		 $(this).attr('class', 'Cancellleave');
	});});
jQuery('.paymentHistorypaymentmonth').live('change',paymentHistory);
jQuery('.paymentHistorypaymentyear').live('change',paymentHistory);
jQuery('.cancelpersonelleave').live('click',cancelpersonelleave);

$("#printdiv").print();
//////////////////////////////////////////////  Common popup function //////////////////////////////////

jQuery.fn.center = function(parent) {
    if (parent) {
        parent = this.parent();
    } else {
        parent = window;
    }
    this.css({
        "position": "absolute",
        "top": ((($(parent).height() - this.outerHeight()) / 2) + $(parent).scrollTop() + "px"),
        "left": ((($(parent).width() - this.outerWidth()) / 2) + $(parent).scrollLeft() + "px")
    });
return 
}
