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/bsc_input_values.js
hr.bsc_input_values.getLocked = function(host, idate, criteriaid){
    var today = contentModule.getDateFrom1970(new Date());
    var locked = true;
    var expireddate;
    switch (systemconfig.bsc_locked_by) {
        case "day":
            expireddate = idate + systemconfig.locked_after + 1;
            break;
        case "week":
            expireddate = contentModule.getDateFrom1970(absol.datetime.nextWeek(new Date(idate*86400000))) + systemconfig.bsc_locked_on_day;
            break;
        case "month":
            expireddate = contentModule.getDateFrom1970(absol.datetime.nextMonth(new Date(idate*86400000))) + systemconfig.bsc_locked_on_day;
            break;
        default:
            expireddate = 0;
    }
    if (expireddate > today) locked = false;
    else {
        if (!host.database.bsc_unlock_values) return true;// TODO:
        var uItem;
        for (var i = 0; i < host.database.bsc_unlock_values.items.length; i++){
            uItem = host.database.bsc_unlock_values.items[i];
            if ((idate >= uItem.startdate) && (idate <= uItem.enddate)){
                if ((uItem.criterias.indexOf(0) >= 0) || (uItem.criterias.indexOf(criteriaid) >= 0)){
                    locked = false;
                    break;
                }
                break;
            }
        }
    }
    return locked;
};

hr.bsc_input_values.makeLockData = function(host){
    host.database.bsc_input_queues.items.forEach(function(item){
        item.locked = hr.bsc_input_values.getLocked(host, item.idate, item.criteriaid);
    });
    host.database.bsc_inputs.items.forEach(function(item){
        item.locked = hr.bsc_input_values.getLocked(host, item.idate, item.criteriaid);
    });
};

hr.bsc_input_values.drawHistory = function(host){
    var viewHistory = DOMElement.div({
        attrs: {
            style: {
                paddingLeft: "var(--control-verticle-distance-2)",
                paddingTop: "var(--control-verticle-distance-2)"
            }
        }
    });
    var res = absol.buildDom({
        attr: {
            "data-sectionid": "history"
        },
        child: [
            absol.buildDom({
                class: 'mk-section-header',
                child: [{
                    class: 'mk-section-header-name',
                    child: { text: LanguageModule.text("txt_history") },
                }]
            }),
            viewHistory
        ]
    });
    return res;
};

hr.bsc_input_values.time_org_change_func = function(host){
    host.orgid = host.org_emp_select.value;
    if (host.orgid == 0){
        DOMElement.removeAllChildren(host.table_ctn);
        host.criteria_select.items = [{value: 0, text: LanguageModule.text("txt_select_value")}];
        if (hr.isMobile) host.criteria_select.changeItemsFunc();
        host.criteria_select.value = 0;
        host.add_btn_ctn.style.display = "none";
        host.add_many_btn_ctn.style.display = "none";
        return;
    }
    if (systemconfig.privSystem < 2 && !data_module.admin_rights_of_me.functional_matrixs_scorecards){
        if (host.orgid != -host.employeeOfMe[0]){
            if (!host.privilegesDic[host.orgid] || (!host.privilegesDic[host.orgid].input_values && !host.privilegesDic[host.orgid].approval_values)){
                host.add_btn_ctn.style.display = "none";
                host.add_many_btn_ctn.style.display = "none";
                host.criteria_select.items = [{value: 0, text: LanguageModule.text("txt_select_value")}];
                if (hr.isMobile) host.criteria_select.changeItemsFunc();
                host.criteria_select.value = 0;
                DOMElement.removeAllChildren(host.table_ctn);
                host.table_ctn.appendChild(DOMElement.div({
                    attrs: {
                        style: {
                            textAlign: "center",
                            paddingTop: "50px",
                            color: "red"
                        }
                    },
                    text: LanguageModule.text("txt_no_permission_with_department_employee")
                }));
                return;
            }
        }
    }
    var rfirstid;
    if (host.orgid > 0){
        var oIndex = host.database.orgs.getIndex(host.orgid);
        rfirstid = host.database.orgs.items[oIndex].firstid;
    }
    else {
        var eIndex = host.database.employees.getIndex(-host.orgid);
        rfirstid = - host.database.employees.items[eIndex].firstid;
    }
    ModalElement.show_loading();
    FormClass.api_call({
        url: "database_load.php",
        params: [
            {name: "task", value: "bsc_input_values_load_kpi_has_input_values_by_orgid_and_time"},
            {name: "rfirstid", value: rfirstid},
            {name: "timestart", value: 0},
            {name: "timeend", value: 0}
        ],
        func: function(success, message){
            ModalElement.close(-1);
            if (success){
                if (message.substr(0, 2) == "ok"){
                    var st = EncodingClass.string.toVariable(message.substr(2));
                    var dic = {};
                    for (var i = 0; i < st.length; i++){
                        dic[st[i].criteriaid] = true;
                    }
                    host.kpiItems = [
                        {value: 0, text: LanguageModule.text("txt_select_value")},
                        {value: -1, text: LanguageModule.text("txt_all_kpi")}
                    ];
                    for (var i = 0; i < host.database.bsc_criteriadefinitions.items.length; i++){
                        if (dic[host.database.bsc_criteriadefinitions.items[i].id]){
                            host.kpiItems.push({
                                value: host.database.bsc_criteriadefinitions.items[i].id,
                                text: host.database.bsc_criteriadefinitions.items[i].name
                            });
                        }
                    }
                    host.criteria_select.items = host.kpiItems;
                    if (hr.isMobile) host.criteria_select.changeItemsFunc();
                    if (host.fromScorecard){
                        host.criteria_select.value = host.paramsScorecard.criteriaid;
                        host.criteria_select.disabled = true;
                    }
                    else {
                        if (host.criteriaid && dic[host.criteriaid]){
                            host.criteria_select.value = host.criteriaid;
                        }
                        else {
                            host.criteria_select.value = -1;
                        }
                    }
                    hr.bsc_input_values.drawTable(host);
                }
                else {
                    ModalElement.alert({message: message});
                }
            }
            else {
                ModalElement.alert({message: message});
            }
        }
    });
};

