0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 3.145.43.200


Current Path : /var/www/html/oums/js/
Upload File :
Current File : /var/www/html/oums/js/attendance.js

function load_page() {
	load_page_data(
		window.location.href.substr(window.location.href.lastIndexOf("/") + 1)
	);
	clrs_data();
	load_dept_data();
	document.getElementById("txtattndate").value = get_today_date();
}

function clrs_data() {
	$("#btn_save").hide();
	$(function () {
		$("#txtattndate").datepicker({ dateFormat: "dd/mm/yy" });
	});
	document.getElementById("selattnmark").selectedIndex = 0;
	document.getElementById("seldeptcode").focus();
	$("#page-container-grid").empty();
}

function load_dept_data() {
	var load_data = "dept_detl";
	$.ajax({
		type: "POST",
		url: "src/attendance.php",
		data: "load_data=" + load_data,
		cache: false,
		beforeSend: function () {
			show_process();
		},
		success: function (data) {
			$("#seldeptcode").html(data);
			load_mark_detl($("#seldeptcode").val());
			hide_process();
		},
		error: function (html) {
			$("#seldeptcode").html("Error: " + data);
		},
	});
}

function load_mark_detl() {
	var load_data = "mark_detl";
	dept_code = document.getElementById("seldeptcode").value;
	$.ajax({
		type: "POST",
		url: "src/attendance.php",
		data: {
			load_data: load_data,
			dept_code: dept_code,
		},
		cache: false,
		beforeSend: function () {
			show_process();
		},
		success: function (data) {
			$("#selattnmark").html(data);
			hide_process();
		},
		error: function (html) {
			$("#selattnmark").html("Error: " + data);
		},
	});
}

function view_data() {
	if (document.getElementById("seldeptcode").value == 0) {
		alert("Please select client!");
		seldeptcode.focus();
		return false;
	}

	if (document.getElementById("txtattndate").value == "") {
		alert("Please enter date!");
		txtattndate.focus();
		return false;
	}

	load_data = "view_data";
	dept_code = document.getElementById("seldeptcode").value;
	attn_date = document.getElementById("txtattndate").value;
	attn_mark = document.getElementById("selattnmark").value;

	$.ajax({
		type: "POST",
		url: "src/attendance.php",
		data: {
			load_data: load_data,
			dept_code: dept_code,
			attn_date: attn_date,
			attn_mark: attn_mark,
		},
		cache: false,
		beforeSend: function () {
			show_process();
		},
		success: function (data) {
			$("#page-container-grid").html(data);
			$("#btn_save").show();
			hide_process();
		},
		error: function (data) {
			hide_process();
			$("#page-container-grid").html("Error: " + data);
		},
	});
}

function display_values(r) {
	var row_index = r.parentNode.parentNode.rowIndex;
	var arr_index = row_index - 1;
	var attn_stat1 = document.getElementsByName("txtattnstat[]");
	var attn_stat2 = attn_stat1[arr_index].value;

    fields = attn_stat2.split("*");
    
	var xlogi_hour = document.getElementsByName("txtlogihour[]");
	xlogi_hour[arr_index].value = fields[2];
	var xlogi_mins = document.getElementsByName("txtlogimins[]");
	xlogi_mins[arr_index].value = fields[3];
	var xlogi_secs = document.getElementsByName("txtlogisecs[]");
	xlogi_secs[arr_index].value = fields[4];
	var xtrvl_amnt = document.getElementsByName("txttrvlamnt[]");
	xtrvl_amnt[arr_index].value = fields[5];
}

//Validate row
function validate_row(r) {
	var row_index = r.parentNode.parentNode.rowIndex;
	var arr_index = row_index - 1;

	//Validate for expense head selection
	var xstat_val1 = document.getElementsByName("txtattnstat[]");
	var xlogi_hrs1 = document.getElementsByName("txtlogihour[]");
	var xlogi_min1 = document.getElementsByName("txtlogimins[]");
	var xlogi_sec1 = document.getElementsByName("txtlogisecs[]");
	var xlogo_hrs1 = document.getElementsByName("txtlogohour[]");
	var xlogo_min1 = document.getElementsByName("txtlogomins[]");
	var xlogo_sec1 = document.getElementsByName("txtlogosecs[]");
	var xtrvl_amnt = document.getElementsByName("txttrvlamnt[]");
	var xover_time = document.getElementsByName("txtovertime[]");
	var xcode_pack = document.getElementsByName("txtcodepack[]");

	var xstat_valx = xstat_val1[arr_index].value;
	var xdefa_valx = xstat_valx.split("*");

	var ldept_code = xdefa_valx[0];
	var lattn_stat = xdefa_valx[1];
	var llogi_hour = xdefa_valx[2];
	var llogi_mins = xdefa_valx[3];
	var llogi_secs = xdefa_valx[4];
	var ltrvl_amnt = xdefa_valx[5];

	var xlogi_hour = xlogi_hrs1[arr_index].value;
	var xlogi_mins = xlogi_min1[arr_index].value;
    var xlogi_secs = xlogi_sec1[arr_index].value;
    
	var xlogo_time = xlogo_hrs1[arr_index].value;
	var xlogo_mins = xlogo_min1[arr_index].value;
	var xlogo_secs = xlogo_sec1[arr_index].value;

	if (lattn_stat == "0") {
		alert("Please select attendance status!");
		xstat_val1[arr_index].focus();
		return false;
	}

	if (lattn_stat == "CD") {
		var xcode_pack = document.getElementsByName("txtcodepack[]");
		if (xcode_pack[arr_index].value == 0) {
			alert("Please enter no of coding packets!");
			xcode_pack[arr_index].focus();
			return false;
		}
	}

	if (llogi_hour != 0 && xlogi_hour == 0) {
		alert("Please select login hour!");
		xlogi_val1[arr_index].focus();
		return false;
    }
    
	if (llogi_time == 0) {
		xlogi_hrs1[arr_index].value = 0;
		xlogi_min1[arr_index].value = 0;
		xlogi_sec1[arr_index].value = 0;
		xlogo_hrs1[arr_index].value = 0;
		xlogo_min1[arr_index].value = 0;
		xlogo_sec1[arr_index].value = 0;
		xtrvl_amnt[arr_index].value = "0.00";
		xover_time[arr_index].value = 0;
		xcode_pack[arr_index].value = 0;
	}
}

