$(document).ready(function(){
	load();
});



// ===============================
function call_medium(id){
	var datastr="shift_id="+id;
	$("#medium_id").load("module/settings/get_medium_list_for_form.php",datastr);
}
function call_class(id){
	var datastr="medium_id="+id;
	$("#class_id").load("module/settings/get_class_list_for_form.php",datastr);
}
function call_department(id){
	var datastr="class_id="+id;
	$("#department_id").load("module/settings/get_department_list_for_form.php",datastr);
}
function call_std_type(id){
		var datastr="department_id="+id;
	$("#student_type_id").load("module/settings/get_student_type_list_for_form.php",datastr);
}
function call_section(id){
		var datastr="student_type_id="+id;
	$("#section_id").load("module/settings/get_section_list_for_form.php",datastr);
}

// ===============
function call_std_list(id){
	var datastr="section_id="+id;
	$(".section_std_list").load( "module/profile/student/sec_wise_std.php" ,  datastr  );
}





$("#btn_go").click(function(){

	var month_id = $("#month_id").val();
	var year_id = $("#year_id").val();
	var section_id=$("#section_id").val();
	
	
	var datastr_sc="month="+month_id+"&year="+year_id+"&section_id="+section_id+"&action=show_data";
	//alert(datastr_sc);

	if(month_id==""){
		alert("Select Month Name");
		$('#month_id').focus();
		return false;
	}
	else if(year_id==""){
		alert("Select Year");
		$('#year_id').focus();
		return false;
	}
	
	else if(section_id==""){
		alert("Select Section");
		$('#section_id').focus();
		return false;
	}
	
	

	else{

//		$("#data").load("module/hr_admin/entry_emp_attendance.php",datastr_sc);

		$("#data").load("module/attendance/entry_std_monthly_attendance.php",datastr_sc);

		//$('#first_part').remove();
		$('#second_part').css("display","block");

	}


});

$("#btn_generate").click(function(){


	var month_id = $("#month_id").val();
	var year_id = $("#year_id").val();
	var section_id=$("#section_id").val();
	
	
	//var datastr_sc="month="+month_id+"&year="+year_id;
	var datastr_sc="month="+month_id+"&year="+year_id+"&section_id="+section_id+"&action=generate_data";
	
	//alert(datastr_sc);

	if(month_id==""){
		alert("Select Month Name");
		$('#month_id').focus();
		return false;
	}
	else if(year_id==""){
		alert("Select Year");
		$('#year_id').focus();
		return false;
	}
	
	else if(section_id==""){
		alert("Select Section");
		$('#section_id').focus();
		return false;
	}
	
	else{

//		$("#data").load("module/hr_admin/entry_emp_attendance.php",datastr_sc);

		$("#data").load("module/attendance/entry_std_monthly_attendance.php",datastr_sc);

		//$('#first_part').remove();
		$('#second_part').css("display","block");

	}

});


// =================================================


$('div#parent').on('click','#save_emp_attnd',function(){

	var present=[];		
	   var pr_div = $('table#datatable_01').find('tbody td input.p');
	   
	   $(pr_div).each(function(i){

	   		present[i] = $(this).val();
	   });
       
    var absent=[];		
	   var ab_div = $('table#datatable_01').find('tbody td input.a');
	   
	   $(ab_div).each(function(i){
	   	
	   		absent[i] = $(this).val();
	   });

	var late=[];		
	   var lt_div = $('table#datatable_01').find('tbody td input.lt');
	   
	   $(lt_div).each(function(i){
	   	
	   		late[i] = $(this).val();
	   });   
    
    var leave=[];		
	   var lv_div = $('table#datatable_01').find('tbody td input.lv');
	   
	   $(lv_div).each(function(i){
	   	
	   		leave[i] = $(this).val();
	   });      	
	

	 var comment=[];		
	   var cm_div = $('table#datatable_01').find('tbody td input.cmnt');
	   
	   $(cm_div).each(function(i){
	   	
	   		comment[i] = $(this).val();
	   });

	 var std_id=[];		
	   var id_div = $('table#datatable_01').find('tbody td input.std_id');
	   
	   $(id_div).each(function(i){
	   	
	   		std_id[i] = $(this).val();
	   });   

      	


      	var month = $("#month_id").val();
	    var year = $("#year_id").val();
		var section_id= $("#section_id").val(); 
	    var opr="update";
        
     var dataStr="section_id="+section_id+"&month="+month+"&year="+year+"&std_id="+std_id+"&comment="+comment+"&leave="+leave+"&late="+late+"&absent="+absent+"&present="+present+"&opr="+opr;
	 //alert(dataStr);

		$.ajax({
			type:"post" ,
		  	url:"module/attendance/entry_std_monthly_attendance_ajax.php" ,
		  	data:dataStr ,
		  	success:function(st){
				alert(st);
				load();

		  	}
        });
	

});