hr.bsc_input_values.deleteRow = function(host, id, queue){
    return new Promise(function(rs, rj){
        if (host.orgid > 0){
            var oIndex = host.database.orgs.getIndex(host.orgid);
            rfirstid = host.database.orgs.items[oIndex].firstid;
        }
        else {
            var eIndex = host.database.employees.getIndex(-host.orgid);
            rfirstid = -host.database.employees.items[eIndex].firstid;
        }
        ModalElement.show_loading();
        FormClass.api_call({
            url: "bsc_input_values_delete.php",
            params: [
                {name: "id", value: id},
                {name: "queue", value: queue},
                {name: "rfirstid", value: rfirstid}
            ],
            func: function(success, message){
                ModalElement.close(-1);
                if (success){
                    if (message.substr(0, 2) == "ok"){
                        if (queue){
                            var k = host.database.bsc_input_queues.getIndex(id);
                            var inputid = host.database.bsc_input_queues.items[k].inputid;
                            host.database.bsc_input_queues.items.splice(k, 1);
                            var k = host.database.bsc_inputs.getIndex(inputid);
                            host.database.bsc_inputs.items.splice(k, 1);
                        }
                        else {
                            var k = host.database.bsc_inputs.getIndex(id);
                            host.database.bsc_inputs.items.splice(k, 1);
                        }
                        rs();
                    }
                    else {
                        ModalElement.alert({message: message});
                    }
                }
                else {
                    ModalElement.alert({message: message});
                }
            }
        });
    });
};

hr.bsc_input_values.deleteRowConfirm = function(host, id, queue){
    return new Promise(function(rs, rj){
        ModalElement.question({
            message: LanguageModule.text2("war_txt_detele", [""]),
            onclick: function(sel){
                if (sel == 0){
                    hr.bsc_input_values.deleteRow(host, id, queue).then(function(){
                        rs();
                    });
                }
            }
        });
    });
};

hr.bsc_input_values.addManyRowSubmit = function(host, data){
    return new Promise(function(resolve, reject){
        if (host.orgid > 0){
            var oIndex = host.database.orgs.getIndex(host.orgid);
            rfirstid = host.database.orgs.items[oIndex].firstid;
        }
        else {
            var eIndex = host.database.employees.getIndex(-host.orgid);
            rfirstid = -host.database.employees.items[eIndex].firstid;
        }
        var privApproval = false;
        if (systemconfig.privSystem >= 2) privApproval = true;
        else if (data_module.admin_rights_of_me.functional_matrixs_scorecards) privApproval = true;
        else if (host.privilegesDic[host.orgid] && host.privilegesDic[host.orgid].approval_values) privApproval = true;
        for (var i = 0; i < data.insert.length; i++){
            if (privApproval) data.insert[i].status = 1;
            else data.insert[i].status = 0;
            data.insert[i].rid = host.orgid;
            data.insert[i].rfirstid = rfirstid;
        }
        for (var i = 0; i < data.update.length; i++){
            if (privApproval) data.update[i].status = 1;
            else data.update[i].status = 0;
        }
        console.log(data);
        ModalElement.show_loading();
        FormClass.api_call({
            url: "bsc_input_values_submit_many.php",
            params: [
                {name: "data", value: EncodingClass.string.fromVariable(data)},
                {name: "rfirstid", value: rfirstid}
            ],
            func: function(success, message){
                if (success){
                    if (message.substr(0, 2) == "ok"){
                        hr.bsc_input_values.drawTable(host);
                        resolve();
                    }
                    else {
                        ModalElement.alert({message: message});
                    }
                }
                else {
                    ModalElement.alert({message: message});
                }
            }
        });
    });
};