function save_data() {
	if (document.getElementById("seldeptcode").value == 0) {
		alert("Please select client!");
		seldeptcode.focus();
		return false;
	}

	if (document.getElementById("txtattndate").value == "") {
		alert("Please enter attendance date!");
		txtattndate.focus();
		return false;
	}

	var rowcount = $("#table_attn tr").length;
	if (rowcount == 0) {
		alert("No attendance details found!");
		cmdview.focus();
		return false;
	}

	xattn_stat = document.getElementsByName("txtattnstat[]");
	for (var i = 0; i < xattn_stat.length; i++) {
		if (xattn_stat[i].value == "0") {
			alert("Please select attendance status!");
			xattn_stat[i].focus();
			return false;
		}
	}

    xlogi_hour = document.getElementsByName("txtlogimins[]");
	for (var i = 0; i < xlogi_hour.length; i++) {
		if (xlogi_hour[i].value == "0") {
			alert("Please select login time (hour)!");
			xlogi_hour[i].focus();
			return false;
		}
	}


	var totl_rows = $("#table_attn tr").length - 1;

	var dept_code = [];
	var dept_code1 = document.getElementsByName("txtdeptcode[]");

	var empl_code = [];
	var empl_code1 = document.getElementsByName("txtemplcode[]");

	var attn_stat = [];
	var attn_stat1 = document.getElementsByName("txtattnstat[]");

	var logi_hour = [];
	var logi_hour1 = document.getElementsByName("txtlogihour[]");

    var logi_mins = [];
	var logi_mins1 = document.getElementsByName("txtlogimins[]");

    var logi_secs = [];
	var logi_secs1 = document.getElementsByName("txtlogisecs[]");

	var logo_hour = [];
	var logo_hour1 = document.getElementsByName("txtlogohour[]");

    var logo_mins = [];
	var logo_mins1 = document.getElementsByName("txtlogomins[]");

    var logo_secs = [];
	var logo_secs1 = document.getElementsByName("txtlogosecs[]");

	var trvl_amnt = [];
	var trvl_amnt1 = document.getElementsByName("txttrvlamnt[]");

	var over_time = [];
	var over_time1 = document.getElementsByName("txtovertime[]");

	var code_pack = [];
	var code_pack1 = document.getElementsByName("txtcodepack[]");

	var attn_remk = [];
	var attn_remk1 = document.getElementsByName("txtattnremk[]");

	for (var i = 0; i < totl_rows; i++) {
		dept_code[i] = dept_code1[i].value;
		empl_code[i] = empl_code1[i].value;
		attn_stat[i] = attn_stat1[i].value;
		logi_hour[i] = logi_hour1[i].value;
		logi_mins[i] = logi_mins1[i].value;
		logi_secs[i] = logi_secs1[i].value;
		logo_hour[i] = logo_hour1[i].value;
		logo_mins[i] = logo_mins1[i].value;
		logo_secs[i] = logo_secs1[i].value;
		trvl_amnt[i] = trvl_amnt1[i].value;
		over_time[i] = over_time1[i].value;
		code_pack[i] = code_pack1[i].value;
		attn_remk[i] = attn_remk1[i].value;
	}

	$.ajax({
		type: "POST",
		url: "src/attendance.php",
		dataType: "json",
		data: {
			load_data: "save_data",
			attn_date: document.getElementById("txtattndate").value,
			dept_code: dept_code,
			empl_code: empl_code,
			attn_stat: attn_stat,
			logi_hour: logi_hour,			logi_mins: logi_mins,			logi_secs: logi_secs,
			logo_hour: logo_hour,			logo_mins: logo_mins,			logo_secs: logo_secs,
			trvl_amnt: trvl_amnt,
			over_time: over_time,
			code_pack: code_pack,
			attn_remk: attn_remk,
		},
		cache: false,
		beforeSend: function () {
			show_process();
		},
		success: function (data) {
			hide_process();
			clrs_data();
			alert(data.mesg);
		},
		error: function (data) {
			hide_process();
			$("#page-container-grid").html("Error: " + data);
		},
	});
}