'use strict';
var sProgramId = getProgramId(),
fnPageInit = function () {
var oLeaveSet = null,
oChangeRecords = null,
oGrid = null,
oGrid1 = null,
oGrid2 = null,
oGrid3 = null,
oSet = null,
sHtmlCategory = '',
sCurrentUserId = parent.UserID,
sCurrentYear = new Date().formate('yyyy'),
oBaseQueryPm = {
sortField: 'CreateDate',
sortOrder: 'asc'
},
/**
* 獲取資料
* @param {Object} args 查詢參數
* @return {Object} ajax物件
*/
fnGetLeaveList = function (args) {
var oQueryPm = {};
$.extend(oQueryPm, oBaseQueryPm, args);
oQueryPm.AskTheDummy = sCurrentUserId;
oQueryPm.Status = 'B,H-O,E';
oQueryPm.LeaveDateStart = sCurrentYear + '/01/01';
oQueryPm.LeaveDateEnd = sCurrentYear + '/12/31';
return g_api.ConnectLite('Leave_Qry', ComFn.GetPage, oQueryPm, function (res) {
if (res.RESULT) {
var oRes = res.DATA.rel;
$('.currentyear').text(sCurrentYear);
}
});
},
/**
* 獲取請假設定
* @return {Object} ajax物件
*/
fnGetLeaveSet = function () {
var limited = g_api.ConnectLite('LeaveRequest_Qry', 'GetAllLeaveRequest', {
UserID: sCurrentUserId,
OrgID: parent.OrgID,
CurrentYear: sCurrentYear
});
return $.whenArray([CallAjax(ComFn.W_Com, ComFn.GetPagePrc, {
Type: 'wenzhong_getlist',
Params: {
querysort: '',
pageindex: 1,
pagesize: 100,
UserID: sCurrentUserId,
Date: sCurrentYear,
LeaveDate: '',
OrgID: parent.OrgID
}
}),
CallAjax(ComFn.W_Com, ComFn.GetOne, {
Type: '',
Params: {
leaveset: {
OrgID: parent.OrgID,
UserID: sCurrentUserId,
TYear: sCurrentYear
}
}
}),
limited
]).done(function (res1, res2, res3) {
var OtherLeave = [];
if (res2[1] === 'success') {
oSet = $.parseJSON(res2[0].d);
var saSet = $.parseJSON(oSet.SetInfo),
oTXJ = {};
saSet = saSet || [];
if (oSet.SetInfo) {
$('#InitLeaveSet').hide();
}
else {
if (parent.UserInfo.roles.indexOf('Admin') > -1) {
$('#InitLeaveSet').show();
}
else {
$('#InitLeaveSet').hide();
}
}
if (res1[1] === 'success') {
oTXJ = $.parseJSON(res1[0].d === '' ? '[]' : res1[0].d);
}
if (res3[1] === 'success') {
OtherLeave = res3[0].DATA.rel;
}
$.each(saSet, function (idx, set) {
var iPaymentHours = 0,
iUsedHours = 0,
iRemainHours = 0,
saMemo = [];
if (set.Id === '09') {
$.each(oTXJ.DataList, function (idx, txj) {
var _iRemainHours = (txj.RemainHours || '0') * 1;
iPaymentHours += txj.PaymentHours * 1;
iUsedHours += txj.UsedHours * 1;
iRemainHours += _iRemainHours;
saMemo.push(newDate(txj.EnableDate, true) + '~' + newDate(txj.ExpirationDate, true) + ':' + txj.PaymentHours + '/' + txj.RemainHours + '(' + i18next.t('common.Hours') + ')');
});
set.PaymentHours = iPaymentHours;
set.UsedHours = iUsedHours;
set.RemainHours = iRemainHours;
set.Memo = saMemo.join(' + ');
}
else {
let MatchtedLeaveRequests = Enumerable.From(OtherLeave).Where(function (item) { return item.Leave === set.Id; }).ToArray();
if (MatchtedLeaveRequests.length > 0) {
$.each(MatchtedLeaveRequests, function (idx, mlr) {
console.log([ 'mlr', mlr]);
iPaymentHours += mlr.PaymentHours * 1;
iUsedHours += mlr.UsedHours * 1;
iRemainHours += mlr.RemainHours * 1;
saMemo.push(newDate(mlr.EnableDate, true) + '~' + newDate(mlr.ExpirationDate, true) + ':' + mlr.PaymentHours + '/' + mlr.RemainHours + '(hr)');
});
if (set.PaymentHours) {
set.PaymentHours = (parseFloat(set.PaymentHours) + parseFloat(iPaymentHours)).toString();
}
set.UsedHours = (parseFloat(set.UsedHours || '0') + parseFloat(iUsedHours)).toString();
set.RemainHours = (parseFloat(set.RemainHours || '0') + parseFloat(iRemainHours)).toString();
set.Memo = saMemo.join(' + ');
}
}
});
fnGetChangeRecords();
oLeaveSet = {
data: saSet,
itemsCount: saSet.length
};
oGrid1.loadData({ IsFilter: true });
}
});
},
/**
* 獲取請假設定變更記錄
* @return {Object} ajax物件
*/
fnGetChangeRecords = function () {
var param = $.extend({}, { UserId: sCurrentUserId, SouseId: oSet.Guid, LogType: 'leavesetchange,WenZhongChange' });
g_api.ConnectLite(sProgramId, "GetChangLog", param, function (res) {
if (res.RESULT) {
var saChangeRecords = $.parseJSON(res.DATA.rel);
oChangeRecords = {
data: saChangeRecords,
itemsCount: saChangeRecords.length
};
oGrid2.loadData({ IsFilter: true });
}
});
},
/**
* 設置人員菜單
* @return {Object} ajax物件
*/
fnSetMemberMenu = function () {
return g_api.ConnectLite(Service.sys, 'GetAllMembersByUserId', {},
function (res) {
if (res.RESULT) {
var saUsers = res.DATA.rel,
saTop = [],
saTreeList = [],
saPass = [],
fnGetParent = function (list, parentid) {
var saParent = Enumerable.From(list).Where(function (item) { return item.ID === parentid; }).ToArray();
return saParent.length > 0 ? saParent[0] : {};
};
$.each(saUsers, function (idx, tb) {
var oParent = fnGetParent(saUsers, tb.ParentID);
if (tb.level === '1' && !oParent.ID && saTop.indexOf(tb.ParentID) === -1) {
saTop.push(tb.ParentID);
}
});
$.each(saTop, function (idx, topid) {
if (saPass.indexOf(topid) === -1) {
var saList = new TreeMenu(saUsers).init(topid, 'ParentID', 'ID', 'Name');
$.each(saList, function (idx, _list) {
saTreeList.push(_list);
});
saPass.push(topid);
}
});
var fnCallBack = function (data) {
sCurrentUserId = data.id;
oBaseQueryPm.IsFilter = undefined;
oGrid.openPage(1);
fnGetLeaveSet();
};
$('#tree_menu').tree({
data: saTreeList,
autoOpen: false
});
bindTreeEvent(fnCallBack);
var node_Dept = $('#tree_menu').tree('getNodeById', parent.UserInfo.DepartmentID),
node_Member = $('#tree_menu').tree('getNodeById', parent.UserID);
$('#tree_menu').tree('openNode', node_Dept);
$(node_Member.element).addClass('jqtree-selected');
}
});
},
/**
* @param {Object} item 要變更的設定
*/
fnUpdateLeaveSet = function (item) {
var oUpdPm = {},
oLogInfoAdd = {
OrgID: parent.OrgID,
SouseId: oSet.Guid,
LogType: 'leavesetchange',
CreateUser: parent.UserID,
CreateDate: newDate()
},
oLogInfo = {
ChangeRecord: item.Name + ':' + (item.PaymentHoursOld === '' ? i18next.t('common.NoLimit') : item.PaymentHoursOld + i18next.t('common.Hours')) + ' => ' + item.PaymentHours + i18next.t('common.Hours'),
ChangeUserName: parent.UserInfo.MemberName,
Memo: item.Memo
},
oLeaveSetUpd = {};
oLogInfoAdd.LogInfo = JSON.stringify(oLogInfo);
oLeaveSetUpd.SetInfo = JSON.stringify(oLeaveSet.data);
oUpdPm.upd = {
leaveset: {
values: oLeaveSetUpd,
keys: {
Guid: oSet.Guid
}
}
};
oUpdPm.add = {};
oUpdPm.add.loginfo = oLogInfoAdd;
CallAjax(ComFn.W_Com, ComFn.GetTran, {
Params: oUpdPm
}, function (res) {
if (res.d > 0) {
fnGetLeaveSet();
showMsg(i18next.t("message.SetUp_Success"), 'success'); // ╠message.SetUp_Success⇒設置成功╣
}
else {
showMsg(i18next.t("message.SetUp_Failed") + '
' + res.MSG, 'error'); // ╠message.SetUp_Failed⇒設置失敗╣
}
}, function () {
showMsg(i18next.t("message.SetUp_Failed"), 'error'); // ╠message.SetUp_Failed⇒設置失敗╣
});
},
/**
* @param {Object} item 要變更的特休假信息
*/
fnUpdateLeaveTX = function (item) {
var param = $.extend({}, { UserId: sCurrentUserId, SouseId: oSet.Guid }, item);
g_api.ConnectLite(sProgramId, 'UpdateLeaveTX', param, function (res) {
if (res.RESULT) {
fnGetLeaveSet();
showMsg(i18next.t("message.SetUp_Success"), 'success'); // ╠message.SetUp_Success⇒設置成功╣
}
else {
showMsg(i18next.t("message.SetUp_Failed") + '
' + res.MSG, 'error'); // ╠message.SetUp_Failed⇒設置失敗╣
}
}, function () {
showMsg(i18next.t("message.SetUp_Failed"), 'error'); // ╠message.SetUp_Failed⇒設置失敗╣
});
},
/**
* 初始化差勤設定
*/
fnInitLeaveSet = function () {
g_api.ConnectLite(sProgramId, 'InitLeaveSet', {
CurrentYear: sCurrentYear
}, function (res) {
if (res.RESULT) {
fnGetLeaveSet();
showMsg(i18next.t("message.SetUp_Success"), 'success'); // ╠message.SetUp_Success⇒設置成功╣
}
else {
showMsg(i18next.t("message.SetUp_Failed") + '
' + res.MSG, 'error'); // ╠message.SetUp_Failed⇒設置失敗╣
}
}, function () {
showMsg(i18next.t("message.SetUp_Error"), 'error'); // ╠message.SetUp_Error⇒設置異常╣
});
},
/**
* 抓取請假規則設定
* @return {Object} ajax
*/
fnGetLeaveSetting = function () {
return g_api.ConnectLite(sProgramId, 'GetLeaveSetting', {});
},
/**
* 修改請假規則設定
* @param {Object} args 參數
* @return {Function} Ajax
*/
fnUpdateLeaveSetting = function (args) {
return g_api.ConnectLite(sProgramId, 'UpdateLeaveSetting', args, function (res) {
if (res.RESULT) {
showMsg(i18next.t("message.SetUp_Success"), 'success'); // ╠message.SetUp_Success⇒設置成功╣
}
else {
showMsg(i18next.t("message.SetUp_Failed") + '
' + res.MSG, 'error'); // ╠message.SetUp_Failed⇒設置失敗╣
}
}, function () {
showMsg(i18next.t("message.SetUp_Error"), 'error');//╠message.SetUp_Error⇒修改資料異常╣
});
},
/**
* 是否小數控件
* @param {Sring}flag 要綁定的資料標記
* @return {HTMLElement} DIV 物件
*/
fnCreateRadiosInput = function (flag) {
var $div = $('