hr.bsc_input_values.addManyRow = function(host){
    var rfirstid, departmentName = "";
    if (host.orgid > 0){
        var oIndex = host.database.orgs.getIndex(host.orgid);
        rfirstid = host.database.orgs.items[oIndex].firstid;
        departmentName = host.database.orgs.items[oIndex].name;
    }
    else {
        var eIndex = host.database.employees.getIndex(-host.orgid);
        rfirstid = -host.database.employees.items[eIndex].firstid;
        departmentName = host.database.employees.items[eIndex].fullname;
    }
    var timestart, timeend, timeText = "";
    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));
            timeText = LanguageModule.text("txt_month") + " " + (host.month_select.value.getMonth() + 1) + "/" + host.month_select.value.getFullYear();
            break;
        case "quarter":
            timestart = contentModule.getDateFrom1970(absol.datetime.beginOfQuarter(host.quarter_select.value));
            timeend = contentModule.getDateFrom1970(absol.datetime.nextQuarter(host.quarter_select.value));
            timeText = LanguageModule.text("txt_quarter") + " " + hr.bsc_reports.getQuarterText(host.quarter_select.value.getMonth() + 1) + "/" + host.quarter_select.value.getFullYear();
            break;
        case "year":
            timestart = contentModule.getDateFrom1970(absol.datetime.beginOfYear(host.year_select.value));
            timeend = contentModule.getDateFrom1970(absol.datetime.nextYear(host.year_select.value));
            timeText = LanguageModule.text("txt_year") + " " + (host.year_select.value.getFullYear());
            break;
        default:
            timestart = contentModule.getDateFrom1970(absol.datetime.beginOfYear(host.year_select.value));
            timeend = contentModule.getDateFrom1970(absol.datetime.nextYear(host.year_select.value));
            timeText = LanguageModule.text("txt_year") + " " + (host.year_select.value.getFullYear());
    }
    host.group_by_ctn = DOMElement.div({attrs: {className: "single-button-header"}});
    host.newDateLink = DOMElement.div({attrs: {className: "single-button-header"}});
    var buttonlist = [
        DOMElement.div({
            attrs: {className: "single-button-header"},
            children: [theme.closeButton({
                onclick: function(){
                    host.frameList.removeLast();
                    window.backLayoutFunc.pop();
                }
            })]
        }),
        DOMElement.div({
            attrs: {className: "single-button-header"},
            children: [theme.saveButton({
                onclick: function(){
                    var data = ctn.getInfo();
                    if (!data) return;
                    if (data.insert.length == 0 && data.update.length == 0) return;
                    hr.bsc_input_values.addManyRowSubmit(host, data).then(function(){
                        DOMElement.removeAllChildren(data_ctn);
                        ctn = batchInputs.kpi(data_ctn, rfirstid, timestart, timeend - 1, host);
                    });
                }
            })]
        }),
        DOMElement.div({
            attrs: {className: "single-button-header", style: {fontWeight: "bold"}},
            text: departmentName + " - " + timeText
        }),
        host.group_by_ctn,
        host.newDateLink
    ];
    var data_ctn = DOMElement.div({attrs: {className: "cardsimpletableclass"}});
    var singlePage = absol.buildDom({
        tag: "singlepage",
        child: [
            DOMElement.div({
                attrs: {className: 'button-panel-header absol-single-page-header'},
                children: buttonlist
            }),
            data_ctn
        ]
    });
    host.frameList.addChild(singlePage);
    singlePage.requestActive();
    window.backLayoutFunc.push({
        func: function(){
            host.frameList.removeLast();
            window.backLayoutFunc.pop();
        }
    });
    var ctn = batchInputs.kpi(data_ctn, rfirstid, timestart, timeend - 1, host);
};