$("#btn_save_daily_atdsheet").click(function(){

AJAXProcess('module/hr_admin/entry_emp_attendance_ajax','attendance_sheet');

});

function ajaxResponse(data) 
{   

 alert(data);

}


$('div#parentdv').on('click','#save_emp_timing',function(){

	var in_time=[];		
	   var pr_div = $('table#datatable_02').find('tbody td input.in');
	   
	   $(pr_div).each(function(i){

	   		in_time[i] = $(this).val();
	   });
       
    var out_time=[];		
	   var ab_div = $('table#datatable_02').find('tbody td input.out');
	   
	   $(ab_div).each(function(i){
	   	
	   		out_time[i] = $(this).val();
	   });

	    var id=[];		
	   var id_div = $('table#datatable_02').find('tbody td input.id');
	   
	   $(id_div).each(function(i){
	   	
	   		id[i] = $(this).val();
	   })

	   opr="update_timing";


	
     var dataStr1="in_time="+in_time+"&out_time="+out_time+"&opr="+opr+"&id="+id;
	//alert(dataStr1);

		$.ajax({
			type:"post" ,
		  	url:"module/hr_admin/entry_emp_attendance_ajax.php" ,
		  	data:dataStr1 ,
		  	success:function(st){
				alert(st);
				load();

		  	}
        });
	

});

function day_select(day_select_id,status){
	var opr="status_update";
	var dataStr11="day_select_id="+ day_select_id +"&status=" + status+"&opr="+opr; 
	//alert(dataStr11);
	
	 $.ajax({
		type:"post",
		url:"module/hr_admin/entry_emp_attendance_ajax.php",data:dataStr11 ,success:function(st){
			 //alert(st);
		
		}
	}); 
}

function absent_status(ab_status){
	var opr="ab_status_update";
	var dataStr_ab="ab_status="+ab_status+"&opr="+opr; 
	//alert(dataStr_ab);
	
	 $.ajax({
		type:"post",
		url:"module/hr_admin/entry_emp_attendance_ajax.php",data:dataStr_ab ,success:function(st){
			 //alert(st);
		
		}
	}); 
}

function late_status(lt_status){
	var opr="lt_status_update";
	var dataStr_lt="lt_status="+lt_status+"&opr="+opr; 
	//alert(dataStr_lt);
	
	 $.ajax({
		type:"post",
		url:"module/hr_admin/entry_emp_attendance_ajax.php",data:dataStr_lt ,success:function(st){
			 //alert(st);
		
		}
	}); 
}

function leave_status(lv_status){
	var opr="lv_status_update";
	var dataStr_lv="lv_status="+lv_status+"&opr="+opr; 
	//alert(dataStr_lv);
	
	 $.ajax({
		type:"post",
		url:"module/hr_admin/entry_emp_attendance_ajax.php",data:dataStr_lv ,success:function(st){
			 //alert(st);
		
		}
	}); 
}


$("#emp_attndnc_rule").click(function(){

	var absent_day = $("#absent").val();
	var late_day = $("#late").val();
	var leave_day = $("#leave").val();
	
	opr="emp_attndnc_rule";
	var datastr_ru="absent_day="+absent_day+"&late_day="+late_day+"&leave_day="+leave_day+"&opr="+opr;
	//alert(datastr_ru);

   	$.ajax({
			type:"post" ,
		  	url:"module/hr_admin/entry_emp_attendance_ajax.php" ,
		  	data:datastr_ru ,
		  	success:function(st){
				alert(st);
				load();

		  	}
        });
	



});

