![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/keeview_app/html/ |
Upload File : |
hr.overtime_request.deleteOvertime_request = function(host, id){ return new Promise(function(resolve,reject){ ModalElement.show_loading(); FormClass.api_call({ url: "overtime_request_delete.php", params: [{name: "id", value: id}], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var index = host.database.overtime_request.getIndex(id); host.database.overtime_request.items.splice(index, 1); resolve(); } else if (message == "lock_system"){ ModalElement.alert({message: LanguageModule.text("war_txt_system_lock")}); } else if (message == "failed_used"){ ModalElement.alert({ message: LanguageModule.text("war_txt_can_not_delete") }); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.overtime_request.deleteOvertime_requestConfirm = function(host, id){ return new Promise(function(resolve,reject){ ModalElement.question({ title: LanguageModule.text("war_title_delete_overtime_request"), message: LanguageModule.text2("war_txt_detele", [""]), onclick: function(sel){ if (sel == 0){ hr.overtime_request.deleteOvertime_request(host, id).then(function(value){ resolve(value); }); } } }); }); }; hr.overtime_request.cancelOvertime_request = function(host, id){ ModalElement.show_loading(); FormClass.api_call({ url: "overtime_request_cancel.php", params: [ {name: "id", value: id} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var index = host.database.overtime_request.getIndex(id); host.database.overtime_request.items[index].status = 3; host.database.overtime_request.items[index].statusType = "canceled"; hr.overtime_request.redraw(host); } else if (message == "lock_system"){ ModalElement.alert({message: LanguageModule.text("war_txt_system_lock")}); } else if (message == "failed_calc"){ ModalElement.alert({ message: LanguageModule.text("war_txt_can_not_cancel_request") }); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; hr.overtime_request.cancelOvertime_requestConfirm = function(host, id){ var index = host.database.overtime_request.getIndex(id); ModalElement.question({ title: LanguageModule.text("war_title_cancel_overtime_request"), message: LanguageModule.text("war_txt_cancel_overtime_request"), onclick: function(sel){ if (sel == 0){ hr.overtime_request.cancelOvertime_request(host, id); } } }); }; hr.overtime_request.approvalRequest = function(host, id, inside){ var listData = []; if (!id){ host.database.overtime_request.items.forEach(function(item){ if (host.inputidboxes["checkbox_" + item.id] && host.inputidboxes["checkbox_" + item.id].checked){ listData.push(item); } }); } else { var index = host.database.overtime_request.getIndex(id); listData = [host.database.overtime_request.items[index]]; } if (listData.length == 0) return; console.log(listData); ModalElement.show_loading(); FormClass.api_call({ url: "overtime_request_approval.php", params: [ {name: "listData", value: EncodingClass.string.fromVariable(listData)} ], func: function(success, message){ if (success){ if (message.substr(0, 2) == "ok"){ host.status_select.value = "all"; hr.overtime_request.init2(host).then(function(){ if (inside){ host.frameList.removeLast(); ModalElement.close(); hr.overtime_request.showOvertime_requestPre(host, host.id); } else { ModalElement.close(-1); } }); } else if (message == "failed_employee"){ ModalElement.alert({message: LanguageModule.text("war_user_not_link_employee")}); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; hr.overtime_request.denyRequest = function(host, listData, comment, inside){ ModalElement.show_loading(); FormClass.api_call({ url: "overtime_request_deny.php", params: [ {name: "listData", value: EncodingClass.string.fromVariable(listData)}, {name: "comment", value: comment} ], func: function(success, message){ if (success){ if (message.substr(0, 2) == "ok"){ ModalElement.close(); if (host.status_select.value !== "all") host.status_select.value = "deny"; hr.overtime_request.init2(host).then(function(){ if (inside){ host.frameList.removeLast(); hr.overtime_request.showOvertime_requestPre(host, host.id); } else { ModalElement.close(-1); } }); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; hr.overtime_request.denyRequestConfirm = function(host, id, inside){ var listData = []; if (!id){ host.database.overtime_request.items.forEach(function(item){ if (host.inputidboxes["checkbox_" + item.id] && host.inputidboxes["checkbox_" + item.id].checked){ listData.push(item); } }); } else { var index = host.database.overtime_request.getIndex(id); listData = [host.database.overtime_request.items[index]]; } if (listData.length == 0) return; var comment_input = DOMElement.textarea({ attrs: { className: "cardSimpleTextarea", style: { minWidth: "250px", width: "100%", height: "100px" } } }); ModalElement.showWindow({ title: LanguageModule.text("txt_deny_request"), bodycontent: DOMElement.div({ children: [ DOMElement.div({ attrs: { style: { height: "var(--control-height)", lineHeight: "var(--control-height)", width: "300px" } }, text: LanguageModule.text("txt_reason_deny") }), comment_input ] }), buttonlist: [ { text: LanguageModule.text("txt_save"), onclick: function(){ ModalElement.close(); var comment = comment_input.value.trim(); hr.overtime_request.denyRequest(host, listData, comment, inside); } }, { text: LanguageModule.text("txt_cancel"), onclick: function(){ ModalElement.close(); } } ] }); comment_input.focus(); }; hr.overtime_request.drawIntro = function(host){ var res = DOMElement.div({ attrs: { className: "hr-intro-view-form request-approval-list" } }); host.drawIntroFunc = function(){ var index = host.database.overtime_request.getIndex(host.id); var pIndex = host.database.overtime_policies.getIndex(host.database.overtime_request.items[index].policyid); var eIndex = host.employeeDic[host.database.overtime_request.items[index].employeeid]; var fullname = host.database.employees.items[eIndex].fullname; var oIndex = host.database.employees.items[eIndex].orgIndex; var orgName = host.database.orgs.items[oIndex].name; var statusElt; switch (host.dataRequestEdit.status) { case 0: var datetime = host.database.overtime_request.items[index].fromdate.setHours(0, 0, 0, 0); var expire_time = datetime - host.database.overtime_policies.items[pIndex].time_hours_needed_for_approval*60*60*1000; if (new Date().getTime() > expire_time){ statusElt = DOMElement.div({ attrs: { className: "hr-status-view-btn over-due" }, text: LanguageModule.text("txt_over_due") }); } else { var remainTime = expire_time - new Date().getTime(); if (remainTime > 24*60*60*1000){ statusElt = DOMElement.div({ attrs: { className: "hr-status-view-btn waiting-approval" }, text: LanguageModule.text("txt_waiting_approval") }); } else { var countdownText = absol.buildDom({ tag: 'countdowntext', props: { finishTime: new Date(expire_time), format: "HH:mm:ss" }, on: { finish: function(){ hr.overtime_request.init2(host); host.frameList.removeLast(); hr.overtime_request.showOvertime_requestPre(host, host.id); } } }); statusElt = DOMElement.div({ attrs: { className: "hr-status-view-btn waiting-approval" }, children: [ DOMElement.span({ attrs: { style: {marginRight: "5px"} }, text: LanguageModule.text("txt_waiting_approval") }), countdownText ] }); } } break; case 1: statusElt = DOMElement.div({ attrs: { className: "hr-status-view-btn approved" }, text: LanguageModule.text("txt_approved") }); break; case 2: statusElt = DOMElement.div({ attrs: { className: "hr-status-view-btn deny" }, text: LanguageModule.text("txt_deny") }); break; case 3: statusElt = DOMElement.div({ attrs: { className: "hr-status-view-btn canceled" }, text: LanguageModule.text("txt_canceled") }); break; } DOMElement.removeAllChildren(res); res.appendChild(DOMElement.table({ data: [ [ {text: LanguageModule.text("txt_approval_status")}, {attrs: {style: {width: "40px"}}}, statusElt ] ] })); }; host.drawIntroFunc(); return res; }; hr.overtime_request.drawGeneralInformation = function(host){ var cmdbutton = {}; if (host.dataRequestEdit.privEdit) cmdbutton.editFunc = function(){ hr.overtime_request.addOvertime_request(host, host.id); }; var res = theme.showOvertimeRequestGeneralInfomation({ cmdbutton: cmdbutton }); contentModule.getApproversTextOfPolicy(host, "overtime", host.dataRequestEdit.policyid, host.dataRequestEdit.employeeid).then(function(value){ host.dataRequestEdit.approvers = value; host.dataRequestEdit.time_hours_needed_for_approval = contentModule.getTime_hours_needed_for_approvalByPolicy(host, "overtime", host.dataRequestEdit.policyid); host.drawGeneralInforFunc(); }); host.drawGeneralInforFunc = function(){ contentModule.makeOutputFormData({ typeid: data_module.form_config.overtime_request.typeid, formid: hr.isMobile? data_module.form_config.overtime_request.mobile_output_form : data_module.form_config.overtime_request.output_form, initialValue: host.dataRequestEdit, formContainer: res.viewGeneralInformation, typelists: data_module.typelists.items, variableType: "system" }).then(function(getValue){ res.viewGeneralInformation.formFragment.setContext('host', host); }); }; return res; }; hr.overtime_request.drawApproval = function(host){ var getApprovalMethod = function(value){ var list = contentModule.getListApprovalMethod(); for (var i = 0; i < list.length; i++){ if (list[i].value == value) return list[i].text; } return ""; }; var getApprovalMethod = function(value){ var list = contentModule.getListApprovalMethod(); for (var i = 0; i < list.length; i++){ if (list[i].value == value) return list[i].text; } return ""; }; var pIndex = host.database.overtime_policies.getIndex(host.dataRequestEdit.policyid); if (pIndex >= 0){ var approval_methodText = getApprovalMethod(host.database.overtime_policies.items[pIndex].approval_method); } else { return DOMElement.div({}); } var res = theme.showOvertimeRequestApproval({ approval_methodText: approval_methodText }); host.drawApprovalFunc = function(){ res.drawApprovalFunc({ database: host.database, dataRequestEdit: host.dataRequestEdit, employeeDic: host.employeeDic }); }; host.drawApprovalFunc(); return res; }; hr.overtime_request.showOvertime_request = function(host, id){ host.id = id; var cmdbutton = {}; if (host.dataRequestEdit.privApproval){ cmdbutton.approval = function(){ hr.overtime_request.approvalRequest(host, host.id, true); }; cmdbutton.deny = function(){ hr.overtime_request.denyRequestConfirm(host, host.id, true); }; } theme.showOvertimeRequest({ id: host.id, frameList: host.frameList, cmdbutton: cmdbutton, info_ctn: hr.overtime_request.drawIntro(host), general_information_ctn: hr.overtime_request.drawGeneralInformation(host), approval_ctn: hr.overtime_request.drawApproval(host), holder: host.holder }); }; hr.overtime_request.showOvertime_requestPre = function(host, id){ if (!host.database.overtime_request || host.database.overtime_request.getIndex(id) < 0) return; ModalElement.show_loading(); FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "overtime_request_view_load_by_id"}, {name: "id", value: id} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); if (st.data.extrainfo == "") st.data.extrainfo = {}; else st.data.extrainfo = EncodingClass.string.toVariable(st.data.extrainfo); st.data.time_period = EncodingClass.string.toVariable(st.data.time_period); st.data.overtime_hours = (st.data.todate - st.data.fromdate + 1)*st.data.time_period.duration/(60*60*1000); st.data.fromdate = absol.datetime.beginOfDay(new Date(st.data.fromdate*86400000)); st.data.todate = absol.datetime.beginOfDay(new Date(st.data.todate*86400000)); var index = host.database.overtime_request.getIndex(id); host.database.overtime_request.items[index] = st.data; host.database.overtime_request_approvers.items = host.database.overtime_request_approvers.items.concat(st.approvers); host.dataRequestEdit = host.database.overtime_request.items[index]; hr.overtime_request.makePrivilegeOvertimeRequest(host); hr.overtime_request.showOvertime_request(host, id); } else if (message == "war_txt_failed_data"){ ModalElement.alert({ message: LanguageModule.text("war_txt_failed_data"), func: function(){ hr.overtime_request.init2(host); } }); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }; hr.overtime_request.addOvertime_requestSubmit = function(host, id, getValueFunction){ return new Promise(function(resolve, reject){ var data = getValueFunction(); if (!data) return; data.id = id; var policyOfEmployee = 0; for (var i = 0; i < host.database.overtime_policies.items.length; i++){ if (host.database.overtime_policies.items[i].employee_applies.indexOf(data.employeeid) >= 0){ policyOfEmployee = host.database.overtime_policies.items[i].id; break; } } if (!policyOfEmployee){ ModalElement.alert({message: LanguageModule.text("war_txt_employee_not_policy")}); return; } data.policyid = policyOfEmployee; var pIndex = host.policyDic[policyOfEmployee]; if (pIndex >= 0){ var overtime_hours = data.time_period.duration/(60*60*1000); if (overtime_hours > host.database.overtime_policies.items[pIndex].maximum_overtime_hours_per_day){ ModalElement.alert({message: "Thời gian đề xuất quá thời gian làm thêm đối đa/ngày"}); return; } var time = (absol.datetime.beginOfDay(data.fromdate).getTime() + data.time_period.dayOffset)/(24*60*60*1000); if (time - new Date().getTime()/(24*60*60*1000) < host.database.overtime_policies.items[pIndex].proposal_submitted_before){ ModalElement.alert({ message: "Thời gian đề xuất làm thêm không hợp lệ, phải đề xuất trước " + host.database.overtime_policies.items[pIndex].proposal_submitted_before + " ngày." }); return; } } if (id > 0){ var index = host.database.overtime_request.getIndex(id); data.ver = host.dataRequestEdit.ver; var oldData = host.dataRequestEdit; var ischange = contentModule.isChanged(oldData, data, ["fromdate", "todate", "reason", "shiftid", "time_period"] ); if (!ischange){ resolve(); return; } } else { data.ver = 0; } var k = host.database.employees.getIndex(data.employeeid); data.employee_peopleid = host.database.employees.items[k].peopleid; data.extrainfo = EncodingClass.string.fromVariable(data.extrainfo); data.time_period = EncodingClass.string.fromVariable(data.time_period); data.fromdate = contentModule.getDateFrom1970(data.fromdate); data.todate = contentModule.getDateFrom1970(data.todate); ModalElement.show_loading(); FormClass.api_call({ url: "overtime_request_save.php", params: [{name: "data", value: EncodingClass.string.fromVariable(data)}], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); st.employeeid = data.employeeid; st.extrainfo = EncodingClass.string.toVariable(st.extrainfo); st.time_period = EncodingClass.string.toVariable(st.time_period); st.overtime_hours = (st.todate - st.fromdate + 1)*st.time_period.duration/(60*60*1000); st.fromdate = absol.datetime.beginOfDay(new Date(st.fromdate*86400000)); st.todate = absol.datetime.beginOfDay(new Date(st.todate*86400000)); if (host.policy_select.value != 0) host.policy_select.value = st.policyid; resolve(); if (id > 0){ var index = host.database.overtime_request.getIndex(id); st.status = host.database.overtime_request.items[index].status; host.database.overtime_request.items[index] = st; host.dataRequestEdit = host.database.overtime_request.items[index]; hr.overtime_request.makePrivilegeOvertimeRequest(host); host.drawGeneralInforFunc(); } else { st.status = 0; host.database.overtime_request.items.push(st); hr.overtime_request.makePrivilegeOvertimeRequest(host); hr.overtime_request.showOvertime_requestPre(host, st.id); } } else if (message == "has_shift_schedule"){ ModalElement.alert({message: "Đã được xếp ca vào khoảng thời gian này, vui lòng kiểm tra lại"}); } else if (message == "lock_system"){ ModalElement.alert({message: LanguageModule.text("war_txt_system_lock")}); } else if (message == "deleted" || message == "edited"){ ModalElement.alert({ message: LanguageModule.text("war_txt_failed_ver_reload_data") }); } else if (message == "exist_name"){ ModalElement.alert({message: LanguageModule.text("war_txt_exist_name")}); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); }; hr.overtime_request.addOvertime_requestClose = function(host, id, getValueFunction){ return new Promise(function(resolve, reject){ var data = getValueFunction("no_alert"); if (!data) { resolve(); return; } var ischange; if (id > 0){ var oldData = host.dataRequestEdit; ischange = contentModule.isChanged(oldData, data, ["fromdate", "todate", "reason", "shiftid", "time_period"] ); } if (!ischange){ resolve(); return; } contentModule.questionChange({ onclick: function(sel){ if (sel == 0){ hr.overtime_request.addOvertime_requestSubmit(host, host.id, getValueFunction).then(function(){ resolve(); }); } else if (sel == 1){ resolve(); } } }); }); }; hr.overtime_request.redrawDetails = function(host, id){ function redraw(value){ theme.formOvertime_requestEdit({ id: id, value: value, form_config: data_module.form_config, database: host.database, employeeOfMe: host.employeeOfMe, frameList: host.frameList, cmdbutton: { save: function(getValueFunction){ return new Promise(function(rs, rj){ hr.overtime_request.addOvertime_requestSubmit(host, id, getValueFunction).then(function(){ rs(); }); }); }, cancel: function(getValueFunction){ return new Promise(function(rs, rj){ hr.overtime_request.addOvertime_requestClose(host, id, getValueFunction).then(function(){ rs(); }); }) } } }); }; if (id > 0) redraw(host.dataRequestEdit); else redraw(); }; hr.overtime_request.addOvertime_request = function(host, id){ if (id > 0){ ModalElement.show_loading(); FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "overtime_request_load_by_id"}, {name: "id", value: id} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ host.dataRequestEdit = EncodingClass.string.toVariable(message.substr(2)); if (host.dataRequestEdit.extrainfo == "") host.dataRequestEdit.extrainfo = {}; else host.dataRequestEdit.extrainfo = EncodingClass.string.toVariable(host.dataRequestEdit.extrainfo); host.dataRequestEdit.time_period = EncodingClass.string.toVariable(host.dataRequestEdit.time_period); host.dataRequestEdit.overtime_hours = (host.dataRequestEdit.todate - host.dataRequestEdit.fromdate + 1)*host.dataRequestEdit.time_period.duration/(60*60*1000); host.dataRequestEdit.fromdate = absol.datetime.beginOfDay(new Date(host.dataRequestEdit.fromdate*86400000)); host.dataRequestEdit.todate = absol.datetime.beginOfDay(new Date(host.dataRequestEdit.todate*86400000)); hr.overtime_request.redrawDetails(host, id); } else if (message == "war_txt_failed_data"){ ModalElement.alert({ message: LanguageModule.text("war_txt_failed_data"), func: function(){ hr.overtime_request.init2(host); } }); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); } else { hr.overtime_request.redrawDetails(host, id); } }; hr.overtime_request.getCellOvertime_request = function(host, id){ var index = host.database.overtime_request.getIndex(id); var res = EncodingClass.string.duplicate(host.database.overtime_request.items[index]); switch (host.status_select.value) { case "waiting_approval": if (res.status != 0) return null; break; case "over_due": return null; break; case "approved": if (res.status != 1) return null; break; case "deny": if (res.status != 2) return null; break; default: } var func = { view: function(){ hr.overtime_request.showOvertime_requestPre(host, id); }, approval: function(){ hr.overtime_request.approvalRequest(host, id, false); }, deny: function(){ hr.overtime_request.denyRequestConfirm(host, id, false); } }; if (res.privDel){ func.delete = function(resolve){ hr.overtime_request.deleteOvertime_requestConfirm(host, id).then(function(){ resolve(); }); }; if (res.status == 0 || res.status == 1) func.cancel = function(){ hr.overtime_request.cancelOvertime_requestConfirm(host, id); }; } var employeeIndex = host.database.employees.getIndex(res.employeeid); res.employeeName = host.database.employees.items[employeeIndex].fullname; var oIndex = host.database.employees.items[employeeIndex].orgIndex; var departmentName = host.database.orgs.items[oIndex].name; res.departmentName = departmentName; if (res.privApproval) host.hasPriv = true; res.status = res.statusType; res.func = func; return res; }; hr.overtime_request.makePrivilegeOvertimeRequest = function(host){ host.database.overtime_request.items.sort(function(a, b){ return a.fromdate.getTime() - b.fromdate.getTime(); }); var overtime_requestDic = contentModule.makeDictionaryIndex(host.database.overtime_request.items); var k; for (var i = 0; i < host.database.user_marked.items.length; i++){ k = overtime_requestDic[host.database.user_marked.items[i].taskid]; if (k >= 0) host.database.overtime_request.items[k].marked = true; } for (var i = 0; i < host.database.overtime_request.items.length; i++){ host.database.overtime_request.items[i].approverIds = []; } for (var i = 0; i < host.database.overtime_request_approvers.items.length; i++){ k = overtime_requestDic[host.database.overtime_request_approvers.items[i].requestid]; if (k >= 0){ host.database.overtime_request.items[k].approverIds.push(host.database.overtime_request_approvers.items[i].employeeid); } } var employeeid; var pIndex, employeeIndex; host.database.overtime_request.items.forEach(function(item){ employeeIndex = host.employeeDic[item.employeeid]; if (employeeIndex === undefined) return; employeeid = item.employeeid; pIndex = host.policyDic[item.policyid]; if (pIndex === undefined) return; if (systemconfig.privSystem >= 2){ item.privDel = true; } else if (item.userid == systemconfig.userid || (host.employeeOfMe.length > 0 && item.employeeid == host.employeeOfMe[0])){ item.privDel = true; } switch (item.status) { case 0: case 2: if (item.status == 0){ var time_hours_needed_for_approval = host.database.overtime_policies.items[host.policyDic[item.policyid]].time_hours_needed_for_approval; var datetime = item.fromdate.setHours(0, 0, 0, 0); if (datetime - time_hours_needed_for_approval*60*60*1000 < new Date().getTime()){ status = "over_due"; } else { status = "waiting_approval"; } } else if (item.status == 2){ status = "deny"; } if ((item.userid == systemconfig.userid || (host.employeeOfMe.length > 0 && item.employeeid == host.employeeOfMe[0])) && (item.approverIds.length == 0)){ item.privEdit = true; } if (host.database.overtime_policies.items[pIndex].direct_manager_approves_first){ if (host.directSubOfMe.indexOf(employeeid) >= 0){ item.privView = true; if (item.status == 0){ if (item.approverIds.indexOf(host.employeeOfMe[0]) < 0){ ex = true; item.privApproval = true; item.approvalRole = "direct_manager"; var done = !host.database.overtime_policies.items[pIndex].indirect_manager_approves_first; if (!done){ if (host.employeeOfMe[0] == host.database.employees.items[employeeIndex].indirect_manager) done = true; else if (item.approverIds.indexOf(host.database.employees.items[employeeIndex].indirect_manager) >= 0) done = true; } if (done){ host.database.overtime_policies.items[pIndex].approvers.forEach((ee) => { if (host.employeeOfMe[0] != ee.employeeid){ if (item.approverIds.indexOf(ee.employeeid) < 0) done = false; } }); } if (done) item.approvalUpdateStatus = true; } } } } if (host.database.overtime_policies.items[pIndex].indirect_manager_approves_first){ if (host.indirectSubOfMe.indexOf(employeeid) >= 0){ item.privView = true; if (item.status == 0){ if (item.approverIds.indexOf(host.employeeOfMe[0]) < 0){ ex = true; item.privApproval = true; item.approvalRole = "indirect_manager"; var done = !host.database.overtime_policies.items[pIndex].direct_manager_approves_first; if (!done){ if (host.employeeOfMe[0] == host.database.employees.items[employeeIndex].direct_manager) done = true; else if (item.approverIds.indexOf(host.database.employees.items[employeeIndex].direct_manager) >= 0) done = true; } if (done){ host.database.overtime_policies.items[pIndex].approvers.forEach((ee) => { if (host.employeeOfMe[0] != ee.employeeid){ if (item.approverIds.indexOf(ee.employeeid) < 0) done = false; } }); } if (done) item.approvalUpdateStatus = true; } } } } var prev_done = true; if (host.database.overtime_policies.items[pIndex].direct_manager_approves_first && host.database.employees.items[employeeIndex].direct_manager > 0){ var ex = false; if (item.approverIds.indexOf(host.database.employees.items[employeeIndex].direct_manager) >= 0) ex = true; if (!ex) prev_done = false; } if (prev_done){ if (host.database.overtime_policies.items[pIndex].indirect_manager_approves_first && host.database.employees.items[employeeIndex].indirect_manager > 0){ var ex = false; if (item.approverIds.indexOf(host.database.employees.items[employeeIndex].indirect_manager) >= 0) ex = true; if (!ex) prev_done = false; } } var approvers = host.database.overtime_policies.items[pIndex].approvers; var approval_method = host.database.overtime_policies.items[pIndex].approval_method; approvers.forEach(function(item1, stt){ var eid = item1.employeeid; if (host.employeeOfMe[0] == eid){ switch (approval_method){ case "one_approver": item.privView = true; break; case "parallel": item.privView = true; break; case "sequence": var checkMe = true; for (i = 0; i < stt; i++){ if (item.approverIds.indexOf(item1.employeeid) < 0){ checkMe = false; } } if (checkMe){ item.privView = true; } break; } } }); if (item.status == 0 && !item.privApproval && prev_done){ var ni; for (var i = 0; i < approvers.length; i++){ ni = approvers[i].employeeid; if (host.employeeOfMe.indexOf(ni) >= 0){ if (item.approverIds.indexOf(ni) < 0){ if (approval_method != "sequence"){ item.privApproval = true; item.approvalRole = ""; } else if (approval_method == "sequence" && prev_done) { item.privApproval = true; item.approvalRole = ""; } } break; } else { if (approval_method == "sequence" && item.approverIds.indexOf(ni) < 0){ prev_done = false; break; } } } if (item.privApproval){ if (approval_method == "one_approver"){ item.approvalUpdateStatus = true; } else { var done = true; for (var i = 0; i < approvers.length; i++){ ni = approvers[i].employeeid; if (ni != host.employeeOfMe[0]){ if (item.approverIds.indexOf(ni) < 0){ done = false; break; } } } if (done){ item.approvalUpdateStatus = true; } } } } if (item.userid == systemconfig.userid || host.employeeOfMe[0] == employeeid){ item.privView = true } break; case 1: status = "approved"; if (host.database.overtime_policies.items[pIndex].direct_manager_approves_first && host.directSubOfMe.indexOf(employeeid) >= 0){ item.privView = true; } if (host.database.overtime_policies.items[pIndex].indirect_manager_approves_first && host.indirectSubOfMe.indexOf(employeeid) >= 0){ item.privView = true; } var approvers = host.database.overtime_policies.items[pIndex].approvers; approvers.forEach(function(item1){ if (host.employeeOfMe.indexOf(item1.employeeid) >= 0){ item.privView = true; } }); break; case 3: status = "canceled"; if (host.database.overtime_policies.items[pIndex].direct_manager_approves_first && host.directSubOfMe.indexOf(employeeid) >= 0){ item.privView = true; } if (host.database.overtime_policies.items[pIndex].indirect_manager_approves_first && host.indirectSubOfMe.indexOf(employeeid) >= 0){ item.privView = true; } var approvers = host.database.overtime_policies.items[pIndex].approvers; approvers.forEach(function(item1){ if (host.employeeOfMe.indexOf(item1.employeeid) >= 0){ item.privView = true; } }); break; default: } item.statusType = status; if (systemconfig.privSystem >= 2 || (host.employeeOfMe.indexOf(item.employeeid) >= 0) || item.userid == systemconfig.userid){ item.privView = true; } console.log(item); }); if (hr.isMobile) hr.overtime_request.redraw(host); else hr.overtime_request.init3(host); }; hr.overtime_request.toggleBtn = function(host){ if (hr.isMobile) return; var ex = 0; for (var i = 0; i < host.database.overtime_request.items.length; i++){ if (host.inputidboxes["checkbox_" + host.database.overtime_request.items[i].id]){ if (host.inputidboxes["checkbox_" + host.database.overtime_request.items[i].id].checked){ ex = 1; break; } } } if (ex){ host.approval_btn_ctn.classList.remove("hidden"); host.deny_btn_ctn.classList.remove("hidden"); } else { host.approval_btn_ctn.classList.add("hidden"); host.deny_btn_ctn.classList.add("hidden"); } }; hr.overtime_request.redraw = function(host){ host.hasPriv = false; host.inputidboxes = {}; hr.overtime_request.toggleBtn(host); var data = [], row; for (var i = 0; i < host.database.overtime_request.items.length; i++){ if (!host.database.overtime_request.items[i].privView) continue; if (host.policy_select.value != 0 && host.policy_select.value != host.database.overtime_request.items[i].policyid) continue; row = hr.overtime_request.getCellOvertime_request(host, host.database.overtime_request.items[i].id); if (row) data.push(row); } var checkbox_all; if (host.hasPriv){ checkbox_all = absol.buildDom({ tag: "checkbox", on: { change: function(){ var item; for (var i = 0; i < host.database.overtime_request.items.length; i++){ item = host.database.overtime_request.items[i]; if (host.inputidboxes["checkbox_" + item.id]){ host.inputidboxes["checkbox_" + item.id].checked = this.checked; } } hr.overtime_request.toggleBtn(host); } } }); } else { checkbox_all = DOMElement.span({}); } DOMElement.removeAllChildren(host.data_container); host.dataView = theme.formOvertime_requestContentData({ data: data, inputsearchbox: host.inputsearchbox, checkbox_all: checkbox_all, inputidboxes: host.inputidboxes, toggleBtnFunc: function(){ hr.overtime_request.toggleBtn(host); }, configColumnOvertimeRequest: host.configColumnOvertimeRequest, configColumnFunc: host.configColumnFunc }); host.data_container.appendChild(host.dataView); }; hr.overtime_request.init3 = function(host){ var displayDic = { type: true, shiftid: true, employeeid: true, fromdate: true, todate: true, time_period: true, overtime_hours: true }; var columnList = contentModule.getColumnListFromDatatype(host, "overtime_request", displayDic); columnList.splice(1, 0, {value: "departmentName", display: true, main: true, type: -1, text: LanguageModule.text("txt_department")}); columnList.push({value: "status", display: true, main: true, type: -1, text: LanguageModule.text("txt_status")}); var redrawTableFunc = function(){ ModalElement.show_loading(); contentModule.getColumnListConfig(host, host.user_column_configsDic, columnList, "overtime_request_list").then(function(value){ ModalElement.close(-1); host.configColumnOvertimeRequest = value; host.configColumnFunc = function(){ contentModule.userColumnConfigForm({ type: "overtime_request_list", columnList: columnList }).then(function(value){ host.user_column_configsDic["overtime_request_list"] = value; redrawTableFunc(); }); }; hr.overtime_request.redraw(host); }); }; redrawTableFunc(); }; hr.overtime_request.init2 = function(host){ return new Promise(function(resolveMn, rejectMn){ ModalElement.show_loading(); var employees = host.employee_select.values; if (employees.length == 0){ ModalElement.close(-1); DOMElement.removeAllChildren(host.data_container); var st = { overtime_request: [], overtime_request_approvers: [] }; contentModule.makeDatabaseContent(host, st); resolveMn(); return; } employees.sort(function(a, b){ return a - b; }); var timestart, timeend; switch (host.period_select.value) { case "month": timestart = contentModule.getDateFrom1970(absol.datetime.beginOfMonth(host.month_select.value)); timeend = contentModule.getDateFrom1970(absol.datetime.nextMonth(host.month_select.value)); break; case "quarter": timestart = contentModule.getDateFrom1970(absol.datetime.beginOfQuarter(host.quarter_select.value)); timeend = contentModule.getDateFrom1970(absol.datetime.nextQuarter(host.quarter_select.value)); break; case "year": timestart = contentModule.getDateFrom1970(absol.datetime.beginOfYear(host.year_select.value)); timeend = contentModule.getDateFrom1970(absol.datetime.nextYear(host.year_select.value)); break; } console.log(employees); FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "overtime_request_load_init2"}, {name: "employeeIdList", value: EncodingClass.string.fromVariable(employees)}, {name: "timestart", value: timestart}, {name: "timeend", value: timeend}, {name: "status", value: host.status_select.value} ], func: function(success, message){ ModalElement.close(-1); if (success){ if (message.substr(0, 2) == "ok"){ var st = EncodingClass.string.toVariable(message.substr(2)); contentModule.makeDatabaseContent(host, st); host.database.overtime_request.items.forEach(function(item){ item.time_period = EncodingClass.string.toVariable(item.time_period); item.overtime_hours = (item.todate - item.fromdate + 1)*item.time_period.duration/(60*60*1000); item.fromdate = absol.datetime.beginOfDay(new Date(item.fromdate*86400000)); item.todate = absol.datetime.beginOfDay(new Date(item.todate*86400000)); }); hr.overtime_request.makePrivilegeOvertimeRequest(host); resolveMn(); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); resolveMn(host); }); }; hr.overtime_request.init = function(host){ return new Promise(function(resolveMn, rejectMn){ FormClass.api_call({ url: "database_load.php", params: [ {name: "task", value: "overtime_request_load_init"} ], func: function(success, message){ if (success){ if (message.substr(0, 2) == "ok"){ var content = EncodingClass.string.toVariable(message.substr(2)); contentModule.makeDatabaseContent(host, content); host.user_column_configsDic = contentModule.getUser_column_configsDic(host); host.policyDic = contentModule.makeDictionaryIndex(host.database.overtime_policies.items); var k; for (var i = 0; i < host.database.overtime_policies.items.length; i++){ host.database.overtime_policies.items[i].employee_applies = []; } for (var i = 0; i < host.database.employee_policies.items.length; i++){ k = host.policyDic[host.database.employee_policies.items[i].policyid]; if (k >= 0) host.database.overtime_policies.items[k].employee_applies.push(host.database.employee_policies.items[i].employeeid); } for (var i = 0; i < host.database.overtime_policies.items.length; i++){ host.database.overtime_policies.items[i].approvers = []; } for (var i = 0; i < host.database.policies_approvers.items.length; i++){ k = host.policyDic[host.database.policies_approvers.items[i].policyid]; host.database.overtime_policies.items[k].approvers.push(host.database.policies_approvers.items[i]); } host.employee_peopleDic = {}; for (var i = 0; i < host.database.employees.items.length; i++){ host.employee_peopleDic[host.database.employees.items[i].peopleid] = host.database.employees.items[i].id; } var listPolicy = []; for (var i = 0; i < host.database.overtime_policies.items.length; i++){ if (!host.database.overtime_policies.items[i].available) continue; listPolicy.push({ value: host.database.overtime_policies.items[i].id, text: host.database.overtime_policies.items[i].name }); } listPolicy.unshift({value: 0, text: LanguageModule.text("txt_all_policy")}); host.listPolicy = listPolicy; host.policy_change_func = function(){ hr.overtime_request.redraw(host); }; resolveMn(); } else { ModalElement.alert({message: message}); } } else { ModalElement.alert({message: message}); } } }); }); };