hr.bsc_input_values.addRow = function(host, id, queue){
    return new Promise(function(resolve, reject){
        var redraw = function(content){
            var saveFunc = function(data){
                return new Promise(function(rs, rj){
                    if (systemconfig.privSystem >= 2) data.status = 1;
                    else if (data_module.admin_rights_of_me.functional_matrixs_scorecards) data.status = 1;
                    else if (host.privilegesDic[host.orgid] && host.privilegesDic[host.orgid].approval_values) data.status = 1;
                    var attachments = data.attachments;
                    data.attachments = [];
                    data.attachmentsAdd = [];
                    var attachmentsAdd = [];
                    for (var i = 0; i < attachments.length; i++){
                        if (attachments[i] instanceof File){
                            data.attachmentsAdd.push(attachments[i].name);
                            attachmentsAdd.push(attachments[i]);
                        }
                        else {
                            data.attachments.push(attachments[i].id);
                        }
                    }
                    data.attachmentsDel = [];
                    if (content){
                        var ex;
                        for (var i = 0; i < content.files.length; i++){
                            ex = false;
                            for (var j = 0; j < attachments.length; j++){
                                if (attachments[j] instanceof File) continue;
                                if (attachments[j].id == content.files[i].id){
                                    ex = true;
                                    break;
                                }
                            }
                            if (!ex) data.attachmentsDel.push({
                                id: content.files[i].id,
                                name: content.files[i].originName
                            });
                        }
                    }
                    var saveFunc2 = function(){
                        var rfirstid;
                        if (host.orgid > 0){
                            var oIndex = host.database.orgs.getIndex(host.orgid);
                            rfirstid = host.database.orgs.items[oIndex].firstid;
                        }
                        else {
                            var eIndex = host.database.employees.getIndex(-host.orgid);
                            rfirstid = - host.database.employees.items[eIndex].firstid;
                        }
                        ModalElement.show_loading();
                        FormClass.api_call({
                            url: "bsc_input_values_submit.php",
                            params: [
                                {name: "data", value: EncodingClass.string.fromVariable(data)},
                                {name: "rfirstid", value: rfirstid}
                            ],
                            func: function(success, message){
                                ModalElement.close(-1);
                                if (success){
                                    if (message.substr(0, 2) == "ok"){
                                        ModalElement.close();
                                        var st = EncodingClass.string.toVariable(message.substr(2));
                                        console.log(st);
                                        if (st.data.details_result == "") st.data.details_result = {};
                                        else st.data.details_result = EncodingClass.string.toVariable(st.data.details_result);
                                        st.data.files = [];
                                        var dic = contentModule.makeDictionaryIndex(st.files);
                                        var fIndex;
                                        for (var i = 0; i < st.data.attachments.length; i++){
                                            fIndex = dic[st.data.attachments[i]];
                                            if (fIndex < 0) continue;
                                            st.data.files.push({
                                                id: st.data.attachments[i],
                                                name: st.files[fIndex].title,
                                                url: window.domainFilesNew + st.data.attachments[i] + "_" + st.files[fIndex].name + ".upload",
                                                originName: st.files[fIndex].name
                                            });
                                        }
                                        if (content){
                                            if (queue){
                                                var index = host.database.bsc_input_queues.getIndex(content.id);
                                                var inputid = host.database.bsc_input_queues.items[index].inputid;
                                                host.database.bsc_input_queues.items[index] = st.data;
                                                var k = host.database.bsc_inputs.getIndex(inputid);
                                                host.database.bsc_inputs.items[k] = EncodingClass.string.duplicate(st.data);
                                                host.database.bsc_inputs.items[k].id = inputid;
                                            }
                                            else {
                                                host.database.bsc_input_queues.items.push(st.data);
                                                var index = host.database.bsc_inputs.getIndex(content.id);
                                                host.database.bsc_inputs.items[index] = EncodingClass.string.duplicate(st.data);
                                                host.database.bsc_inputs.items[index].id = content.id;
                                            }
                                            st.data.queue = 1;
                                        }
                                        else {
                                            host.database.bsc_input_queues.items.push(st.data);
                                        }
                                        function saveFile(){
                                            for (var i = 0; i < attachmentsAdd.length; i++){
                                                systemconfig.connectorFile.upload({
                                                    index: 0,
                                                    path: ["hr", "files"],
                                                    filehandle: attachmentsAdd[i],
                                                    filename: st.data.attachmentsAdd[i] + "_" + attachmentsAdd[i].name + ".upload",
                                                    onsuccess: function (content){
                                                        console.log(content);
                                                    },
                                                    onfailed: function (content){
                                                        ModalElement.alert({message: LanguageModule.text("war_txt_no_upload_file")});
                                                        console.log(message);
                                                    }
                                                });
                                            }
                                            for (var i = 0; i < data.attachmentsDel.length; i++){
                                                systemconfig.connectorFile.delete({
                                                    index: 0,
                                                    path: ["hr", "files"],
                                                    files: [data.attachmentsDel[i].id + "_" + data.attachmentsDel[i].name + ".upload"],
                                                    onsuccess: function (){
                                                        console.log("success");
                                                    },
                                                    onfailed: function (content){
                                                        console.log(content);
                                                    }
                                                });
                                            }
                                        };
                                        systemconfig.loadFolderFunc().then(function(value){
                                            if (value) saveFile();
                                            else {
                                                systemconfig.reconnectFile().then(function(){
                                                    saveFile();
                                                });
                                            }
                                        });
                                        resolve(st.data);
                                        rs();
                                    }
                                    else {
                                        ModalElement.alert({message: message});
                                    }
                                }
                                else {
                                    ModalElement.alert({message: message});
                                }
                            }
                        });
                    };
                    if (data.weight_requirement && data.weight == 0){
                        contentModule.questionChange({
                            message: LanguageModule.text2("war_txt_weight_is_zero_value_not_used_to_report", [weight_name]),
                            onclick: function(sel){
                                if (sel == 0){
                                    saveFunc2();
                                }
                                else if (sel == 1){
                                    ModalElement.close();
                                }
                            }
                        });
                    }
                    else {
                        saveFunc2();
                    }
                });
            };
            var kpiItems = EncodingClass.string.duplicate(host.kpiItems);
            kpiItems.splice(1, 1);
            var unit = "";
            var decpre = 0;
            var weight_requirement;
            var weight_name = "", value_name = "";
            var average_unit_as_percentage;
            var criteriaid = 0;
            var c_select_disabled = false;
            if (host.fromScorecard) c_select_disabled = true;
            if (content || host.criteriaid > 0){
                if (content){
                    var cIndex = host.database.bsc_criteriadefinitions.getIndex(content.criteriaid);
                    criteriaid = content.criteriaid;
                    c_select_disabled = true;
                }
                else {
                    var cIndex = host.database.bsc_criteriadefinitions.getIndex(host.criteriaid);
                    criteriaid = host.criteriaid;
                }
                decpre = host.database.bsc_criteriadefinitions.items[cIndex].decpre;
                unit = host.database.bsc_criteriadefinitions.items[cIndex].unit;
                weight_requirement = host.database.bsc_criteriadefinitions.items[cIndex].weight_requirement;
                average_unit_as_percentage = host.database.bsc_criteriadefinitions.items[cIndex].average_unit_as_percentage;
                weight_name = host.database.bsc_criteriadefinitions.items[cIndex].weight_name;
                value_name = host.database.bsc_criteriadefinitions.items[cIndex].value_name;
            }
            var rfirstid;
            if (host.orgid > 0){
                var oIndex = host.database.orgs.getIndex(host.orgid);
                rfirstid = host.database.orgs.items[oIndex].firstid;
            }
            else {
                var eIndex = host.database.employees.getIndex(-host.orgid);
                rfirstid = -host.database.employees.items[eIndex].firstid;
            }
            theme.formBscInputValuesEdit({
                id: content? content.id : 0,
                queue: queue,
                title: content? LanguageModule.text("txt_edit") : LanguageModule.text("txt_add"),
                orgEmpItems: contentModule.getOrgsAndEmployeesListSelectTreeMenu(host),
                orgid: host.orgid,
                kpiItems: kpiItems,
                database: host.database,
                criteriaid: criteriaid,
                c_select_disabled: c_select_disabled,
                decpre: decpre,
                unit: unit,
                weight_requirement: weight_requirement,
                average_unit_as_percentage: average_unit_as_percentage,
                weight_name: weight_name,
                value_name: value_name,
                idate: content? new Date(content.idate*86400000) : new Date(),
                value: content? contentModule.moneyFormat2(content.value, 0, decpre) : "",
                weight: content? contentModule.moneyFormat2(content.weight, 0, decpre) : "",
                result: content? (content.is_illegal? "-" : average_unit_as_percentage? contentModule.moneyFormat2(content.result*100, 0, decpre) : contentModule.moneyFormat2(content.result, 0, decpre)) : "",
                comment: (content && content.comment)? content.comment : "",
                files: (content)? content.files : [],
                func: {
                    save: function(data){
                        return new Promise(function(rs, rj){
                            saveFunc(data).then(function(){
                                rs();
                            });
                        });
                    },
                    getLocked: function(idate, criteriaid){
                        return hr.bsc_input_values.getLocked(host, idate, criteriaid);
                    }
                },
                rfirstid: rfirstid,
                frameList: host.frameList,
                details_result: content? content.details_result : {}
            });
        };
        if (id > 0){
            ModalElement.show_loading();
            FormClass.api_call({
                url: "database_load.php",
                params: [
                    {name: "task", value: "bsc_input_values_load_bsc_input_queues_by_id"},
                    {name: "id", value: id},
                    {name: "queue", value: queue}
                ],
                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.details_result != "") st.data.details_result = EncodingClass.string.toVariable(st.data.details_result);
                            var dic = contentModule.makeDictionaryIndex(st.files);
                            var fIndex;
                            for (var i = 0; i < st.data.attachments.length; i++){
                                fIndex = dic[st.data.attachments[i]];
                                if (fIndex === undefined) continue;
                                st.data.files.push({
                                    id: st.data.attachments[i],
                                    name: st.files[fIndex].title,
                                    url: window.domainFilesNew + st.data.attachments[i] + "_" + st.files[fIndex].name + ".upload",
                                    originName: st.files[fIndex].name
                                });
                            }
                            redraw(st.data);
                        }
                        else if (message.startsWith("war_txt_")){
                            ModalElement.alert({message: LanguageModule.text(message)});
                        }
                        else {
                            ModalElement.alert({message: message});
                        }
                    }
                    else {
                        ModalElement.alert({message: message});
                    }
                }
            });
        }
        else {
            redraw();
        }
    });
};

