VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/keeview_app/html/partner_checkin.js
hr.partner_checkin.abnormalReport = function(host){
    var redraw = function(minutes, viewMaps){
        var dic = {};
        host.database.partner_checkin.items.forEach(function(item){
            if (!dic[item.employeeid]) dic[item.employeeid] = [];
            dic[item.employeeid].push(item);
        });
        var dataView = [];
        for (var employeeid in dic){
            for (var i = 0; i < dic[employeeid].length - 1; i++){
                if (Math.abs(dic[employeeid][i].checkintime.getTime() - dic[employeeid][i + 1].checkintime.getTime()) < minutes*60*1000){
                    dataView.push(dic[employeeid][i], dic[employeeid][i + 1]);
                }
            }
        }
        var dicData = {};
        dataView.forEach(function(item){
            if (!dicData[item.id]) dicData[item.id] = item;
        });
        dataView = [];
        for (var id in dicData){
            dataView.push(dicData[id]);
        }
        dataView.sort(function(a, b){
            if (a.employeeid == b.employeeid) return a.checkintime.getTime() - b.checkintime.getTime();
            return a.employeeid - b.employeeid;
        });
        var formPartner_checkinGetRow = function(content){
            var cells = [
                {
                    style: {textAlign: "center"},
                    render: function(tdElt){
                        tdElt.addChild(DOMElement.span({attrs: {className: "as-dt-row-index"}}));
                    }
                }
            ];
            var item;
            var paramsFunc;
            if (content.func.view){
                paramsFunc = {
                    onclick: function(){
                        content.func.view();
                    }
                };
            }
            for (var i = 0; i < configColumnPartner_checkin.length; i++){
                if (configColumnPartner_checkin[i].main){
                    item = contentModule.getCellDynamicTable(configColumnPartner_checkin[i], content[configColumnPartner_checkin[i].value], paramsFunc);
                }
                else {
                    item = contentModule.getCellDynamicTable(configColumnPartner_checkin[i], content.extrainfo[configColumnPartner_checkin[i].value], paramsFunc);
                }
                cells.push(item);
            }
            var row = {
                cells: cells
            };
            return row;
        };
        var data = [], x;
        for (var i = 0; i < dataView.length; i++){
            data.push(formPartner_checkinGetRow(dataView[i]));
        }
        tableView.clearRows();
        tableView.addRows(data);
        if (viewMaps){
            var listEmp = {}, empid, lat, lng, x, gps;
            var employeesDic = contentModule.makeDictionaryIndex(host.database.employees.items);
            var eIndex, partnerData;
            for (var i = 0; i < dataView.length; i++){
                empid = dataView[i].employeeid;
                eIndex = employeesDic[empid];
                if (eIndex === undefined) continue;
                partnerData = data_module.getContent("partners", dataView[i].partnerid);
                if (partnerData === undefined) continue;
                if (!listEmp[empid]){
                    listEmp[empid] = [];
                }
                if (dataView[i].checkin_follow_gps){
                    gps = dataView[i].checkingps;
                }
                else {
                    gps = dataView[i].gps;
                }
                x = gps.indexOf(",");
                if (x > 0){
                    lat = parseFloat(gps.substr(0, x));
                    lng = parseFloat(gps.substr(x + 1));
                }
                else continue;
                listEmp[empid].push({
                    lat: lat,
                    lng: lng,
                    info: {
                        content: partnerData.name + "<br>" +
                                 host.database.employees.items[eIndex].fullname + "<br>" +
                                 "<strong>"+ contentModule.getDateTimeView(dataView[i].checkintime) + "</strong>"
                    }
                });
            }
            var polylines = [];
            for (var x in listEmp){
                polylines.push({
                    path: listEmp[x],
                    id: x
                });
            };
            theme.formPartner_checkinViewMaps({
                polylines: polylines,
                view_line: dataView.length <= 10,
                database: host.database,
                frameList: host.frameList
            });
        }
    };
    if (!host.dataView.configColumnPartner_checkin) return;
    var configColumnPartner_checkin = host.dataView.configColumnPartner_checkin;
    var minutes_input = theme.input({
        style: {
            width: "80px"
        },
        type: "number",
        value: 5
    });
    var header = [
        {child: DOMElement.span({text: LanguageModule.text("txt_index")})}
    ];
    for (var i = 0; i < configColumnPartner_checkin.length; i++){
        header.push(contentModule.getCellHeaderDynamicTable(configColumnPartner_checkin[i]));
    }
    var tableView = absol.buildDom({
        tag: "dynamictable",
        style: {
            height: "calc(90vh - 300px)",
        },
        props: {
            id: "partner_checkin",
            adapter: {
               data: {
                   head: {
                       rows: [
                           {
                               cells: header
                           }
                       ]
                   },
                   body: {
                       rows: []
                   }
               }
           }
        }
    });
    var data_ctn = DOMElement.div({
        attrs: {
            className: "cardsimpletableclass"
        },
        children: [tableView]
    });
    ModalElement.showWindow({
        title: "Điểm bất thường",
        bodycontent: DOMElement.div({
            children: [
                DOMElement.table({
                    data: [
                        [
                            {text: "Số phút"},
                            {attrs: {style: {width: "var(--control-horizontal-distance-2)"}}},
                            minutes_input,
                            {attrs: {style: {width: "var(--control-horizontal-distance-2)"}}},
                            theme.viewButton({
                                onclick: function(){
                                    redraw(parseFloat(minutes_input.value));
                                }
                            }),
                            {attrs: {style: {width: "var(--control-horizontal-distance-2)"}}},
                            theme.viewButton({
                                text: LanguageModule.text("txt_view_maps"),
                                onclick: function(){
                                    redraw(parseFloat(minutes_input.value), true);
                                }
                            })
                        ],
                        [{attrs: {style: {height: "var(--control-verticle-distance-2)"}}}]
                    ]
                }),
                data_ctn
            ]
        }),
        buttonlist: [
            {
                text: LanguageModule.text("txt_close"),
                onclick: function(){
                    ModalElement.close();
                }
            }
        ]
    });
    redraw(5);
};