function leave_setting_status(id,status){
	var opr="leave_status_update";
	var dataStr110="id="+id +"&status=" + status+"&opr="+opr; 
	//alert(dataStr110);
	
	 $.ajax({
		type:"post",
		url:"module/hr_admin/entry_emp_attendance_ajax.php",data:dataStr110 ,success:function(st){
			 //alert(st);
		
		}
	}); 
}


$('div#parentdvi').on('click','#emp_leave_setting',function(){

	var days=[];		
	   var pr_div = $('table#datatable_021').find('tbody td input.day');
	   
	   $(pr_div).each(function(i){

	   		days[i] = $(this).val();
	   });
       

	    var id=[];		
	   var id_div = $('table#datatable_021').find('tbody td input.id');
	   
	   $(id_div).each(function(i){
	   	
	   		id[i] = $(this).val();
	   })

	   opr="update_setting_leave";


	
     var dataStr111="days="+days+"&opr="+opr+"&id="+id;
	//alert(dataStr111);

		$.ajax({
			type:"post" ,
		  	url:"module/hr_admin/entry_emp_attendance_ajax.php" ,
		  	data:dataStr111 ,
		  	success:function(st){
				alert(st);
				load();

		  	}
        });
	

});

$("#btn_leave_head_add").click(function(){

	var leave_name = $("#lv_name").val();
	var allow = $("#allow").val();
	var days = $("#lv_days").val();

	if(leave_name==""){
		alert("Enter Leave Name");
		$('#lv_name').focus();
		return false;
	}

	if(allow==""){
		alert("allow ");
		$('#allow').focus();
		return false;
	}
	
	opr="leave_head_add";
	var datastr_ru="leave_name="+leave_name+"&allow="+allow+"&days="+days+"&opr="+opr;
	//alert(datastr_ru);
	reset();

   	$.ajax({
			type:"post" ,
		  	url:"module/hr_admin/entry_emp_attendance_ajax.php" ,
		  	data:datastr_ru ,
		  	success:function(st){
				alert(st);				
				load();

		  	}
        });
	



});



function load(){
	$(".setup_load").load("module/hr_admin/get_setting.php");
	
}
// ============================================


$(".pid").click(function () {
   var id=( $(this).parents('td:first').find('.e_id').val());
   var datastr132="emp_id="+id;
   //alert(datastr132);
	$("#lv_id1").load("module/hr_admin/get_leave_type_without.php",datastr132);
	 
});

$(".pwi").click(function () {
   var id=( $(this).parents('td:first').find('.em_id').val());
   var datastr142="emp_id="+id;
	$("#lv_id").load("module/hr_admin/get_leave_type.php",datastr142);
});



function check_remain(head_id){
	//var opr="leave_status_update";
	var emp_id = $("#emp_id").val();
	var dataStr110="leave_id="+head_id +"&id="+emp_id; 
	//alert(dataStr110);
	
$(".remaining_leave").load("module/hr_admin/get_leave_emplv_info.php",dataStr110); 
}

function check_remain_without(head_id){
	//var opr="leave_status_update";
	var emp_id = $("#emp_id").val();
	var dataStr110="leave_id="+head_id +"&id="+emp_id; 
	//alert(dataStr110);
	
$(".remaining_leave_without").load("module/hr_admin/get_leave_emplv_info.php",dataStr110); 
}





function modal_reset_with_pay(){
	$(".remaining_leave").load("module/hr_admin/get_leave_emplv_info.php"); 
	$("#remark_w").val('');
	$("#lv_date").val('');
	
}

// ========================================================================