hr.bsc_input_values.getRow = function(host, content){
    var privApproval = false;
    if (systemconfig.privSystem >= 2 || data_module.admin_rights_of_me.functional_matrixs_scorecards) privApproval = true;
    else if (host.privilegesDic[host.orgid] && host.privilegesDic[host.orgid].approval_values) privApproval = true;

    var cIndex = host.database.bsc_criteriadefinitions.getIndex(content.criteriaid);
    var weight_requirement = host.database.bsc_criteriadefinitions.items[cIndex].weight_requirement;
    var value_name = host.database.bsc_criteriadefinitions.items[cIndex].value_name;
    var weight_name = host.database.bsc_criteriadefinitions.items[cIndex].weight_name;
    var average_unit_as_percentage = host.database.bsc_criteriadefinitions.items[cIndex].average_unit_as_percentage;
    var decpre = host.database.bsc_criteriadefinitions.items[cIndex].decpre;
    var accumulateValuesToText = "";
    host.database.bsc_criteria_rlinks.items.forEach(function(rItem){
        if (rItem.criteriaid != content.criteriaid) return;
        if ((rItem.startdate <= content.idate) && ((rItem.expireddate > content.idate) || (rItem.expireddate == 0))){
            var k;
            if (rItem.rtofirstid > 0){
                k = host.database.orgs.getIndexByFirstid(rItem.rtofirstid);
                if (k >= 0) accumulateValuesToText += ", " + host.database.orgs.items[k].name;
            }
            else {
                k = host.database.employees.getIndexByFirstid(-rItem.rtofirstid);
                if (k >= 0) accumulateValuesToText += ", " + host.database.employees.items[k].fullname;
            }
        }
    });
    if (accumulateValuesToText.length > 0) accumulateValuesToText = accumulateValuesToText.substr(2);
    var func;
    if (!content.locked && (content.status == 0 || privApproval)){
        func = {
            edit: function(rs){
                hr.bsc_input_values.addRow(host, content.id, content.queue).then(function(value){
                    rs(hr.bsc_input_values.getRow(host, value));
                });
            },
            delete: function(){
                return new Promise(function(rs, rj){
                    hr.bsc_input_values.deleteRowConfirm(host, content.id, content.queue).then(function(){
                        rs();
                    });
                });
            }
        };
    }
    var method_details = [];
    if (host.database.bsc_criteriadefinitions.items[cIndex].result_input_method != 0){
        var k = host.database.bsc_result_input_methods.getIndex(host.database.bsc_criteriadefinitions.items[cIndex].result_input_method);
        method_details = host.database.bsc_result_input_methods.items[k].content.details;
    }
    var result = content.result;
    if (host.database.bsc_criteriadefinitions.items[cIndex].average_unit_as_percentage) result = result*100;
    return {
        idate: content.idate,
        is_illegal: content.is_illegal,
        decpre: decpre,
        result: result,
        details_result: content.details_result,
        weight_requirement: weight_requirement,
        value: content.value,
        weight: content.weight,
        comment: content.comment,
        accumulateValuesToText: accumulateValuesToText,
        files: content.files,
        locked: content.locked,
        status: content.status,
        type: "value",
        func: func,
        method_details: method_details
    };
};