hr.partner_checkin.deletePartner_checkin = function(host, id){
    return new Promise(function(resolve,reject){
        ModalElement.show_loading();
        FormClass.api_call({
            url: "partner_checkin_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.partner_checkin.getIndex(id);
                        host.database.partner_checkin.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.partner_checkin.deletePartner_checkinConfirm = function(host, id){
    return new Promise(function(resolve,reject){
        var index = host.database.partner_checkin.getIndex(id);
        ModalElement.question({
            title: LanguageModule.text("war_title_delete_partner_checkin"),
            message: LanguageModule.text2("war_txt_detele", [""]),
            onclick: function(sel){
                if (sel == 0){
                    hr.partner_checkin.deletePartner_checkin(host, id).then(function(value){
                        resolve(value);
                    });
                }
            }
        });
    });
};

hr.partner_checkin.addPartner_checkinSubmit = function(host, data){
    return new Promise(function(resolve, reject){
        console.log(host.subOfMe);
        if (data.checkin_follow_gps && host.employeeOfMe[0] != data.employeeid){
            ModalElement.alert({
                message: LanguageModule.text("war_txt_no_privilege_with_this_employee")
            });
            return;
        }
        if (!data.checkin_follow_gps && host.subOfMe.indexOf(data.employeeid) < 0){
            ModalElement.alert({
                message: LanguageModule.text("war_txt_no_privilege_with_this_employee")
            });
            return;
        }
        ModalElement.show_loading();
        FormClass.api_call({
            url: "partner_checkin_save_auto.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));
                        var partnerData = data_module.getContent("partners", st.partnerid);
                        if (!partnerData){
                            console.log("failed partnerid " + st.partnerid);
                            st.partnergps = "";
                            st.address = "";
                            st.partner = "";
                        }
                        else {
                            st.partnergps = partnerData.gps;
                            st.partner = partnerData.name;
                            st.address = partnerData.address;
                        }
                        host.database.partner_checkin.items.push(st);
                        hr.partner_checkin.redraw(host);
                        resolve();
                    }
                    else {
                        ModalElement.alert({message: message});
                        return;
                    }
                }
                else {
                    ModalElement.alert({message: message});
                    return;
                }
            }
        });
    });
};

hr.partner_checkin.addPartner_checkin = function(host){
    theme.formPartner_checkinEdit({
        database: host.database,
        employeeOfMe: host.employeeOfMe,
        frameList: host.frameList,
        func: {
            save: function(data){
                return hr.partner_checkin.addPartner_checkinSubmit(host, data);
            }
        },
        partner_select_click_func: function(value){
            return contentModule.selectPartnerForm(host.hostSelectPartner, {selectValue: true, value: value});
        }
    });
};

hr.partner_checkin.getCellPartner_checkin = function(host, item){
    var func = {};
    if (host.employeeOfMe[0] == item.employeeid) func.delete = function(){
        return new Promise(function(resolve,reject){
            hr.partner_checkin.deletePartner_checkinConfirm(host, item.id).then(function(value){
                resolve(value);
                for (var i = 0; i < host.dataView.length; i++){
                    if (host.dataView[i].id == item.id){
                        host.dataView.splice(i, 1);
                        break;
                    }
                }
            });
        });
    };
    var res = item;
    res.func = func;
    return res;
};

hr.partner_checkin.viewMaps = function(host){
    var listEmp = {}, empid, lat, lng, x, gps;
    host.dataView.sort(function(a, b){
        return a.checkintime.getTime() - b.checkintime.getTime();
    });
    var employeesDic = contentModule.makeDictionaryIndex(host.database.employees.items);
    var eIndex, partnerData;
    for (var i = 0; i < host.dataView.length; i++){
        empid = host.dataView[i].employeeid;
        eIndex = employeesDic[empid];
        if (eIndex === undefined) continue;
        partnerData = data_module.getContent("partners", host.dataView[i].partnerid);
        if (partnerData === undefined) continue;
        if (!listEmp[empid]){
            listEmp[empid] = [];
        }
        if (host.dataView[i].checkin_follow_gps){
            gps = host.dataView[i].checkingps;
        }
        else {
            gps = host.dataView[i].gps;
        }
        x = gps.indexOf(",");
        if (x > 0){
            lat = parseFloat(gps.substr(0, x));
            lng = parseFloat(gps.substr(x + 1));
        }
        else continue;
        listEmp[empid].push({
            lat: lat,
            lng: lng,
            info: {
                content: partnerData.name + "<br>" +
                         host.database.employees.items[eIndex].fullname + "<br>" +
                         "<strong>"+ contentModule.getDateTimeView(host.dataView[i].checkintime) + "</strong>"
            }
        });
    }
    var polylines = [];
    for (var x in listEmp){
        polylines.push({
            path: listEmp[x],
            id: x
        });
    };
    theme.formPartner_checkinViewMaps({
        polylines: polylines,
        view_line: host.dataView.length <= 10,
        database: host.database,
        frameList: host.frameList
    });
};

hr.partner_checkin.loadDataPartnerList = function(host){
    data_module.loadTables(["partners"], function(){
        host.partnerDataLoaded = true;
    });
};

hr.partner_checkin.export = function(host){
    if (host.typeView == "details"){
        var x = contentModule.getDateTimeExcelExport(new Date());
        var startWorker = function(result, fileName = "check_in_list_"+x+".xlsx") {
            var w;
            if(typeof(Worker) !== "undefined") {
                if(typeof(w) == "undefined") {
                    w = new Worker(window.domain + "js/exceljs.js");
                    w.postMessage(result);
                }
                w.onmessage = function(event) {
                    var data = event.data;
                    if(data.name == "end")
                    {
                        var link = document.createElement('a');
                        link.href = window.URL.createObjectURL(data.data);
                        link.download = fileName;
                        link.click();
                    }
                }
            } else {
                console.log("Sorry, your browser does not support Web Workers...");
            }
        }
        startWorker(host.data_container.excelData);
    }
    else {
        var x = contentModule.getDateTimeExcelExport(new Date());
        var startWorker = function(result, fileName = "check_in_list_summary_"+x+".xlsx") {
            var w;
            if(typeof(Worker) !== "undefined") {
                if(typeof(w) == "undefined") {
                    w = new Worker(window.domain + "js/exceljs.js");
                    w.postMessage(result);
                }
                w.onmessage = function(event) {
                    var data = event.data;
                    if(data.name == "end")
                    {
                        var link = document.createElement('a');
                        link.href = window.URL.createObjectURL(data.data);
                        link.download = fileName;
                        link.click();
                    }
                }
            } else {
                console.log("Sorry, your browser does not support Web Workers...");
            }
        }
        startWorker(host.data_container.excelData);
    }
};

hr.partner_checkin.redraw = function(host){
    if (!host.filter_column_name) host.filter_column_name = "partner_checkin_list";
    var partnerid, employeeid, cityid;
    if (host.fromPartner){
        partnerid = host.partnerid;
        cityid = 0;
    }
    else if (host.fromReport){
        partnerid = 0;
        cityid = 0;
    }
    else {
        partnerid = host.partner_select.value;
        cityid = host.nation_city_select.value[1];
    }
    host.dataView = theme.formPartner_checkinContentData({
        database: host.database,
        inputsearchbox: host.inputsearchbox,
        ctn: host.data_container,
        user_column_configsDic: host.user_column_configsDic,
        partnerid: partnerid,
        employeeid: employeeid,
        cityid: cityid,
        filter_column_name: host.filter_column_name,
        typeView: host.typeView,
        getCellPartner_checkin: function(item){
            return hr.partner_checkin.getCellPartner_checkin(host, item);
        }
    });
};

hr.partner_checkin.init3 = function(host){
    if (!host.partnerDataLoaded){
        setTimeout(function(resolve, reject){
            hr.partner_checkin.init3(host);
        }, 50);
        return;
    }
    ModalElement.close(-1);
    host.database.partner_checkin.items.sort(function(a, b){
        return b.checkintime.getTime() - a.checkintime.getTime();
    });
    contentModule.makeParnerCheckinData(host);
    hr.partner_checkin.redraw(host);
};

hr.partner_checkin.init2 = function(host){
    return new Promise(function(resolveMn, rejectMn){
        var x = contentModule.generateRelativeTime({
            value: host.time_select.value,
            from: host.start_input.value,
            to: host.end_input.value
        });
        x.start = new Date(x.start);
        x.end = new Date(x.end);
        var employees = host.employee_select.values;
        var employeeIdList = [];
        var orgDic = contentModule.makeDictionaryIndex(host.database.orgs.items);
        employees.forEach(function(employeeid){
            if (employeeid > 0){
                employeeIdList.push(employeeid);
            }
            else {
                var oIndex = host.database.orgs.getIndex(-employeeid);
                var orgIDList = contentModule.getDepartmentIDListPrivView(host, oIndex);
                for (var i = 0; i < orgIDList.length; i++){
                    oIndex = orgDic[orgIDList[i]];
                    host.database.orgs.items[oIndex].employeeIndexList.forEach(function(empIndex){
                        if (host.database.employees.items[empIndex].available){
                            employeeIdList.push(host.database.employees.items[empIndex].id);
                        }
                    });
                }
            }
        });
        employeeIdList.sort(function(a, b){
            return a - b;
        });
        if (employeeIdList.length == 0){
            ModalElement.close(-1);
            DOMElement.removeAllChildren(host.data_container);
            return;
        }
        ModalElement.show_loading();
        FormClass.api_call({
            url: "database_load.php",
            params: [
                {name: "task", value: "partner_checkin_load_init2"},
                {name: "params", value: EncodingClass.string.fromVariable(x)},
                {name: "employeeIdList", value: EncodingClass.string.fromVariable(employeeIdList)}
            ],
            func: function(success, message){
                if (success){
                    if (message.substr(0, 2) == "ok"){
                        var st = EncodingClass.string.toVariable(message.substr(2));
                        st.partner_checkin.sort(function(a, b){
                            return b.checkintime.getTime() - a.checkintime.getTime();
                        });
                        contentModule.makeDatabaseContent(host, st);
                        hr.partner_checkin.init3(host);
                        resolveMn();
                    }
                    else {
                        ModalElement.alert({message: message});
                    }
                }
                else {
                    ModalElement.alert({message: message});
                }
            }
        });
    });
};

hr.partner_checkin.init = function(host){
    return new Promise(function(resolveMn, rejectMn){
        hr.menu.changeCurrentUrlTab(host, "partner_checkin_list");
        host.hostSelectPartner = {};
        host.database = {};
        host.typeView = "details";
        ModalElement.show_loading();
        data_module.loadPartnerCheckinsInit().then(function(content){
            host.employeeOfMe = content.employeeOfMe;
            delete content.employeeOfMe;
            host.subOfMe = content.subOfMe;
            delete content.subOfMe;
            contentModule.makeDatabaseContent(host, content);
            host.user_column_configsDic = contentModule.getUser_column_configsDic(host);
            contentModule.makeCitiesIndex(host);
            contentModule.makeOrgsIndex(host);
            contentModule.makeEmployeeData(host);
            contentModule.makeEmployeesIndex(host);
            var cmdbutton = {
                close: function() {
                    if (hr.isMobile){
                        host.holder.selfRemove();
                        theme.mobileInitBack();
                    }
                    else {
                        hr.menu.tabPanel.removeTab(host.holder.id);
                    }
                    host = null;
                },
                add: function() {
                    hr.partner_checkin.addPartner_checkin(host, 0);
                },
                view_maps: function(){
                    hr.partner_checkin.viewMaps(host);
                },
                abnormal_report: function(){
                    hr.partner_checkin.abnormalReport(host);
                }
            };
            host.data_container = DOMElement.div({});
            host.holder.addChild(host.frameList);
            var singlePage = theme.formPartner_checkinInit({
                employeeOfMe: host.employeeOfMe,
                database: host.database,
                cmdbutton: cmdbutton,
                data_container: host.data_container,
                typeView: host.typeView,
                changeTimeFunc: function(){
                    hr.partner_checkin.init2(host);
                },
                filter_change_func: function(){
                    hr.partner_checkin.redraw(host);
                },
                change_type_view: function(type){
                    host.typeView = type;
                    hr.partner_checkin.redraw(host);
                },
                employeeOfMe: host.employeeOfMe,
                partner_select_click_func: function(value){
                    return contentModule.selectPartnerForm(host.hostSelectPartner, {allValue: true, value: value});
                },
                export: function(){
                    hr.partner_checkin.export(host);
                }
            });
            host.employee_select = singlePage.employee_select;
            host.partner_select = singlePage.partner_select;
            host.nation_city_select = singlePage.nation_city_select;
            host.inputsearchbox = singlePage.inputsearchbox;
            host.time_select = singlePage.time_select;
            host.start_input = singlePage.start;
            host.end_input = singlePage.end;
            host.frameList.addChild(singlePage);
            singlePage.requestActive();
            hr.partner_checkin.init2(host).then(function(){
                resolveMn(host);
            });
        });
        hr.partner_checkin.loadDataPartnerList(host);
    });
};

VaKeR 2022