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/hrprocesses.js
hrprocesses = function () {
var retval = {};
var module = retval;
// node: hrprocesses.bsc
var v135 = (function (module) { return function () {
var retval = {};
var v141 = {};
// resource: hrprocesses.bsc.core
var t = function (module, me, core) {return function () {return function () {
var retval = {};
// function: hrprocesses.bsc.core.callbackReturn
var v147 = function(module, me, core) {
return function (callbackfunc, success, content) {
setTimeout(function (callbackfunc, success, content) {
    return function () {
        try {
            callbackfunc(success, content);
        }
        catch (e) {
            console.error(e);
        }
    }
} (callbackfunc, success, content), 10);

}
} (module, retval, core);
// function: hrprocesses.bsc.core.checkCLinks
var v202 = function(module, me, core) {
return function (links) {
var rids;
var marked = {}, rmarked = {};
var id, fid, tid, mid, tsum, ok;
var i, j, k;

if ((links === undefined) || (links === null)) {
    return { result: true };
}
rids = Object.keys(links);
for (j = 0; j < rids.length; j++) {
    for (k = 0; k < links[rids[j]].length; k++) {
        tid = links[rids[j]][k].rtofirstid;
        fid = links[rids[j]][k].rfromfirstid;
        rmarked[fid] = true;
        rmarked[tid] = true;
        if (marked[fid] === undefined) marked[fid] = {};
        marked[fid][tid] = 1;
    }
}
rids = Object.keys(rmarked);
for (i = 0; i < rids.length; i++) {
    rids[i] = parseInt(rids[i]);
}
for (i = 0; i < rids.length; i++) {
    mid = rids[i];
    if (marked[mid] === undefined) continue;
    for (j = 0; j < rids.length; j++) {
        fid = rids[j];
        if (marked[fid] === undefined) continue;
        if (marked[fid][mid] === undefined) continue;
        for (k = 0; k < rids.length; k++) {
            tid = rids[k];
            if (marked[mid][tid] === undefined) continue;
            ok = false;
            tsum = marked[fid][mid] + marked[mid][tid];
            if (marked[fid][tid] === undefined) {
                ok = true;
            }
            else if (marked[fid][tid] > tsum) {
                ok = true;
            }
            if (ok) {
                marked[fid][tid] = tsum;
            }
        }
    }
}
for (i = 0; i < rids.length; i++) {
    mid = rids[i];
    if (marked[mid] === undefined) continue;
    if (marked[mid][mid] !== undefined) {
        rmarked = [mid];
        fid = tid = mid;
        while (true) {
            if (marked[tid][mid] == 1) break;
            for (k = 0; k < rids.length; k++) {
                tid = rids[k];
                if (marked[tid] === undefined) continue;
                if (marked[tid][mid] === undefined) continue;
                if ((marked[fid][tid] == 1) && (marked[tid][mid] + 1 == marked[fid][mid])) {
                    rmarked.push(tid);
                    break;
                }
            }
            fid = tid;
        }
        return {
            result: false,
            rids: rmarked
        };
    }
}

return {
    result: true
}
}
} (module, retval, core);
// function: hrprocesses.bsc.core.exec
var v146 = function(module, me, core) {
return function (task, params, callbackfunc) {
FormClass.api_call({
    url: "hr_bsc.php",
    params: [
        {
            name: "task",
            value: task
        },
        {
            name: "params",
            value: EncodingClass.string.fromVariable(params)
        }
    ],
    func: function (callbackfunc) {
        return function (success, message) {
            var r;
            if (success) {
                if (message.substr(0, 2) == "ok") {
                    r = EncodingClass.string.toVariable(message.substr(2));
                    if (r.result) {
                        core.callbackReturn(callbackfunc, true, r.content);
                    }
                    else {
                        core.callbackReturn(callbackfunc, false, {
                            type: "denied",
                            message: r.message
                        });
                    }
                }
                else {
                    core.callbackReturn(callbackfunc, false, {
                        type: "run-time",
                        message: message
                    });
                }
            }
            else {
                core.callbackReturn(callbackfunc, false, {
                    type: "system",
                    message: message
                });
            }
        }
    } (callbackfunc)
});
}
} (module, retval, core);
// function: hrprocesses.bsc.core.makeKPIReport
var v157 = function(module, me, core) {
return function (params) {
var host = {
    id: params.id,
    startdate: params.startdate,
    expireddate: params.expireddate,
    callbackfunc: params.callbackfunc,
    checkCLinks: core.checkCLinks,
    data: {},
    links: {},
}

host.handler = core.reports_genKPIReport(host);

core.exec("loadKPIs", {
    criteriaid: host.id,
    startdate: host.startdate,
    expireddate: host.expireddate
},
function (host) {
    return function (success, content) {
        var i, j, h, m, n, t, w;
        var sid, fid, rid, keys;
        var tinputs = {}, issorted = {}, tlinks = {};
        if (!success) {
            core.callbackReturn(host.callbackfunc, false, content);
            return;
        }
        host.data.scorecards = core.rebuildTable_id(content.scorecards);
        host.data.inputs = core.rebuildTable(content.inputs);
        host.data.rlinks = core.rebuildTable(content.rlinks);
        host.data.criteria = content.criteria;
        host.data.formula = content.formula;
        t = contentModule.getBscFormulasSystem();
        for (i = 0; i < t.length; i++) {
            if (content.criteria.formulaid == t[i].id) {
                host.data.formula = {
                    id: t[i].id,
                    name: t[i].name,
                    content: t[i].content
                }
                break;
            }
        }
        if (host.data.formula === null) {
            core.callbackReturn(host.callbackfunc, false, {
                type: "denied",
                message: "formula not found!"
            });
            return;
        }
        h = EncodingClass.base64.decode(host.data.formula.content).split("\n");
        m = (h.length - 1) / 2;
        w = [];
        for (j = 0; j < m; j++) {
            w.push({
                cond: h[j * 2],
                result: h[j * 2 + 1]
            });
        }
        host.data.formula.content = w;
        h = "na";
        for (j = w.length-1; j >= 0; j--) {
            h = "if (" + w[j].cond + "," + w[j].result + "," + h + ")";
        }
        host.data.formula.parsedData = MathClass.Expression.parse(h);
        host.data.formula.func = host.data.formula.parsedData.calc;
        n = host.data.inputs.length;
        for (i = 0; i < n; i++) {
            fid = host.data.inputs[i].rfirstid;
            if (tinputs[fid] === undefined) {
                tinputs[fid] = [];
            }
            tinputs[fid].push(host.data.inputs[i]);
        }
        for (i = 0; i < n; i++) {
            fid = host.data.inputs[i].rfirstid;
            if (issorted[fid] === undefined) {
                issorted[fid] = true;
                tinputs[fid].sort(function (a, b) {
                    if (a.idate != b.idate) return a.idate - b.idate;
                    return a.id - b.id;
                });
            }
        }
        host.data.inputs = tinputs;
        n = host.data.rlinks.length;
        for (i = 0; i < n; i++) {
            fid = host.data.rlinks[i].rtofirstid;
            if (tlinks[fid] === undefined) tlinks[fid] = [];
            tlinks[fid].push(host.data.rlinks[i]);
        }
        host.data.rlinks = tlinks;
        t = host.checkCLinks(tlinks);
        if (!t.result) {
            core.callbackReturn(host.callbackfunc, false, {
                type: "data",
                code: "circular_reference",
                details: {
                    criteriaid: host.id,
                    rids: t.rids
                },
                message: "circular reference detected"
            });
            return;
        }
        setTimeout(function (host) {
            return function () {
                host.handler();
            }
        } (host), 10);
    }
} (host));

}
} (module, retval, core);
// function: hrprocesses.bsc.core.makeReports
var v143 = function(module, me, core) {
return function (params) {
var host = {
    scorecardids: EncodingClass.string.duplicate(params.ids),
    progressfunc: params.progressfunc,
    callbackfunc: params.callbackfunc,
    data: {},
    links: {},
    progressval: {
        loadScorecard: "pending",
        loadRLinks: "pending",
        loadResults: "pending",
    }
}
host.loadScorecardHandler = core.reports_loadScorecardHandler(host);
host.loadRLinksHandler = core.reports_loadRLinksHandler(host);
host.makeLinks = core.reports_makeLinks(host);
host.genReports = core.reports_genReports(host);
host.getCriteria = core.reports_getCriteria(host);
host.checkCLinks = core.checkCLinks;
host.checkCircularReference = core.reports_checkCircularReference(host);

host.progressval.loadScorecard = "running";
core.exec("loadScorecards", host.scorecardids, function (host) {
    return function (success, content) {
        var i, n;
        if (!success) {
            host.progressval.loadScorecard = "failed";
            host.loadScorecardHandler(false, content);
            return;
        }
        host.progressval.loadScorecard = "succeeded";
        host.loadScorecardHandler(true, content);
    }
} (host));

}
} (module, retval, core);
// function: hrprocesses.bsc.core.rebuildTable
var v148 = function(module, me, core) {
return function (cTable) {
var i, j, n, m, r, t;
n = cTable.content.length;
m = cTable.header.length;
r = [];
for (i = 0; i < n; i++) {
    t = {};
    for (j = 0; j < m; j++) {
        t[cTable.header[j]] = cTable.content[i][j];
    }
    r.push(t);
}
return r;
}
} (module, retval, core);
// function: hrprocesses.bsc.core.rebuildTable_id
var v149 = function(module, me, core) {
return function (cTable) {
var r = {}, x = core.rebuildTable(cTable);
var i, n = x.length;
for (i = 0; i < n; i++) {
    r[x[i].id] = x[i];
}
return r;
}
} (module, retval, core);
// function: hrprocesses.bsc.core.reports_checkCircularReference
var v201 = function(module, me, core) {
return function (host) {
return function () {
    var critids = Object.keys(host.data.criteria);
    var i, t;
    for (i = 0; i < critids.length; i++) {
        id = critids[i];
        t = host.checkCLinks(host.data.criteria[id].links);
        if (!t.result) {
            return {
                result: false,
                details: {
                    criteriaid: id,
                    rids: t.rids
                }
            }
        }
    }
    return {
        result: true
    }
}
}
} (module, retval, core);
// function: hrprocesses.bsc.core.reports_genKPIReport
var v158 = function(module, me, core) {
return function (host) {
return function () {
    var results = {}, rkeys, ikeys, skeys, scr;
    var i, v, stime, vfunc;
    var tid;

    var getCriteria = function (rid, startdate, expireddate) {
        var i, j;
        var sd, ed, stime;
        var fid;
        var ts, tw, xw;
        var tr = {
            self_result: "pending",
            self_weight: "pending",
            others_result: "pending",
            others_weight: "pending",
            total_result: "pending",
            total_weight: "pending",
            children: []
        };
        var myinputs = host.data.inputs[rid];
        var rlinks = host.data.rlinks;
        var crit = host.data.criteria;
        var sumup_method = crit.sumup_method, share_method = crit.share_method, xmethod;
        var idate, queue = [];
        if (myinputs === undefined) {
            tr.self_result = null;
            tr.self_weight = null;
        }
        else {
            switch (sumup_method) {
                case "accumulate":
                    ts = null;
                    for (i = 0; i < myinputs.length; i++) {
                        idate = myinputs[i].idate;
                        if ((idate >= startdate) && (idate < expireddate)) {
                            if (ts === null) {
                                ts = myinputs[i].result;
                            }
                            else {
                                ts += myinputs[i].result;
                            }
                        }
                    }
                    if (ts !== null) {
                        tr.self_result = ts;
                        tr.self_weight = 0;
                    }
                    else {
                        tr.self_result = null;
                        tr.self_weight = null;
                    }
                    break;
                case "average":
                    ts = tw = 0;
                    for (i = 0; i < myinputs.length; i++) {
                        idate = myinputs[i].idate;
                        if ((idate >= startdate) && (idate < expireddate)) {
                            if (crit.weight_requirement) {
                                xw = myinputs[i].weight;
                            }
                            else {
                                xw = 1;
                            }
                            ts += myinputs[i].result * xw;
                            tw += xw;
                        }
                    }
                    if (tw !== 0) {
                        tr.self_result = ts / tw;
                        tr.self_weight = tw;
                    }
                    else {
                        tr.self_result = null;
                        tr.self_weight = null;
                    }
                    break;
                case "min":
                    ts = null;
                    for (i = 0; i < myinputs.length; i++) {
                        idate = myinputs[i].idate;
                        if ((idate >= startdate) && (idate < expireddate)) {
                            if (ts === null) {
                                ts = myinputs[i].result;
                            }
                            else if (ts > myinputs[i].result) {
                                ts = myinputs[i].result;
                            }
                        }
                    }
                    if (tw !== null) {
                        tr.self_result = ts;
                        tr.self_weight = 0;
                    }
                    else {
                        tr.self_result = null;
                        tr.self_weight = null;
                    }
                    break;
                case "max":
                    ts = null;
                    for (i = 0; i < myinputs.length; i++) {
                        idate = myinputs[i].idate;
                        if ((idate >= startdate) && (idate < expireddate)) {
                            if (ts === null) {
                                ts = myinputs[i].result;
                            }
                            else if (ts < myinputs[i].result) {
                                ts = myinputs[i].result;
                            }
                        }
                    }
                    if (tw !== null) {
                        tr.self_result = ts;
                        tr.self_weight = 0;
                    }
                    else {
                        tr.self_result = null;
                        tr.self_weight = null;
                    }
                    break;
                case "last":
                    ts = null;
                    for (i = 0; i < myinputs.length; i++) {
                        idate = myinputs[i].idate;
                        if (idate >= expireddate) break;
                        ts = myinputs[i].result;
                        tw = idate;
                    }
                    if (tw !== null) {
                        tr.self_result = ts;
                        tr.self_weight = tw;
                    }
                    else {
                        tr.self_result = null;
                        tr.self_weight = null;
                    }
                    break;
            }
        }
        xmethod = share_method;
        if (rlinks[rid] !== undefined) {
            for (i = 0; i < rlinks[rid].length; i++) {
                fid = rlinks[rid][i].rfromfirstid;
                if (startdate > rlinks[rid][i].startdate) {
                    sd = startdate;
                }
                else {
                    sd = rlinks[rid][i].startdate;
                }
                if ((rlinks[rid][i].expireddate == 0) || (expireddate < rlinks[rid][i].expireddate)) {
                    ed = expireddate;
                }
                else {
                    ed = rlinks[rid][i].expireddate;
                }
                if (sd >= ed) continue;
                stime = sd + "_" + ed;
                if (results[stime] === undefined) results[stime] = {};
                if (results[stime][fid] === undefined) results[stime][fid] = getCriteria(fid, startdate, expireddate);
                queue.push({
                    stime: stime,
                    fid: fid
                });
                if (rlinks[rid][i].method != "default") xmethod = rlinks[rid][i].method;
            }
            tr.children = queue;
            switch (xmethod) {
                case "accumulate":
                    ts = null;
                    for (i = 0; i < queue.length; i++) {
                        if (results[queue[i].stime][queue[i].fid].total_result === null) continue;
                        if (ts === null) {
                            ts = results[queue[i].stime][queue[i].fid].total_result;
                        }
                        else {
                            ts += results[queue[i].stime][queue[i].fid].total_result;
                        }
                    }
                    if (ts !== null) {
                        tr.others_result = ts;
                        tr.others_weight = 0;
                    }
                    else {
                        tr.others_result = null;
                        tr.others_weight = null;
                    }
                    if (tr.others_result === null) {
                        tr.total_result = tr.self_result;
                        tr.total_weight = tr.self_weight;
                    }
                    else if (tr.self_result === null) {
                        tr.total_result = tr.others_result;
                        tr.total_weight = tr.others_weight;
                    }
                    else {
                        tr.total_result = tr.self_result + tr.others_result;
                        tr.total_weight = 0;
                    }
                    break;
                case "average":
                    ts = tw = 0;
                    for (i = 0; i < queue.length; i++) {
                        if (results[queue[i].stime][queue[i].fid].total_result === null) continue;
                        if (crit.weight_requirement) {
                            xw = results[queue[i].stime][queue[i].fid].total_weight;
                        }
                        else {
                            xw = 1;
                        }
                        ts += results[queue[i].stime][queue[i].fid].total_result * xw;
                        tw += xw;
                    }
                    if (tw !== 0) {
                        tr.others_result = ts / tw;
                        tr.others_weight = tw;
                    }
                    else {
                        tr.others_result = null;
                        tr.others_weight = null;
                    }
                    if (tr.others_result === null) {
                        tr.total_result = tr.self_result;
                        tr.total_weight = tr.self_weight;
                    }
                    else if (tr.self_result === null) {
                        tr.total_result = tr.others_result;
                        tr.total_weight = tr.others_weight;
                    }
                    else {
                        t = tr.self_weight + tw;
                        if (t != 0) {
                            tr.total_result = (tr.self_result * tr.self_weight + ts) / t;
                            tr.total_weight = t;
                        }
                        else {
                            tr.total_result = null;
                            tr.total_weight = null;
                        }
                    }
                    break;
                case "min":
                    ts = null;
                    for (i = 0; i < queue.length; i++) {
                        if (results[queue[i].stime][queue[i].fid].total_result === null) continue;
                        if (ts === null) {
                            ts = results[queue[i].stime][queue[i].fid].total_result;
                        }
                        else if (ts > results[queue[i].stime][queue[i].fid].total_result) {
                            ts = results[queue[i].stime][queue[i].fid].total_result;
                        }
                    }
                    if (ts !== null) {
                        tr.others_result = ts;
                        tr.others_weight = 0;
                    }
                    else {
                        tr.others_result = null;
                        tr.others_weight = null;
                    }
                    if (ts === null) {
                        tr.total_result = tr.self_result;
                        tr.total_weight = tr.self_weight;
                    }
                    else if (tr.self_result === null) {
                        tr.total_result = tr.others_result;
                        tr.total_weight = tr.others_weight;
                    }
                    else if (tr.self_result < ts) {
                        tr.total_result = tr.self_result;
                        tr.total_weight = 0;
                    }
                    else {
                        tr.total_result = tr.others_result;
                        tr.total_weight = 0;
                    }
                    break;
                case "max":
                    ts = null;
                    for (i = 0; i < queue.length; i++) {
                        if (results[queue[i].stime][queue[i].fid].total_result === null) continue;
                        if (ts === null) {
                            ts = results[queue[i].stime][queue[i].fid].total_result;
                        }
                        else if (ts < results[queue[i].stime][queue[i].fid].total_result) {
                            ts = results[queue[i].stime][queue[i].fid].total_result;
                        }
                    }
                    if (ts !== null) {
                        tr.others_result = ts;
                        tr.others_weight = 0;
                    }
                    else {
                        tr.others_result = null;
                        tr.others_weight = null;
                    }
                    if (ts === null) {
                        tr.total_result = tr.self_result;
                        tr.total_weight = tr.self_weight;
                    }
                    else if (tr.self_result === null) {
                        tr.total_result = tr.others_result;
                        tr.total_weight = tr.others_weight;
                    }
                    else if (tr.self_result > ts) {
                        tr.total_result = tr.self_result;
                        tr.total_weight = 0;
                    }
                    else {
                        tr.total_result = tr.others_result;
                        tr.total_weight = 0;
                    }
                    break;
                case "last":
                    ts = tw = null;
                    for (i = 0; i < queue.length; i++) {
                        if (results[queue[i].stime][queue[i].fid].total_result === null) continue;
                        idate = results[queue[i].stime][queue[i].fid].total_weight;
                        if (idate >= expireddate) continue;
                        if (ts === null) {
                            ts = results[queue[i].stime][queue[i].fid].total_result
                            tw = results[queue[i].stime][queue[i].fid].total_weight;
                        }
                        else if (tw < results[queue[i].stime][queue[i].fid].total_weight) {
                            ts = results[queue[i].stime][queue[i].fid].total_result
                            tw = results[queue[i].stime][queue[i].fid].total_weight;
                        }
                    }
                    if (tw !== null) {
                        tr.others_result = ts;
                        tr.others_weight = tw;
                    }
                    else {
                        tr.others_result = null;
                        tr.others_weight = null;
                    }
                    if (ts === null) {
                        tr.total_result = tr.self_result;
                        tr.total_weight = tr.self_weight;
                    }
                    else if (tr.self_result === null) {
                        tr.total_result = tr.others_result;
                        tr.total_weight = tr.others_weight;
                    }
                    else if (tr.self_weight > tw) {
                        tr.total_result = tr.self_result;
                        tr.total_weight = tr.self_weight;
                    }
                    else {
                        tr.total_result = tr.others_result;
                        tr.total_weight = tr.others_weight;
                    }
                    break;
            }
        }
        else {
            tr.others_result = null;
            tr.others_weight = null;
            tr.total_result = tr.self_result;
            tr.total_weight = tr.self_weight;
        }
        return tr;
    }

    rkeys = Object.keys(host.data.rlinks);
    stime = host.startdate + "_" + host.expireddate;
    if (results[stime] === undefined) results[stime] = {};
    for (i = 0; i < rkeys.length; i++) {
        tid = parseInt(rkeys[i]);
        if (results[stime][tid] === undefined) results[stime][tid] = getCriteria(tid, host.startdate, host.expireddate);
    }
    ikeys = Object.keys(host.data.inputs);
    for (i = 0; i < ikeys.length; i++) {
        tid = parseInt(ikeys[i]);
        if (results[stime][tid] === undefined) results[stime][tid] = getCriteria(tid, host.startdate, host.expireddate);
    }
    host.results = results;
    skeys = Object.keys(host.data.scorecards);
    scr = {};
    for (i = 0; i < skeys.length; i++) {
        tid = parseInt(skeys[i]);
        if (results[stime][host.data.scorecards[tid].rfirstid] === undefined) {
            v = null;
        }
        else {
            v = results[stime][host.data.scorecards[tid].rfirstid].total_result;
        }
        if (v === null) {
            host.data.scorecards[tid].score = null;
            host.data.scorecards[tid].result = null;
        }
        else {
            vfunc = function (data) {
                return function (varname) {
                    switch (varname) {
                        case "h":
                            return data.max;
                        case "l":
                            return data.min;
                        case "g":
                            return data.goal;
                        case "v":
                            return data.achievement;
                        default:
                            return NaN;
                    }
                }
            } ({
                goal: host.data.scorecards[tid].goal,
                min: host.data.scorecards[tid].min,
                max: host.data.scorecards[tid].max,
                achievement: v
            });

            host.data.scorecards[tid].result = v;
            host.data.scorecards[tid].score = host.data.formula.func(vfunc);
        }
        if (scr[host.data.scorecards[tid].rfirstid] === undefined) scr[host.data.scorecards[tid].rfirstid] = [];
        scr[host.data.scorecards[tid].rfirstid].push(host.data.scorecards[tid]);
    }
    core.callbackReturn(host.callbackfunc, true, {
        info: {
            type: "kpi",
            criteriaid: host.id,
            startdate: host.startdate,
            expireddate: host.expireddate,
            formatver: 1
        },
        criteria: host.data.criteria,
        formula: {
            id: host.data.formula.id,
            name: host.data.formula.name,
            content: host.data.formula.content
        },
        inputs: host.data.inputs,
        rlinks: host.data.rlinks,
        scorecards: scr,
        result: results
    });
}
}
} (module, retval, core);
// function: hrprocesses.bsc.core.reports_genReports
var v152 = function(module, me, core) {
return function (host) {
return function () {
    var local;
    local = {
        n: host.scorecardids.length,
        i: -1,
        depth: 0
    };
    local.finalizeReport = function (host, local) {
        return function (scid) {
            var i, j, k, t, tv, tw, pid, rid, cid, fid, rindex;
            var func, vfunc;
            var keys;
            rid = local.rid;
            for (i = 0; i < local.exportdata.results.length; i++) {
                if (local.exportdata.results[i].results[local.stime][rid].total_result === null) {
                    local.exportdata.results[i].score = null;
                }
                else {
                    cid = local.exportdata.results[i].criteriaid;
                    fid = host.data.criteria[cid].formulaid;
                    func = host.data.formulas[fid].func;
                    t = local.exportdata.results[i].results[local.stime][rid].total_result;
                    /*
                    if ((host.data.criteria[cid].value_name.length != 0) && (host.data.criteria[cid].weight_name.length != 0) && (host.data.criteria[cid].sumup_method == "average")) {
                        t = local.exportdata.results[i].results[rid].total_result * local.exportdata.results[i].results[rid].total_weight;
                    }
                    else {
                        t = local.exportdata.results[i].results[rid].total_result;
                    }
                    */
                    vfunc = function (data) {
                        return function (varname) {
                            switch (varname) {
                                case "h":
                                    return data.max;
                                case "l":
                                    return data.min;
                                case "g":
                                    return data.goal;
                                case "v":
                                    return data.achievement;
                                default:
                                    return NaN;
                            }
                        }
                    } ({
                        goal: local.exportdata.results[i].goal,
                        min: local.exportdata.results[i].min,
                        max: local.exportdata.results[i].max,
                        achievement: t
                    });
                    local.exportdata.results[i].score = func(vfunc);
                }
            }
            keys = Object.keys(local.exportdata.strategies);
            for (i = 0; i < keys.length; i++) {
                tv = tw = 0;
                for (j = 0; j < local.exportdata.strategies[keys[i]].content.length; j++) {
                    rindex = local.exportdata.strategies[keys[i]].content[j];
                    if (local.exportdata.results[rindex].score === null) continue;
                    tv += local.exportdata.results[rindex].score * local.exportdata.results[rindex].weight;
                    tw += local.exportdata.results[rindex].weight;
                }
                if (tw == 0) {
                    local.exportdata.strategies[keys[i]].score = null;
                }
                else {
                    local.exportdata.strategies[keys[i]].score = tv / tw;
                }
            }
            keys = Object.keys(local.exportdata.perspectives);
            for (i = 0; i < keys.length; i++) {
                tv = tw = 0;
                for (j = 0; j < local.exportdata.perspectives[keys[i]].content.length; j++) {
                    sid = local.exportdata.perspectives[keys[i]].content[j];
                    if (local.exportdata.strategies[sid].score === null) continue;
                    tv += local.exportdata.strategies[sid].score * local.exportdata.strategies[sid].weight;
                    tw += local.exportdata.strategies[sid].weight;
                }
                if (tw == 0) {
                    local.exportdata.perspectives[keys[i]].score = null;
                }
                else {
                    local.exportdata.perspectives[keys[i]].score = tv / tw;
                }
            }
            for (i = 0; i < host.links.scorecards[scid].sections.length; i++) {
                tv = tw = 0;
                keys = host.links.scorecards[scid].sections[i].perspectives.keys;
                for (j = 0; j < keys.length; j++) {
                    pid = keys[j];
                    if (local.exportdata.perspectives[pid].score === null) continue;

                    tv += local.exportdata.perspectives[pid].score * local.exportdata.perspectives[pid].weight;
                    tw += local.exportdata.perspectives[pid].weight;
                }
                if (tw == 0) {
                    local.exportdata.sections[i].score = null;
                }
                else {
                    local.exportdata.sections[i].score = tv / tw;
                }
                local.exportdata.sections[i].perspectives = keys;
            }
            tv = {};
            for (i = 0; i < local.exportdata.sections.length; i++) {
                tw = local.exportdata.sections[i].code.toLowerCase();
                if (local.exportdata.sections[i].score === null) {
                    tv[tw] = NaN;
                }
                else {
                    tv[tw] = local.exportdata.sections[i].score;
                }
            }
            local.exportdata.info.sectionFormula = tw = host.data.scorecards[scid].template.formula;
            while (tw.length > 0) {
                if (tw.substr(0, 1) == "=") {
                    tw = tw.substr(1);
                }
                else {
                    break;
                }
            }
            func = host.data.parser.parse(tw).calc;
            vfunc = function (tv) {
                return function (varname) {
                    var t = varname.toLowerCase();
                    if (tv[t] === undefined) return NaN;
                    return tv[t];
                }
            } (tv);
            local.exportdata.info.score = func(vfunc);
        }
    } (host, local)
    local.wprocess = function (host, local) {
        return function () {
            var fid;
            while (true) {
                switch (local.depth) {
                    case 0:
                        local.i++;
                        if (local.i >= local.n) {
                            try {
                                host.progressfunc(false, null);
                            }
                            catch (e) {
                                console.error(e);
                            }
                            return;
                        }
                        local.scid = host.scorecardids[local.i];
                        local.startdate = host.data.scorecards[local.scid].startdate;
                        local.expireddate = host.data.scorecards[local.scid].expireddate;
                        local.sc = host.links.scorecards[local.scid];
                        if (local.sc === undefined) {
                            host.progressfunc(true, {
                                info: {
                                    type: "scorecard",
                                    id: local.scid,
                                    rid: host.data.scorecards[local.scid].rid,
                                    rfirstid: host.data.scorecards[local.scid].rfirstid,
                                    startdate: local.startdate,
                                    expireddate: local.expireddate,
                                    formatver: 2,
                                    score: null
                                },
                                sections: [],
                                perspectives: {},
                                strategies: {},
                                criteria: {},
                                formulas: {},
                                results: []
                            });
                            break;
                        }
                        local.rid = host.data.scorecards[local.scid].rfirstid;
                        local.sc.rfirstid = local.rid;
                        local.sc.rid = host.data.scorecards[local.scid].rid;
                        local.sc.startdate = local.startdate;
                        local.sc.expireddate = local.expireddate;
                        local.stime = local.startdate + "_" + local.expireddate;
                        if (local.sc.perspectives === undefined) {
                            host.progressfunc(true, {
                                info: {
                                    type: "scorecard",
                                    id: local.scid,
                                    rid: host.data.scorecards[local.scid].rid,
                                    rfirstid: host.data.scorecards[local.scid].rfirstid,
                                    startdate: local.startdate,
                                    expireddate: local.expireddate,
                                    formatver: 2,
                                    score: null
                                },
                                sections: [],
                                perspectives: {},
                                strategies: {},
                                criteria: {},
                                formulas: {},
                                results: []
                            });
                            break;
                        }
                        if (local.sc.perspectives.keys === undefined) {
                            host.progressfunc(true, {
                                info: {
                                    type: "scorecard",
                                    id: local.scid,
                                    rid: host.data.scorecards[local.scid].rid,
                                    rfirstid: host.data.scorecards[local.scid].rfirstid,
                                    startdate: local.startdate,
                                    expireddate: local.expireddate,
                                    formatver: 2,
                                    score: null
                                },
                                sections: [],
                                perspectives: {},
                                strategies: {},
                                criteria: {},
                                formulas: {},
                                results: []
                            });
                            break;
                        }
                        local.m = local.sc.perspectives.keys.length;
                        local.exportdata = {
                            info: {
                                type: "scorecard",
                                id: local.scid,
                                rid: host.data.scorecards[local.scid].rid,
                                rfirstid: host.data.scorecards[local.scid].rfirstid,
                                startdate: local.startdate,
                                expireddate: local.expireddate,
                                formatver: 2
                            },
                            sections: EncodingClass.string.duplicate(host.data.scorecards[local.scid].template.details),
                            perspectives: {},
                            strategies: {},
                            criteria: {},
                            formulas: {},
                            results: []
                        };
                        local.depth++;
                        local.j = -1;
                    case 1:
                        local.j++;
                        if (local.j >= local.m) {
                            local.depth--;
                            setTimeout(function (host, local) {
                                try {
                                    local.finalizeReport(local.scid);
                                    host.progressfunc(true, local.exportdata);
                                    local.wprocess();
                                }
                                catch (e) {
                                    console.error(e);
                                }
                            } (host, local), 10);
                            return;
                        }
                        local.pid = local.sc.perspectives.keys[local.j];
                        local.pers = local.sc.perspectives[local.pid];
                        if (local.pers === undefined) break;
                        local.exportdata.perspectives[local.pid] = {
                            id: host.data.perspectives[local.pid].id,
                            name: host.data.perspectives[local.pid].name,
                            content: [],
                            weight: local.pers.weight
                        };
                        if (local.pers.strategies === undefined) break;
                        if (local.pers.strategies.keys === undefined) break;
                        local.o = local.pers.strategies.keys.length;

                        local.depth++;
                        local.k = -1;
                    case 2:
                        local.k++;
                        if (local.k >= local.o) {
                            local.depth--;
                            break;
                        }
                        local.sid = local.pers.strategies.keys[local.k];
                        local.stra = local.pers.strategies[local.sid];
                        if (local.stra === undefined) break;
                        local.exportdata.perspectives[local.pid].content.push(local.sid);
                        local.exportdata.strategies[local.sid] = {
                            id: host.data.strategies[local.sid].id,
                            name: host.data.strategies[local.sid].name,
                            parentid: host.data.strategies[local.sid].parentid,
                            perspectiveid: host.data.strategies[local.sid].perspectiveid,
                            weight: host.data.strategies[local.sid].weight,
                            content: []
                        };
                        if (local.stra.criteria === undefined) break;
                        if (local.stra.criteria.keys === undefined) break;
                        local.p = local.stra.criteria.keys.length;

                        local.depth++;
                        local.l = -1;
                    case 3:
                        local.l++;
                        if (local.l >= local.p) {
                            local.depth--;
                            break;
                        }
                        local.cid = local.stra.criteria.keys[local.l];
                        local.crit = local.stra.criteria[local.cid].info;
                        fid = host.data.criteria[local.cid].formulaid;
                        local.exportdata.criteria[local.cid] = {
                            id: host.data.criteria[local.cid].id,
                            name: host.data.criteria[local.cid].name,
                            decpre: host.data.criteria[local.cid].decpre,
                            average_unit_as_percentage: host.data.criteria[local.cid].average_unit_as_percentage,
                            formulaid: fid,
                            share_method: host.data.criteria[local.cid].share_method,
                            sumup_method: host.data.criteria[local.cid].sumup_method,
                            unit: host.data.criteria[local.cid].unit,
                            value_name: host.data.criteria[local.cid].value_name,
                            weight_name: host.data.criteria[local.cid].weight_name,
                            weight_requirement: host.data.criteria[local.cid].weight_requirement
                        };
                        if (host.data.formulas[fid] !== undefined) {
                            local.exportdata.formulas[fid] = {
                                id: fid,
                                name: host.data.formulas[fid].name,
                                content: host.data.formulas[fid].content
                            };
                        }
                        else {
                            console.error("Formula not found!");
                            local.depth = 0;
                            break;
                        }
                        if (local.crit.results === undefined) local.crit.results = {};
                        if (local.crit.results[local.stime] === undefined) local.crit.results[local.stime] = {};
                        if (local.crit.results[local.stime][local.rid] === undefined) {
                            host.getCriteria(local.cid, local.rid, local.startdate, local.expireddate);
                        }
                        local.exportdata.strategies[local.sid].content.push(local.exportdata.results.length);
                        local.exportdata.results.push({
                            strategyid: local.sid,
                            criteriaid: local.cid,
                            goal: local.stra.criteria[local.cid].goal,
                            min: local.stra.criteria[local.cid].min,
                            max: local.stra.criteria[local.cid].max,
                            weight: local.stra.criteria[local.cid].weight,
                            results: local.crit.results,
                            inputs: local.stra.criteria[local.cid].info.inputs
                        });
                        local.exportdata.criteria[local.cid].links = local.stra.criteria[local.cid].info.links;
                }
            }
        }
    } (host, local);
    local.wprocess();
}
}
} (module, retval, core);
// function: hrprocesses.bsc.core.reports_getCriteria
var v153 = function(module, me, core) {
return function (host) {
return function (cid, rid, startdate, expireddate) {
    var i, n, t;
    var fid;
    var crit = host.data.criteria[cid];
    var stime = startdate + "_" + expireddate, sd, ed, ttime;
    var sumup_method = crit.sumup_method, share_method = crit.share_method;
    var xmethod, idate, cmark = {};
    var ts, tw, xw;
    var tr = {
        self_result: "pending",
        self_weight: "pending",
        others_result: "pending",
        others_weight: "pending",
        total_result: "pending",
        total_weight: "pending",
        children: []
    };
    if (crit.results[stime] === undefined) crit.results[stime] = {};
    crit.results[stime][rid] = tr;
    if (crit.inputs === undefined) crit.inputs = [];
    switch (sumup_method) {
        case "accumulate":
            if (crit.inputs[rid] !== undefined) {
                n = crit.inputs[rid].length;
                ts = 0;
                for (i = 0; i < n; i++) {
                    idate = crit.inputs[rid][i].idate;
                    if ((startdate <= idate) && (idate < expireddate)) ts += crit.inputs[rid][i].result;
                }
                tr.self_result = ts;
                tr.self_weight = 0;
            }
            else {
                tr.self_result = null;
                tr.self_weight = null;
            }
            break;
        case "average":
            if (crit.inputs[rid] !== undefined) {
                n = crit.inputs[rid].length;
                ts = 0;
                tw = 0;
                for (i = 0; i < n; i++) {
                    idate = crit.inputs[rid][i].idate;
                    if ((startdate <= idate) && (idate < expireddate)) {
                        if (crit.weight_requirement) {
                            xw = crit.inputs[rid][i].weight;
                        }
                        else {
                            xw = 1;
                        }
                        ts += crit.inputs[rid][i].result * xw;
                        tw += xw;
                    }
                }
                if (tw !== 0) {
                    tr.self_result = ts / tw;
                    tr.self_weight = tw;
                }
                else {
                    tr.self_result = null;
                    tr.self_weight = null;
                }
            }
            else {
                tr.self_result = null;
                tr.self_weight = null;
            }
            break;
        case "min":
            if (crit.inputs[rid] !== undefined) {
                n = crit.inputs[rid].length;
                ts = null;
                for (i = 0; i < n; i++) {
                    idate = crit.inputs[rid][i].idate;
                    if ((startdate <= idate) && (idate < expireddate)) {
                        if (ts === null) {
                            ts = crit.inputs[rid][i].result;
                        }
                        else if (ts > crit.inputs[rid][i].result) {
                            ts = crit.inputs[rid][i].result;
                        }
                    }
                }
                tr.self_result = ts;
                tr.self_weight = 0;
            }
            else {
                tr.self_result = null;
                tr.self_weight = null;
            }
            break;
        case "max":
            if (crit.inputs[rid] !== undefined) {
                n = crit.inputs[rid].length;
                ts = null;
                for (i = 0; i < n; i++) {
                    idate = crit.inputs[rid][i].idate;
                    if ((startdate <= idate) && (idate < expireddate)) {
                        if (ts === null) {
                            ts = crit.inputs[rid][i].result;
                        }
                        else if (ts < crit.inputs[rid][i].result) {
                            ts = crit.inputs[rid][i].result;
                        }
                    }
                }
                tr.self_result = ts;
                tr.self_weight = 0;
            }
            else {
                tr.self_result = null;
                tr.self_weight = null;
            }
            break;
        case "last":
            if (crit.inputs[rid] !== undefined) {
                n = crit.inputs[rid].length;
                ts = 0;
                tw = 0;
                for (i = 0; i < n; i++) {
                    idate = crit.inputs[rid][i].idate;
                    if (idate >= expireddate) break;
                    ts = crit.inputs[rid][i].result;
                    tw = idate;
                }
                tr.self_result = ts;
                tr.self_weight = tw;
            }
            else {
                tr.self_result = null;
                tr.self_weight = null;
            }
            break;
        default:
            console.error("unknown method!");
    }
    if (crit.links === undefined) {
        n = 0;
    }
    else {
        if (crit.links[rid] === undefined) {
            n = 0;
        }
        else {
            n = crit.links[rid].length;
        }
    }
    xmethod = share_method;
    for (i = 0; i < n; i++) {
        fid = crit.links[rid][i].rfromfirstid;
        if (startdate > crit.links[rid][i].startdate) {
            sd = startdate;
        }
        else {
            sd = crit.links[rid][i].startdate;
        }
        if ((crit.links[rid][i].expireddate == 0) || (expireddate < crit.links[rid][i].expireddate)) {
            ed = expireddate;
        }
        else {
            ed = crit.links[rid][i].expireddate;
        }
        if (sd >= ed) continue;
        ttime = sd + "_" + ed;
        if (crit.results[ttime] === undefined) crit.results[ttime] = {};
        if (crit.results[ttime][fid] === undefined) {
            host.getCriteria(cid, fid, sd, ed);
        }
        if (crit.links[rid][i].method != "default") {
            xmethod = crit.links[rid][i].method;
        }
    }
    switch (xmethod) {
        case "accumulate":
            ts = null;
            for (i = 0; i < n; i++) {
                fid = crit.links[rid][i].rfromfirstid;
                if (startdate > crit.links[rid][i].startdate) {
                    sd = startdate;
                }
                else {
                    sd = crit.links[rid][i].startdate;
                }
                if ((crit.links[rid][i].expireddate == 0) || (expireddate < crit.links[rid][i].expireddate)) {
                    ed = expireddate;
                }
                else {
                    ed = crit.links[rid][i].expireddate;
                }
                if (sd >= ed) continue;
                ttime = sd + "_" + ed;
                //if (cmark[fid] === undefined) {
                    //cmark[fid] = true;
                    //tr.children.push(fid);
                //}
                tr.children.push({
                    stime: ttime,
                    fid: fid
                });
                if (crit.results[ttime][fid].total_result === null) continue;
                if (crit.results[ttime][fid].total_result === "pending") continue;
                if (ts === null) {
                    ts = crit.results[ttime][fid].total_result;
                }
                else {
                    ts += crit.results[ttime][fid].total_result;
                }
            }
            tr.others_result = ts;
            if (ts === null) {
                tr.others_weight = null;
            }
            else {
                tr.others_weight = 0;
            }
            if (ts === null) {
                tr.total_result = tr.self_result;
                tr.total_weight = tr.self_weight;
            }
            else if (tr.self_result === null) {
                tr.total_result = tr.others_result;
                tr.total_weight = tr.others_weight;
            }
            else {
                tr.total_result = tr.self_result + tr.others_result;
                tr.total_weight = 0;
            }
            break;
        case "average":
            ts = null;
            tw = null;
            for (i = 0; i < n; i++) {
                fid = crit.links[rid][i].rfromfirstid;
                if (startdate > crit.links[rid][i].startdate) {
                    sd = startdate;
                }
                else {
                    sd = crit.links[rid][i].startdate;
                }
                if ((crit.links[rid][i].expireddate == 0) || (expireddate < crit.links[rid][i].expireddate)) {
                    ed = expireddate;
                }
                else {
                    ed = crit.links[rid][i].expireddate;
                }
                if (sd >= ed) continue;
                ttime = sd + "_" + ed;
                tr.children.push({
                    stime: ttime,
                    fid: fid
                });
                // if (cmark[fid] === undefined) {
                //     cmark[fid] = true;
                //     tr.children.push(fid);
                // }
                if (crit.results[ttime][fid].total_result === null) continue;
                if (crit.results[ttime][fid].total_result === "pending") continue;
                if (crit.weight_requirement) {
                    xw = crit.results[ttime][fid].total_weight;
                }
                else {
                    xw = 1;
                }
                if (ts === null) {
                    ts = crit.results[ttime][fid].total_result * xw;
                    tw = xw;
                }
                else {
                    ts += crit.results[ttime][fid].total_result * xw;
                    tw += xw;
                }
            }
            if ((tw !== null) && (tw != 0)) {
                tr.others_result = ts / tw;
                tr.others_weight = tw;
            }
            else {
                tr.others_result = null;
                tr.others_weight = null;
            }
            if (tr.others_result === null) {
                tr.total_result = tr.self_result;
                tr.total_weight = tr.self_weight;
            }
            else if (tr.self_result === null) {
                tr.total_result = tr.others_result;
                tr.total_weight = tr.others_weight;
            }
            else {
                t = tr.self_weight + tw;
                if (t != 0) {
                    tr.total_result = (tr.self_result * tr.self_weight + ts) / t;
                    tr.total_weight = t;
                }
                else {
                    tr.total_result = null;
                    tr.total_weight = null;
                }
            }
            break;
        case "min":
            ts = null;
            for (i = 0; i < n; i++) {
                fid = crit.links[rid][i].rfromfirstid;
                if (startdate > crit.links[rid][i].startdate) {
                    sd = startdate;
                }
                else {
                    sd = crit.links[rid][i].startdate;
                }
                if ((crit.links[rid][i].expireddate == 0) || (expireddate < crit.links[rid][i].expireddate)) {
                    ed = expireddate;
                }
                else {
                    ed = crit.links[rid][i].expireddate;
                }
                if (sd >= ed) continue;
                ttime = sd + "_" + ed;
                tr.children.push({
                    stime: ttime,
                    fid: fid
                });
                // if (cmark[fid] === undefined) {
                //     cmark[fid] = true;
                //     tr.children.push(fid);
                // }
                if (crit.results[ttime][fid].total_result === null) continue;
                if (crit.results[ttime][fid].total_result === "pending") continue;
                if (ts === null) {
                    ts = crit.results[ttime][fid].total_result;
                }
                else if (ts > crit.results[ttime][fid].total_result) {
                    ts = crit.results[ttime][fid].total_result;
                }
            }
            tr.others_result = ts;
            if (ts === null) {
                tr.others_weight = null;
            }
            else {
                tr.others_weight = 0;
            }
            if (ts === null) {
                tr.total_result = tr.self_result;
                tr.total_weight = tr.self_weight;
            }
            else if (tr.self_result === null) {
                tr.total_result = tr.others_result;
                tr.total_weight = tr.others_weight;
            }
            else if (tr.self_result < ts) {
                tr.total_result = tr.self_result;
                tr.total_weight = 0;
            }
            else {
                tr.total_result = tr.others_result;
                tr.total_weight = 0;
            }
            break;
        case "max":
            ts = null;
            for (i = 0; i < n; i++) {
                fid = crit.links[rid][i].rfromfirstid;
                if (startdate > crit.links[rid][i].startdate) {
                    sd = startdate;
                }
                else {
                    sd = crit.links[rid][i].startdate;
                }
                if ((crit.links[rid][i].expireddate == 0) || (expireddate < crit.links[rid][i].expireddate)) {
                    ed = expireddate;
                }
                else {
                    ed = crit.links[rid][i].expireddate;
                }
                if (sd >= ed) continue;
                ttime = sd + "_" + ed;
                tr.children.push({
                    stime: ttime,
                    fid: fid
                });
                // if (cmark[fid] === undefined) {
                //     cmark[fid] = true;
                //     tr.children.push(fid);
                // }
                if (crit.results[ttime][fid].total_result === null) continue;
                if (crit.results[ttime][fid].total_result === "pending") continue;
                if (ts === null) {
                    ts = crit.results[ttime][fid].total_result;
                }
                else if (ts < crit.results[ttime][fid].total_result) {
                    ts = crit.results[ttime][fid].total_result;
                }
            }
            tr.others_result = ts;
            if (ts === null) {
                tr.others_weight = null;
            }
            else {
                tr.others_weight = 0;
            }
            if (ts === null) {
                tr.total_result = tr.self_result;
                tr.total_weight = tr.self_weight;
            }
            else if (tr.self_result === null) {
                tr.total_result = tr.others_result;
                tr.total_weight = tr.others_weight;
            }
            else if (tr.self_result > ts) {
                tr.total_result = tr.self_result;
                tr.total_weight = 0;
            }
            else {
                tr.total_result = tr.others_result;
                tr.total_weight = 0;
            }
            break;
        case "last":
            ts = null;
            tw = null;
            for (i = 0; i < n; i++) {
                fid = crit.links[rid][i].rfromfirstid;
                if (startdate > crit.links[rid][i].startdate) {
                    sd = startdate;
                }
                else {
                    sd = crit.links[rid][i].startdate;
                }
                if ((crit.links[rid][i].expireddate == 0) || (expireddate < crit.links[rid][i].expireddate)) {
                    ed = expireddate;
                }
                else {
                    ed = crit.links[rid][i].expireddate;
                }
                if (sd >= ed) continue;
                ttime = sd + "_" + ed;
                tr.children.push({
                    stime: ttime,
                    fid: fid
                });
                // if (cmark[fid] === undefined) {
                //     cmark[fid] = true;
                //     tr.children.push(fid);
                // }
                if (crit.results[ttime][fid].total_result === null) continue;
                if (crit.results[ttime][fid].total_result === "pending") continue;
                if (ts === null) {
                    ts = crit.results[ttime][fid].total_result;
                    tw = crit.results[ttime][fid].total_weight;
                }
                else if (tw < crit.results[ttime][fid].total_weight) {
                    ts = crit.results[ttime][fid].total_result;
                    tw = crit.results[ttime][fid].total_weight;
                }
            }
            tr.others_result = ts;
            tr.others_weight = tw;
            if (ts === null) {
                tr.total_result = tr.self_result;
                tr.total_weight = tr.self_weight;
            }
            else if (tr.self_result === null) {
                tr.total_result = tr.others_result;
                tr.total_weight = tr.others_weight;
            }
            else if (tr.self_weight > tw) {
                tr.total_result = tr.self_result;
                tr.total_weight = tr.self_weight;
            }
            else {
                tr.total_result = tr.others_result;
                tr.total_weight = tr.others_weight;
            }
            break;
    }
}
}
} (module, retval, core);
// function: hrprocesses.bsc.core.reports_loadRLinksHandler
var v150 = function(module, me, core) {
return function (host) {
return function (success, content) {
    var r;
    if (!success) {
        core.callbackReturn(host.callbackfunc, false, content);
        return;
    }
    host.data.inputs = core.rebuildTable(content.inputs);
    host.data.rlinks = core.rebuildTable(content.rlinks);
    host.makeLinks();
    r = host.checkCircularReference();
    if (!r.result) {
        core.callbackReturn(host.callbackfunc, false, {type: "data", code: "circular_reference", details: r.details, message: "circular reference detected"});
        return;
    };
    host.genReports();
    console.log(host);
}
}
} (module, retval, core);
// function: hrprocesses.bsc.core.reports_loadScorecardHandler
var v144 = function(module, me, core) {
return function (host) {
return function (success, content) {
    if (!success) {
        core.callbackReturn(host.callbackfunc, false, content);
        return;
    }
    var xstartdate = 1000000000;
    var xenddate = 0;
    var i, j, n, m, t, h, w, clist;
    host.data.scorecards = core.rebuildTable_id(content.scorecards);
    host.data.perspectives = core.rebuildTable_id(content.perspectives);
    host.data.strategies = core.rebuildTable_id(content.strategies);
    host.data.criteria = core.rebuildTable_id(content.criteria);
    host.data.formulas = core.rebuildTable_id(content.formulas);
    t = contentModule.getBscFormulasSystem();
    for (i = 0; i < t.length; i++) {
        host.data.formulas[t[i].id] = {
            id: t[i].id,
            name: t[i].name,
            content: t[i].content
        };
    }
    var mbuilder = contentModule.getJsMathNewSampleGeneral();
    host.data.parser = mbuilder = mbuilder.build();
    host.data.scorecard_perspective_links = core.rebuildTable(content.plinks);
    host.data.strategy_criteria_links = core.rebuildTable(content.clinks);
    t = Object.keys(host.data.formulas);
    for (i = 0; i < t.length; i++) {
        h = EncodingClass.base64.decode(host.data.formulas[t[i]].content).split("\n");
        m = (h.length - 1) / 2;
        w = [];
        for (j = 0; j < m; j++) {
            w.push({
                cond: h[j * 2],
                result: h[j * 2 + 1]
            });
        }
        host.data.formulas[t[i]].content = w;
        h = "na";
        for (j = w.length-1; j >= 0; j--) {
            h = "if (" + w[j].cond + "," + w[j].result + "," + h + ")";
        }
        host.data.formulas[t[i]].parsedData = mbuilder.parse(h);
        host.data.formulas[t[i]].func = host.data.formulas[t[i]].parsedData.calc;
    }
    t = core.rebuildTable(content.scorecards);
    for (i = 0; i < t.length; i++) {
        if (xstartdate > t[i].startdate) xstartdate = t[i].startdate;
        if (xenddate < t[i].expireddate) xenddate = t[i].expireddate;
    }
    host.progressval.loadRLinks = "running";
    clist = [];
    t = core.rebuildTable(content.criteria);
    for (i = 0; i < t.length; i++) {
        clist.push(t[i].id);
    }
    core.exec("loadRLinks",
        {
            startdate: xstartdate,
            enddate: xenddate,
            clist: clist
        },
        function (host) {
            return function (success, content) {
                var i, n;
                if (!success) {
                    host.progressval.loadRLinks = "failed";
                    host.loadRLinksHandler(false, content);
                    return;
                }
                host.progressval.loadRLinks = "succeeded";
                host.loadRLinksHandler(true, content);
            }
        } (host)
    );
}

}
} (module, retval, core);
// function: hrprocesses.bsc.core.reports_makeLinks
var v151 = function(module, me, core) {
return function (host) {
return function () {
    var i, j, n;
    var keys, xsid, sid, pid, cid, fid, issorted;
    host.links.scorecards = {};
    host.original = {
        criteria: EncodingClass.string.duplicate(host.data.criteria),
        strategies: EncodingClass.string.duplicate(host.data.strategies)
    };
    n = host.data.scorecard_perspective_links.length;
    for (i = 0; i < n; i++) {
        sid = host.data.scorecard_perspective_links[i].scorecardid;
        sid2 = host.data.scorecard_perspective_links[i].sectionindex;
        pid = host.data.scorecard_perspective_links[i].perspectiveid;
        if (host.links.scorecards[sid] === undefined) {
            host.links.scorecards[sid] = {
                sections: host.data.scorecards[sid].template.details
            };
            for (j = 0; j < host.links.scorecards[sid].sections.length; j++) {
                host.links.scorecards[sid].sections[j].perspectives = {
                    keys: []
                };
            }
        };
        if (host.links.scorecards[sid].perspectives === undefined) {
            host.links.scorecards[sid].perspectives = {
                keys: []
            };
        }
        host.links.scorecards[sid].perspectives.keys.push(pid);
        host.links.scorecards[sid].perspectives[pid] = host.data.scorecard_perspective_links[i];
        host.links.scorecards[sid].sections[sid2].perspectives.keys.push(pid);
        host.links.scorecards[sid].sections[sid2].perspectives[pid] = host.data.scorecard_perspective_links[i];
    }
    keys = Object.keys(host.data.strategies);
    n = keys.length;
    for (i = 0; i < n; i++) {
        sid = parseInt(keys[i]);
        xsid = host.data.strategies[sid].scorecardid;
        pid = host.data.strategies[sid].perspectiveid;
        if (host.links.scorecards[xsid] === undefined) host.links.scorecards[xsid] = {};
        if (host.links.scorecards[xsid].perspectives === undefined) {
            host.links.scorecards[xsid].perspectives = {
                keys: []
            };
        }
        if (host.links.scorecards[xsid].perspectives[pid] === undefined) {
            host.links.scorecards[xsid].perspectives[pid] = {
                scorecardid: xsid,
                perspectiveid: pid,
                weight: 0
            };
            host.links.scorecards[sid].perspectives.keys.push(pid);
        }
        if (host.links.scorecards[xsid].perspectives[pid].strategies === undefined) {
            host.links.scorecards[xsid].perspectives[pid].strategies = {
                keys: []
            };
        }
        host.links.scorecards[xsid].perspectives[pid].strategies.keys.push(sid);
        host.links.scorecards[xsid].perspectives[pid].strategies[sid] = host.data.strategies[sid];
    }
    n = host.data.strategy_criteria_links.length;
    for (i = 0; i < n; i++) {
        sid = host.data.strategy_criteria_links[i].strategyid;
        cid = host.data.strategy_criteria_links[i].criteriaid;
        if (host.data.strategies[sid].criteria === undefined) {
            host.data.strategies[sid].criteria = {
                keys: []
            };
        }
        host.data.strategies[sid].criteria.keys.push(cid);
        host.data.strategies[sid].criteria[cid] = {
            info: host.data.criteria[cid],
            goal: host.data.strategy_criteria_links[i].goal,
            min: host.data.strategy_criteria_links[i].min,
            max: host.data.strategy_criteria_links[i].max,
            weight: host.data.strategy_criteria_links[i].weight
        };
    }
    n = host.data.inputs.length;
    for (i = 0; i < n; i++) {
        cid = host.data.inputs[i].criteriaid;
        fid = host.data.inputs[i].rfirstid;
        if (host.data.criteria[cid].inputs === undefined) {
            host.data.criteria[cid].inputs = {};
        }
        if (host.data.criteria[cid].inputs[fid] === undefined) {
            host.data.criteria[cid].inputs[fid] = [];
        }
        host.data.criteria[cid].inputs[fid].push(host.data.inputs[i]);
    }
    issorted = {};
    for (i = 0; i < n; i++) {
        cid = host.data.inputs[i].criteriaid;
        fid = host.data.inputs[i].rfirstid;
        keys = cid + "_" + fid;
        if (issorted[keys] === undefined) {
            issorted[keys] = true;
            host.data.criteria[cid].inputs[fid].sort(function (a, b) {
                if (a.idate != b.idate) return a.idate - b.idate;
                return a.id - b.id;
            });
        }
    }
    n = host.data.rlinks.length;
    for (i = 0; i < n; i++) {
        cid = host.data.rlinks[i].criteriaid;
        fid = host.data.rlinks[i].rtofirstid;
        if (host.data.criteria[cid].links === undefined) host.data.criteria[cid].links = {};
        if (host.data.criteria[cid].links[fid] === undefined) host.data.criteria[cid].links[fid] = [];
        host.data.criteria[cid].links[fid].push(host.data.rlinks[i]);
    }
}
}
} (module, retval, core);
retval.callbackReturn = v147;
retval.checkCLinks = v202;
retval.exec = v146;
retval.makeKPIReport = v157;
retval.makeReports = v143;
retval.rebuildTable = v148;
retval.rebuildTable_id = v149;
retval.reports_checkCircularReference = v201;
retval.reports_genKPIReport = v158;
retval.reports_genReports = v152;
retval.reports_getCriteria = v153;
retval.reports_loadRLinksHandler = v150;
retval.reports_loadScorecardHandler = v144;
retval.reports_makeLinks = v151;
return retval;
}
 ();
}} (module, retval, v141);
t = t();
CodeCenterLibs.copyMembers(v141, t);
// function: hrprocesses.bsc.deleteReport
var v159 = function(module, me, core) {
return function (id, callbackfunc) {
core.exec("deleteReport", id, function (callbackfunc) {
    return function (success, content) {
        var i, n;
        if (success) {
            core.callbackReturn(callbackfunc, true);
            return;
        }
        core.callbackReturn(callbackfunc, false, content);
    }
} (callbackfunc));

}
} (module, retval, v141);
// function: hrprocesses.bsc.deleteReports
var v173 = function(module, me, core) {
return function (ids, callbackfunc) {
core.exec("deleteReports", ids, function (callbackfunc) {
    return function (success, content) {
        var i, n;
        if (success) {
            core.callbackReturn(callbackfunc, true, content);
            return;
        }
        core.callbackReturn(callbackfunc, false, content);
    }
} (callbackfunc));

}
} (module, retval, v141);
// function: hrprocesses.bsc.getDataAvailableCriteriaList
var v177 = function(module, me, core) {
return function (startDate, expiredDate, callbackfunc) {
if (callbackfunc === undefined) return;
if (!EncodingClass.type.isFunction(callbackfunc)) return;
core.exec("getDataAvailableCriteriaList",
    {
        startdate: startDate,
        expireddate: expiredDate
    },
    function (callbackfunc) {
        return function (success, content) {
            core.callbackReturn(callbackfunc, success, content);
        }
    } (callbackfunc)
);

}
} (module, retval, v141);
// function: hrprocesses.bsc.loadReport
var v155 = function(module, me, core) {
return function (id, callbackfunc) {
var fname = "zipreports_" + systemconfig.prefix + "_" + id;
fname = "bsc_reports/" + id + "_" + EncodingClass.md5.encode(fname) + "." + (new Date()).getTime() + ".zip";

var response = function (callbackfunc) {
    return function (success, content) {
        try {
            callbackfunc(success, content);
        }
        catch (e) {
            console.error(e);
        }
    }
} (callbackfunc);
FormClass.api_call({
    url: fname,
    params: [],
    rawcontent: true,
    func: function (response) {
        return function (success, message) {
            var i, r = {};
            var keys, sname;
            if (success) {
                ZipClass.extract([{content: message}], function (retcontent) {
                    keys = Object.keys(retcontent);
                    for (i = 0; i < keys.length; i++) {
                        sname = keys[i].substr(0, keys[i].length - 5);
                        r[sname] = JSON.parse(retcontent[keys[i]].content);
                    }
                    response(true, r);
                });
            }
            else {
                response(false, "invalid id");
            }
        }
    } (response)

});
}
} (module, retval, v141);
// function: hrprocesses.bsc.makeKPIReport
var v156 = function(module, me, core) {
return function (kpiid, startdate, expireddate, callbackfunc) {
if (callbackfunc === undefined) callbackfunc = function () {};
if (kpiid === undefined) {
    core.callbackReturn(callbackfunc, false, {
        type: "system",
        message: "kpi id is missing"
    });
    return;
}
if (startdate === undefined) {
    core.callbackReturn(callbackfunc, false, {
        type: "system",
        message: "startdate id is missing"
    });
    return;
}
if (expireddate === undefined) {
    core.callbackReturn(callbackfunc, false, {
        type: "system",
        message: "expireddate id is missing"
    });
    return;
}

core.makeKPIReport({
    id: kpiid,
    startdate: startdate,
    expireddate: expireddate,
    callbackfunc: callbackfunc
});
}
} (module, retval, v141);
// function: hrprocesses.bsc.makeReport
var v137 = function(module, me, core) {
return function (scorecardid, callbackfunc, progressfunc) {
if (progressfunc === undefined) progressfunc = function () {};
if (callbackfunc === undefined) callbackfunc = function () {};
core.makeReports({
    ids: [scorecardid],
    progressfunc: progressfunc,
    callbackfunc: callbackfunc
});
}
} (module, retval, v141);
// function: hrprocesses.bsc.makeReports
var v142 = function(module, me, core) {
return function (scorecardids, callbackfunc, progressfunc) {
if (progressfunc === undefined) progressfunc = function () {};
if (callbackfunc === undefined) callbackfunc = function () {};
core.makeReports({
    ids: scorecardids,
    progressfunc: progressfunc,
    callbackfunc: callbackfunc
});
}
} (module, retval, v141);
// function: hrprocesses.bsc.saveReport
var v154 = function(module, me, core) {
return function (id, content, callbackfunc) {
var zcontent = [];
var keys = Object.keys(content);
for (i = 0; i < keys.length; i++) {
    zcontent.push({
        type: "file",
        name: keys[i] + ".json",
        content: JSON.stringify(content[keys[i]])
    });
}
var response = function (callbackfunc) {
    return function (success, content) {
        try {
            callbackfunc(success, content);
        }
        catch (e) {
            console.error(e);
        }
    }
} (callbackfunc);

ZipClass.compress(zcontent, function (id, response) {
    return function (compressedContent) {
        var t = EncodingClass.base64.encode(compressedContent);
        FormClass.api_call({
            url: "bsc_savereport.php",
            params: [
                {
                    name: "id",
                    value: id
                },
                {
                    name: "content",
                    value: t
                }
            ],
            func: function (success, message) {
                var r;
                if (success) {
                    if (message.substr(0, 2) == "ok") {
                        r = EncodingClass.string.toVariable(message.substr(2));
                        if (r.result) {
                            response(true);
                        }
                        else {
                            response(false, {
                                type: "denied",
                                message: r.message
                            });
                        }
                    }
                    else {
                        response(false, {
                            type: "run-time",
                            message: message
                        });
                    }
                }
                else {
                    response(false, {
                        type: "system",
                        message: message
                    });
                }
            }
        });
    }
} (id, response));
}
} (module, retval, v141);
retval.deleteReport = v159;
retval.deleteReports = v173;
retval.getDataAvailableCriteriaList = v177;
retval.loadReport = v155;
retval.makeKPIReport = v156;
retval.makeReport = v137;
retval.makeReports = v142;
retval.saveReport = v154;
return retval;
}
} (module)) ();
// node: hrprocesses.data
var v94 = (function (module) { return function () {
var retval = {};
var v96 = {};
// resource: hrprocesses.data.core
var t = function (module, me, core) {return function () {return function () {
var retval = {};
// value: hrprocesses.data.core.queue
var v97 = function () {
return [];
}
 ();
// value: hrprocesses.data.core.rqueue
var v110 = function () {
return [];
}
 ();
// function: hrprocesses.data.core.exec
var v103 = function(module, me, core) {
return function (task, params, callbackfunc) {
core.queue.push({
    task: task,
    params: EncodingClass.string.fromVariable(params),
    callbackfunc: callbackfunc
});
if (core.queue.length == 1) core.processqueue();
}
} (module, retval, core);
// function: hrprocesses.data.core.processqueue
var v108 = function(module, me, core) {
return function () {
var task = core.queue[0].task;
var params = core.queue[0].params;
var callbackfunc = core.queue[0].callbackfunc;

FormClass.api_call({
    url: "hr_tasks.php",
    params: [
        {
            name: "task",
            value: task
        },
        {
            name: "params",
            value: params
        }
    ],
    func: function (callbackfunc) {
        return function (success, message) {
            //console.log(success, message);
            var r;
            if (success) {
                if (message.substr(0, 2) == "ok") {
                    r = EncodingClass.string.toVariable(message.substr(2));
                    try {
                        callbackfunc(r.result, r.content);
                    }
                    catch (e) {
                        console.error(e);
                    }
                }
                else {
                    try {
                        callbackfunc(false, {
                            type: "run-time",
                            content: message
                        });
                    }
                    catch (e) {
                        console.error(e);
                    }
                }
            }
            else {
                try {
                    callbackfunc(false, {
                        type: "system",
                        content: message
                    });
                }
                catch (e) {
                    console.error(e);
                }
            }
            core.queue.shift();
            if (core.queue.length > 0) setTimeout(function () {
                core.processqueue();
            }, 2);
        }
    } (callbackfunc)
});
}
} (module, retval, core);
retval.queue = v97;
retval.rqueue = v110;
retval.exec = v103;
retval.processqueue = v108;
return retval;
}
 ();
}} (module, retval, v96);
t = t();
CodeCenterLibs.copyMembers(v96, t);
// node: hrprocesses.data.assign_employee_shifts
var v125 = (function (module, core) { return function () {
var retval = {};
// function: hrprocesses.data.assign_employee_shifts.read_assign_has_shift_by_employee_list_and_time
var v197 = function(module, me, core) {
return function (employeeIdList, timestart, timeend) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
timeend = new Date(absol.datetime.nextDate(timeend).getTime() - 1);
data_module.loadAssign_employee_shifts({employeeIdList: employeeIdList, timestart: contentModule.getDateFrom1970(timestart), timeend: contentModule.getDateFrom1970(timeend), typeDic: {"" : true, ot : true}}).then(function(content){
    host.content = EncodingClass.string.duplicate(content);
    host.result = success;
    host.finished = true;
});
return retval;

}
} (module, retval, core);
// function: hrprocesses.data.assign_employee_shifts.read_by_employee_list_and_time
var v129 = function(module, me, core) {
return function (employeeIdList, timestart, timeend) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
timeend = new Date(absol.datetime.nextDate(timeend).getTime() - 1);
data_module.loadAssign_employee_shifts({employeeIdList: employeeIdList, timestart: contentModule.getDateFrom1970(timestart), timeend: contentModule.getDateFrom1970(timeend)}).then(function(content){
    host.content = EncodingClass.string.duplicate(content);
    host.result = success;
    host.finished = true;
});
return retval;

}
} (module, retval, core);
retval.read_assign_has_shift_by_employee_list_and_time = v197;
retval.read_by_employee_list_and_time = v129;
return retval;
}
} (module, v96)) ();
// node: hrprocesses.data.employee_benefit_and_liability_list
var v191 = (function (module, core) { return function () {
var retval = {};
// function: hrprocesses.data.employee_benefit_and_liability_list.loadListByEmployeeIdListAndCycle
var v192 = function(module, me, core) {
return function (list_type, employeeIdList, cycleid, payroll_date) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
core.exec("employee_benefit_and_liability_list.load_list_by_employeeid_list_and_cycle", {list_type: list_type, employeeIdList: employeeIdList, cycleid: cycleid, payroll_date: contentModule.getDateFrom1970(payroll_date)}, function (host) {
    return function (success, content) {
        if (success){
            if (content.list.length == 0){
                host.content = {};
                host.result = success;
                host.finished = true;
                return;
            }
            var host1 = {database: {}};
            contentModule.makeDatabaseContent(host1, content);
            console.log(host1.database);
            var employee_peopleDic = {};
            host1.database.employees.items.forEach(function(item){
                employee_peopleDic[item.peopleid] = item.id;
            });
            var policyDic = contentModule.makeDictionaryIndex(host1.database.policies.items);
            var listDic = {};
            host1.database.list.items.forEach(function(item){
                listDic[item.id] = item.policyid;
            });
            var data = {};
            host1.database.list_details.items.forEach(function(item){
                var policyid = listDic[item.listid];
                if (policyid === undefined) return;
                if (!data[policyid]){
                    var pIndex = policyDic[policyid];
                    if (pIndex === undefined) return;
                    data[policyid] = EncodingClass.string.duplicate(host1.database.policies.items[pIndex]);
                    data[policyid].employees = {};
                }
                var employeeid = employee_peopleDic[item.employee_peopleid];
                if (employeeid === undefined) return;
                if (!data[policyid].employees[employeeid]){
                    data[policyid].employees[employeeid] = {
                        amount: 0
                    };
                    if (list_type === "salary_adjustment"){
                        data[policyid].employees[employeeid].tax_exempt = 0;
                        data[policyid].employees[employeeid].insurance_exempt = 0;
                    }
                }
                data[policyid].employees[employeeid].amount += item.amount;
                if (list_type === "salary_adjustment"){
                    data[policyid].employees[employeeid].tax_exempt += item.tax_exempt;
                    data[policyid].employees[employeeid].insurance_exempt += item.insurance_exempt;
                }
            });
            host.content = data;
            host.result = success;
            host.finished = true;
        }
        else {
            console.log(content);
        }
    }
} (host));
return retval;

}
} (module, retval, core);
retval.loadListByEmployeeIdListAndCycle = v192;
return retval;
}
} (module, v96)) ();
// node: hrprocesses.data.employee_profile
var v194 = (function (module, core) { return function () {
var retval = {};
// function: hrprocesses.data.employee_profile.loadData
var v195 = function(module, me, core) {
return function (employeeid, typeid) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
console.log(employeeid);
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
core.exec("employee_profile.loadData", {employeeid: employeeid}, function (host) {
    return function (success, content) {
        if (success){
            var keys, i, n, id;
            content = EncodingClass.string.duplicate(content);
            content.people.content = EncodingClass.string.toVariable(content.people.content);
            if (content.people.education_history === "") content.people.education_history = [];
            else content.people.education_history = EncodingClass.string.toVariable(content.people.education_history);
            if (content.people.work_history === "") content.people.work_history = [];
            else content.people.work_history = EncodingClass.string.toVariable(content.people.work_history);
            Object.assign(content.people, content.people.content);
            if (content.extrainfo) {
                content.employee.extrainfo = content.extrainfo;
                //Object.assign(content.people, content.extrainfo);
            }
            delete content.people.id;
            Object.assign(content.employee, content.people);
            content.employee = form_module.convertLocalidToKey(typeid, [content.employee], true)[0];
            host.content = content;
            host.result = success;
            host.finished = true;
        }
        else {
            console.log(content);
        }

    }
} (host));

console.log(retval);
return retval;
}
} (module, retval, core);
// function: hrprocesses.data.employee_profile.makeEmployeeProfileData
var v196 = function(module, me, core) {
return function (content, typeid) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
var data = {
    picture: content.employee.image,
    name: content.employee.database_id,
    dayofbirth: content.employee.dayofbirth,
    placeofbirth: content.employee.placeofbirth,
    sex: content.employee.sex,
    ethnic: content.employee.ethnic,
    religion: content.employee.religion,
    hometown: content.employee.hometown,
    permanent_address: content.employee.permanent_address,
    temporary_address: content.employee.temporary_address,
    recruiment_date: content.employee.start_date,
    official_date: content.employee.official_date,
    nationalidno: content.people.nationalidno,
    nationalidno_date: content.employee.nationalidno_date,
    nationalidno_place: content.employee.nationalidno_place,
    social_security_number: content.employee.social_security_number,
    signature: content.employee.database_id,
    education_history: [],
    emulation_reward: [],
    discipline: [],
    work_history: [],
    family_members: [],
    extrainfo: {}
};
for (var i = 0; i < content.employee_positions.length; i++){
    if (content.employee_positions[i].type == "position") {
        data.position = content.employee_positions[i].positionid;
    }
    if (content.employee_positions[i].type == "concurrent_position") {
        data.concurrent_position = content.employee_positions[i].positionid;
    }
}

for (var i = 0; i < content.emulation_reward.length; i++){
    data.emulation_reward.push({
        employeeid: content.emulation_reward[i].employeeid,
        reference_number: content.emulation_reward[i].reference_number,
        date: {
            level: content.emulation_reward[i].stage,
            value: content.emulation_reward[i].date
        },
        company: content.emulation_reward[i].company,
        content: content.emulation_reward[i].content
    });
}

for (var i = 0; i < content.discipline.length; i++){
    data.discipline.push({
        employeeid: content.discipline[i].employeeid,
        reference_number: content.discipline[i].reference_number,
        date: {
            level: content.discipline[i].stage,
            value: content.discipline[i].date
        },
        company: content.discipline[i].company,
        content: content.discipline[i].content
    });
}

for (var i = 0; i < content.family_members.length; i++){
    data.family_members.push({
        fullname: content.family_members[i].fullname,
        dayofbirth: EncodingClass.string.toVariable(content.family_members[i].dayofbirth),
        sex: content.family_members[i].sex,
        relation: content.family_members[i].relation,
        comment: content.family_members[i].comment
    });
}

for (var i = 0; i < content.people.work_history.length; i++){
    data.work_history.push({
        position: content.people.work_history[i].position,
        organization: content.people.work_history[i].organization,
        from_month: content.people.work_history[i].from_month,
        to_month: content.people.work_history[i].to_month,
        comment: content.people.work_history[i].comment
    });
}

for (var i = 0; i < content.people.education_history.length; i++){
    data.education_history.push({
        major: content.people.education_history[i].major,
        school: content.people.education_history[i].school,
        degree: content.people.education_history[i].degree,
        from_month: content.people.education_history[i].from_month,
        to_month: content.people.education_history[i].to_month,
        comment: content.people.education_history[i].comment,
        top_level: content.people.education_history[i].top_level
    });
}

//data = form_module.convertKeyToLocalid(typeid, [data], true);

//host.content = data[0];
host.content = data;
host.result = true;
host.finished = true;

return retval;






}
} (module, retval, core);
retval.loadData = v195;
retval.makeEmployeeProfileData = v196;
return retval;
}
} (module, v96)) ();
// node: hrprocesses.data.employees
var v116 = (function (module, core) { return function () {
var retval = {};
// function: hrprocesses.data.employees.dđ
var v121 = function(module, me, core) {
return function () {

}
} (module, retval, core);
// function: hrprocesses.data.employees.read
var v117 = function(module, me, core) {
return function (forceReload) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
if (forceReload === undefined) forceReload = false;
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
if (!forceReload) {
    if (core.employees !== undefined) {
        host.content = EncodingClass.string.duplicate(core.employees);
        host.result = true;
        host.finished = true;
        return retval;
    }
}
core.exec("employees.read", {}, function (host) {
    return function (success, content) {
        var keys, i, n, id;
        if (success) core.employees = content;
        host.content = EncodingClass.string.duplicate(content);
        host.result = success;
        host.finished = true;
    }
} (host));
return retval;
}
} (module, retval, core);
// function: hrprocesses.data.employees.write_arr
var v120 = function(module, me, core) {
return function (arr) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
core.exec("employees.write_arr", arr, function (host) {
    return function (success, content) {
        host.content = EncodingClass.string.duplicate(content);
        host.result = success;
        host.finished = true;
    }
} (host));
return retval;
}
} (module, retval, core);
retval.dđ = v121;
retval.read = v117;
retval.write_arr = v120;
return retval;
}
} (module, v96)) ();
// node: hrprocesses.data.employment_contract
var v187 = (function (module, core) { return function () {
var retval = {};
// function: hrprocesses.data.employment_contract.loadData
var v188 = function(module, me, core) {
return function (contractid) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
console.log(contractid);
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
core.exec("employment_contract.loadData", {contractid: contractid}, function (host) {
    return function (success, content) {
        if (success){
            var keys, i, n, id;
            host.content = EncodingClass.string.duplicate(content);
            //console.log(host.content);
            host.result = success;
            host.finished = true;
        }
        else {
            console.log(content);
        }

    }
} (host));
console.log(retval);
return retval;
}
} (module, retval, core);
// function: hrprocesses.data.employment_contract.makeEmploymentContractData
var v189 = function(module, me, core) {
return function (content) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});

var makeDict = function(list){
    var dict = {};
    list.forEach(function(cur){
        dict[cur.id] = cur;
    });
    return dict;
}
var dict = {
    leave_policies: makeDict(content.leave_policies),
    late_early_checkin_policies: makeDict(content.late_early_checkin_policies),
    advance_payment_policies: makeDict(content.advance_payment_policies),
    allowance_policies: makeDict(content.allowance_policies),
    benefit_policies: makeDict(content.benefit_policies),
    bonus_policies: makeDict(content.bonus_policies),
    punishment_policies: makeDict(content.punishment_policies),
    insurance_policies: makeDict(content.insurance_policies),
    trade_union_policies: makeDict(content.trade_union_policies),
    tax_policies: makeDict(content.tax_policies),
    other_liability_policies: makeDict(content.other_liability_policies)
};
content.people.content = EncodingClass.string.toVariable(content.people.content);
var data = {
    number: content.contract.contract_number,
    name: content.people.fullname,
    address: content.people.content.temporary_address,
    sex: content.people.content.sex,
    dayofbirth: content.people.dayofbirth,
    nationalidno: content.people.nationalidno,
    nationalidno_date: content.people.content.nationalidno_date,
    nationalidno_place: content.people.content.nationalidno_place,
    permanent_address: content.people.content.permanent_address,
    type: content.contract.contractid,
    effective_date_from: content.contract.effective_date_from,
    effective_date_to: content.contract.effective_date_to,
    department: content.employee.orgid,
    signature: content.people.fullname,
    leave_policy: "",
    late_early_checkin_policy: "",
    advance_payment_policy: "",
    allowance_policy: "",
    benefit_policy: "",
    bonus_policy: "",
    punishment_policy: "",
    insurance_policy: "",
    trade_union_policy: "",
    tax_policy: "",
    other_liability_policy: ""
};

if (content.geopos.length > 0) {
    data.workplace = content.geopos[0].geoid;
}

if (content.employee_salary_decisions.length > 0) {
    data.gross_salary = content.employee_salary_decisions[0].gross_salary_amount;
    data.basic_salary = content.employee_salary_decisions[0].basic_salary_amount;
    data.salary_caculated_on = content.employee_salary_decisions[0].calculated_on;
    data.salary_grade = content.employee_salary_decisions[0].salary_grade;
}

for (var i = 0; i < content.employee_positions.length; i++){
    if (content.employee_positions[i].type == "position") data.position = content.employee_positions[i].positionid;
    else data.concurrent_position = content.employee_positions[i].positionid;
}

var frequenceText = {
    week: LanguageModule.text("txt_week"),
    month: LanguageModule.text("txt_month"),
    quarter: LanguageModule.text("txt_quarter"),
    six_months: LanguageModule.text("txt_six_months"),
    year: LanguageModule.text("txt_year"),
    one_time: LanguageModule.text("txt_one_time")
};

for (var i = 0; i < content.employee_policies.length; i++){
    var str = "";
    switch (content.employee_policies[i].type){
        case "leave":
            if (!dict.leave_policies[content.employee_policies[i].policyid]) break;
            if (data.leave_policy.length !== 0) data.leave_policy += "<br>";
            str += "- " + dict.leave_policies[content.employee_policies[i].policyid].name;
            if (dict.leave_policies[content.employee_policies[i].policyid].groupid == -1){
                str += ": " + dict.leave_policies[content.employee_policies[i].policyid].leave_days_per_year + " " + LanguageModule.text("txt_day").toLowerCase();
            }
            data.leave_policy += str;
            break;
        case "late_early_checkin":
            if (!dict.late_early_checkin_policies[content.employee_policies[i].policyid]) break;
            if (data.late_early_checkin_policy.length !== 0) data.late_early_checkin_policy += "<br>";
            str += "- " + dict.late_early_checkin_policies[content.employee_policies[i].policyid].name;
            str += ": " + LanguageModule.text("txt_late_check_in_lower").toLowerCase() + " " + dict.late_early_checkin_policies[content.employee_policies[i].policyid].late + " " + LanguageModule.text("txt_minutes_lower");
            str += ", " + LanguageModule.text("txt_early_check_out_lower").toLowerCase() + " " + dict.late_early_checkin_policies[content.employee_policies[i].policyid].early + " " + LanguageModule.text("txt_minutes_lower");
            data.late_early_checkin_policy += str;
            break;
        case "advance_payment":
            if (!dict.advance_payment_policies[content.employee_policies[i].policyid]) break;
            if (data.advance_payment_policy.length !== 0) data.advance_payment_policy += "<br>";
            str += "- " + dict.advance_payment_policies[content.employee_policies[i].policyid].name;
            if (dict.advance_payment_policies[content.employee_policies[i].policyid].advance_payment_on == "fixed_amount"){
                str += ": " + LanguageModule.text("txt_advance_payment_on").toLowerCase() + " " + LanguageModule.text("txt_fixed_amount").toLowerCase();
                str += ", " + LanguageModule.text("txt_maximum_amount").toLowerCase() + " " + dict.advance_payment_policies[content.employee_policies[i].policyid].maximum_amount + " $";
            }
            else {
                str += ": " + LanguageModule.text("txt_advance_payment_on").toLowerCase();
                if (dict.advance_payment_policies[content.employee_policies[i].policyid].advance_payment_on == "basic_salary") str += " " + LanguageModule.text("txt_basic_salary").toLowerCase();
                else str += " " + LanguageModule.text("txt_gross_salary").toLowerCase()
                str += ", " + LanguageModule.text("txt_maximum_percentage").toLowerCase() + " " + dict.advance_payment_policies[content.employee_policies[i].policyid].maximum_percentage + " %";
            }
            data.advance_payment_policy += str;
            break;
        case "allowance":
            if (!dict.allowance_policies[content.employee_policies[i].policyid]) break;
            if (data.allowance_policy.length !== 0) data.allowance_policy += "<br>";
            str += "- " + dict.allowance_policies[content.employee_policies[i].policyid].name;
            if (dict.allowance_policies[content.employee_policies[i].policyid].allowance_type != "actual_expenses"){
                str += ": " + LanguageModule.text("txt_allowance").toLowerCase();
                if (dict.allowance_policies[content.employee_policies[i].policyid].allowance_type != "actual_expenses_with_limit") {
                    str += " " + LanguageModule.text("txt_actual_expenses_with_limit").toLowerCase();
                }
                else {
                    str += " " + LanguageModule.text("txt_fixed_amount").toLowerCase();
                }
                str += " " + dict.allowance_policies[content.employee_policies[i].policyid].value + " $/";
                str += frequenceText[dict.allowance_policies[content.employee_policies[i].policyid].frequency];
            }
            data.allowance_policy += str;
            break;
        case "benefit":
            if (!dict.benefit_policies[content.employee_policies[i].policyid]) break;
            if (data.benefit_policy.length !== 0) data.benefit_policy += "<br>";
            str += "- " + dict.benefit_policies[content.employee_policies[i].policyid].name + ": " + dict.benefit_policies[content.employee_policies[i].policyid].description;
            if (dict.benefit_policies[content.employee_policies[i].policyid].benefit_type != "actual_expenses"){
                //str += ": " + LanguageModule.text("txt_benefit").toLowerCase();
                if (dict.benefit_policies[content.employee_policies[i].policyid].benefit_type != "actual_expenses_with_limit") {
                    str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_benefit_type") + ": " + LanguageModule.text("txt_actual_expenses_with_limit").toLowerCase();
                }
                else {
                    str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_benefit_type") + ": " + LanguageModule.text("txt_fixed_amount").toLowerCase();
                }
                str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_value") + ": " + dict.benefit_policies[content.employee_policies[i].policyid].value;
                str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_frequency") + ": " + frequenceText[dict.benefit_policies[content.employee_policies[i].policyid].frequency];
            }
            else {
                str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_benefit_type") + ": " + LanguageModule.text("txt_actual_expenses").toLowerCase();
            }
            data.benefit_policy += str;
            break;
        case "bonus":
            if (!dict.bonus_policies[content.employee_policies[i].policyid]) break;
            if (data.bonus_policy.length !== 0) data.bonus_policy += "<br>";
            str += "- " + dict.bonus_policies[content.employee_policies[i].policyid].name + ": " + dict.bonus_policies[content.employee_policies[i].policyid].description;
            str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_taxable_income") + ": ";
            str += (dict.bonus_policies[content.employee_policies[i].policyid].taxable_income == 0) ? LanguageModule.text("txt_no") : LanguageModule.text("txt_yes");
            str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_income_subject_to_insurance_contribution") + ": ";
            str += (dict.bonus_policies[content.employee_policies[i].policyid].income_subject_to_insurance_contribution == 0) ? LanguageModule.text("txt_no") : LanguageModule.text("txt_yes");
            data.bonus_policy += str;
            break;
        case "punishment":
            if (!dict.punishment_policies[content.employee_policies[i].policyid]) break;
            if (data.punishment_policy.length !== 0) data.punishment_policy += "<br>";
            str += "- " + dict.punishment_policies[content.employee_policies[i].policyid].name + ": " + dict.punishment_policies[content.employee_policies[i].policyid].description;
            str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_tax_relief") + ": ";
            str += (dict.punishment_policies[content.employee_policies[i].policyid].tax_relief == 0) ? LanguageModule.text("txt_no") : LanguageModule.text("txt_yes");
            str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_insurance_contribution_relief") + ": ";
            str += (dict.punishment_policies[content.employee_policies[i].policyid].insurance_contribution_relief == 0) ? LanguageModule.text("txt_no") : LanguageModule.text("txt_yes");
            data.punishment_policy += str;
            break;
        case "insurance":
            if (!dict.insurance_policies[content.employee_policies[i].policyid]) break;
            if (data.insurance_policy.length !== 0) data.insurance_policy += "<br>";
            str += "- " + dict.insurance_policies[content.employee_policies[i].policyid].name + ":";
            str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_contributed_by_company") + " (%): " + dict.insurance_policies[content.employee_policies[i].policyid].contributed_by_company;
            str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_contributed_by_employee") + " (%): " + dict.insurance_policies[content.employee_policies[i].policyid].contributed_by_employee;
            data.insurance_policy += str;
            break;
        case "trade_union":
            if (!dict.trade_union_policies[content.employee_policies[i].policyid]) break;
            if (data.trade_union_policy.length !== 0) data.trade_union_policy += "<br>";
            str += "- " + dict.trade_union_policies[content.employee_policies[i].policyid].name;
            if (dict.trade_union_policies[content.employee_policies[i].policyid].fee_type == "percentage"){
                str += ": " + LanguageModule.text("txt_percentage").toLowerCase() + " " + dict.trade_union_policies[content.employee_policies[i].policyid].rate + " %";
            }
            else {
                str += ": " + LanguageModule.text("txt_fixed_amount").toLowerCase() + " " + dict.trade_union_policies[content.employee_policies[i].policyid].amount + " $";
            }
            data.trade_union_policy += str;
            break;
        case "tax":
            if (!dict.tax_policies[content.employee_policies[i].policyid]) break;
            if (data.tax_policy.length !== 0) data.tax_policy += "<br>";
            str += "- " + dict.tax_policies[content.employee_policies[i].policyid].name;
            if (dict.tax_policies[content.employee_policies[i].policyid].fee_type == "progressive_tax"){
                str += ": " + LanguageModule.text("txt_progressive_tax").toLowerCase() + " " + dict.tax_policies[content.employee_policies[i].policyid].tax_rate_progressive_tax;
            }
            else {
                str += ": " + LanguageModule.text("txt_fixed_percentage").toLowerCase() + " " + dict.tax_policies[content.employee_policies[i].policyid].tax_rate_fixed_percentage + " %";
            }
            data.tax_policy += str;
            break;
        case "other_liability":
            if (!dict.other_liability_policies[content.employee_policies[i].policyid]) break;
            if (data.other_liability_policy.length !== 0) data.other_liability_policy += "<br>";
            str += "- " + dict.other_liability_policies[content.employee_policies[i].policyid].name + ": " + dict.other_liability_policies[content.employee_policies[i].policyid].description;
            if (dict.other_liability_policies[content.employee_policies[i].policyid].other_liability_type != "actual_expenses"){
                if (dict.other_liability_policies[content.employee_policies[i].policyid].other_liability_type != "actual_expenses_with_limit") {
                    str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_other_liability_type") + ": " + LanguageModule.text("txt_actual_expenses_with_limit").toLowerCase();
                }
                else {
                    str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_other_liability_type") + ": " + LanguageModule.text("txt_fixed_amount").toLowerCase();
                }
                str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_value") + " (&): " + dict.other_liability_policies[content.employee_policies[i].policyid].value;
                str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_frequency") + ": " + frequenceText[dict.other_liability_policies[content.employee_policies[i].policyid].frequency];
            }
            else {
                str += "<br>&nbsp;&nbsp;+ " + LanguageModule.text("txt_other_liability_type") + ": " + LanguageModule.text("txt_actual_expenses").toLowerCase();
            }
            data.other_liability_policy += str;
            break;
    }
}
host.content = data;
host.result = true;
host.finished = true;

return retval;






}
} (module, retval, core);
retval.loadData = v188;
retval.makeEmploymentContractData = v189;
return retval;
}
} (module, v96)) ();
// node: hrprocesses.data.orgs
var v183 = (function (module, core) { return function () {
var retval = {};
return retval;
}
} (module, v96)) ();
// node: hrprocesses.data.shifts
var v123 = (function (module, core) { return function () {
var retval = {};
// function: hrprocesses.data.shifts.read
var v128 = function(module, me, core) {
return function (forceLoad) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
if (forceLoad === undefined) forceLoad = false;
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
if (!forceLoad) {
    if (core.shifts !== undefined) {
        host.content = EncodingClass.string.duplicate(core.shifts);
        host.result = true;
        host.finished = true;
        return retval;
    }
}
core.exec("shifts.read", {}, function (host) {
    return function (success, content) {
        for (var i = 0; i < content.length; i++){
            contentModule.makeShiftData(content[i]);
        }
        if (success) core.shifts = content;
        host.content = EncodingClass.string.duplicate(content);
        host.result = success;
        host.finished = true;
    }
} (host));
return retval;

}
} (module, retval, core);
retval.read = v128;
return retval;
}
} (module, v96)) ();
// node: hrprocesses.data.timesheet
var v179 = (function (module, core) { return function () {
var retval = {};
// function: hrprocesses.data.timesheet.loadDataForMealsCalculation
var v198 = function(module, me, core) {
return function (employeeIdList, timesheetid) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
console.log(employeeIdList, timesheetid);
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
core.exec("timesheet.loadDataForMealsCalculation", {employeeIdList: employeeIdList, timesheetid: timesheetid}, function (host) {
    return function (success, content) {
        if (success){
            var keys, i, n, id;
            host.content = EncodingClass.string.duplicate(content);
            host.content.timesheetid = timesheetid;
            host.result = success;
            host.finished = true;
        }
        else {
            console.log(content);
        }

    }
} (host));
return retval;
}
} (module, retval, core);
// function: hrprocesses.data.timesheet.loadDataForTimeKeeping
var v180 = function(module, me, core) {
return function (employeeIdList, timesheetid) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
console.log(employeeIdList, timesheetid);
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
core.exec("timesheet.loadDataForTimeKeeping", {employeeIdList: employeeIdList, timesheetid: timesheetid}, function (host) {
    return function (success, content) {
        if (success){
            var keys, i, n, id;
            host.content = EncodingClass.string.duplicate(content);
            host.content.timesheetid = timesheetid;
            host.result = success;
            host.finished = true;
        }
        else {
            console.log(content);
        }

    }
} (host));
return retval;
}
} (module, retval, core);
// function: hrprocesses.data.timesheet.mealsCalculation
var v200 = function(module, me, core) {
return function (content, timesheetid) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
var host1 = {database: {}};
var timesheetid = content.timesheetid;
var employeeIdList = content.employeeIdList;
delete content.employeeIdList;
delete content.timesheetid;
contentModule.makeDatabaseContent(host1, content);
var shift_meal_rulesDic = {
    temp: {},
    result: {}
};
var employee_meals_policiesDic = {};
host1.database.employee_meals_policies.items.forEach(function(item){
    employee_meals_policiesDic[item.employeeid] = true;
});
hr.shifts.generateMathExpression(host1);
host1.database.shift_meal_rule_temporary_variables.items.forEach(function(item){
    item.content = contentModule.convertPaysheetFormula(item.content);
    item.content = host1.mathExpression.parse(item.content);
    if (!item.content){
        ModalElement.alert({message: LanguageModule.text("war_txt_expression_is_invalid")});
        return;
    }
    if (!shift_meal_rulesDic.temp[item.shiftid]) shift_meal_rulesDic.temp[item.shiftid] = {list: []};
    shift_meal_rulesDic.temp[item.shiftid].list.push(item);
});
host1.database.shift_meal_rules.items.forEach(function(item){
    item.content = contentModule.convertPaysheetFormula(item.content);
    item.content = host1.mathExpression.parse(item.content);
    if (!item.content){
        ModalElement.alert({message: LanguageModule.text("war_txt_expression_is_invalid")});
        return;
    }
    if (!shift_meal_rulesDic.result[item.shiftid]) shift_meal_rulesDic.result[item.shiftid] = [];
    shift_meal_rulesDic.result[item.shiftid].push(item);
});
for (var shiftid in shift_meal_rulesDic.temp){
    var res = hr.shifts.getCalOrderList(shift_meal_rulesDic.temp[shiftid].list);
    if (!res.status){
        ModalElement.alert({message: res.content.type});
        return;
    }
    shift_meal_rulesDic.temp[shiftid].indexList = res.content;
}
var leave_policiesDic = contentModule.makeDictionaryIndex(host1.database.leave_policies.items);
host1.timesheet_employeesDic = {};
host1.database.timesheet_employees.items.forEach(function(item){
    host1.timesheet_employeesDic[item.employeeid] = item;
});
for (var i = 0; i < host1.database.worktime_logs.items.length; i++){
    host1.database.worktime_logs.items[i].date = contentModule.getDateFrom1970(host1.database.worktime_logs.items[i].intime);
}
host1.database.worktime_logs.items.forEach(function(item){
    item.intimeMS = item.intime.getTime();
    item.outtimeMS = item.outtime.getTime();
});
host1.database.assign_employee_shifts.items.forEach(function(item){
    item.intimeMS = new Date(item.date*86400000).setHours(0, 0, 0, 0) + item.time_in;
    item.outtimeMS = new Date(item.date*86400000).setHours(0, 0, 0, 0) + item.time_out;
});
host1.database.assign_employee_shifts.items.sort(function(a, b){
    if (a.employeeid == b.employeeid) return a.date - b.date;
    return a.employeeid - b.employeeid;
});
var logsDic = {};
host1.database.worktime_logs.items.forEach(function  (item){
    if (!logsDic[item.employeeid]) logsDic[item.employeeid] = {};
    if (!logsDic[item.employeeid][item.date]) logsDic[item.employeeid][item.date] = [];
    logsDic[item.employeeid][item.date].push(item);
});
contentModule.makeShift_work_day_ratioData(host1);
contentModule.makeShiftsData(host1);
host1.database.shifts.items.sort(function(a, b){
    return b.fromdate - a.fromdate;
});
host1.database.shift_work_day_ratio.items.sort(function(a, b){
    return a.windex - b.windex;
});
host1.shiftDic = contentModule.makeDictionaryIndex(host1.database.shifts.items);
host1.database.shifts.items.forEach(function(item){
    item.ratioIndexList = [];
});
host1.database.shift_work_day_ratio.items.forEach(function(item, index){
    item.time = EncodingClass.string.toVariable(item.time);
    var k = host1.shiftDic[item.shiftid];
    if (k >= 0){
        host1.database.shifts.items[k].ratioIndexList.push(index);
    }
});
host1.database.holidays.items.forEach(function(item){
    item.startdate = contentModule.getDateFrom1970(item.timestart);
    item.enddate = contentModule.getDateFrom1970(item.timeend);
});
var holidaysDic = contentModule.makeDictionaryIndex(host1.database.holidays.items);
host1.shift_holidayDic = {};
host1.database.shift_holidays.items.forEach(function(item){
    var hIndex = holidaysDic[item.holidayid];
    if (hIndex >= 0){
        if (item.shiftid == 0){
            host1.database.shifts.items.forEach(function(sItem){
                if (!host1.shift_holidayDic[sItem.id]) host1.shift_holidayDic[sItem.id] = [];
                host1.shift_holidayDic[sItem.id].push(host1.database.holidays.items[hIndex]);
            });
            return;
        }
        if (!host1.shift_holidayDic[item.shiftid]) host1.shift_holidayDic[item.shiftid] = [];
        host1.shift_holidayDic[item.shiftid].push(host1.database.holidays.items[hIndex]);
    }
});
var holidaysDateDic = {};
host1.database.holidays.items.forEach(function(item){
    if (!item.available) return;
    for (var d = absol.datetime.beginOfDay(item.timestart); absol.datetime.compareDate(d, item.timeend) <= 0; d = absol.datetime.nextDate(d)){
        if (!holidaysDateDic[contentModule.getDateFrom1970(d)]) holidaysDateDic[contentModule.getDateFrom1970(d)] = [];
        holidaysDateDic[contentModule.getDateFrom1970(d)].push(item);
    }
});
var late_early_checkinDic = {};
host1.database.late_early_checkin_request.items.forEach(function(item){
    item.fromdateInt = contentModule.getDateFrom1970(item.fromdate);
    item.todateInt = contentModule.getDateFrom1970(item.todate);
    if (!late_early_checkinDic[item.employeeid]) late_early_checkinDic[item.employeeid] = {};
    for (var i = item.fromdateInt; i <= item.todateInt; i++){
        if (!late_early_checkinDic[item.employeeid][i]){
            late_early_checkinDic[item.employeeid][i] = {
                late: item.late,
                early: item.early
            };
        }
        else {
            if (late_early_checkinDic[item.employeeid][i].late < item.late) item.late = late_early_checkinDic[item.employeeid][i].late;
            if (late_early_checkinDic[item.employeeid][i].early < item.early) item.early = late_early_checkinDic[item.employeeid][i].early;
        }
    }
});
var assignDic = contentModule.makeDictionaryIndex(host1.database.assign_employee_shifts.items);
var listDetails_1 = [];
var listDetails_2 = [];
host1.database.timesheet_employees.items.forEach(function(item){
    for (var i = item.startdate; i <= item.enddate; i++){
        if (!holidaysDateDic[i]) continue;
        for (var j = 0; j < holidaysDateDic[i].length; j++){
            if (holidaysDateDic[i][j].type == "holiday"){
                listDetails_2.push({
                    timesheetid: item.timesheetid,
                    employee_peopleid: item.employee_peopleid,
                    employeeid: item.employeeid,
                    workdate: i,
                    task: "holiday",
                    taskid: holidaysDateDic[i][j].id,
                    pay_percentageid: holidaysDateDic[i][j].pay_percentageid,
                    assignid: 0,
                    shift_work_day_ratioid: 0,
                    workdays: 1,
                    intime: 0,
                    outtime: 0,
                    lastmodifiedtime: new Date(),
                    lastmodified_userid: systemconfig.userid,
                    ot_in_breaktime: 0,
                    working_hours: 0,
                    shiftid: 0
                });

                break;
            }
        }
    }
});
var business_tripDic = {};
var otherLeaveDic = {};
var compensatory_leaveDic = {};
var data_for_meals = {};
host1.database.assign_employee_shifts.items.forEach(function(aItem){
    if (host1.timesheet_employeesDic[aItem.employeeid].startdate > aItem.date) return;
    if (host1.timesheet_employeesDic[aItem.employeeid].enddate < aItem.date) return;
    if (aItem.type == "cl"){
        if (!compensatory_leaveDic[aItem.employeeid]) compensatory_leaveDic[aItem.employeeid] = {};
        if (!compensatory_leaveDic[aItem.employeeid][aItem.date]) compensatory_leaveDic[aItem.employeeid][aItem.date] = [];
        compensatory_leaveDic[aItem.employeeid][aItem.date].push(aItem);
    }
    else if (aItem.type == "hrp"){
        var pIndex = leave_policiesDic[aItem.policyid];
        if (pIndex >= 0){
            if (host1.database.leave_policies.items[pIndex].work_paid){
                aItem.pay_percentageid = host1.database.leave_policies.items[pIndex].pay_percentage;
                var pay_percentageIndex = host1.database.pay_percentage.getIndex(aItem.pay_percentageid);
                if (pay_percentageIndex >= 0){
                    aItem.pay_percentage_ratio = host1.database.pay_percentage.items[pay_percentageIndex].percentage;
                    aItem.pay_percentage_name =  host1.database.pay_percentage.items[pay_percentageIndex].name;
                }
                else {
                    aItem.pay_percentage_ratio = 0;
                    aItem.pay_percentage_name = "";
                }
                if (host1.database.leave_policies.items[pIndex].groupid == -2){
                    if (!business_tripDic[aItem.employeeid]) business_tripDic[aItem.employeeid] = {};
                    if (!business_tripDic[aItem.employeeid][aItem.date]) business_tripDic[aItem.employeeid][aItem.date] = [];
                    business_tripDic[aItem.employeeid][aItem.date].push(aItem);
                }
                else {
                    if (!otherLeaveDic[aItem.employeeid]) otherLeaveDic[aItem.employeeid] = {};
                    if (!otherLeaveDic[aItem.employeeid][aItem.date]) otherLeaveDic[aItem.employeeid][aItem.date] = [];
                    aItem.annual_leave = host1.database.leave_policies.items[pIndex].groupid == -1;
                    otherLeaveDic[aItem.employeeid][aItem.date].push(aItem);
                }
            }
        }
    }
});
var getDetails2ItemLeave = function(shiftContent, time_in, time_out, aItem, policyData){
    var working_hours = contentModule.getOverTimeHoursHasShiftContent(
        host1,
        new Date(aItem.date*86400000),
        new Date(aItem.date*86400000),
        {
            dayOffset: time_in,
            duration: time_out - time_in
        },
        shiftContent,
        false
    );
    var working_hours1 = working_hours;
    if (working_hours > 0){
        var workdays = (working_hours/shiftContent.number_of_standard_working_hours)*(policyData.pay_percentage_ratio/100)
        return {
            timesheetid: timesheetid,
            employee_peopleid: aItem.employee_peopleid,
            employeeid: aItem.employeeid,
            workdate: aItem.date,
            task: "hrp",
            taskid: policyData.policyid,
            pay_percentageid: policyData.pay_percentageid,
            pay_percentage_name: policyData.pay_percentage_name,
            assignid: aItem.id,
            shift_work_day_ratioid: 0,
            workdays: workdays,
            intime: time_in,
            outtime: time_out,
            lastmodifiedtime: new Date(),
            lastmodified_userid: systemconfig.userid,
            ot_in_breaktime: aItem.ot_in_breaktime,
            working_hours: working_hours1
        };
    }
};
var listLogsUpdate = [];
var listLogsUpdateDic = {};
host1.database.assign_employee_shifts.items.forEach(function(aItem){
    if (!employee_meals_policiesDic[aItem.employeeid]) return;
    if (aItem.type != "" && aItem.type != "ot") return;
    if (host1.timesheet_employeesDic[aItem.employeeid].startdate > aItem.date) return;
    if (host1.timesheet_employeesDic[aItem.employeeid].enddate < aItem.date) return;
    var shiftContent = contentModule.getContentShiftFollowDateById(host1, aItem.shiftid, aItem.date);
    if (!shiftContent) return;
    if (!data_for_meals[aItem.employeeid]) data_for_meals[aItem.employeeid] = {};
    if (!data_for_meals[aItem.employeeid][aItem.id]) data_for_meals[aItem.employeeid][aItem.id] = {
        employee_peopleid: aItem.employee_peopleid,
        shiftid: aItem.shiftid,
        date: aItem.date,
        work_hours: 0,
        leave_hours: 0,
        business_trip_hours: 0,
        total_off_hours: 0,
        shift_type: aItem.type == "ot"? 1 : 0,
        wht: {},
        whc: {}
    };
    var timeList2 = [];
    var timeList = [{
        start: aItem.time_in,
        end: aItem.time_out
    }];
    while (timeList.length > 0) {
        var out_of = false;
        var timeItem = timeList.shift();
        if (aItem.type == ""){
            if (otherLeaveDic[aItem.employeeid] && otherLeaveDic[aItem.employeeid][aItem.date]){
                for (var i = 0; i < otherLeaveDic[aItem.employeeid][aItem.date].length; i++){
                    if (otherLeaveDic[aItem.employeeid][aItem.date][i].days_portion == "full_workday"){
                        var details2Item = getDetails2ItemLeave(shiftContent, aItem.time_in, aItem.time_out, aItem, otherLeaveDic[aItem.employeeid][aItem.date][i]);
                        if (details2Item){
                            details2Item.shiftContent = shiftContent;
                            details2Item.shiftid = aItem.shiftid;
                            listDetails_2.push(details2Item);
                            if (otherLeaveDic[aItem.employeeid][aItem.date][i].annual_leave){
                                data_for_meals[aItem.employeeid][aItem.id].leave_hours += details2Item.working_hours;
                            }
                            data_for_meals[aItem.employeeid][aItem.id].total_off_hours += details2Item.working_hours;
                            if (!data_for_meals[aItem.employeeid][aItem.id].wht[details2Item.pay_percentage_name]) data_for_meals[aItem.employeeid][aItem.id].wht[details2Item.pay_percentage_name] = 0;
                            data_for_meals[aItem.employeeid][aItem.id].wht[details2Item.pay_percentage_name] += details2Item.working_hours;
                        }
                        out_of = true;
                        break;
                    }
                }
                if (!out_of){
                    var leaveItem;
                    for (var i = 0; i < otherLeaveDic[aItem.employeeid][aItem.date].length; i++){
                        leaveItem = otherLeaveDic[aItem.employeeid][aItem.date][i];
                        var xx = contentModule.splitRange(timeItem, {start: leaveItem.time_in, end: leaveItem.time_out});
                        for (var k = 0; k < xx.union.length; k++){
                            var details2Item = getDetails2ItemLeave(shiftContent, xx.union[i].start, xx.union[i].end, aItem, leaveItem);
                            if (details2Item){
                                details2Item.shiftContent = shiftContent;
                                details2Item.shiftid = aItem.shiftid;
                                listDetails_2.push(details2Item);
                                if (otherLeaveDic[aItem.employeeid][aItem.date][i].annual_leave){
                                    data_for_meals[aItem.employeeid][aItem.id].leave_hours += details2Item.working_hours;
                                }
                                data_for_meals[aItem.employeeid][aItem.id].total_off_hours += details2Item.working_hours;
                                if (!data_for_meals[aItem.employeeid][aItem.id].wht[details2Item.pay_percentage_name]) data_for_meals[aItem.employeeid][aItem.id].wht[details2Item.pay_percentage_name] = 0;
                                data_for_meals[aItem.employeeid][aItem.id].wht[details2Item.pay_percentage_name] += details2Item.working_hours;
                            }
                        }
                        if (xx.union.length > 0){
                            for (var k = 0; k < xx.remain.length; k++){
                                timeList.unshift(xx.remain[k]);
                            }
                            out_of = true;
                            break;
                        }
                    }
                }
            }
        }
        if (!out_of){
            if (business_tripDic[aItem.employeeid] && business_tripDic[aItem.employeeid][aItem.date]){
                for (var i = 0; i < business_tripDic[aItem.employeeid][aItem.date].length; i++){
                    if (business_tripDic[aItem.employeeid][aItem.date][i].days_portion == "full_workday"){
                        if (aItem.type == ""){
                            var details2Item = getDetails2ItemLeave(shiftContent, aItem.time_in, aItem.time_out, aItem, business_tripDic[aItem.employeeid][aItem.date][i]);
                            if (details2Item){
                                details2Item.shiftContent = shiftContent;
                                details2Item.shiftid = aItem.shiftid;
                                listDetails_2.push(details2Item);
                                data_for_meals[aItem.employeeid][aItem.id].business_trip_hours += details2Item.working_hours;
                                data_for_meals[aItem.employeeid][aItem.id].total_off_hours += details2Item.working_hours;
                                if (!data_for_meals[aItem.employeeid][aItem.id].wht[details2Item.pay_percentage_name]) data_for_meals[aItem.employeeid][aItem.id].wht[details2Item.pay_percentage_name] = 0;
                                data_for_meals[aItem.employeeid][aItem.id].wht[details2Item.pay_percentage_name] += details2Item.working_hours;
                            }
                        }
                        else {
                            listDetails_1.push({
                                timesheetid: timesheetid,
                                employee_peopleid: aItem.employee_peopleid,
                                employeeid: aItem.employeeid,
                                workdate: aItem.date,
                                assignid: aItem.id,
                                intime: aItem.time_in,
                                outtime: aItem.time_out,
                                aIntime: aItem.time_in,
                                aOuttime: aItem.time_out,
                                lastmodifiedtime: new Date(),
                                lastmodified_userid: systemconfig.userid,
                                type: aItem.type,
                                shiftid: aItem.shiftid,
                                business_trip: true
                            });
                        }
                        out_of = true;
                        break;
                    }
                }
                if (!out_of){
                    var business_tripItem;
                    for (var i = 0; i < business_tripDic[aItem.employeeid][aItem.date].length; i++){
                        business_tripItem = business_tripDic[aItem.employeeid][aItem.date][i];
                        var xx = contentModule.splitRange(timeItem, {start: business_tripItem.time_in, end: business_tripItem.time_out});
                        for (var k = 0; k < xx.union.length; k++){
                            if (aItem.type == ""){
                                var details2Item = getDetails2ItemLeave(shiftContent, xx.union[k].start, xx.union[k].end, aItem, business_tripItem);
                                if (details2Item){
                                    details2Item.shiftContent = shiftContent;
                                    details2Item.shiftid = aItem.shiftid;
                                    listDetails_2.push(details2Item);
                                    data_for_meals[aItem.employeeid][aItem.id].business_trip_hours += details2Item.working_hours;
                                    data_for_meals[aItem.employeeid][aItem.id].total_off_hours += details2Item.working_hours;
                                    if (!data_for_meals[aItem.employeeid][aItem.id].wht[details2Item.pay_percentage_name]) data_for_meals[aItem.employeeid][aItem.id].wht[details2Item.pay_percentage_name] = 0;
                                    data_for_meals[aItem.employeeid][aItem.id].wht[details2Item.pay_percentage_name] += details2Item.working_hours;
                                }
                            }
                            else {
                                listDetails_1.push({
                                    timesheetid: timesheetid,
                                    employee_peopleid: aItem.employee_peopleid,
                                    employeeid: aItem.employeeid,
                                    workdate: aItem.date,
                                    assignid: aItem.id,
                                    intime: xx.union[k].start,
                                    outtime: xx.union[k].end,
                                    aIntime: aItem.time_in,
                                    aOuttime: aItem.time_out,
                                    lastmodifiedtime: new Date(),
                                    lastmodified_userid: systemconfig.userid,
                                    type: aItem.type,
                                    shiftid: aItem.shiftid,
                                    business_trip: true
                                });
                            }
                        }
                        if (xx.union.length > 0){
                            for (var k = 0; k < xx.remain.length; k++){
                                timeList.unshift(xx.remain[k]);
                            }
                            out_of = true;
                            break;
                        }
                    }
                }
            }
        }
        if (!out_of){
            timeList2.push(timeItem);
        }
    }
    while (timeList2.length > 0){
        var timeItem = timeList2.shift();
        var employee_logid = aItem.employeeid;
        if (aItem.substitute != 0){
            employee_logid = aItem.substitute;
        }
        if (logsDic[employee_logid] && logsDic[employee_logid][aItem.date]){
            var lItem;
            for (var i = 0; i < logsDic[employee_logid][aItem.date].length; i++){
                lItem = logsDic[employee_logid][aItem.date][i];
                var xx = contentModule.splitRange(timeItem, {start: lItem.intimeMS - new Date(aItem.date*86400000).setHours(0, 0, 0, 0), end: lItem.outtimeMS - new Date(aItem.date*86400000).setHours(0, 0, 0, 0)});
                for (var k = 0; k < xx.union.length; k++){
                    listDetails_1.push({
                        timesheetid: timesheetid,
                        employee_peopleid: aItem.employee_peopleid,
                        employeeid: aItem.employeeid,
                        workdate: aItem.date,
                        assignid: aItem.id,
                        intime: xx.union[k].start,
                        outtime: xx.union[k].end,
                        aIntime: aItem.time_in,
                        aOuttime: aItem.time_out,
                        lastmodifiedtime: new Date(),
                        lastmodified_userid: systemconfig.userid,
                        ot: aItem.ot,
                        shiftid: aItem.shiftid
                    });
                }
                if (xx.union.length > 0){
                    for (var k = 0; k < xx.remain.length; k++){
                        timeList2.unshift(xx.remain[k]);
                    };
                    if (aItem.substitute != 0){
                        if (!listLogsUpdateDic[lItem.id]){
                            listLogsUpdateDic[lItem.id] = true;
                            listLogsUpdate.push({
                                id: lItem.id,
                                substitute_employee_peopleid: aItem.employee_peopleid,
                                substitute_employeeid: aItem.employeeid
                            });
                        }
                    }
                    break;
                }
            }
        }
    }
});
listDetails_1.forEach(function(item, ddddd){
    var shiftContent = contentModule.getContentShiftFollowDateById(host1, item.shiftid, item.workdate);
    var late_checkin_minutes = shiftContent.late_checkin_minutes;
    var early_checkout_minutes = shiftContent.early_checkout_minutes;
    if ((item.intime - item.aIntime) < late_checkin_minutes*60*1000){
        item.intime = item.aIntime;
    }
    if ((item.aOuttime - item.outtime) < early_checkout_minutes*60*1000){
        item.outtime = item.aOuttime;
    }
    if (late_early_checkinDic[item.employeeid] && late_early_checkinDic[item.employeeid][item.workdate]){
        if ((item.intime - item.aIntime) < (late_checkin_minutes + late_early_checkinDic[item.employeeid][item.workdate].late)*60*1000){
            item.intime = item.aIntime;
        }
        if ((item.aOuttime - item.outtime) < (early_checkout_minutes + late_early_checkinDic[item.employeeid][item.workdate].early)*60*1000){
            item.outtime = item.aOuttime;
        }
    }
    var aIndex = assignDic[item.assignid];
    var aItem = host1.database.assign_employee_shifts.items[aIndex];
    var work_day_ratio = contentModule.getShift_work_day_ratioListFollowDateByShiftid(host1, item.shiftid, item.workdate);
    var isCL = false;
    if (compensatory_leaveDic[item.employeeid] && compensatory_leaveDic[item.employeeid][item.workdate]) isCL = true;
    var daytypeDic = contentModule.getDayTypeDicByShiftIdAndDateOfEmployee(host1, item.workdate, item.shiftid, shiftContent, isCL);
    var timeList = [{
        start: item.intime,
        end: item.outtime
    }];
    while (timeList.length > 0) {
        var timeItem = timeList.shift();
        for (var i = 0; i < work_day_ratio.length; i++){
            if (daytypeDic[work_day_ratio[i].day_type]){
                duration_h = contentModule.getOverTimeHoursHasShiftContent(
                    host1,
                    new Date(item.workdate*86400000),
                    new Date(item.workdate*86400000),
                    {
                        dayOffset: work_day_ratio[i].time.dayOffset,
                        duration: work_day_ratio[i].time.duration
                    },
                    shiftContent,
                    aItem.ot_in_breaktime
                );
                if (duration_h == 0) continue;
                var xx = contentModule.splitRange(timeItem, {start: work_day_ratio[i].time.dayOffset, end: work_day_ratio[i].time.dayOffset + work_day_ratio[i].time.duration});
                for (var k = 0; k < xx.union.length; k++){
                    duration_h = contentModule.getOverTimeHoursHasShiftContent(
                        host1,
                        new Date(item.workdate*86400000),
                        new Date(item.workdate*86400000),
                        {
                            dayOffset: xx.union[k].start,
                            duration: xx.union[k].end - xx.union[k].start
                        },
                        shiftContent,
                        aItem.ot_in_breaktime
                    );
                    var duration_h1 = duration_h;
                    if (duration_h > 0){
                        workdays = (duration_h*work_day_ratio[i].ratio/(shiftContent.number_of_standard_working_hours*100))*shiftContent.number_of_work_days;
                        listDetails_2.push({
                            timesheetid: item.timesheetid,
                            employee_peopleid: item.employee_peopleid,
                            employeeid: item.employeeid,
                            workdate: item.workdate,
                            assignid: item.assignid,
                            shift_work_day_ratioid: work_day_ratio[i].id,
                            workdays: workdays,
                            intime:  xx.union[k].start,
                            outtime: xx.union[k].end,
                            lastmodifiedtime: new Date(),
                            lastmodified_userid: systemconfig.userid,
                            ot_in_breaktime: aItem.ot_in_breaktime,
                            working_hours: duration_h1,
                            pay_percentageid: work_day_ratio[i].pay_percentageid,
                            task: "shift",
                            taskid: item.shiftid,
                            shiftContent: shiftContent,
                            shiftid: item.shiftid,
                        });
                        if (item.business_trip){
                            data_for_meals[aItem.employeeid][aItem.id].business_trip_hours += duration_h1;
                            data_for_meals[aItem.employeeid][aItem.id].total_off_hours += duration_h1;
                        }
                        else {
                            data_for_meals[aItem.employeeid][aItem.id].work_hours += duration_h1;
                        }
                        if (!data_for_meals[aItem.employeeid][aItem.id].wht[work_day_ratio[i].pay_percentage_name]) data_for_meals[aItem.employeeid][aItem.id].wht[work_day_ratio[i].pay_percentage_name] = 0;
                        data_for_meals[aItem.employeeid][aItem.id].wht[work_day_ratio[i].pay_percentage_name] += duration_h1;
                        if (!data_for_meals[aItem.employeeid][aItem.id].whc[work_day_ratio[i].code]) data_for_meals[aItem.employeeid][aItem.id].whc[work_day_ratio[i].code] = 0;
                        data_for_meals[aItem.employeeid][aItem.id].whc[work_day_ratio[i].code] += duration_h1;
                    }
                }
                if (xx.union.length > 0){
                    for (var k = 0; k < xx.remain.length; k++){
                        timeList.unshift(xx.remain[k]);
                    }
                    break;
                }
            }
        }
    }
});
var l2 = {};
var workday_meals = {};
for (var employeeid in data_for_meals){
    workday_meals[employeeid] = [];
    if (!l2[employeeid]){
        l2[employeeid] = {
            id: host1.timesheet_employeesDic[employeeid].id,
            meals: 0
        };
    }
    for (var assignid in data_for_meals[employeeid]){
        var shiftid = data_for_meals[employeeid][assignid].shiftid;
        hr.data_for_meals = data_for_meals[employeeid][assignid];
        if (shift_meal_rulesDic.result[shiftid]){
            if (shift_meal_rulesDic.temp[shiftid]){
                shift_meal_rulesDic.temp[shiftid].indexList.forEach(function(index){
                    hr.data_for_meals[shift_meal_rulesDic.temp[shiftid].list[index].code] = shift_meal_rulesDic.temp[shiftid].list[index].content.calc(function(varname){
                        return hr.data_for_meals[varname];
                    });
                });
            }
            shift_meal_rulesDic.result[shiftid].forEach(function(item){
                var meals = item.content.calc(function(varname){
                    return hr.data_for_meals[varname];
                });
                if (meals > 0){
                    workday_meals[employeeid].push({
                        timesheetid: timesheetid,
                        employeeid: employeeid,
                        employee_peopleid: data_for_meals[employeeid][assignid].employee_peopleid,
                        workdate: data_for_meals[employeeid][assignid].date,
                        task: "shift",
                        name: item.name,
                        shiftid: shiftid,
                        mealid: item.id,
                        meals: meals,
                        lastmodifiedtime: new Date(),
                        lastmodified_userid: systemconfig.userid
                    });
                    l2[employeeid].meals += meals;
                }
            });
        }
    }
}
for (var i = 0; i < employeeIdList.length; i++){
    if (!l2[employeeIdList[i]]) {
        l2[employeeIdList[i]] = {
            id: host1.timesheet_employeesDic[employeeIdList[i]].id,
            meals: 0
        };
    }
}
host.content = {
    employeeIdList: employeeIdList,
    timesheet_employees: l2,
    workday_meals: workday_meals,
    listLogsUpdate: listLogsUpdate
};
host.result = true;
host.finished = true;
return retval;

}
} (module, retval, core);
// function: hrprocesses.data.timesheet.saveMeals
var v199 = function(module, me, core) {
return function (timesheetid, employeeIdList, dataWorkdays) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
var dataList = [];
var dataWorkdays1;
var employeeIdList1;
for (var i = 0; i < dataWorkdays.employeeIdList.length; i++){
    if (i%20 == 0){
        employeeIdList1 = [];
        dataWorkdays1 = {
            timesheet_employees: [],
            workday_meals: []
        };
        dataList.push({
            employeeIdList: employeeIdList1,
            timesheetid: timesheetid,
            dataWorkdays: dataWorkdays1
        });
    }
    if (i == 0){
        dataWorkdays1.listLogsUpdate = dataWorkdays.listLogsUpdate;
    }
    if (dataWorkdays.timesheet_employees[dataWorkdays.employeeIdList[i]]) dataWorkdays1.timesheet_employees.push(dataWorkdays.timesheet_employees[dataWorkdays.employeeIdList[i]]);
    if (dataWorkdays.workday_meals[dataWorkdays.employeeIdList[i]]) dataWorkdays1.workday_meals = dataWorkdays1.workday_meals.concat(dataWorkdays.workday_meals[dataWorkdays.employeeIdList[i]]);
    employeeIdList1.push(dataWorkdays.employeeIdList[i]);
}
var finished = dataList.reduce(function(ac, item) {
    return ac.then(function(){
        return new Promise(function(resolve) {
            core.exec("timesheet.saveMeals", item, function (success, content) {
                if (success){
                    resolve();
                }
                else {
                    console.log(content);
                }

            });
        })
    });
}, Promise.resolve());
finished.then(function(){
    host.content = true;
    host.result = "ok";
    host.finished = true;
});
return retval;

}
} (module, retval, core);
// function: hrprocesses.data.timesheet.saveWorkdays
var v190 = function(module, me, core) {
return function (timesheetid, employeeIdList, dataWorkdays) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
var dataList = [];
var dataWorkdays1;
var employeeIdList1;
for (var i = 0; i < dataWorkdays.employeeIdList.length; i++){
    if (i%20 == 0){
        employeeIdList1 = [];
        dataWorkdays1 = {
            timesheet_employees: [],
            workday_details_1: [],
            workday_details_2: [],
            workday_details_3: []
        };
        dataList.push({
            employeeIdList: employeeIdList1,
            timesheetid: timesheetid,
            dataWorkdays: dataWorkdays1
        });
    }
    if (i == 0){
        dataWorkdays1.listLogsUpdate = dataWorkdays.listLogsUpdate;
    }
    if (dataWorkdays.timesheet_employees[dataWorkdays.employeeIdList[i]]) dataWorkdays1.timesheet_employees.push(dataWorkdays.timesheet_employees[dataWorkdays.employeeIdList[i]]);
    if (dataWorkdays.workday_details_1[dataWorkdays.employeeIdList[i]]) dataWorkdays1.workday_details_1 = dataWorkdays1.workday_details_1.concat(dataWorkdays.workday_details_1[dataWorkdays.employeeIdList[i]]);
    if (dataWorkdays.workday_details_2[dataWorkdays.employeeIdList[i]]) dataWorkdays1.workday_details_2 = dataWorkdays1.workday_details_2.concat(dataWorkdays.workday_details_2[dataWorkdays.employeeIdList[i]]);
    if (dataWorkdays.workday_details_3[dataWorkdays.employeeIdList[i]]) dataWorkdays1.workday_details_3 = dataWorkdays1.workday_details_3.concat(dataWorkdays.workday_details_3[dataWorkdays.employeeIdList[i]]);
    employeeIdList1.push(dataWorkdays.employeeIdList[i]);
}
var finished = dataList.reduce(function(ac, item) {
    return ac.then(function(){
        return new Promise(function(resolve) {
            core.exec("timesheet.saveWorkdays", item, function (success, content) {
                if (success){
                    resolve();
                }
                else {
                    console.log(content);
                }

            });
        })
    });
}, Promise.resolve());
finished.then(function(){
    host.content = true;
    host.result = "ok";
    host.finished = true;
});
return retval;

}
} (module, retval, core);
// function: hrprocesses.data.timesheet.workCalculation
var v181 = function(module, me, core) {
return function (content, timesheetid) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
var host1 = {database: {}};
var timesheetid = content.timesheetid;
var employeeIdList = content.employeeIdList;
delete content.employeeIdList;
delete content.timesheetid;
contentModule.makeDatabaseContent(host1, content);
var leave_policiesDic = contentModule.makeDictionaryIndex(host1.database.leave_policies.items);
host1.timesheet_employeesDic = {};
host1.database.timesheet_employees.items.forEach(function(item){
    host1.timesheet_employeesDic[item.employeeid] = item;
});
for (var i = 0; i < host1.database.worktime_logs.items.length; i++){
    host1.database.worktime_logs.items[i].date = contentModule.getDateFrom1970(host1.database.worktime_logs.items[i].intime);
}
host1.database.worktime_logs.items.forEach(function(item){
    item.intimeMS = item.intime.getTime();
    item.outtimeMS = item.outtime.getTime();
});
host1.database.assign_employee_shifts.items.forEach(function(item){
    item.intimeMS = new Date(item.date*86400000).setHours(0, 0, 0, 0) + item.time_in;
    item.outtimeMS = new Date(item.date*86400000).setHours(0, 0, 0, 0) + item.time_out;
});
host1.database.assign_employee_shifts.items.sort(function(a, b){
    if (a.employeeid == b.employeeid) return a.date - b.date;
    return a.employeeid - b.employeeid;
});
var logsDic = {};
host1.database.worktime_logs.items.forEach(function (item){
    if (!logsDic[item.employeeid]) logsDic[item.employeeid] = {};
    if (!logsDic[item.employeeid][item.date]) logsDic[item.employeeid][item.date] = [];
    logsDic[item.employeeid][item.date].push(item);
});
contentModule.makeShift_work_day_ratioData(host1);
contentModule.makeShiftsData(host1);
host1.database.shifts.items.sort(function(a, b){
    return b.fromdate - a.fromdate;
});
host1.database.shift_work_day_ratio.items.sort(function(a, b){
    return a.windex - b.windex;
});
host1.shiftDic = contentModule.makeDictionaryIndex(host1.database.shifts.items);
host1.database.shifts.items.forEach(function(item){
    item.ratioIndexList = [];
});
host1.database.shift_work_day_ratio.items.forEach(function(item, index){
    item.time = EncodingClass.string.toVariable(item.time);
    var k = host1.shiftDic[item.shiftid];
    if (k >= 0){
        host1.database.shifts.items[k].ratioIndexList.push(index);
    }
});
host1.database.holidays.items.forEach(function(item){
    item.startdate = contentModule.getDateFrom1970(item.timestart);
    item.enddate = contentModule.getDateFrom1970(item.timeend);
});
var holidaysDic = contentModule.makeDictionaryIndex(host1.database.holidays.items);
host1.shift_holidayDic = {};
host1.database.shift_holidays.items.forEach(function(item){
    var hIndex = holidaysDic[item.holidayid];
    if (hIndex >= 0){
        if (item.shiftid == 0){
            host1.database.shifts.items.forEach(function(sItem){
                if (!host1.shift_holidayDic[sItem.id]) host1.shift_holidayDic[sItem.id] = [];
                host1.shift_holidayDic[sItem.id].push(host1.database.holidays.items[hIndex]);
            });
            return;
        }
        if (!host1.shift_holidayDic[item.shiftid]) host1.shift_holidayDic[item.shiftid] = [];
        host1.shift_holidayDic[item.shiftid].push(host1.database.holidays.items[hIndex]);
    }
});
var holidaysDateDic = {};
host1.database.holidays.items.forEach(function(item){
    if (!item.available) return;
    for (var d = absol.datetime.beginOfDay(item.timestart); absol.datetime.compareDate(d, item.timeend) <= 0; d = absol.datetime.nextDate(d)){
        if (!holidaysDateDic[contentModule.getDateFrom1970(d)]) holidaysDateDic[contentModule.getDateFrom1970(d)] = [];
        holidaysDateDic[contentModule.getDateFrom1970(d)].push(item);
    }
});
var late_early_checkinDic = {};
host1.database.late_early_checkin_request.items.forEach(function(item){
    item.fromdateInt = contentModule.getDateFrom1970(item.fromdate);
    item.todateInt = contentModule.getDateFrom1970(item.todate);
    if (!late_early_checkinDic[item.employeeid]) late_early_checkinDic[item.employeeid] = {};
    for (var i = item.fromdateInt; i <= item.todateInt; i++){
        if (!late_early_checkinDic[item.employeeid][i]){
            late_early_checkinDic[item.employeeid][i] = {
                late: item.late,
                early: item.early
            };
        }
        else {
            if (late_early_checkinDic[item.employeeid][i].late < item.late) item.late = late_early_checkinDic[item.employeeid][i].late;
            if (late_early_checkinDic[item.employeeid][i].early < item.early) item.early = late_early_checkinDic[item.employeeid][i].early;
        }
    }
});
var assignDic = contentModule.makeDictionaryIndex(host1.database.assign_employee_shifts.items);
var listDetails_1 = [];
var listDetails_2 = [];
host1.database.timesheet_employees.items.forEach(function(item){
    for (var i = item.startdate; i <= item.enddate; i++){
        if (!holidaysDateDic[i]) continue;
        for (var j = 0; j < holidaysDateDic[i].length; j++){
            if (holidaysDateDic[i][j].type == "holiday"){
                listDetails_2.push({
                    timesheetid: item.timesheetid,
                    employee_peopleid: item.employee_peopleid,
                    employeeid: item.employeeid,
                    workdate: i,
                    task: "holiday",
                    taskid: holidaysDateDic[i][j].id,
                    pay_percentageid: holidaysDateDic[i][j].pay_percentageid,
                    assignid: 0,
                    shift_work_day_ratioid: 0,
                    workdays: 1,
                    intime: 0,
                    outtime: 0,
                    lastmodifiedtime: new Date(),
                    lastmodified_userid: systemconfig.userid,
                    ot_in_breaktime: 0,
                    working_hours: 0,
                    shiftid: 0
                });

                break;
            }
        }
    }
});
var business_tripDic = {};
var otherLeaveDic = {};
var compensatory_leaveDic = {};
host1.database.assign_employee_shifts.items.forEach(function(aItem){
    if (host1.timesheet_employeesDic[aItem.employeeid].startdate > aItem.date) return;
    if (host1.timesheet_employeesDic[aItem.employeeid].enddate < aItem.date) return;
    if (aItem.type == "cl"){
        if (!compensatory_leaveDic[aItem.employeeid]) compensatory_leaveDic[aItem.employeeid] = {};
        if (!compensatory_leaveDic[aItem.employeeid][aItem.date]) compensatory_leaveDic[aItem.employeeid][aItem.date] = [];
        compensatory_leaveDic[aItem.employeeid][aItem.date].push(aItem);
    }
    else if (aItem.type == "hrp"){
        var pIndex = leave_policiesDic[aItem.policyid];
        if (pIndex >= 0){
            if (host1.database.leave_policies.items[pIndex].work_paid){
                aItem.pay_percentageid = host1.database.leave_policies.items[pIndex].pay_percentage;
                var pay_percentageIndex = host1.database.pay_percentage.getIndex(aItem.pay_percentageid);
                if (pay_percentageIndex >= 0){
                    aItem.pay_percentage_ratio = host1.database.pay_percentage.items[pay_percentageIndex].percentage;
                    aItem.pay_percentage_name =  host1.database.pay_percentage.items[pay_percentageIndex].name;
                }
                else {
                    aItem.pay_percentage_ratio = 0;
                    aItem.pay_percentage_name = "";
                }
                if (host1.database.leave_policies.items[pIndex].groupid == -2){
                    if (!business_tripDic[aItem.employeeid]) business_tripDic[aItem.employeeid] = {};
                    if (!business_tripDic[aItem.employeeid][aItem.date]) business_tripDic[aItem.employeeid][aItem.date] = [];
                    business_tripDic[aItem.employeeid][aItem.date].push(aItem);
                }
                else {
                    if (!otherLeaveDic[aItem.employeeid]) otherLeaveDic[aItem.employeeid] = {};
                    if (!otherLeaveDic[aItem.employeeid][aItem.date]) otherLeaveDic[aItem.employeeid][aItem.date] = [];
                    aItem.annual_leave = host1.database.leave_policies.items[pIndex].groupid == -1;
                    otherLeaveDic[aItem.employeeid][aItem.date].push(aItem);
                }
            }
        }
    }
});
var getDetails2ItemLeave = function(shiftContent, time_in, time_out, aItem, policyData){
    var working_hours = contentModule.getOverTimeHoursHasShiftContent(
        host1,
        new Date(aItem.date*86400000),
        new Date(aItem.date*86400000),
        {
            dayOffset: time_in,
            duration: time_out - time_in
        },
        shiftContent,
        false
    );
    var working_hours1 = working_hours;
    if (working_hours > 0){
        var workdays = (working_hours/shiftContent.number_of_standard_working_hours)*(policyData.pay_percentage_ratio/100)
        return {
            timesheetid: timesheetid,
            employee_peopleid: aItem.employee_peopleid,
            employeeid: aItem.employeeid,
            workdate: aItem.date,
            task: "hrp",
            taskid: policyData.policyid,
            pay_percentageid: policyData.pay_percentageid,
            pay_percentage_name: policyData.pay_percentage_name,
            assignid: aItem.id,
            shift_work_day_ratioid: 0,
            workdays: workdays,
            intime: time_in,
            outtime: time_out,
            lastmodifiedtime: new Date(),
            lastmodified_userid: systemconfig.userid,
            ot_in_breaktime: aItem.ot_in_breaktime,
            working_hours: working_hours1
        };
    }
};
var listLogsUpdate = [];
var listLogsUpdateDic = {};
host1.database.assign_employee_shifts.items.forEach(function(aItem){
    if (aItem.type != "" && aItem.type != "ot") return;
    if (host1.timesheet_employeesDic[aItem.employeeid].startdate > aItem.date) return;
    if (host1.timesheet_employeesDic[aItem.employeeid].enddate < aItem.date) return;
    var shiftContent = contentModule.getContentShiftFollowDateById(host1, aItem.shiftid, aItem.date);
    if (!shiftContent) return;
    var timeList2 = [];
    var timeList = [{
        start: aItem.time_in,
        end: aItem.time_out
    }];
    while (timeList.length > 0) {
        var out_of = false;
        var timeItem = timeList.shift();
        if (aItem.type == ""){
            if (otherLeaveDic[aItem.employeeid] && otherLeaveDic[aItem.employeeid][aItem.date]){
                for (var i = 0; i < otherLeaveDic[aItem.employeeid][aItem.date].length; i++){
                    if (otherLeaveDic[aItem.employeeid][aItem.date][i].days_portion == "full_workday"){
                        var details2Item = getDetails2ItemLeave(shiftContent, aItem.time_in, aItem.time_out, aItem, otherLeaveDic[aItem.employeeid][aItem.date][i]);
                        if (details2Item){
                            details2Item.shiftContent = shiftContent;
                            details2Item.shiftid = aItem.shiftid;
                            listDetails_2.push(details2Item);
                        }
                        out_of = true;
                        break;
                    }
                }
                if (!out_of){
                    var leaveItem;
                    for (var i = 0; i < otherLeaveDic[aItem.employeeid][aItem.date].length; i++){
                        leaveItem = otherLeaveDic[aItem.employeeid][aItem.date][i];
                        var xx = contentModule.splitRange(timeItem, {start: leaveItem.time_in, end: leaveItem.time_out});
                        for (var k = 0; k < xx.union.length; k++){
                            var details2Item = getDetails2ItemLeave(shiftContent, xx.union[i].start, xx.union[i].end, aItem, leaveItem);
                            if (details2Item){
                                details2Item.shiftContent = shiftContent;
                                details2Item.shiftid = aItem.shiftid;
                                listDetails_2.push(details2Item);
                            }
                        }
                        if (xx.union.length > 0){
                            for (var k = 0; k < xx.remain.length; k++){
                                timeList.unshift(xx.remain[k]);
                            }
                            out_of = true;
                            break;
                        }
                    }
                }
            }
        }
        if (!out_of){
            if (business_tripDic[aItem.employeeid] && business_tripDic[aItem.employeeid][aItem.date]){
                for (var i = 0; i < business_tripDic[aItem.employeeid][aItem.date].length; i++){
                    if (business_tripDic[aItem.employeeid][aItem.date][i].days_portion == "full_workday"){
                        if (aItem.type == ""){
                            var details2Item = getDetails2ItemLeave(shiftContent, aItem.time_in, aItem.time_out, aItem, business_tripDic[aItem.employeeid][aItem.date][i]);
                            if (details2Item){
                                details2Item.shiftContent = shiftContent;
                                details2Item.shiftid = aItem.shiftid;
                                listDetails_2.push(details2Item);
                            }
                        }
                        else {
                            listDetails_1.push({
                                timesheetid: timesheetid,
                                employee_peopleid: aItem.employee_peopleid,
                                employeeid: aItem.employeeid,
                                workdate: aItem.date,
                                assignid: aItem.id,
                                intime: aItem.time_in,
                                outtime: aItem.time_out,
                                aIntime: aItem.time_in,
                                aOuttime: aItem.time_out,
                                lastmodifiedtime: new Date(),
                                lastmodified_userid: systemconfig.userid,
                                type: aItem.type,
                                shiftid: aItem.shiftid,
                                business_trip: true
                            });
                        }
                        out_of = true;
                        break;
                    }
                }
                if (!out_of){
                    var business_tripItem;
                    for (var i = 0; i < business_tripDic[aItem.employeeid][aItem.date].length; i++){
                        business_tripItem = business_tripDic[aItem.employeeid][aItem.date][i];
                        var xx = contentModule.splitRange(timeItem, {start: business_tripItem.time_in, end: business_tripItem.time_out});
                        for (var k = 0; k < xx.union.length; k++){
                            if (aItem.type == ""){
                                var details2Item = getDetails2ItemLeave(shiftContent, xx.union[k].start, xx.union[k].end, aItem, business_tripItem);
                                if (details2Item){
                                    details2Item.shiftContent = shiftContent;
                                    details2Item.shiftid = aItem.shiftid;
                                    listDetails_2.push(details2Item);
                                }
                            }
                            else {
                                listDetails_1.push({
                                    timesheetid: timesheetid,
                                    employee_peopleid: aItem.employee_peopleid,
                                    employeeid: aItem.employeeid,
                                    workdate: aItem.date,
                                    assignid: aItem.id,
                                    intime: xx.union[k].start,
                                    outtime: xx.union[k].end,
                                    aIntime: aItem.time_in,
                                    aOuttime: aItem.time_out,
                                    lastmodifiedtime: new Date(),
                                    lastmodified_userid: systemconfig.userid,
                                    type: aItem.type,
                                    shiftid: aItem.shiftid,
                                    business_trip: true
                                });
                            }
                        }
                        if (xx.union.length > 0){
                            for (var k = 0; k < xx.remain.length; k++){
                                timeList.unshift(xx.remain[k]);
                            }
                            out_of = true;
                            break;
                        }
                    }
                }
            }
        }
        if (!out_of){
            timeList2.push(timeItem);
        }
    }
    while (timeList2.length > 0){
        var timeItem = timeList2.shift();
        var employee_logid = aItem.employeeid;
        if (aItem.substitute != 0){
            employee_logid = aItem.substitute;
        }
        if (logsDic[employee_logid] && logsDic[employee_logid][aItem.date]){
            var lItem;
            for (var i = 0; i < logsDic[employee_logid][aItem.date].length; i++){
                lItem = logsDic[employee_logid][aItem.date][i];
                var xx = contentModule.splitRange(timeItem, {start: lItem.intimeMS - new Date(aItem.date*86400000).setHours(0, 0, 0, 0), end: lItem.outtimeMS - new Date(aItem.date*86400000).setHours(0, 0, 0, 0)});
                for (var k = 0; k < xx.union.length; k++){
                    listDetails_1.push({
                        timesheetid: timesheetid,
                        employee_peopleid: aItem.employee_peopleid,
                        employeeid: aItem.employeeid,
                        workdate: aItem.date,
                        assignid: aItem.id,
                        intime: xx.union[k].start,
                        outtime: xx.union[k].end,
                        aIntime: aItem.time_in,
                        aOuttime: aItem.time_out,
                        lastmodifiedtime: new Date(),
                        lastmodified_userid: systemconfig.userid,
                        ot: aItem.ot,
                        shiftid: aItem.shiftid
                    });
                }
                if (xx.union.length > 0){
                    for (var k = 0; k < xx.remain.length; k++){
                        timeList2.unshift(xx.remain[k]);
                    };
                    if (aItem.substitute != 0){
                        if (!listLogsUpdateDic[lItem.id]){
                            listLogsUpdateDic[lItem.id] = true;
                            listLogsUpdate.push({
                                id: lItem.id,
                                substitute_employee_peopleid: aItem.employee_peopleid,
                                substitute_employeeid: aItem.employeeid
                            });
                        }
                    }
                    break;
                }
            }
        }
    }
});
listDetails_1.forEach(function(item, ddddd){
    var shiftContent = contentModule.getContentShiftFollowDateById(host1, item.shiftid, item.workdate);
    var late_checkin_minutes = shiftContent.late_checkin_minutes;
    var early_checkout_minutes = shiftContent.early_checkout_minutes;
    if ((item.intime - item.aIntime) < late_checkin_minutes*60*1000){
        item.intime = item.aIntime;
    }
    if ((item.aOuttime - item.outtime) < early_checkout_minutes*60*1000){
        item.outtime = item.aOuttime;
    }
    if (late_early_checkinDic[item.employeeid] && late_early_checkinDic[item.employeeid][item.workdate]){
        if ((item.intime - item.aIntime) < (late_checkin_minutes + late_early_checkinDic[item.employeeid][item.workdate].late)*60*1000){
            item.intime = item.aIntime;
        }
        if ((item.aOuttime - item.outtime) < (early_checkout_minutes + late_early_checkinDic[item.employeeid][item.workdate].early)*60*1000){
            item.outtime = item.aOuttime;
        }
    }
    var aIndex = assignDic[item.assignid];
    var aItem = host1.database.assign_employee_shifts.items[aIndex];
    var work_day_ratio = contentModule.getShift_work_day_ratioListFollowDateByShiftid(host1, item.shiftid, item.workdate);
    var isCL = false;
    if (compensatory_leaveDic[item.employeeid] && compensatory_leaveDic[item.employeeid][item.workdate]) isCL = true;
    var daytypeDic = contentModule.getDayTypeDicByShiftIdAndDateOfEmployee(host1, item.workdate, item.shiftid, shiftContent, isCL);
    var timeList = [{
        start: item.intime,
        end: item.outtime
    }];
    while (timeList.length > 0) {
        var timeItem = timeList.shift();
        for (var i = 0; i < work_day_ratio.length; i++){
            if (daytypeDic[work_day_ratio[i].day_type]){
                duration_h = contentModule.getOverTimeHoursHasShiftContent(
                    host1,
                    new Date(item.workdate*86400000),
                    new Date(item.workdate*86400000),
                    {
                        dayOffset: work_day_ratio[i].time.dayOffset,
                        duration: work_day_ratio[i].time.duration
                    },
                    shiftContent,
                    aItem.ot_in_breaktime
                );
                if (duration_h == 0) continue;
                var xx = contentModule.splitRange(timeItem, {start: work_day_ratio[i].time.dayOffset, end: work_day_ratio[i].time.dayOffset + work_day_ratio[i].time.duration});
                for (var k = 0; k < xx.union.length; k++){
                    duration_h = contentModule.getOverTimeHoursHasShiftContent(
                        host1,
                        new Date(item.workdate*86400000),
                        new Date(item.workdate*86400000),
                        {
                            dayOffset: xx.union[k].start,
                            duration: xx.union[k].end - xx.union[k].start
                        },
                        shiftContent,
                        aItem.ot_in_breaktime
                    );
                    var duration_h1 = duration_h;
                    if (duration_h > 0){
                        workdays = (duration_h*work_day_ratio[i].ratio/(shiftContent.number_of_standard_working_hours*100))*shiftContent.number_of_work_days;
                        listDetails_2.push({
                            timesheetid: item.timesheetid,
                            employeeid: item.employeeid,
                            employee_peopleid: item.employee_peopleid,
                            workdate: item.workdate,
                            assignid: item.assignid,
                            shift_work_day_ratioid: work_day_ratio[i].id,
                            workdays: workdays,
                            intime:  xx.union[k].start,
                            outtime: xx.union[k].end,
                            lastmodifiedtime: new Date(),
                            lastmodified_userid: systemconfig.userid,
                            ot_in_breaktime: aItem.ot_in_breaktime,
                            working_hours: duration_h1,
                            pay_percentageid: work_day_ratio[i].pay_percentageid,
                            task: "shift",
                            taskid: item.shiftid,
                            shiftContent: shiftContent,
                            shiftid: item.shiftid,
                        });
                    }
                }
                if (xx.union.length > 0){
                    for (var k = 0; k < xx.remain.length; k++){
                        timeList.unshift(xx.remain[k]);
                    }
                    break;
                }
            }
        }
    }
});

var dic = {};
var listDetails_k = {};
listDetails_2.forEach(function(item){
    item = EncodingClass.string.duplicate(item);
    if (!listDetails_k[item.employeeid]){
        listDetails_k[item.employeeid] = {};
        dic[item.employeeid] = {};
    }
    if (!listDetails_k[item.employeeid][item.workdate]){
        listDetails_k[item.employeeid][item.workdate] = [];
        dic[item.employeeid][item.workdate] = {};
    }
    if (dic[item.employeeid][item.workdate][item.shiftid + "_" + item.pay_percentageid] === undefined) dic[item.employeeid][item.workdate][item.shiftid + "_" + item.pay_percentageid] = -1;
    if (dic[item.employeeid][item.workdate][item.shiftid + "_" + item.pay_percentageid] >= 0){
        listDetails_k[item.employeeid][item.workdate][dic[item.employeeid][item.workdate][item.shiftid + "_" + item.pay_percentageid]].working_hours += item.working_hours;
        listDetails_k[item.employeeid][item.workdate][dic[item.employeeid][item.workdate][item.shiftid + "_" + item.pay_percentageid]].workdays += item.workdays;
    }
    else {
        if (item.pay_percentageid == -1 && item.shiftContent) item.rt100 = true;
        dic[item.employeeid][item.workdate][item.shiftid + "_" + item.pay_percentageid] = listDetails_k[item.employeeid][item.workdate].length;
        listDetails_k[item.employeeid][item.workdate].push(item);
    }
});
var l2 = {};
var listDetails_3 = [];
for (var employeeid in listDetails_k){
    l2[employeeid] = {
        id: host1.timesheet_employeesDic[employeeid].id,
        workdays: 0
    };
    for (var workdate in listDetails_k[employeeid]){
        var workdays = 0;
        for (var i = 0; i < listDetails_k[employeeid][workdate].length; i++){
            if (listDetails_k[employeeid][workdate][i].rt100){
                var shiftContent = listDetails_k[employeeid][workdate][i].shiftContent;
                var working_hours = listDetails_k[employeeid][workdate][i].working_hours;
                if (shiftContent.workdays_accumulation_method == "by_actual_working_time"){
                    if (working_hours*60 < shiftContent.minimum_working_minutes_required_for_salary_calculation) working_hours = 0;
                    if (working_hours < shiftContent.number_of_standard_working_hours && working_hours >= shiftContent.round_to_one_days_wage){
                        working_hours = shiftContent.number_of_standard_working_hours;
                    }
                }
                else {
                    var block_duration = shiftContent.block_duration;
                    var x = working_hours*60*60*1000/(block_duration*60*1000);
                    if (shiftContent.block_rounding_method == "round_up"){
                        working_hours = Math.ceil(x);
                    }
                    else {
                        working_hours = Math.floor(x);
                    }
                }
                listDetails_k[employeeid][workdate][i].workdays = (working_hours/shiftContent.number_of_standard_working_hours)*shiftContent.number_of_work_days;
                listDetails_k[employeeid][workdate][i].working_hours = working_hours;
            }
            listDetails_3.push({
                timesheetid: timesheetid,
                shiftid: listDetails_k[employeeid][workdate][i].shiftid,
                pay_percentageid: listDetails_k[employeeid][workdate][i].pay_percentageid,
                employee_peopleid: listDetails_k[employeeid][workdate][i].employee_peopleid,
                employeeid: employeeid,
                workdate: workdate,
                workdays: listDetails_k[employeeid][workdate][i].workdays,
                working_hours: listDetails_k[employeeid][workdate][i].working_hours
            });
            workdays += listDetails_k[employeeid][workdate][i].workdays;
        }
        l2[employeeid].workdays += workdays;
    }
}
var workday_details_1 = {};
listDetails_1.forEach(function(item){
    if (!workday_details_1[item.employeeid]) workday_details_1[item.employeeid] = [];
    workday_details_1[item.employeeid].push(item);
});
var workday_details_2 = {};
listDetails_2.forEach(function(item){
    if (!workday_details_2[item.employeeid]) workday_details_2[item.employeeid] = [];
    workday_details_2[item.employeeid].push(item);
});
var workday_details_3 = {};
listDetails_3.forEach(function(item){
    if (!workday_details_3[item.employeeid]) workday_details_3[item.employeeid] = [];
    workday_details_3[item.employeeid].push(item);
});
host.content = {
    employeeIdList: employeeIdList,
    timesheet_employees: l2,
    workday_details_1: workday_details_1,
    workday_details_2: workday_details_2,
    workday_details_3: workday_details_3,
    listLogsUpdate: listLogsUpdate
};
host.result = true;
host.finished = true;
return retval;

}
} (module, retval, core);
retval.loadDataForMealsCalculation = v198;
retval.loadDataForTimeKeeping = v180;
retval.mealsCalculation = v200;
retval.saveMeals = v199;
retval.saveWorkdays = v190;
retval.workCalculation = v181;
return retval;
}
} (module, v96)) ();
// node: hrprocesses.data.users
var v95 = (function (module, core) { return function () {
var retval = {};
// function: hrprocesses.data.users.read
var v98 = function(module, me, core) {
return function (forceReload) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
if (forceReload === undefined) forceReload = false;
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
if (!forceReload) {
    if (core.users !== undefined) {
        host.content = EncodingClass.string.duplicate(core.users);
        host.result = true;
        host.finished = true;
        return retval;
    }
}
core.exec("users.read", {}, function (host) {
    return function (success, content) {
        var keys, i, n, id;
        if (success) core.users = content;
        host.content = EncodingClass.string.duplicate(content);
        host.result = success;
        host.finished = true;
    }
} (host));
return retval;
}
} (module, retval, core);
// function: hrprocesses.data.users.write
var v104 = function(module, me, core) {
return function (content) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
core.exec("users.write", content, function (host) {
    return function (success, content) {
        host.content = EncodingClass.string.duplicate(content);
        host.result = success;
        host.finished = true;
    }
} (host));
return retval;
}
} (module, retval, core);
retval.read = v98;
retval.write = v104;
return retval;
}
} (module, v96)) ();
// node: hrprocesses.data.worktime
var v184 = (function (module, core) { return function () {
var retval = {};
// function: hrprocesses.data.worktime.confirmDataCheckins
var v185 = function(module, me, core) {
return function (checkinsList) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
console.log(checkinsList);
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
console.log(checkinsList);
ModalElement.show_loading();
core.exec("worktime.load_orgs_emps_worktime_machine_list", {}, function (host) {
    return function (success, content) {
        ModalElement.close(-1);
        if (success){
            var changeData = false;
            var keys, i, n, id;
            var host1 = {database: {}};
            contentModule.makeDatabaseContent(host1, content);
            contentModule.makeOrgsIndex(host1);
            contentModule.makeEmployeeData(host1);
            contentModule.makeEmployeesIndex(host1);
            var employeeDic = contentModule.makeDictionaryIndex(host1.database.employees.items);
            var orgDic = contentModule.makeDictionaryIndex(host1.database.orgs.items);
            var machineDic = contentModule.makeDictionaryIndex(host1.database.worktime_machines.items);
            var queue = [];
            var node;
            for (var employeeid in checkinsList){
                var eIndex = employeeDic[employeeid];
                if (eIndex >= 0){
                    node = {
                        data: host1.database.employees.items[eIndex],
                        children: [],
                        type: 'emp',
                        id: employeeid,
                        text: absol.string.nonAccentVietnamese(host1.database.employees.items[eIndex].fullname.toLowerCase())
                    };
                    queue.push(node);
                }
            }
            var getParent = function(type, data){
                var pIndex;
                switch (type) {
                    case "org":
                        if (data.parentid == 0) return null;
                        pIndex = orgDic[data.parentid];
                        return {
                            data: host1.database.orgs.items[pIndex],
                            children: [],
                            type: "org",
                            id: - host1.database.orgs.items[pIndex].id,
                            text: absol.string.nonAccentVietnamese(host1.database.orgs.items[pIndex].name.toLowerCase())
                        };
                    case "emp":
                        pIndex = orgDic[data.orgid];
                        return {
                            data: host1.database.orgs.items[pIndex],
                            children: [],
                            type: "org",
                            id: - host1.database.orgs.items[pIndex].id,
                            text: absol.string.nonAccentVietnamese(host1.database.orgs.items[pIndex].name.toLowerCase())
                        };
                }
            };
            var dic = {};
            var cur, node, parent;
            var roots = [];
            while (queue.length > 0){
                cur = queue.shift();
                parent = getParent(cur.type, cur.data);
                if (parent !== undefined){
                    if (parent === null){
                        roots.push(cur);
                    }
                    else {
                        if (!dic[parent.id]){
                            dic[parent.id] = parent;
                            queue.push(parent);
                        }
                        dic[parent.id].children.push(cur);
                    }
                }
            }
            var cmp = function(a, b){
                var types = ['emp', 'org'];
                if (a.type !== b.type) {
                    return types.indexOf(a.type) - types.indexOf(b.type);
                }
                if (a.text < b.text) return -1;
                if (a.text > a.text) return 1;
                return 0;
             };
             var getNode = function(content){
                 content.children.sort(cmp);
                 var items = [], ni;
                 for (var i = 0; i < content.children.length; i++){
                     items.push(getNode(content.children[i]));
                 }
                 if (content.type == "org"){
                     var row = {
                         name: content.data.name,
                         ident: content.id,
                         icon: {tag:'span', class:['mdi', 'mdi-folder-account']},
                         children: items
                     };
                 }
                 else {
                     var row = {
                         name: content.data.fullname,
                         ident: content.id,
                         icon: {tag:'span', class:['mdi', 'mdi-account']},
                         children: items
                     };
                     if (checkinsList[content.id].edited){
                         row.extendClasses = "as-text-red";
                     }
                 }
                 return row;
             };
             var nodes = [];
             for ( var i = 0; i < roots.length; i++){
                 nodes.push(getNode(roots[i]));
             }
             var leftCtn = absol.buildDom({
                 class: 'mk-main-left-ctn',
                 style:{
                     display:'flex',
                     'flex-direction': 'column',
                     overflowY: "auto",
                     maxHeight: "calc(90vh - 200px)"
                 }
             });
             var inputsearchbox = absol.buildDom({
                 tag:'searchcrosstextinput',
                 style: {
                     width: "calc(100% - var(--control-horizontal-distance-2))",
                     minWidth: "300px"
                 },
                 props:{
                     placeholder: LanguageModule.text("txt_search")
                 }
             });
             leftCtn.addChild(DOMElement.div({
                 attrs: {
                     style: {
                         paddingBottom: "var(--control-verticle-distance-2)"
                     }
                 },
                 children: [
                     inputsearchbox
                 ]
             }));
             var drawTable = function(employeeid){
                 var deleteRow = function(id){
                     return new Promise(function(resolve,reject){
                         ModalElement.show_loading();
                         FormClass.api_call({
                             url: "worktime_checkins_delete.php",
                             params: [{name: "id", value: id}],
                             func: function(success, message){
                                 ModalElement.close(-1);
                                 if (success){
                                     if (message.substr(0, 2) == "ok"){
                                         for (var i = 0; i < checkinsList[employeeid].list.length; i++){
                                             if (checkinsList[employeeid].list[i].id == id){
                                                 checkinsList[employeeid].list.splice(i, 1);
                                                 break;
                                             }
                                         }
                                         resolve();
                                     }
                                     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});
                                 }
                             }
                         });
                     });
                 };
                 var deleteRowConfirm = function(id){
                     return new Promise(function(resolve,reject){
                         ModalElement.question({
                             title: LanguageModule.text("war_title_delete_worktime_checkin"),
                             message: LanguageModule.text2("war_txt_detele", [""]),
                             onclick: function(sel){
                                 if (sel == 0){
                                     deleteRow(id).then(function(value){
                                         resolve(value);
                                     });
                                 }
                             }
                         });
                     });
                 };
                 var saveRow = function(content){
                     return new Promise(function(rs, rj){
                         var eIndex = employeeDic[employeeid];
                         var data = {
                             machineid: content.machineid,
                             employeeid: employeeid,
                             employee_peopleid: host1.database.employees.items[eIndex].peopleid,
                             ctime: content.time,
                             type: content.type,
                             importer_userid: systemconfig.userid,
                             lastmodified_userid: systemconfig.userid,
                             lastmodified_time: new Date(),
                             extrainfo: "obj#0#",
                             ver: 0,
                             available: 1
                         };
                         ModalElement.show_loading();
                         core.exec("worktime.save_worktime_checkins", {data: data}, function (host) {
                             return function (success, content1) {
                                 console.log(success, content1);
                                 ModalElement.close(-1);
                                 if (success){
                                     delete content.add;
                                     content.id = content1.id;
                                     rs(content);
                                 }
                                 else {
                                     ModalElement.alert({message: content});
                                 }
                             }
                         }(host));
                     });
                 };
                 var getRow = function(content){
                     function applyParam(elt){
                         // if (!content.add){
                         //     elt.classList.add("hr-table-cell-link");
                         //     elt.onclick = function(){
                         //         editRow(content).then(function(value){
                         //             tableView.replaceRow(getRow(value), row);
                         //             changeData = true;
                         //         });
                         //     };
                         // }
                         return elt;
                     };
                     var mName = "";
                     var mIndex = machineDic[content.machineid];
                     if (mIndex >= 0) mName = host1.database.worktime_machines.items[mIndex].name;
                     var cells = [
                         {
                             style: {
                                 whiteSpace: "nowrap",
                                 color: (content.add || content.del)? "red" : "",
                                 "text-decoration": content.del? "line-through" : ""
                             },
                             child: applyParam(DOMElement.span({text: contentModule.getDateTimeView(content.time)}))
                         },
                         {
                             style: {
                                 whiteSpace: "nowrap",
                                 color: (content.add || content.del)? "red" : "",
                                 "text-decoration": content.del? "line-through" : ""
                             },
                             child: applyParam(DOMElement.span({text: mName}))
                         },
                         {
                             style: {
                                 whiteSpace: "nowrap",
                                 color: (content.add || content.del)? "red" : "",
                                 "text-decoration": content.del? "line-through" : ""
                             },
                             child: applyParam(DOMElement.span({text: LanguageModule.text("txt_" + content.type)}))
                         }
                     ];
                     // cells.push({
                     //    child: DOMElement.span({text: content.fau})
                     // });
                     if (content.add) cells.push({
                         style: {
                             color: "red",
                             whiteSpace: "nowrap"
                         },
                         child: applyParam(DOMElement.span({text: LanguageModule.text("txt_auto_add")}))
                     });
                     else if (content.del) cells.push({
                         style: {
                             whiteSpace: "nowrap",
                             color: "red",
                             "text-decoration": "line-through"
                         },
                         child: applyParam(DOMElement.span({text: LanguageModule.text("txt_pass")}))
                     });
                     else cells.push({});
                     var qmenuButton = DOMElement.div({
                         attrs: {
                             className: "card-icon-cover"
                         },
                         children: [DOMElement.i({
                             attrs: {
                                 className: "material-icons bsc-icon-hover-black"
                             },
                             text: "more_vert"
                         })]
                     });
                     absol.QuickMenu.toggleWhenClick(qmenuButton, {
                         getMenuProps: function(){
                             var quickMenuItems = [];
                             if (content.add){
                                 quickMenuItems.push({
                                     text: LanguageModule.text("txt_save_checkin"),
                                     extendClasses: "bsc-quickmenu",
                                     icon: DOMElement.i({
                                         attrs: {
                                             className: "material-icons"
                                         },
                                         text: "save"
                                     }),
                                     cmd: function(){
                                         saveRow(content).then(function(value){
                                             tableView.replaceRow(getRow(value), row);
                                             changeData = true;
                                         });
                                     }
                                 });
                             }
                             else {
                                 // quickMenuItems.push({
                                 //     text: LanguageModule.text("txt_edit"),
                                 //     extendClasses: "bsc-quickmenu",
                                 //     icon: DOMElement.i({
                                 //         attrs: {
                                 //             className: "material-icons"
                                 //         },
                                 //         text: "create"
                                 //     }),
                                 //     cmd: function(){
                                 //         editRow(content).then(function(value){
                                 //             tableView.replaceRow(getRow(value), row);
                                 //             changeData = true;
                                 //         });
                                 //     }
                                 // });
                                 quickMenuItems.push({
                                     text: LanguageModule.text("txt_delete"),
                                     extendClasses: ["bsc-quickmenu", "red"],
                                     icon: DOMElement.i({
                                         attrs: {
                                             className: "material-icons"
                                         },
                                         text: "delete"
                                     }),
                                     cmd: function(){
                                         deleteRowConfirm(content.id).then(function(value){
                                             changeData = true;
                                             var x = tableView.rowOf(row)
                                             x.remove();
                                         });
                                     }
                                 });
                             }
                             return {items: quickMenuItems};
                         },
                         onSelect: function (item){
                             item.cmd();
                         },
                         anchor: [3, 4]
                     });
                     cells.push({
                         style: {width: "40px"},
                         child: qmenuButton
                     });
                     var row = {
                         cells: cells
                     };
                     return row;
                 };
                 DOMElement.removeAllChildren(rightCtn);
                 var data = [];
                 for (var i = 0; i < checkinsList[employeeid].list.length; i++){
                     data.push(getRow(checkinsList[employeeid].list[i]));
                 }
                 var tableView = absol.buildDom({
                     tag: "dynamictable",
                     props: {
                         adapter: {
                            data: {
                                head: {
                                    rows: [
                                        {
                                            cells: [
                                                {
                                                    child:  absol.buildDom({text: LanguageModule.text("txt_checkintime")})
                                                },
                                                {
                                                    child:  absol.buildDom({text: LanguageModule.text("txt_worktime_machine")})
                                                },
                                                {
                                                    child:  absol.buildDom({text: LanguageModule.text("txt_type")})
                                                },
                                                // {},
                                                {},
                                                {}
                                            ]
                                        }
                                    ]
                                },
                                body: {
                                    rows: data
                                }
                            }
                        }
                    }
                 });
                 tableView.attachSearchInput(inputsearchbox);
                 rightCtn.appendChild(tableView);
             };
             var tree_org_list = absol.buildDom({
                 tag: "toclist",
                 style: {
                     width: "450px",
                     'flex-grow': 1,
                     overflowY: 'auto'
                 },
                 props: {
                     searchInput: inputsearchbox,
                     nodes: nodes
                 },
                 on: {
                     pressnode: function (event) {
                         if (event.nodeData.ident > 0){
                             tree_org_list.activeNode(event.nodeData.ident);
                             drawTable(event.nodeData.ident);
                         }
                     }
                 }
             });
             tree_org_list.openAllNodeRecursive(Infinity);
             leftCtn.appendChild(tree_org_list);
             var rightCtn = absol.buildDom({
                 class: 'mk-main-right',
                 style: {
                     overflowY: "auto",
                     maxHeight: "calc(90vh - 200px)"
                 }
             });
             for (var employeeid in checkinsList){
                 console.log(checkinsList[employeeid]);
                 if (checkinsList[employeeid].edited){
                     tree_org_list.activeNode(employeeid);
                     drawTable(employeeid);
                     break;
                 }
             }
             var data_container = absol._({
                 class: 'mk-main',
                 style: {
                     height: "100%",
                     paddingTop: "var(--control-verticle-distance-2)"
                 },
                 child: [
                     leftCtn,
                     rightCtn
                 ]
             });
             ModalElement.showWindow({
                title: "Xác nhận dữ liệu check-in",
                bodycontent: data_container,
                buttonlist: [
                    {
                        text: LanguageModule.text("txt_ok"),
                        onclick: function(){
                            if (changeData) return;
                            host.content = true;
                            host.result = success;
                            host.finished = true;
                            ModalElement.close();
                        }
                    },
                    {
                        text: LanguageModule.text("txt_cancel"),
                        onclick: function(){
                            ModalElement.close();
                        }
                    }
                ]
             });
        }
        else {
            console.log(content);
        }

    }
} (host));
return retval;

}
} (module, retval, core);
// function: hrprocesses.data.worktime.convertCheckinsToLogs
var v186 = function(module, me, core) {
return function (shifts, worktime_checkins, assign_employee_shifts) {
var host = {
    database: {}
};
contentModule.makeDatabaseContent(host, {
    shifts: shifts, worktime_checkins: worktime_checkins, assign_employee_shifts: assign_employee_shifts
});
var include_func = function(a, b){
    if (a.in >= b.in && a.out <= b.out) return true;
    return false;
};
var shiftsDic = contentModule.makeDictionaryIndex(host.database.shifts.items);
var empCheckinsList = {};
host.database.worktime_checkins.items.sort(function(a, b){
    return a.ctime.getTime() - b.ctime.getTime();
});
host.database.assign_employee_shifts.items.sort(function(a, b){
    return a.time_out - b.time_out;
});
host.database.worktime_checkins.items.forEach(function(item){
    if (!empCheckinsList[item.employeeid]) empCheckinsList[item.employeeid] = [];
    empCheckinsList[item.employeeid].push(item);
});
for (var i = 0; i < host.database.assign_employee_shifts.items.length; i++){
    host.database.assign_employee_shifts.items[i].date_num = host.database.assign_employee_shifts.items[i].date;
    host.database.assign_employee_shifts.items[i].date = new Date(new Date(host.database.assign_employee_shifts.items[i].date*24*60*60*1000).setHours(0, 0, 0, 0));
}
var empAssignsList = {};
host.database.assign_employee_shifts.items.forEach(function(item){
    if (item.substitute == 0){
        if (!empAssignsList[item.employeeid]) empAssignsList[item.employeeid] = {};
        if (!empAssignsList[item.employeeid][item.date_num]) empAssignsList[item.employeeid][item.date_num] = [];
        empAssignsList[item.employeeid][item.date_num].push(item);
    }
    else {
        if (!empAssignsList[item.substitute]) empAssignsList[item.substitute] = {};
        if (!empAssignsList[item.substitute][item.date_num]) empAssignsList[item.substitute][item.date_num] = [];
        empAssignsList[item.substitute][item.date_num].push(item);
    }
});
var punishmentFault = 10800000;
var best, date_num, sIn, sOut, date_num1, value1, value2, ctime;
var logsList = {};
var checkins1List = {};
var listAssign;
for (var employeeid in empCheckinsList){
    if (!empAssignsList[employeeid]) continue;
    best = [];
    employeeid = parseFloat(employeeid);
    var countCheckin = empCheckinsList[employeeid].length;
    for (var index = 0; index < countCheckin; index++){
        best[index] = [];
        for (var status = 0; status <= 1; status++){
            best[index][status] = [];
            for (var fault = 0; fault < countCheckin; fault++){
                var worktime1 = function(index1){

                    var d_num = contentModule.getDateFrom1970(empCheckinsList[employeeid][index1].ctime);
                    var v1 = 0;
                    var listAssign1 = [];
                    if (empAssignsList[employeeid][d_num - 1]) listAssign1 = listAssign1.concat(empAssignsList[employeeid][d_num - 1]);
                    if (empAssignsList[employeeid][d_num]) listAssign1 = listAssign1.concat(empAssignsList[employeeid][d_num]);
                    for (var i = listAssign1.length - 1; i >= 0; i--){
                        if ((listAssign1[i].date.getTime() + listAssign1[i].time_in) >= empCheckinsList[employeeid][index1].ctime.getTime()) continue;
                        if ((listAssign1[i].date.getTime() + listAssign1[i].time_out) <= empCheckinsList[employeeid][index1].ctime.getTime()) continue;
                        v1 = listAssign1[i].date.getTime() + listAssign1[i].time_out - empCheckinsList[employeeid][index1].ctime.getTime();
                        break;
                    }
                    var v2 = empCheckinsList[employeeid][index1 + 1].ctime.getTime() - empCheckinsList[employeeid][index1].ctime.getTime();
                    if (v1 <= v2) return v1;
                    else return v2;
                };
                var worktime2 = function(index1){
                    var d1 = contentModule.getDateFrom1970(empCheckinsList[employeeid][index1].ctime);
                    var listAssign1 = [];
                    for (var k = d1; k <= date_num; k++){
                        if (empAssignsList[employeeid][k]) listAssign1 = listAssign1.concat(empAssignsList[employeeid][k]);
                    }
                    var res = 0, a_time_out1, a_time_in1, x_in1, x_out1, countShift = 0;
                    for (var kk = listAssign1.length - 1; kk >= 0; kk--){
                        if (res > 16*60*60*1000) break;
                        a_time_out1 = listAssign1[kk].date.getTime() + listAssign1[kk].time_out;
                        a_time_in1 = listAssign1[kk].date.getTime() + listAssign1[kk].time_in;
                        if (empCheckinsList[employeeid][index1].ctime.getTime() >= a_time_out1) continue;
                        if (empCheckinsList[employeeid][index1 + 1].ctime.getTime() <= a_time_in1) continue;
                        if (empCheckinsList[employeeid][index1].ctime.getTime() >= a_time_in1){
                            x_in1 = empCheckinsList[employeeid][index1].ctime.getTime();
                        }
                        else {
                            x_in1 = a_time_in1;
                        }
                        if (empCheckinsList[employeeid][index1 + 1].ctime.getTime() <= a_time_out1){
                            x_out1 = empCheckinsList[employeeid][index1 + 1].ctime.getTime();
                        }
                        else {
                            x_out1 = a_time_out1;
                        }
                        res += (x_out1 - x_in1);
                        countShift++;
                        if (countShift == 2) break;
                    }
                    return res;
                };
                var worktime3 = function(index1){
                    var v1, v2;
                    var d_num = contentModule.getDateFrom1970(empCheckinsList[employeeid][index1].ctime);
                    var v1 = 0;
                    var listAssign1 = [];
                    if (empAssignsList[employeeid][d_num - 1]) listAssign1 = listAssign1.concat(empAssignsList[employeeid][d_num - 1]);
                    if (empAssignsList[employeeid][d_num]) listAssign1 = listAssign1.concat(empAssignsList[employeeid][d_num]);
                    for (var i = 0; i < listAssign1.length; i++){
                        if ((listAssign1[i].date.getTime() + listAssign1[i].time_in) >= empCheckinsList[employeeid][index1].ctime.getTime()) continue;
                        if ((listAssign1[i].date.getTime() + listAssign1[i].time_out) <= empCheckinsList[employeeid][index1].ctime.getTime()) continue;
                        v1 = empCheckinsList[employeeid][index1].ctime.getTime() - (listAssign1[i].date.getTime() + listAssign1[i].time_in);
                        break;
                    }
                    var v2 = empCheckinsList[employeeid][index1].ctime.getTime() - empCheckinsList[employeeid][index1 - 1].ctime.getTime();
                    if (v1 <= v2) return v1;
                    else return v2;
                };
                date_num1 = 0;
                sIn = false;
                sOut = false;
                date_num = contentModule.getDateFrom1970(empCheckinsList[employeeid][index].ctime);
                listAssign = [];
                if (empAssignsList[employeeid][date_num - 1]) listAssign = listAssign.concat(empAssignsList[employeeid][date_num - 1]);
                if (empAssignsList[employeeid][date_num]) listAssign = empAssignsList[employeeid][date_num];
                var assignItem;
                for (var i = 0; i < listAssign.length; i++){
                    assignItem = listAssign[i];
                    if (Math.abs((assignItem.date.getTime() + assignItem.time_in) - empCheckinsList[employeeid][index].ctime.getTime()) <= 30*60*1000){
                        sIn = true;
                        if (index > 0){
                            if (Math.abs((assignItem.date.getTime() + assignItem.time_in) - empCheckinsList[employeeid][index - 1].ctime.getTime()) <= 30*60*1000){
                                sIn = false;
                            }
                        }
                        if (sIn){
                            if (index < empCheckinsList[employeeid].length - 1){
                                if (Math.abs((assignItem.date.getTime() + assignItem.time_in) - empCheckinsList[employeeid][index + 1].ctime.getTime()) <= 30*60*1000){
                                    sIn = false;
                                }
                            }
                        }
                        break;
                    }
                }
                if (!sIn){
                    for (var i = 0; i < listAssign.length; i++){
                        assignItem = listAssign[i];
                        if (Math.abs((assignItem.date.getTime() + assignItem.time_out) - empCheckinsList[employeeid][index].ctime.getTime()) <= 30*60*1000){
                            sOut = true;
                            if (index > 0){
                                if (Math.abs((assignItem.date.getTime() + assignItem.time_out) - empCheckinsList[employeeid][index - 1].ctime.getTime()) <= 30*60*1000){
                                    sOut = false;
                                }
                            }
                            if (sOut){
                                if (index < empCheckinsList[employeeid].length - 1){
                                    if (Math.abs((assignItem.date.getTime() + assignItem.time_out) - empCheckinsList[employeeid][index + 1].ctime.getTime()) <= 30*60*1000){
                                        sOut = false;
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                best[index][status][fault] = {};
                if (status == 0){
                    if (sOut){
                        best[index][status][fault] = {
                            value: -1000000000
                        };
                    }
                    else {
                        if (index == 0){
                            if (fault == 0){
                                best[index][status][fault] = {
                                    value: 0
                                };
                            }
                            else {
                                best[index][status][fault] = {
                                    value: -1000000000
                                };
                            }
                        }
                        else {
                            value1 = best[index - 1][1][fault].value;
                            if (fault > 0){
                                value2 = best[index - 1][0][fault - 1].value + worktime1(index - 1) - punishmentFault;
                            }
                            else value2 = -1000000000000000;
                            if (value1 >= value2){
                                best[index][status][fault] = {
                                    choice: 1,
                                    value: value1
                                };
                            }
                            else {
                                best[index][status][fault] = {
                                    choice: 2,
                                    value: value2
                                };
                            }
                        }
                    }
                }
                else {
                    if (sIn){
                        best[index][status][fault] = {
                            value: -1000000000
                        };
                    }
                    else {
                        if (index == 0){
                            if (fault == 0){
                                best[index][status][fault] = {
                                    value: 0
                                };
                            }
                            else {
                                best[index][status][fault] = {
                                    value: -1000000000
                                };
                            }
                        }
                        else {
                            value1 = best[index - 1][0][fault].value + worktime2(index - 1);
                            if (fault > 0){
                                value2 = best[index - 1][1][fault - 1].value + worktime3(index) - punishmentFault;
                            }
                            else value2 = -1000000000000000;
                            if (value1 >= value2){
                                best[index][status][fault] = {
                                    choice: 3,
                                    value: value1
                                };
                            }
                            else {
                                best[index][status][fault] = {
                                    choice: 4,
                                    value: value2
                                };
                            }
                        }
                    }
                }
            }
        }
    }
    var best1 = [];

    for (var index = 0; index < best.length; index++){
        var t1 = [];
        for (var fault = 0; fault < best[index].length; fault++){
            var t2 = [];
            for (var k = 0; k < best[index][fault].length; k++) {
                t2.push({
                    choice: best[index][fault][k].choice,
                    value: best[index][fault][k].value / 60/60/1000
                });
            }
            t1.push(t2);
        }
        best1.push(t1);
    }
    console.log(best1);
    var value, choice, index, date_num, ctime, l, fau, x_in, x_out;
    employeeid = parseFloat(employeeid);
    value = -Infinity;
    index = empCheckinsList[employeeid].length - 1;
    fau = countCheckin - 1;
    for (var fault = countCheckin - 1; fault >= 0; fault--){
        for (var status = 0; status < 2; status ++){
            if ((best[index][status][fault].value > value) || ((best[index][status][fault].value == value) && fault < fau)){
                value = best[index][status][fault].value;
                choice = best[index][status][fault].choice;
                fau = fault;
            }
        }
    }
    logsList[employeeid] = [];
    checkins1List[employeeid] = {
        edited: false,
        list: []
    };
    while (index >= 0){
        date_num = contentModule.getDateFrom1970(empCheckinsList[employeeid][index].ctime);
        var listAssign = [];
        if (empAssignsList[employeeid][date_num - 1]) listAssign = listAssign.concat(empAssignsList[employeeid][date_num - 1]);
        if (empAssignsList[employeeid][date_num]) listAssign = listAssign.concat(empAssignsList[employeeid][date_num]);
        var a_time_out, a_time_in;
        switch (choice){
            case 1:
            case 2:
                var ex = false;
                for (var i = listAssign.length - 1; i >= 0; i--){
                    a_time_out = listAssign[i].date.getTime() + listAssign[i].time_out;
                    a_time_in = listAssign[i].date.getTime() + listAssign[i].time_in;
                    if (empCheckinsList[employeeid][index].ctime.getTime() > a_time_out) continue;
                    if (empCheckinsList[employeeid][index + 1].ctime.getTime() < a_time_in) continue;
                    if (empCheckinsList[employeeid][index].ctime.getTime() > (listAssign[i].date.getTime() + listAssign[i].time_in)){
                        x_in = empCheckinsList[employeeid][index].ctime;
                    }
                    else {
                        x_in = new Date(listAssign[i].date.getTime() + listAssign[i].time_in);
                    }
                    if ((index == (empCheckinsList[employeeid].length - 1))){
                        x_out = new Date(listAssign[i].date.getTime() + listAssign[i].time_out);
                    }
                    else {
                        if (empCheckinsList[employeeid][index + 1].ctime.getTime() < a_time_out){
                            x_out = empCheckinsList[employeeid][index + 1].ctime;
                        }
                        else {
                            x_out = new Date(listAssign[i].date.getTime() + listAssign[i].time_out);
                        }
                    }
                    logsList[employeeid].unshift({
                        in: x_in,
                        out: x_out,
                        machineid: empCheckinsList[employeeid][index].machineid,
                        shiftid: listAssign[i].shiftid,
                        not_done: 1,
                        comment: LanguageModule.text("txt_check_out_time_is_added_automatically"),
                        ttt: 1111
                    });
                    checkins1List[employeeid].list.unshift({
                        time: empCheckinsList[employeeid][index].ctime,
                        machineid: empCheckinsList[employeeid][index].machineid,
                        shiftid: listAssign[i].shiftid,
                        type: "in",
                        id: empCheckinsList[employeeid][index].id,
                        fau: fau
                    });
                    ex = true;
                    checkins1List[employeeid].edited = true;
                    checkins1List[employeeid].list.unshift({
                        time: x_out,
                        machineid: empCheckinsList[employeeid][index + 1].machineid,
                        shiftid: listAssign[i].shiftid,
                        type: "out",
                        add: true,
                        fau: fau
                    });
                }
                if (!ex){
                    checkins1List[employeeid].edited = true;
                    checkins1List[employeeid].list.unshift({
                        time: empCheckinsList[employeeid][index].ctime,
                        machineid: empCheckinsList[employeeid][index].machineid,
                        type: "in",
                        id: empCheckinsList[employeeid][index].id,
                        del: true,
                        fau: fau
                    });
                }
                index--;
                if (index > 0){
                    if (choice == 2){
                        fau--;
                        if (fau >= 0) choice = best[index][0][fau].choice;
                        else {
                            console.log(index, fau);
                            index = -1;
                        }
                    }
                    else {
                        choice = best[index][1][fau].choice;
                    }
                }
                else {
                    if (choice == 1){
                        choice = 4;
                    }
                    else {
                        choice = 1;
                    }
                }
                break;
            case 3:
                var a_time_in, a_time_out;
                var ex = false;
                for (var ii = listAssign.length - 1; ii >= 0; ii--){
                    a_time_in = listAssign[ii].date.getTime() + listAssign[ii].time_in;
                    a_time_out = listAssign[ii].date.getTime() + listAssign[ii].time_out;
                    if (empCheckinsList[employeeid][index - 1].ctime.getTime() >= a_time_out) continue;
                    if (empCheckinsList[employeeid][index].ctime.getTime() <= a_time_in) continue;
                    if (empCheckinsList[employeeid][index - 1].ctime.getTime() > a_time_in){
                        x_in = empCheckinsList[employeeid][index - 1].ctime;
                    }
                    else {
                        x_in = new Date(a_time_in);
                    }
                    if (empCheckinsList[employeeid][index].ctime.getTime() < a_time_out){
                        x_out = empCheckinsList[employeeid][index].ctime;
                    }
                    else {
                        x_out = new Date(a_time_out);
                    }
                    if ((x_out.getTime() - x_in.getTime()) > 60000){
                        var logItem = {
                            in: x_in,
                            out: x_out,
                            machineid: empCheckinsList[employeeid][index - 1].machineid,
                            shiftid: listAssign[ii].shiftid,
                            not_done: 0,
                            comment: "",
                            ttt: 9999
                        };
                        logsList[employeeid].unshift(logItem);
                        ex = true;
                    }
                }
                checkins1List[employeeid].list.unshift({
                    time: empCheckinsList[employeeid][index].ctime,
                    machineid: empCheckinsList[employeeid][index].machineid,
                    type: "out",
                    id: empCheckinsList[employeeid][index].id,
                    del: !ex,
                    fau: fau
                });
                checkins1List[employeeid].list.unshift({
                    time: empCheckinsList[employeeid][index - 1].ctime,
                    machineid: empCheckinsList[employeeid][index - 1].machineid,
                    type: "in",
                    id: empCheckinsList[employeeid][index - 1].id,
                    del: !ex,
                    fau: fau
                });
                index--;
                choice = best[index][0][fau].choice;
                index--;
                if (index > 0){
                    if (choice == 1){
                        choice = best[index][1][fau].choice;
                    }
                    else {
                        fau--;
                        if (fau >= 0) choice = best[index][0][fau].choice;
                        else {
                            console.log(index, fau);
                            index = -1;
                        }
                    }
                }
                else {
                    if (choice == 1){
                        choice = 4;
                    }
                    else {
                        choice = 1;
                    }
                }
                break;
            case 4:
                var a_time_in, a_time_out;
                var ex = false;
                for (var i = listAssign.length - 1; i >= 0; i--){
                    a_time_in = listAssign[i].date.getTime() + listAssign[i].time_in;
                    a_time_out = listAssign[i].date.getTime() + listAssign[i].time_out;
                    if (empCheckinsList[employeeid][index].ctime.getTime() < a_time_in) continue;
                    if (index > 0){
                        if (empCheckinsList[employeeid][index - 1].ctime.getTime() >= a_time_out) continue;
                        if (empCheckinsList[employeeid][index - 1].ctime.getTime() > a_time_in){
                            x_in = empCheckinsList[employeeid][index - 1].ctime;
                        }
                        else {
                            x_in = new Date(a_time_in);
                        }
                    }
                    else {
                        x_in = new Date(a_time_in);
                    }
                    if (a_time_out < empCheckinsList[employeeid][index].ctime.getTime()){
                        x_out = new Date(a_time_out);
                    }
                    else {
                        x_out = empCheckinsList[employeeid][index].ctime;
                    }
                    logsList[employeeid].unshift({
                        in: x_in,
                        out: x_out,
                        machineid: empCheckinsList[employeeid][index].machineid,
                        shiftid: listAssign[i].shiftid,
                        not_done: 1,
                        comment: LanguageModule.text("txt_check_in_time_is_added_automatically"),
                        ttt: 14141414
                    });
                    checkins1List[employeeid].list.unshift({
                        time: x_in,
                        machineid: empCheckinsList[employeeid][index].machineid,
                        shiftid: listAssign[i].shiftid,
                        type: "in",
                        add: true,
                        fau: fau
                    });
                    ex = true;
                }
                checkins1List[employeeid].edited = true;
                checkins1List[employeeid].list.unshift({
                    time: empCheckinsList[employeeid][index].ctime,
                    machineid: empCheckinsList[employeeid][index].machineid,
                    type: "out",
                    id: empCheckinsList[employeeid][index].id,
                    del: !ex,
                    fau: fau
                });
                index--;
                if (index > 0){
                    fau--;
                    if (fau >= 0) choice = best[index][1][fau].choice;
                    else {
                        console.log(index, fau);
                        index = -1;
                    }
                }
                else {
                    choice = 4;
                }
                break;
            default:
                // console.log(index);
                value = -Infinity;
                var fault1 = countCheckin - 1;
                for (var fault = countCheckin - 1; fault >= 0; fault--){
                    for (var status = 0; status < 2; status ++){
                        if ((best[index][status][fault].value > value) || ((best[index][status][fault].value == value) && (fault1 > fault))){
                            value = best[index][status][fault].value;
                            choice = best[index][status][fault].choice;
                            fault1 = fault;
                        }
                    }
                }
                index--;
                break;
        }
    }
    logsList[employeeid].sort(function(a, b){
        return a.in.getTime() - b.in.getTime();
    });
    for (var i = logsList[employeeid].length - 1; i > 0; i--){
        if (include_func(logsList[employeeid][i], logsList[employeeid][i - 1])){
            logsList[employeeid].splice(i, 1);
        }
        else if (include_func(logsList[employeeid][i - 1], logsList[employeeid][i])){
            logsList[employeeid].splice(i - 1, 1);
        }
    }
}
return {
    logsList: logsList,
    checkinsList: checkins1List
};

}
} (module, retval, core);
retval.confirmDataCheckins = v185;
retval.convertCheckinsToLogs = v186;
return retval;
}
} (module, v96)) ();
// node: hrprocesses.data.worktime_checkins
var v124 = (function (module, core) { return function () {
var retval = {};
// function: hrprocesses.data.worktime_checkins.read_by_employee_list_and_time
var v130 = function(module, me, core) {
return function (employeeIdList, timestart, timeend) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
timeend = absol.datetime.nextDate(timeend);
core.exec("worktime_checkins.read_by_employee_list_and_time", {employeeIdList: employeeIdList, timestart: timestart, timeend: timeend}, function (host) {
    return function (success, content) {
        if (success){
            var keys, i, n, id;
            host.content = EncodingClass.string.duplicate(content);
            host.result = success;
            host.finished = true;
        }
        else {
            console.log(content);
        }
    }
} (host));
return retval;

}
} (module, retval, core);
retval.read_by_employee_list_and_time = v130;
return retval;
}
} (module, v96)) ();
// node: hrprocesses.data.worktime_logs
var v126 = (function (module, core) { return function () {
var retval = {};
// function: hrprocesses.data.worktime_logs.write_lists
var v133 = function(module, me, core) {
return function (lists, timestart, timeend, employeeIdList, checkinsList) {
var retval = {};
var host = {
    finished: false,
    result: null,
    content: null
};
Object.defineProperty(retval, "finished", {
    get: function (host) {
        return function () {
            return host.finished;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "result", {
    get: function (host) {
        return function () {
            return host.result;
        }
    } (host),
    set: function (value) {
    }
});
Object.defineProperty(retval, "content", {
    get: function (host) {
        return function () {
            return host.content;
        }
    } (host),
    set: function (value) {
    }
});
timeend = absol.datetime.nextDate(timeend);
console.log(lists, timestart, timeend, employeeIdList, checkinsList);
ModalElement.show_loading();
core.exec("worktime_logs.write_lists", {lists: lists, timestart: timestart, timeend: timeend, employeeIdList: employeeIdList, checkinsList: checkinsList}, function (host) {
    return function (success, content) {
        ModalElement.close(-1);
        host.content = EncodingClass.string.duplicate(content);
        host.result = success;
        host.finished = true;
    }
} (host));
return retval;
}
} (module, retval, core);
retval.write_lists = v133;
return retval;
}
} (module, v96)) ();
retval.assign_employee_shifts = v125;
retval.employee_benefit_and_liability_list = v191;
retval.employee_profile = v194;
retval.employees = v116;
retval.employment_contract = v187;
retval.orgs = v183;
retval.shifts = v123;
retval.timesheet = v179;
retval.users = v95;
retval.worktime = v184;
retval.worktime_checkins = v124;
retval.worktime_logs = v126;
return retval;
}
} (module)) ();
// node: hrprocesses.libs
var v105 = (function (module) { return function () {
var retval = {};
// node: hrprocesses.libs.string
var v111 = (function (module) { return function () {
var retval = {};
// function: hrprocesses.libs.string.toUpperCase1
var v112 = function(module, me) {
return function (str) {
var words = str.split(" ");

for (let i = 0; i < words.length; i++) {
    words[i] = words[i][0].toUpperCase() + words[i].substr(1);
}

return words.join(" ");

}
} (module, retval);
// function: hrprocesses.libs.string.toUpperCase2
var v119 = function(module, me) {
return function (str) {
return str.toUpperCase();
}
} (module, retval);
retval.toUpperCase1 = v112;
retval.toUpperCase2 = v119;
return retval;
}
} (module)) ();
// function: hrprocesses.libs.createObject
var v113 = function(module, me) {
return function (params) {
var i, n = ~~(params.length / 2);
var r = {};
for (i = 0; i < n; i++) {
    r[params[i*2]] = params[i*2+1];
}
return r;
}
} (module, retval);
// function: hrprocesses.libs.log
var v107 = function(module, me) {
return function (content) {
console.log(content);
}
} (module, retval);
// function: hrprocesses.libs.waitForResult
var v106 = function(module, me) {
return function (handler) {
var host = {
    handler: handler
}
host.waitFunc = function (host) {
    return function () {
        if (host.handler.finished) {
            host.resolve(host.handler);
        }
        else {
            setTimeout(function () {
                host.waitFunc();
            }, 100);
        }
    }
} (host);
var myPromise = new Promise(function (host) {
    return function (resolve, reject) {
        host.resolve = resolve;
        host.waitFunc();
    }
} (host));
return myPromise;
}
} (module, retval);
// function: hrprocesses.libs.waitForResults
var v127 = function(module, me) {
return function (handleList) {
return new Promise(function(resolve, reject){
    function wait(){
        var finished = handleList.every(function(handler){
            return handler.finished;
        });
        if (finished) {
            resolve();
        }
        else setTimeout(wait, 100);
    }
    wait();
});
}
} (module, retval);
retval.string = v111;
retval.createObject = v113;
retval.log = v107;
retval.waitForResult = v106;
retval.waitForResults = v127;
return retval;
}
} (module)) ();
retval.bsc = v135;
retval.data = v94;
retval.libs = v105;
// postload: hrprocesses.postload
var v93 = function(module, me) {
return function () {
if( hr.systemFunctions === undefined) {
    hr.systemFunctions = {};
}
hr.systemFunctions.data = {};
hr.systemFunctions.data.users = me.data.users;
hr.systemFunctions.data.employees = me.data.employees;
hr.systemFunctions.data.shifts = me.data.shifts;
hr.systemFunctions.data.worktime_checkins = me.data.worktime_checkins;
hr.systemFunctions.data.worktime_logs = me.data.worktime_logs;
hr.systemFunctions.data.assign_employee_shifts = me.data.assign_employee_shifts;
hr.systemFunctions.data.timesheet = me.data.timesheet;
hr.systemFunctions.data.worktime = me.data.worktime;
hr.systemFunctions.data.employment_contract = me.data.employment_contract;
hr.systemFunctions.data.employee_profile = me.data.employee_profile;
hr.systemFunctions.data.employee_benefit_and_liability_list = me.data.employee_benefit_and_liability_list;
hr.systemFunctions.libs = me.libs;
hr.systemFunctions.payroll = me.payroll;
me.libs.Math = Math;

}
} (module, retval);
v93();
return retval;
}
 ();
//# sourceURL=codecenter:///codecenter/host.php/hrprocesses.js?

VaKeR 2022