hr.bsc_input_values.getKpiRow = function(host, criteriaid){
    var cIndex = host.criteriasDic[criteriaid];
    return {
        type: "kpi",
        kpiName: host.database.bsc_criteriadefinitions.items[cIndex].name,
        kpiUnit: host.database.bsc_criteriadefinitions.items[cIndex].unit
    };
};

hr.bsc_input_values.drawTable2 = function(host){
    console.log(2222);
    DOMElement.removeAllChildren(host.table_ctn);
    hr.bsc_input_values.makeLockData(host);
    var fIndex;
    for (var i = 0; i < host.database.bsc_input_queues.items.length; i++){
        host.database.bsc_input_queues.items[i].files = [];
        for (var j = 0; j < host.database.bsc_input_queues.items[i].attachments.length; j++){
            fIndex = host.database.files.getIndex(host.database.bsc_input_queues.items[i].attachments[j]);
            if (fIndex >= 0){
                host.database.bsc_input_queues.items[i].files.push({
                    id: host.database.bsc_input_queues.items[i].attachments[j],
                    name: host.database.files.items[fIndex].title,
                    url: window.domainFilesNew + host.database.bsc_input_queues.items[i].attachments[j] + "_" + host.database.files.items[fIndex].name + ".upload",
                    originName: host.database.files.items[fIndex].name
                });
            }
        }
    }
    for (var i = 0; i < host.database.bsc_inputs.items.length; i++){
        host.database.bsc_inputs.items[i].files = [];
    }
    var data = [];
    var iDic = {};
    for (var i = 0; i < host.database.bsc_input_queues.items.length; i++){
        host.database.bsc_input_queues.items[i].queue = 1;
        data.push(host.database.bsc_input_queues.items[i]);
        iDic[host.database.bsc_input_queues.items[i].inputid] = true;
    }
    for (var i = 0; i < host.database.bsc_inputs.items.length; i++){
        if (!iDic[host.database.bsc_inputs.items[i].id]){
            host.database.bsc_inputs.items[i].queue = 0;
            host.database.bsc_inputs.items[i].status = 1;
            data.push(host.database.bsc_inputs.items[i]);
        }
    }
    data.sort(function(a, b){
        return a.idate - b.idate;
    });
    var criteriasDic = contentModule.makeDictionaryIndex(host.database.bsc_criteriadefinitions.items);
    var criteriaidList = [];
    var list = {}, k, k1, k2;
    var listMethod = [];
    var methodDic = {};
    for (var i = 0; i < data.length; i++){
        k = host.criteriasDic[data[i].criteriaid];
        if (k >= 0){
            if (!list[data[i].criteriaid]){
                list[data[i].criteriaid] = [];
                criteriaidList.push(data[i].criteriaid);
                k1 = criteriasDic[data[i].criteriaid];
                if (host.database.bsc_criteriadefinitions.items[k1].result_input_method != 0){
                    if (!methodDic[host.database.bsc_criteriadefinitions.items[k1].result_input_method]){
                        k2 = host.database.bsc_result_input_methods.getIndex(host.database.bsc_criteriadefinitions.items[k1].result_input_method);
                        listMethod.push(host.database.bsc_result_input_methods.items[k2]);
                        methodDic[host.database.bsc_criteriadefinitions.items[k1].result_input_method] = true;
                    }
                }
            }
            list[data[i].criteriaid].push(data[i]);
        }
    }
    var hasWeight = false;
    var dataTable = [];
    var cIndex, value_name, weight_name;
    criteriaidList.forEach(function(criteriaid){
        if (list[criteriaid].length > 0){
            dataTable.push(hr.bsc_input_values.getKpiRow(host, criteriaid));
            cIndex = host.criteriasDic[criteriaid];
            if (host.database.bsc_criteriadefinitions.items[cIndex].weight_requirement){
                value_name = host.database.bsc_criteriadefinitions.items[cIndex].value_name;
                weight_name = host.database.bsc_criteriadefinitions.items[cIndex].weight_name;
                if (value_name != "" && weight_name != ""){
                    dataTable.push({
                        type: "value_weight_name",
                        value_name: value_name,
                        weight_name: weight_name
                    });
                }
                hasWeight = true;
            }
            else if (listMethod.length > 0 && host.database.bsc_criteriadefinitions.items[cIndex].result_input_method != 0){
                var k = host.database.bsc_result_input_methods.getIndex(host.database.bsc_criteriadefinitions.items[cIndex].result_input_method);
                if (listMethod.length > 1){
                    dataTable.push({
                        type: "method_details",
                        details: host.database.bsc_result_input_methods.items[k].content.details
                    });
                }
            }
            for (var i = 0; i < list[criteriaid].length; i++){
                dataTable.push(hr.bsc_input_values.getRow(host, list[criteriaid][i]));
            }
        }
    });
    console.log(2111);
    host.tableView = theme.formBscInputValuesTableData({
        dataTable: dataTable,
        hasWeight: hasWeight,
        listMethod: listMethod
    });
    host.table_ctn.appendChild(host.tableView);
};