$("#btn_leave_with_pay").click(function(){
    
	var remark = $("#remark_w").val();
	var leave_dates =$("#lv_date").val();
	var emp_id = $("#emp_id").val();
	var leave_id =$("select[name=lv_idr]").val();
	
	var opr="entry_leave_with_pay";
	
	
	var datastr_lv_withpay="leave_dates="+leave_dates+"&opr="+opr+"&emp_id="+emp_id+"&leave_id="+leave_id+"&remark="+remark;

	//alert(datastr_lv_withpay);
	var month_id = $("#month_id").val();
	var year_id = $("#year_id").val();
	
	
	var datastr_sc="month="+month_id+"&year="+year_id;
	//alert(datastr_sc);

	if(remark==""){
		alert("Enter Remark");
		$('#remark_w').focus();
		return false;
	}
   else if(leave_dates==""){
		alert("Select Leave Dates");
		$('#lv_date').focus();
		return false;
	}
	else{

	$.ajax({
			type:"post" ,
		  	url:"module/hr_admin/leave_entry_ajax.php" ,
		  	data:datastr_lv_withpay,
		  	success:function(st){
			alert(st);
			$("#data").load("module/hr_admin/entry_emp_attendance.php",datastr_sc);
			
		  	}
		  });
		}
modal_reset_with_pay();
});


function modal_reset_without_pay(){
	$(".remaining_leave_without").load("module/hr_admin/get_leave_emplv_info.php"); 
	$("#remark_wot").val('');
	$("#lv_date1").val('');
	
}


$("#btn_leave_without_pay").click(function(){

	var remark = $("#remark_wot").val();
	var leave_dates =$("#lv_date1").val();
	var emp_id = $("#emp_id").val();
	//var leave_id =$("select[name=lv_idr]").val();
	var leave_id =$("#leave_head_id").val();
	
	var opr="entry_leave_without_pay";
	
	
	var datastr_lv_withoutpay="leave_dates="+leave_dates+"&opr="+opr+"&emp_id="+emp_id+"&leave_id="+leave_id+"&remark="+remark;
	//alert(datastr_lv_withoutpay);
	var month_id = $("#month_id").val();
	var year_id = $("#year_id").val();
	
	
	var datastr_sc="month="+month_id+"&year="+year_id;
	//alert(datastr_sc);
	

	if(remark==""){
		alert("Enter Remark");
		$('#remark_wot').focus();
		return false;
	}
   else if(leave_dates==""){
		alert("Select Leave Dates");
		$('#lv_date1').focus();
		return false;
	}

	else{

	$.ajax({
			type:"post" ,
		  	url:"module/hr_admin/leave_entry_ajax.php" ,
		  	data:datastr_lv_withoutpay,
		  	success:function(st){
			alert(st);
			$("#data").load("module/hr_admin/entry_emp_attendance.php",datastr_sc);
			
		  	}
		  });
		}
modal_reset_without_pay();
});

function show_edit_view_leave_head(id){
	
	var operation='edit';
	var datastr="id="+id +"&operation="+operation;
    //alert(datastr);
	$("#value_for_leave_head").load("module/hr_admin/pay_head_edit.php",datastr);

}


// ============================================================

$("#btn_leave_head_update").click(function(){

	var leave_head = $("#e_lv_head").val();
	var leave_days =$("#e_lv_days").val();
	var allow = $("#e_allow").val();
	var id = $("#edit_pay_head_id").val();

	var opr="update_leave_head";
	
	
	var datastr_lv_head_update="leave_head="+leave_head+"&leave_days="+leave_days+"&allow="+allow+"&opr="+opr+"&id="+id;
	//alert(datastr_lv_head_update);

	

	$.ajax({
			type:"post" ,
		  	url:"module/hr_admin/leave_entry_ajax.php" ,
		  	data:datastr_lv_head_update,
		  	success:function(st){
			alert(st);
			load();
			
		  	}
		  });
});


function delete_data(id){
	 var datastr="id="+id+"&opr="+"delete";
	//alert(datastr);
		 $.ajax({
				type:"post",
				url:"module/hr_admin/leave_entry_ajax.php",
				data:datastr ,
				success:function(st){
					alert(st);
					load();
				}
			}); 
	
}

function reset(){

	$('#lv_name').val('');
	$('#lv_days').val('');
	$('#allow').val('');

}