jQuery(function() {
jQuery("#clock_in").datetimepicker({
format: "Y/m/d g:i:s A",
formatTime: "g:i A"
});
jQuery("#clock_out").datetimepicker({
format: "Y/m/d g:i:s A",
formatTime: "g:i A"
});
if (jQuery("#aio_tc_lite_news").length > 0){
jQuery("#aio_tc_lite_news").steps({
headerTag: "h3",
bodyTag: "section",
transitionEffect: "slideLeft",
stepsOrientation: "vertical",
autoFocus: true,
onFinished: function () {
window.location = "?page=aio-tc-lite";
}
});
}
jQuery("#aio_generate_report").click(function(e) {
e.preventDefault();
var nonce = jQuery(this).attr("date-nonce");
var report_action = "generate_report";
jQuery("#aio-reports-results").html('
').show();
jQuery.ajax({
type: "post",
dataType: "json",
url: timeClockAdminAjax.ajaxurl,
data: {
action: "aio_time_clock_lite_admin_js",
report_action: report_action,
aio_pp_start_date: jQuery("#aio_pp_start_date").val(),
aio_pp_end_date: jQuery("#aio_pp_end_date").val(),
employee: jQuery("#employee").val(),
nonce: nonce
},
success: function(data) {
console.log(data)
if (data["response"] == "success") {
var shiftRows = data["shifts"]["shift_array"];
jQuery("#aio-reports-results").html("");
var reportHtml =
'' +
'' +
'' +
'| Name | ' +
'Clock In | ' +
'Clock Out | ' +
'Shift Total | ' +
'Options | ' +
'
' +
'' +
'' +
'' +
'| Name | ' +
'Clock In | ' +
'Clock Out | ' +
'Shift Total | ' +
'Options | ' +
'
' +
'' +
'';
var count = 0;
shiftRows.forEach(function (item) {
count++;
var alternate_class = "";
if (isEven(count)) {
alternate_class = 'alternate';
}
var employee_clock_in_time = "";
if (item["employee_clock_in_time"] != null){
employee_clock_in_time = item["employee_clock_in_time"];
}
var employee_clock_out_time = "";
if (item["employee_clock_out_time"] != null){
employee_clock_out_time = item["employee_clock_out_time"];
}
var shift_sum = "";
if (item["shift_sum"]){
shift_sum = item["shift_sum"];
}
reportHtml +=
'' +
'| ' + item["last_name"] + ', ' + item["first_name"] + ' | ' +
'' + employee_clock_in_time + ' | ' +
'' + employee_clock_out_time + ' | ' +
'' + shift_sum + ' | ' +
' | ' +
'
';
});
reportHtml += '' +
'
';
var shift_total_time = "0";
if (data["shifts"]["shift_total_time"]){
shift_total_time = data["shifts"]["shift_total_time"];
}
reportHtml += '' +
'Total Shifts: ' + data["shifts"]["shift_count"] + '
' +
'Total Shift Time: ' + shift_total_time + '
' +
'
' +
'';
jQuery("#aio-reports-results").html(reportHtml);
jQuery("#aio-reports-results").show();
}
}
});
});
});
function editClockTime(type) {
if (type == "in") {
jQuery("#clock_in").show("fast");
}
if (type == "out") {
jQuery("#clock_out").show("fast");
}
}
function editEmployee() {
jQuery("#employee_id").show("fast");
}
function isEven(number) {
if (number % 2 == 0) {
return true;
} // even
else {
return false;
} // odd
}