hr.bsc_input_values.drawTable = function(host){
    host.orgid = host.org_emp_select.value;
    host.criteriaid = host.criteria_select.value;
    if (host.criteriaid == 0 || host.criteriaid == -1){
        host.measurement_unit_elt.innerText = "";
    }
    else {
        var cIndex = host.database.bsc_criteriadefinitions.getIndex(host.criteriaid);
        host.measurement_unit_elt.innerText = "(" + LanguageModule.text("txt_measurement_unit") + ": " + host.database.bsc_criteriadefinitions.items[cIndex].unit + ")";
    }
    if (host.orgid == 0){
        host.add_btn_ctn.style.display = "none";
        host.add_many_btn_ctn.style.display = "none";
    }
    else {
        host.add_btn_ctn.style.display = "";
        host.add_many_btn_ctn.style.display = "";
    }
    if (host.orgid == 0 || host.criteriaid == 0){
        DOMElement.removeAllChildren(host.table_ctn);
        return;
    }
    var rfirstid;
    if (host.orgid > 0){
        var oIndex = host.database.orgs.getIndex(host.orgid);
        rfirstid = host.database.orgs.items[oIndex].firstid;
    }
    else {
        var eIndex = host.database.employees.getIndex(-host.orgid);
        rfirstid = - host.database.employees.items[eIndex].firstid;
    }
    switch (host.period_select.value){
        case "month":
            host.timestart = contentModule.getDateFrom1970(absol.datetime.beginOfMonth(host.month_select.value));
            host.timeend = contentModule.getDateFrom1970(absol.datetime.nextMonth(host.month_select.value));
            break;
        case "quarter":
            host.timestart = contentModule.getDateFrom1970(absol.datetime.beginOfQuarter(host.quarter_select.value));
            host.timeend = contentModule.getDateFrom1970(absol.datetime.nextQuarter(host.quarter_select.value));
            break;
        case "year":
            host.timestart = contentModule.getDateFrom1970(absol.datetime.beginOfYear(host.year_select.value));
            host.timeend = contentModule.getDateFrom1970(absol.datetime.nextYear(host.year_select.value));
            break;
        default:
            host.timestart = 0;
            host.timeend = 0;
    }
    ModalElement.show_loading();
    FormClass.api_call({
        url: "database_load.php",
        params: [
            {name: "task", value: "bsc_input_values_load_input_queues_by_rfirstid_and_criteriaid_and_time"},
            {name: "rfirstid", value: rfirstid},
            {name: "criteriaid", value: host.criteriaid},
            {name: "startdate", value: host.timestart},
            {name: "expireddate", value: host.timeend},
            {name: "today", value: contentModule.getDateFrom1970(new Date())}
        ],
        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.bsc_unlock_values.items.forEach(function(item){
                        item.criterias = [];
                    });
                    var dic = contentModule.makeDictionaryIndex(host.database.bsc_unlock_values.items);
                    host.database.bsc_unlock_value_criterias.items.forEach(function(item){
                        var k = dic[item.uid];
                        if (k >= 0) host.database.bsc_unlock_values.items[k].criterias.push(item.criteriaid);
                    });
                    hr.bsc_input_values.drawTable2(host);
                }
                else {
                    ModalElement.alert({message: message});
                }
            }
            else {
                ModalElement.alert({message: message});
            }
        }
    })
};

hr.bsc_input_values.redraw = function(host){
    host.table_ctn = DOMElement.div({});
    host.kpiItems = [];
    var res = theme.formBscInputValuesContentData({
        frameList: host.frameList,
        holder: host.holder,
        historyCtn: hr.bsc_input_values.drawHistory(host),
        table_ctn: host.table_ctn,
        func: {
            close: function(){
                if (host.fromScorecard){
                    host.frameList.removeLast();
                }
                else hr.menu.tabPanel.removeTab(host.holder.id);
            },
            add: function(){
                hr.bsc_input_values.addRow(host, 0, 1).then(function(){
                    hr.bsc_input_values.drawTable2(host);
                });
            },
            add_many: function(){
                hr.bsc_input_values.addManyRow(host);
            },
            time_org_change_func: function(){
                hr.bsc_input_values.time_org_change_func(host);
            },
            getOrgEmpItems: function(employee_type){
                return contentModule.getOrgsAndEmployeesListSelectTreeMenu(host, {employee_type: employee_type});
            },
            criteria_change_func: function(){
                hr.bsc_input_values.drawTable(host);
            }
        }
    });
    host.add_btn_ctn = res.add_btn_ctn;
    host.add_many_btn_ctn = res.add_many_btn_ctn;
    host.period_select = res.period_select;
    host.month_select = res.month_select;
    host.year_select = res.year_select;
    host.quarter_select = res.quarter_select;
    host.employee_type_select = res.employee_type_select;
    host.org_emp_select = res.org_emp_select;
    host.criteria_select = res.criteria_select;
    host.measurement_unit_elt = res.measurement_unit_elt;
    if (host.fromScorecard){
        var startdate = new Date(host.paramsScorecard.startdate*86400000);
        var enddate = new Date(host.paramsScorecard.enddate*86400000);
        if (startdate.getFullYear() == enddate.getFullYear()){
            if (startdate.getMonth() == enddate.getMonth()){
                host.period_select.value = "month";
                host.month_select.value = startdate;
            }
            else {
                host.period_select.value = "year";
                host.year_select.value = startdate;
            }
        }
        else {
            host.period_select.value = "all";
        }
        if (host.paramsScorecard.orgid < 0){
            var eIndex = host.database.employees.getIndex(- host.paramsScorecard.orgid);
            if (eIndex >= 0){
                if (!host.database.employees.items[eIndex].available){
                    host.employee_type_select.value = "inactive";
                    host.org_emp_select.items = contentModule.getOrgsAndEmployeesListSelectTreeMenu(host, {employee_type: "inactive"});
                }
            }
        }
        host.org_emp_select.value = host.paramsScorecard.orgid;
        host.employee_type_select.disabled = true;
        host.org_emp_select.disabled = true;
    }
    if (hr.isMobile) hr.bsc_input_values.time_org_change_func(host);
    else host.period_select.emit("change");
};

hr.bsc_input_values.init = function(host, fromScorecard, params = {}){
    return new Promise(function(resolveMn, rejectMn){
        host.fromScorecard = fromScorecard;
        host.paramsScorecard = params;
        if (!host.fromScorecard) hr.menu.changeCurrentUrlTab(host, "bsc_input_values");
        host.database = {};
        ModalElement.show_loading();
        data_module.loadBscInputValuesInit().then(function(content){
            ModalElement.close(-1);
            host.employeeOfMe = content.employeeOfMe;
            delete content.employeeOfMe;
            contentModule.makeDatabaseContent(host, content);
            if (host.database.bsc_result_input_methods.items.length > 0){
                var sample = contentModule.getJsMathNewSampleGeneral();
                var mathExpression = sample.build();
                host.database.bsc_result_input_methods.items.forEach(function(item){
                    item.content = EncodingClass.string.toVariable(item.content);
                    var formula = contentModule.convertPaysheetFormula(item.content.formula);
                    item.parsedContent = mathExpression.parse(formula);
                });
            }
            contentModule.makeOrgsIndex(host);
            contentModule.makeEmployeeData(host);
            contentModule.makeEmployeesIndex(host);
            var orgEmployeeItems = contentModule.getOrgsAndEmployeesListSelectTreeMenu(host);
            orgEmployeeItems.splice(0, 1);
            if (content.configs_privileges){
                contentModule.makeEmployeeGroupMemberIndex(host);
                contentModule.makeConfigPrivileges(host);
            }
            host.database.orgs.getIndexByFirstid = function(firstid){
                for (var i = 0; i < host.database.orgs.items.length; i++){
                    if (host.database.orgs.items[i].firstid == firstid) return i;
                }
                return -1;
            };
            host.database.employees.getIndexByFirstid = function(firstid){
                for (var i = 0; i < host.database.employees.items.length; i++){
                    if (host.database.employees.items[i].firstid == firstid) return i;
                }
                return -1;
            };
            host.criteriasDic = contentModule.makeDictionaryIndex(host.database.bsc_criteriadefinitions.items);
            if (!host.fromScorecard) host.holder.addChild(host.frameList);
            hr.bsc_input_values.redraw(host);
            resolveMn(host);
        });
    });
};

VaKeR 2022