You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1206 lines
60 KiB

2 years ago
  1. 'use strict';
  2. var DaysOfLeaves = new Array();
  3. var LeaveRequestUsing = [];
  4. var RoundToInterger = false;
  5. var sProgramId = getProgramId(),
  6. sQueryPrgId = getQueryPrgId(),
  7. sViewPrgId = sProgramId.replace('_Upd', '_View'),
  8. sAction = getUrlParam('Action') || 'Add',
  9. sDataId = getUrlParam('Guid'),
  10. sCheckId = sDataId,
  11. sLeaveSet = {},
  12. fnPageInit = function () {
  13. var oCurData = { CheckOrder: [] },
  14. oForm = $('#form_main'),
  15. oValidator = null,
  16. oGrid = null,
  17. oLeaveSet = {},
  18. LeaveRules = {},
  19. sHolidays = '',
  20. iOneDayHours = 8,
  21. saUsers = [],
  22. saLeaveSetInfo = null,
  23. saLeaveRequstList = {},
  24. /**
  25. * 獲取資料
  26. * @return {Object} ajax 物件
  27. */
  28. fnGet = function () {
  29. if (sDataId) {
  30. return g_api.ConnectLite(sQueryPrgId, ComFn.GetOne,
  31. {
  32. Guid: sDataId
  33. },
  34. function (res) {
  35. if (res.RESULT) {
  36. var oRes = res.DATA.rel;
  37. oCurData = oRes;
  38. oCurData.CheckOrder = $.parseJSON(oCurData.CheckOrder);
  39. setFormVal(oForm, oRes);
  40. $('.AskTheDummy').text(oCurData.AskTheDummyName + '(' + oCurData.AskTheDummy + ') ' + oCurData.DeptName);
  41. $('#StartDate').val(newDate(oCurData.StartDate));
  42. $('#EndDate').val(newDate(oCurData.EndDate));
  43. fnGetUploadFiles(oCurData.Guid, fnUpload);
  44. fnGetLeaveSettingByType(oCurData.HolidayCategory);
  45. if (oCurData.Handle_DeptID) {
  46. fnSetUserDrop([
  47. {
  48. Select: $('#Handle_Person'),
  49. DepartmentID: oCurData.Handle_DeptID,
  50. ShowId: true,
  51. Select2: true,
  52. Action: sAction,
  53. DefultVal: oCurData.Handle_Person
  54. }
  55. ]);
  56. }
  57. if (oCurData.Agent_DeptID) {
  58. fnSetUserDrop([
  59. {
  60. Select: $('#Agent_Person'),
  61. DepartmentID: oCurData.Agent_DeptID,
  62. ShowId: true,
  63. Select2: true,
  64. Action: sAction,
  65. DefultVal: oCurData.Agent_Person
  66. }
  67. ]);
  68. }
  69. if (oCurData.Flows_Lock === 'Y') {
  70. $(".checkordertoolbox").hide();
  71. }
  72. else {
  73. $(".checkordertoolbox").show();
  74. }
  75. if (oCurData.Handle_Lock === 'Y') {
  76. $("#Handle_DeptID,#Handle_Person").attr('disabled', true);
  77. }
  78. else {
  79. $("#Handle_DeptID,#Handle_Person").removeAttr('disabled');
  80. }
  81. $("#jsGrid").jsGrid("loadData");
  82. setNameById().done(function () {
  83. getPageVal();//緩存頁面值,用於清除
  84. });
  85. }
  86. });
  87. }
  88. else {
  89. $('.AskTheDummy').text(parent.UserInfo.MemberName + '(' + parent.UserInfo.MemberID + ') ' + parent.UserInfo.DepartmentName);
  90. $('#AskTheDummy').val(parent.UserInfo.MemberID);
  91. oCurData.CheckOrder = [];
  92. oCurData.Guid = guid();
  93. fnUpload();
  94. return $.Deferred().resolve().promise();
  95. }
  96. },
  97. /**
  98. * 新增資料
  99. * @param {String} flag 新增或儲存後新增
  100. */
  101. fnAdd = function (flag) {
  102. var data = getFormSerialize(oForm);
  103. data = packParams(data);
  104. data.OrgID = parent.OrgID;
  105. data.Guid = oCurData.Guid;
  106. data.SignedNumber = 'SerialNumber|' + parent.UserInfo.OrgID + '|QJ|MinYear|3|' + parent.UserInfo.ServiceCode + '|' + parent.UserInfo.ServiceCode;
  107. data.CheckFlows = fnCheckFlows(oCurData, true, true, saUsers);
  108. data.HandleFlows = fnHandleFlows(oCurData, saUsers);
  109. data.CheckOrder = JSON.stringify(oCurData.CheckOrder);
  110. data.Status = 'A';
  111. data.IsHandled = 'N';
  112. data.Inspectors = '';
  113. data.Reminders = '';
  114. data.Flows_Lock = oCurData.Flows_Lock;
  115. data.Handle_Lock = oCurData.Handle_Lock;
  116. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  117. Params: {
  118. leave: data
  119. }
  120. }, function (res) {
  121. if (res.d > 0) {
  122. bRequestStorage = false;
  123. if (flag === 'add') {
  124. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Upd&Guid=' + data.Guid); // ╠message.Save_Success⇒新增成功╣
  125. }
  126. else {
  127. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Add'); // ╠message.Save_Success⇒新增成功╣
  128. }
  129. }
  130. else {
  131. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  132. }
  133. }, function () {
  134. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  135. });
  136. },
  137. /**
  138. * 修改資料
  139. * @param {Boolean} balert 是否提示
  140. * @return {Object} ajax 物件
  141. */
  142. fnUpd = function (balert) {
  143. var data = getFormSerialize(oForm);
  144. data = packParams(data, 'upd');
  145. data.CheckFlows = fnCheckFlows(oCurData, true, true, saUsers);
  146. data.HandleFlows = fnHandleFlows(oCurData, saUsers);
  147. data.CheckOrder = JSON.stringify(oCurData.CheckOrder);
  148. data.Flows_Lock = oCurData.Flows_Lock;
  149. data.Handle_Lock = oCurData.Handle_Lock;
  150. return CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  151. Params: {
  152. leave: {
  153. values: data,
  154. keys: { Guid: sDataId }
  155. }
  156. }
  157. }, function (res) {
  158. if (res.d > 0) {
  159. if (!balert) {
  160. bRequestStorage = false;
  161. showMsg(i18next.t("message.Modify_Success"), 'success'); //╠message.Modify_Success⇒修改成功╣
  162. if (window.bLeavePage) {
  163. setTimeout(function () {
  164. pageLeave();
  165. }, 1000);
  166. }
  167. }
  168. }
  169. else {
  170. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  171. }
  172. }, function () {
  173. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  174. });
  175. },
  176. /**
  177. * 資料刪除
  178. */
  179. fnDel = function () {
  180. CallAjax(ComFn.W_Com, ComFn.GetDel, {
  181. Params: {
  182. leave: {
  183. Guid: sDataId
  184. }
  185. }
  186. }, function (res) {
  187. if (res.d > 0) {
  188. DelTask(sDataId);
  189. showMsgAndGo(i18next.t("message.Delete_Success"), sQueryPrgId); // ╠message.Delete_Success⇒刪除成功╣
  190. }
  191. else {
  192. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  193. }
  194. }, function () {
  195. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  196. });
  197. },
  198. /**
  199. * 上傳附件
  200. * @param {Array} files 上傳的文件
  201. */
  202. fnUpload = function (files) {
  203. var option = {};
  204. option.input = $('#fileInput');
  205. option.theme = 'dragdropbox';
  206. option.folder = 'Leave';
  207. option.type = 'list';
  208. option.parentid = oCurData.Guid;
  209. if (files) {
  210. option.files = files;
  211. }
  212. fnUploadRegister(option);
  213. },
  214. /**
  215. * 計算時差
  216. * @return {Object} 物件
  217. */
  218. fnGetDateDiff = function (Rules) {
  219. try {
  220. //ExFeild4代表是否為小數。Y=可為小數。N=不能為小數(直接進位)
  221. if (!!Rules.ExFeild4 && Rules.ExFeild4 === 'N') {
  222. RoundToInterger = true;
  223. }
  224. else {
  225. RoundToInterger = false;
  226. }
  227. DaysOfLeaves = new Array();
  228. var sStartDate = $('#StartDate').val(),
  229. sEndDate = $('#EndDate').val();
  230. if (sStartDate === '' || sEndDate === '') {
  231. return false;
  232. }
  233. var date_s = sStartDate.split(" ")[0].replaceAll('/', '-'),//開始的日期部分
  234. date_e = sEndDate.split(" ")[0].replaceAll('/', '-'),//結束的日期部分
  235. time_s = sStartDate.split(" ")[1],//開始的時間部分
  236. time_e = sEndDate.split(" ")[1],//結束的日期部分
  237. newdate_s = new Date(date_s + ' 00:00').getTime();
  238. newdate_s = new Date(newdate_s + 24 * 60 * 60 * 1000);
  239. var newdate_e = new Date(date_e + ' 23:59').getTime();
  240. newdate_e = new Date(newdate_e - 24 * 60 * 60 * 1000);
  241. var intDays = 0;
  242. var intHours = 0;
  243. var intDaysHours = "";
  244. let StartLeaveData = "";
  245. let MiddleLeaveData = new Array();
  246. let EndLeaveData = "";
  247. //完整日期區間
  248. while (newdate_s <= newdate_e) {
  249. intDaysHours = fnDaysAndHours(newdate_s);
  250. intDays += parseInt(intDaysHours.split('|')[0]);
  251. intHours += parseInt(intDaysHours.split('|')[1]);
  252. let NextNewDate = newdate_s.formate("yyyy-MM-dd") + ":" + intDaysHours;
  253. MiddleLeaveData.push(NextNewDate);
  254. newdate_s = new Date(newdate_s.getTime() + 24 * 60 * 60 * 1000);
  255. }
  256. //計算第一天和最後一天
  257. if (date_s === date_e) {//若都是當天
  258. let AllIntDay = 0;
  259. let AllIntHour = 0;
  260. intDaysHours = fnDateSE(date_s, time_s, time_e);
  261. AllIntDay = parseInt(intDaysHours.split('|')[0]);
  262. AllIntHour = (intDaysHours.split('|')[1] * 1);
  263. if (RoundToInterger)//看特休與設定,能否小數
  264. AllIntHour = Math.ceil(AllIntHour);
  265. StartLeaveData = new Date(date_s + ' 00:00').formate("yyyy-MM-dd") + ":" + AllIntDay + "|" + AllIntHour;
  266. intDays += AllIntDay;
  267. intHours += AllIntHour;
  268. }
  269. else {
  270. let FirstIntDay = 0;
  271. let FirstIntHour = 0;
  272. let LastIntDay = 0;
  273. let LastIntHour = 0;
  274. //第一天
  275. intDaysHours = fnDateSE(date_s, time_s, "23:59");
  276. FirstIntDay = parseInt(intDaysHours.split('|')[0]);
  277. FirstIntHour = intDaysHours.split('|')[1] * 1;
  278. //不准為小數,要無條件進位
  279. if (RoundToInterger)
  280. FirstIntHour = Math.ceil(FirstIntHour);
  281. StartLeaveData = new Date(date_s + ' 00:00').formate("yyyy-MM-dd") + ":" + FirstIntDay + "|" + FirstIntHour;
  282. //最後一天
  283. intDaysHours = fnDateSE(date_e, "00:00", time_e);
  284. LastIntDay = parseInt(intDaysHours.split('|')[0]);
  285. LastIntHour = intDaysHours.split('|')[1] * 1;
  286. //不准為小數,要無條件進位
  287. if (RoundToInterger)
  288. LastIntHour = Math.ceil(LastIntHour);
  289. EndLeaveData = new Date(date_e + ' 00:00').formate("yyyy-MM-dd") + ":" + LastIntDay + "|" + LastIntHour;
  290. intDays += FirstIntDay + LastIntDay;
  291. intHours += FirstIntHour + LastIntHour;
  292. }
  293. DaysOfLeaves.push(StartLeaveData);
  294. MiddleLeaveData.forEach((e, idx) => {
  295. DaysOfLeaves.push(e);
  296. });
  297. DaysOfLeaves.push(EndLeaveData);
  298. let TotalHours = (intDays * iOneDayHours + intHours).toFloat(1);
  299. $('#TotalTime').val(TotalHours);
  300. } catch (e) { console.log(e); }
  301. },
  302. /**
  303. * 返回週幾信息
  304. * @param {Date} times 開始時間
  305. * @param {Date} timee 結束時間
  306. * @return {Number} 分鐘
  307. */
  308. fnDiffTimeSE = function (times, timee) {
  309. var minute = 1000 * 60 * 60,
  310. DateS1 = new Date(times).getTime(),
  311. DateE1 = new Date(timee).getTime(),
  312. diffValue = DateE1 - DateS1,
  313. minC = diffValue / minute;
  314. return minC;
  315. },
  316. /**
  317. * 日期和時間
  318. * @param {Date} dates 當前日期
  319. * @param {Date} times 開始時間
  320. * @param {Date} timee 結束時間
  321. * @return {Object} 物件
  322. */
  323. fnDateSE = function (dates, times, timee) {
  324. try {
  325. var intDays = 0,
  326. inthour = 0,
  327. intAllhour = 0,
  328. aryTimeSE = [parent.SysSet.WorkTimePM, parent.SysSet.WorkTimeAM];
  329. if (sHolidays.indexOf(dates) > -1) {
  330. //是節假日
  331. intDays = 0;
  332. inthour = 0;
  333. }
  334. else {//非節假日
  335. var IsCheckAllDay = "";
  336. for (var i = 0; i < aryTimeSE.length; i++) {
  337. if (aryTimeSE[i]) {
  338. var aryTimeS = dates + " " + aryTimeSE[i].split('~')[0];//設小
  339. var aryTimeE = dates + " " + aryTimeSE[i].split('~')[1];//設大
  340. if (new Date(dates + " " + timee) >= new Date(dates + " " + '12:00') && new Date(dates + " " + timee) <= new Date(dates + " " + '13:00') && new Date(aryTimeE) <= new Date(dates + " " + '13:00')) {
  341. timee = aryTimeSE[i].split('~')[1];
  342. }
  343. if (fnDiffTimeSE(dates + " " + times, aryTimeS) >= 0 && fnDiffTimeSE(aryTimeE, dates + " " + timee) >= 0) {
  344. IsCheckAllDay += "Y";
  345. intAllhour += fnDiffTimeSE(aryTimeS, aryTimeE);
  346. }
  347. else {
  348. IsCheckAllDay += "N";
  349. //傳小>設小 AND 傳大>=設大
  350. if (fnDiffTimeSE(aryTimeS, dates + " " + times) >= 0 && fnDiffTimeSE(dates + " " + timee, aryTimeE) > 0 || fnDiffTimeSE(aryTimeS, dates + " " + times) > 0 && fnDiffTimeSE(dates + " " + timee, aryTimeE) >= 0) {
  351. intAllhour += fnDiffTimeSE(dates + " " + times, dates + " " + timee);
  352. }
  353. else if (fnDiffTimeSE(aryTimeS, dates + " " + times) > 0 && fnDiffTimeSE(aryTimeE, dates + " " + timee) > 0 && fnDiffTimeSE(dates + " " + times, aryTimeE) > 0) {
  354. intAllhour += fnDiffTimeSE(dates + " " + times, aryTimeE);
  355. }
  356. else if (fnDiffTimeSE((dates + " " + times), aryTimeS) > 0 && fnDiffTimeSE(aryTimeS, dates + " " + timee) > 0 && fnDiffTimeSE(dates + " " + timee, aryTimeE) > 0) {
  357. intAllhour += fnDiffTimeSE(aryTimeS, dates + " " + timee);
  358. }
  359. }
  360. }
  361. }
  362. if (IsCheckAllDay.indexOf("N") > -1) {//非全天
  363. intDays = 0;
  364. inthour = intAllhour;
  365. var days = Math.floor(inthour / iOneDayHours);
  366. if (days > 0) {
  367. //全天
  368. intDays = 1;
  369. inthour = 0;
  370. }
  371. }
  372. else {
  373. intDays = 1;
  374. inthour = 0;
  375. }
  376. }
  377. return intDays + "|" + inthour;
  378. } catch (e) { console.log(e); }
  379. },
  380. /**
  381. * 日期和小時
  382. * @param {Date} curdate 當前日期
  383. * @return {Object} 物件
  384. */
  385. fnDaysAndHours = function (curdate) {
  386. try {
  387. var intDays = 0,
  388. inthour = 0;
  389. if (sHolidays.indexOf(curdate.formate("yyyy-MM-dd")) > -1) { //是節假日
  390. intDays = 0;
  391. inthour = 0;
  392. }
  393. else {//非節假日
  394. intDays = 1;
  395. inthour = 0;
  396. }
  397. return intDays + "|" + inthour;
  398. } catch (e) { console.log(e); }
  399. },
  400. /**
  401. * 獲取假日信息
  402. */
  403. fnGetHolidays = function () {
  404. var sYear = new Date().getFullYear() + ',' + new Date().dateAdd('y', 1).getFullYear();
  405. CallAjax(ComFn.W_Com, ComFn.GetList, {
  406. Type: '',
  407. Params: {
  408. holidays: {
  409. _CHARINDEX_Year: sYear,
  410. OrgID: parent.OrgID
  411. }
  412. }
  413. }, function (res) {
  414. if (res.d) {
  415. var saRes = $.parseJSON(res.d);
  416. $.each(saRes, function (idx, _data) {
  417. sHolidays += _data.Holidays;
  418. });
  419. }
  420. });
  421. },
  422. /**
  423. * 提交簽呈
  424. */
  425. fnSubmitPetition = function () {
  426. ////為了確保資料由前端提供。
  427. //fnGetDateDiff(LeaveRules);
  428. var sHolidayCategory = $('#HolidayCategory').val(),
  429. sTotalTime = $('#TotalTime').val(),
  430. sLeaveSetInfo = JSON.stringify(saLeaveSetInfo);
  431. g_api.ConnectLite(sProgramId, 'LeaveToAudit', {
  432. guid: oCurData.Guid,
  433. LeaveSetGuid: oLeaveSet.Guid,
  434. TotalTime: sTotalTime,
  435. HolidayCategory: sHolidayCategory,
  436. LeaveSetInfo: sLeaveSetInfo,
  437. OrgID: parent.OrgID,
  438. StartDate: $('#StartDate').val(),
  439. EndDate: $('#EndDate').val(),
  440. CreateUser: oCurData.AskTheDummy,
  441. DaysOfLeaves: DaysOfLeaves,
  442. RoundToInterger: RoundToInterger,
  443. LeaveRequestUsing: LeaveRequestUsing,
  444. }, function (res) {
  445. if (res.RESULT) {
  446. showMsgAndGo(i18next.t("message.ToAudit_Success"), sViewPrgId, '?Action=Upd&Guid=' + oCurData.Guid);// ╠message.ToAudit_Success⇒提交審核成功╣
  447. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  448. }
  449. else {
  450. showMsg(i18next.t('message.ToAudit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  451. }
  452. }, function () {
  453. showMsg(i18next.t('message.ToAudit_Failed'), 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  454. });
  455. },
  456. /**
  457. * 假別時數檢核
  458. * @return {String} 名稱
  459. */
  460. fnCheckLeaveHours = function () {
  461. var sMsg = '',
  462. sHolidayCategory = $('#HolidayCategory').val(),
  463. sTotalTime = $('#TotalTime').val(),
  464. iTotalTime = parseFloat(!sTotalTime ? '0' : sTotalTime);
  465. LeaveRequestUsing = [];
  466. //有限制的假別
  467. if (saLeaveRequstList.length) {
  468. $.each(saLeaveRequstList, function (idx, lr) {
  469. if (sHolidayCategory === lr.Leave && iTotalTime > 0) {
  470. let UsedHour = 0;
  471. if (iTotalTime - lr.RemainHours > 0) {
  472. UsedHour = lr.RemainHours;
  473. iTotalTime = iTotalTime - lr.RemainHours;
  474. }
  475. else {
  476. UsedHour = iTotalTime;
  477. lr.RemainHours = lr.RemainHours - iTotalTime;
  478. iTotalTime = 0;
  479. }
  480. LeaveRequestUsing.push({ Guid: lr.guid, UsedHours: UsedHour });
  481. }
  482. })
  483. }
  484. //無限制的假別
  485. $.each(saLeaveSetInfo, function (idx, set) {
  486. if (set.Id === sHolidayCategory) {
  487. var intTotalUsable = set.PaymentHours + parseInt(sLeaveSet.Correlation) - set.UsedHours; //可用時數+可預支時數-已用時數
  488. sHolidayCategory == '09' ? intTotalUsable = set.RemainHours:""; //額外判斷,特休假直接取剩餘時數(特休無可預支時數)
  489. if (set.PaymentHours !== '' && sLeaveSet.Correlation !== '' && intTotalUsable < iTotalTime) { //可用時數及預支時數不為空(不限制),可用時數+可預支時數-已用時數小於請假時間
  490. sMsg = set.Name;
  491. }
  492. else {
  493. if (set.PaymentHours === '') {
  494. set.UsedHours = set.UsedHours * 1 + iTotalTime;
  495. }
  496. else {
  497. set.UsedHours = set.UsedHours * 1 + iTotalTime;
  498. set.RemainHours = set.PaymentHours * 1 - set.UsedHours * 1;
  499. }
  500. }
  501. return false;
  502. }
  503. });
  504. return sMsg;
  505. },
  506. /**
  507. * 獲取請假設定
  508. * @return {Boolean} 停止標記
  509. */
  510. fnGetLeaveSet = function () {
  511. var sEndDate = $('#EndDate').val(),
  512. sLeaveDate = newDate(sEndDate, true),
  513. sCurrentYear = (new Date(sEndDate)).formate('yyyy');
  514. return $.whenArray([CallAjax(ComFn.W_Com, ComFn.GetPagePrc, {
  515. Type: 'wenzhong_getlist',
  516. Params: {
  517. querysort: 'UserID asc',
  518. pageindex: 1,
  519. pagesize: 100,
  520. UserID: oCurData.AskTheDummy,
  521. Date: '',
  522. LeaveDate: sEndDate,
  523. OrgID: parent.OrgID
  524. }
  525. }),
  526. CallAjax(ComFn.W_Com, ComFn.GetOne, {
  527. Type: '',
  528. Params: {
  529. leaveset: {
  530. OrgID: parent.OrgID,
  531. UserID: oCurData.AskTheDummy,
  532. TYear: sCurrentYear
  533. }
  534. }
  535. })]).done(function (res1, res2) {
  536. if (res2[1] === 'success') {
  537. var oTXJ = {};
  538. oLeaveSet = $.parseJSON(res2[0].d);
  539. saLeaveSetInfo = $.parseJSON(oLeaveSet.SetInfo);
  540. if (!saLeaveSetInfo) {
  541. showMsg(i18next.t('message.LeaveSetNotInit')); //考勤設定未初始化,請聯絡管理人員初始化考勤設定
  542. return false;
  543. }
  544. if (res1[1] === 'success') {
  545. oTXJ = $.parseJSON(res1[0].d);
  546. if (oTXJ.DataList) {
  547. $.each(saLeaveSetInfo, function (idx, set) {
  548. if (set.Id === '09') {
  549. var iRemainHours = 0;
  550. $.each(oTXJ.DataList, function (idx, txj) {
  551. if (txj.RemainHours > 0) {
  552. iRemainHours += txj.RemainHours * 1;
  553. }
  554. });
  555. set.RemainHours = iRemainHours;
  556. set.PaymentHours = 0;
  557. return false;
  558. }
  559. });
  560. }
  561. }
  562. var limited = g_api.ConnectLite('LeaveRequest_Qry', 'GetAvailableHLeaveHours', {
  563. UserID: parent.UserID,
  564. OrgID: parent.OrgID,
  565. LeaveDateStart: $('#StartDate').val(),
  566. LeaveDateEnd: $('#EndDate').val()
  567. });
  568. var Unlimited = g_api.ConnectLite(sProgramId, 'GetLeaveSetting', {
  569. ArgumentID: $('#HolidayCategory').val(),
  570. OrgID: parent.OrgID,
  571. });
  572. //取得出勤設定資料
  573. $.whenArray([limited, Unlimited]).done(function (res1, res2) {
  574. if (res1[0].RESULT && res1[0].DATA.rel.length) {
  575. saLeaveRequstList = res1[0].DATA.rel
  576. }
  577. else {
  578. saLeaveRequstList = [];
  579. }
  580. if (res2[0].RESULT) {
  581. sLeaveSet = res2[0].DATA.rel;
  582. //為了確保資料由前端提供。
  583. fnGetDateDiff(LeaveRules);
  584. var sMsg = fnCheckLeaveHours();
  585. if (sMsg) {
  586. showMsg(i18next.t('message.HolidayLimit').replace('HolidayName', sMsg)); //您選擇的假別[HolidayName]當年剩餘可用時數已不足<br>請聯絡管理人員核查
  587. return false;
  588. }
  589. fnUpd(true).done(function () {
  590. fnSubmitPetition();
  591. });
  592. }
  593. });
  594. }
  595. });
  596. },
  597. /**
  598. * 依據假別獲取假別限制規則
  599. * @param {String}val 假別
  600. */
  601. fnGetLeaveSettingByType = function (val) {
  602. g_api.ConnectLite('LeaveSet', 'GetLeaveSettingByType',
  603. {
  604. LeaveType: val
  605. },
  606. function (res) {
  607. if (res.RESULT) {
  608. LeaveRules = res.DATA.rel;
  609. }
  610. });
  611. },
  612. /**
  613. * ToolBar 按鈕事件 function
  614. * @param {Object}inst 按鈕物件對象
  615. * @param {Object} e 事件對象
  616. * @return {Boolean} 停止標記
  617. */
  618. fnButtonHandler = function (inst, e) {
  619. var sId = inst.id;
  620. switch (sId) {
  621. case "Toolbar_Qry":
  622. break;
  623. case "Toolbar_Save":
  624. if (!$("#form_main").valid()) {
  625. oValidator.focusInvalid();
  626. return false;
  627. }
  628. if (sAction === 'Add') {
  629. fnAdd('add');
  630. }
  631. else {
  632. fnUpd();
  633. }
  634. break;
  635. case "Toolbar_ReAdd":
  636. if (!$("#form_main").valid()) {
  637. oValidator.focusInvalid();
  638. return false;
  639. }
  640. fnAdd('readd');
  641. break;
  642. case "Toolbar_Clear":
  643. clearPageVal();
  644. break;
  645. case "Toolbar_Leave":
  646. pageLeave();
  647. break;
  648. case "Toolbar_Add":
  649. break;
  650. case "Toolbar_Upd":
  651. break;
  652. case "Toolbar_Copy":
  653. break;
  654. case "Toolbar_Petition":
  655. if (!$("#form_main").valid()) {
  656. oValidator.focusInvalid();
  657. return false;
  658. }
  659. fnGetLeaveSet();
  660. break;
  661. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  662. layer.confirm(i18next.t("message.ConfirmToDelete"), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  663. fnDel();
  664. layer.close(index);
  665. });
  666. break;
  667. default:
  668. alert("No handle '" + sId + "'");
  669. break;
  670. }
  671. },
  672. /**
  673. * 初始化 function
  674. */
  675. init = function () {
  676. var saCusBtns = null;
  677. if (sAction === 'Upd') {
  678. saCusBtns = [{
  679. id: 'Toolbar_Petition',
  680. value: 'common.SubmitPetition'// ╠common.SubmitPetition⇒提交簽呈╣
  681. }];
  682. }
  683. commonInit({
  684. PrgId: sProgramId,
  685. ButtonHandler: fnButtonHandler,
  686. Buttons: saCusBtns,
  687. GoTop: true,
  688. onSelect: function (d, el) {
  689. fnGetDateDiff(LeaveRules);
  690. }
  691. });
  692. $.validator.addMethod("daterule", function (value) {
  693. if (sHolidays.indexOf(new Date(newDate(value)).formate("yyyy-MM-dd")) > -1) { //是節假日
  694. return false;
  695. }
  696. else {//非節假日
  697. return true;
  698. }
  699. });
  700. $.validator.addMethod("daterule_interval", function (value) {
  701. //if (LeaveRules.ExFeild2) {
  702. // var intCurHours = parseInt($('#TotalTime').val()); //使用時數
  703. // var intExFeild2 = parseInt(LeaveRules.ExFeild2); //倍率機數
  704. // var blnResidue = intCurHours % intExFeild2; //判斷餘數是否為0
  705. // if (LeaveRules.ExFeild2 !== '' && blnResidue !== 0) { //請假時數必需為X的倍數
  706. // return false;
  707. // }
  708. // else {
  709. // return true;
  710. // }
  711. //}
  712. var bRetn = true;
  713. if (LeaveRules.ExFeild2) {
  714. g_api.ConnectLite(sProgramId, 'QueryCout',
  715. {
  716. EndTime: value,
  717. Hours: LeaveRules.ExFeild2
  718. },
  719. function (res) {
  720. if (res.RESULT && res.DATA.rel > 0) {
  721. bRetn = false;
  722. oValidator.settings.messages.StartDate.daterule_interval = LeaveRules.ArgumentValue + i18next.t("message.LeaveIntervalRule") + LeaveRules.ExFeild2 + i18next.t("common.Hours");
  723. }
  724. }, null, false);
  725. }
  726. return bRetn;
  727. });
  728. $.validator.addMethod("daterule_maxpermonth", function (value) {
  729. var bRetn = true;
  730. if (LeaveRules.ExFeild3) {
  731. g_api.ConnectLite(sProgramId, 'CheckMaxHours',
  732. {
  733. Date: value,
  734. CurHours: $('#TotalTime').val(),
  735. MaxHours: LeaveRules.ExFeild3
  736. },
  737. function (res) {
  738. if (res.RESULT && res.DATA.rel) {
  739. bRetn = false;
  740. // ╠message.ToSelectOtherDate⇒請修改請假時間或選擇其他日期╣
  741. oValidator.settings.messages.StartDate.daterule_maxpermonth = LeaveRules.ArgumentValue + i18next.t("message.LeaveMaxHoursPerMonthRule") + LeaveRules.ExFeild3 + i18next.t("common.Hours") + ',' + i18next.t("message.ToSelectOtherDate");
  742. }
  743. }, null, false);
  744. }
  745. return bRetn;
  746. });
  747. $.validator.addMethod("timesrule", function (value) {
  748. if (LeaveRules.ExFeild4 !== 'Y' && value.indexOf('.') > -1) { //請假(特修假)時數不可以是小數
  749. return false;
  750. }
  751. else {//小數
  752. return true;
  753. }
  754. });
  755. $.validator.addMethod("timesrule_min", function (value) {
  756. if (LeaveRules.ExFeild1 && LeaveRules.ExFeild1 * 1 > value * 1) { //最小請假時數
  757. oValidator.settings.messages.TotalTime.timesrule_min = LeaveRules.ArgumentValue + i18next.t("message.MinimumLeaveHoursFor") + LeaveRules.ExFeild1 + i18next.t("common.Hours");
  758. return false;
  759. }
  760. else {//小數
  761. return true;
  762. }
  763. });
  764. $.validator.addMethod("compardatetime", function (value, element, parms) {
  765. if (new Date(value) <= new Date($('#StartDate').val())) {
  766. return false;
  767. }
  768. return true;
  769. });
  770. oValidator = $("#form_main").validate({ //表單欄位驗證
  771. rules: {
  772. StartDate: {
  773. daterule: true,
  774. daterule_interval: true,
  775. daterule_maxpermonth: true
  776. },
  777. EndDate: { daterule: true },
  778. TotalTime: {
  779. timesrule: true,
  780. timesrule_min: true
  781. }
  782. },
  783. messages: {
  784. StartDate: {
  785. daterule: i18next.t("message.DateNotHolidays"),// ╠message.DateNotHolidays⇒日期不能是節假日╣
  786. daterule_interval: i18next.t("message.LeaveIntervalRule"),// ╠message.LeaveIntervalRule⇒最小間隔時間為╣
  787. daterule_maxpermonth: i18next.t("message.LeaveMaxHoursPerMonthRule")// ╠message.LeaveMaxHoursPerMonthRule⇒當月最大請假時數為╣
  788. },
  789. EndDate: { daterule: i18next.t("message.DateNotHolidays") },// ╠message.DateNotHolidays⇒日期不能是節假日╣
  790. TotalTime: {
  791. timesrule: i18next.t("message.HoursNotDecimal"),// ╠message.HoursNotDecimal⇒請假時數不可以是小數╣
  792. timesrule_min: i18next.t("message.MinimumLeaveHoursFor")// ╠message.MinimumLeaveHoursFor⇒最小請假時數為╣
  793. }
  794. }
  795. });
  796. $.whenArray([
  797. fnSetDeptDrop($('#Handle_DeptID,#Agent_DeptID')),
  798. fnSetFlowDrop({
  799. Flow_Type: parent.SysSet.Eip_001,
  800. ShareTo: parent.UserID,
  801. CallBack: function (data) {
  802. $.each(data, function (idx, item) {
  803. var saFlows = $.parseJSON(item.Flows),
  804. saFlowsText = [],
  805. sFlowsText = '';
  806. $.each(saFlows, function (idx, flow) {
  807. var sFlowType = i18next.t('common.' + flow.SignedWay);
  808. if (flow.SignedWay !== 'flow1') {
  809. saFlowsText.push(sFlowType + '(' + Enumerable.From(flow.SignedMember).ToString(",", "$.name") + ')');
  810. }
  811. else {
  812. saFlowsText.push(Enumerable.From(flow.SignedMember).ToString(",", "$.name"));
  813. }
  814. });
  815. sFlowsText = saFlowsText.join(' → ');
  816. item.text = item.Flow_Name + ' - ' + (sFlowsText.length > 60 ? sFlowsText.substr(0, 60) + '...' : sFlowsText);
  817. });
  818. $('#FlowId').html(createOptions(data, 'Guid', 'text')).on('change', function () {
  819. var sFlowId = this.value;
  820. if (sFlowId) {
  821. CallAjax(ComFn.W_Com, ComFn.GetOne, {
  822. Type: '',
  823. Params: {
  824. checkflow: {
  825. Guid: sFlowId
  826. }
  827. }
  828. }, function (res) {
  829. if (res.d) {
  830. var oRes = $.parseJSON(res.d);
  831. oRes.Flows = $.parseJSON(oRes.Flows);
  832. oCurData.CheckOrder = oRes.Flows;
  833. oCurData.Flows_Lock = oRes.Flows_Lock;
  834. oCurData.Handle_Lock = oRes.Handle_Lock;
  835. $("#Handle_DeptID").val(oRes.Handle_DeptID);
  836. $("#Handle_Person").val(oRes.Handle_Person).trigger('change');
  837. if (oRes.Flows_Lock === 'Y') {
  838. $(".checkordertoolbox").hide();
  839. }
  840. else {
  841. $(".checkordertoolbox").show();
  842. }
  843. if (oRes.Handle_Lock === 'Y') {
  844. $("#Handle_DeptID,#Handle_Person").attr('disabled', true);
  845. }
  846. else {
  847. $("#Handle_DeptID,#Handle_Person").removeAttr('disabled');
  848. }
  849. $("#jsGrid").jsGrid("loadData");
  850. }
  851. });
  852. }
  853. else {
  854. oCurData.CheckOrder = [];
  855. $(".checkordertoolbox").hide();
  856. $("#jsGrid").jsGrid("loadData");
  857. $("#Handle_DeptID,#Handle_Person").removeAttr('disabled');
  858. }
  859. });
  860. }
  861. }),
  862. fnGetHolidays(),
  863. fnSetUserDrop([
  864. {
  865. Select: $('#Handle_Person'),
  866. Select2: true,
  867. ShowId: true,
  868. Action: sAction,
  869. CallBack: function (data) {
  870. saUsers = data;
  871. }
  872. }
  873. ]),
  874. fnSetUserDrop([
  875. {
  876. Select: $('#Agent_Person'),
  877. Select2: true,
  878. ShowId: true,
  879. Action: sAction,
  880. NotUserIDs: parent.UserID,
  881. CallBack: function (data) {
  882. saUsers = data;
  883. }
  884. }
  885. ]),
  886. fnSetArgDrop([
  887. {
  888. ArgClassID: 'LeaveType',
  889. Select: $('#HolidayCategory'),
  890. ShowId: true,
  891. OnChange: function (val) {
  892. fnGetLeaveSettingByType(val);
  893. }
  894. }
  895. ])])
  896. .done(function () {
  897. fnGet();
  898. });
  899. $('#Handle_DeptID').on('change', function () {
  900. fnSetUserDrop([
  901. {
  902. Select: $('#Handle_Person'),
  903. DepartmentID: this.value,
  904. ShowId: true,
  905. Select2: true,
  906. Action: sAction
  907. }
  908. ]);
  909. });
  910. $('#Agent_Person').on('change', function () {
  911. oCurData.Agent_Person = this.value;
  912. });
  913. $('#Agent_DeptID').on('change', function () {
  914. fnSetUserDrop([
  915. {
  916. Select: $('#Agent_Person'),
  917. DepartmentID: this.value,
  918. ShowId: true,
  919. Select2: true,
  920. Action: sAction,
  921. NotUserIDs: parent.UserID
  922. }
  923. ]);
  924. });
  925. $('.flowlink').on('click', function () {
  926. var oOption = {};
  927. oOption.SignedWay = this.id;
  928. oOption.Callback = function (data) {
  929. if (data.Users.length > 0) {
  930. var oFlow = {};
  931. if (data.FlowType === 'flow1') {
  932. $.each(data.Users, function (idx, user) {
  933. oFlow = {};
  934. oFlow.id = guid();
  935. oFlow.Order = oCurData.CheckOrder.length + 1;
  936. oFlow.SignedWay = data.FlowType;
  937. oFlow.SignedMember = [{
  938. id: user.id,
  939. name: user.name,
  940. deptname: user.deptname,
  941. jobname: user.jobname
  942. }];
  943. oCurData.CheckOrder.push(oFlow);
  944. });
  945. }
  946. else {
  947. var saUsers = [];
  948. $.each(data.Users, function (idx, user) {
  949. saUsers.push({
  950. id: user.id,
  951. name: user.name,
  952. deptname: user.deptname,
  953. jobname: user.jobname
  954. });
  955. });
  956. oFlow.id = guid();
  957. oFlow.Order = oCurData.CheckOrder.length + 1;
  958. oFlow.SignedWay = data.FlowType;
  959. oFlow.SignedMember = saUsers;
  960. oCurData.CheckOrder.push(oFlow);
  961. }
  962. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  963. $("#jsGrid").jsGrid("loadData");
  964. }
  965. };
  966. oPenUserListPop(oOption);
  967. });
  968. $("#jsGrid").jsGrid({
  969. width: "100%",
  970. height: "auto",
  971. autoload: true,
  972. filtering: false,
  973. pageLoading: true,
  974. pageIndex: 1,
  975. pageSize: 10000,
  976. fields: [
  977. {
  978. name: "Order", title: 'common.Order', width: 50, align: "center",
  979. itemTemplate: function (val, item) {
  980. return val < 10 ? '0' + val : val;
  981. }
  982. },
  983. {
  984. name: "SignedWay", title: 'common.SignedWay', width: 120, align: "center",
  985. itemTemplate: function (val, item) {
  986. return i18next.t('common.' + val);
  987. }
  988. },
  989. {
  990. type: "Icon", width: 50, align: "center",
  991. itemTemplate: function (val, item) {
  992. var oIcon = {
  993. flow1: '<img src="../../images/flow_check.gif">',
  994. flow2: '<img src="../../images/flow_check.gif"><img src="../../images/flow_check.gif">',
  995. flow3: '<img src="../../images/flow_check.gif"><img src="../../images/flow_nocheck.gif">',
  996. flow4: '<img src="../../images/flow4.gif">'
  997. },
  998. sIcon = oIcon[item.SignedWay];
  999. if (item.Order !== oCurData.CheckOrder.length) {
  1000. sIcon += '<br><img src="../../images/flow_arrow.gif" style="vertical-align:top;">'
  1001. }
  1002. return sIcon;
  1003. }
  1004. },
  1005. {
  1006. name: "SignedMember", title: 'common.SignedMember', width: 500,
  1007. itemTemplate: function (val, item) {
  1008. return Enumerable.From(val).ToString(",", "$.name");
  1009. }
  1010. },
  1011. {
  1012. type: "control", title: 'common.Action', width: 200,
  1013. itemTemplate: function (val, item) {
  1014. var oBtns = [$('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  1015. class: 'glyphicon glyphicon-pencil' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  1016. title: i18next.t('common.Edit'),// ╠common.Edit⇒編輯╣
  1017. click: function () {
  1018. if ($(this).hasClass('disabled')) { return false; }
  1019. var oOption = {};
  1020. oOption.SignedWay = item.SignedWay;
  1021. oOption.SignedMember = item.SignedMember;
  1022. oOption.Callback = function (data) {
  1023. if (data.Users.length > 0) {
  1024. var oFlow = {};
  1025. if (data.FlowType === 'flow1') {
  1026. $.each(data.Users, function (idx, user) {
  1027. var oFlow = {};
  1028. oFlow.id = guid();
  1029. oFlow.Order = item.Order + idx;
  1030. oFlow.SignedWay = data.FlowType;
  1031. oFlow.SignedMember = [{
  1032. id: user.id,
  1033. name: user.name,
  1034. deptname: user.deptname,
  1035. jobname: user.jobname
  1036. }];
  1037. oCurData.CheckOrder.insert(item.Order + idx, oFlow);
  1038. });
  1039. }
  1040. else {
  1041. var saUsers = [];
  1042. $.each(data.Users, function (idx, user) {
  1043. saUsers.push({
  1044. id: user.id,
  1045. name: user.name,
  1046. deptname: user.deptname,
  1047. jobname: user.jobname
  1048. });
  1049. });
  1050. oFlow.id = guid();
  1051. oFlow.Order = item.Order;
  1052. oFlow.SignedWay = data.FlowType;
  1053. oFlow.SignedMember = saUsers;
  1054. oCurData.CheckOrder.insert(item.Order, oFlow);
  1055. }
  1056. var iOrder = 1;
  1057. $.each(oCurData.CheckOrder, function (idx, _data) {
  1058. if (item.id !== _data.id) {
  1059. _data.Order = iOrder;
  1060. iOrder++;
  1061. }
  1062. });
  1063. oCurData.CheckOrder = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id !== item.id; }).ToArray();
  1064. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  1065. $("#jsGrid").jsGrid("loadData");
  1066. }
  1067. };
  1068. oPenUserListPop(oOption);
  1069. }
  1070. })),
  1071. $('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  1072. class: 'glyphicon glyphicon-trash' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  1073. title: i18next.t('common.Toolbar_Del'),// ╠common.Toolbar_Del⇒刪除╣
  1074. click: function () {
  1075. if ($(this).hasClass('disabled')) { return false; }
  1076. var saNewList = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id !== item.id; }).ToArray();
  1077. oCurData.CheckOrder = saNewList;
  1078. $.each(oCurData.CheckOrder, function (idx, _data) {
  1079. _data.Order = idx + 1;
  1080. });
  1081. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  1082. $("#jsGrid").jsGrid("loadData");
  1083. }
  1084. }))];
  1085. if (oCurData.CheckOrder.length !== item.Order) {
  1086. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  1087. class: 'glyphicon glyphicon-arrow-down' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  1088. title: i18next.t('common.Down'),// ╠common.Down⇒下移╣
  1089. click: function () {
  1090. if ($(this).hasClass('disabled')) { return false; }
  1091. var sOrder = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  1092. iOrder = sOrder * 1;
  1093. $.each(oCurData.CheckOrder, function (idx, _data) {
  1094. if (iOrder === _data.Order) {
  1095. _data.Order++;
  1096. }
  1097. else if ((iOrder + 1) === _data.Order) {
  1098. _data.Order--;
  1099. }
  1100. });
  1101. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  1102. $("#jsGrid").jsGrid("loadData");
  1103. }
  1104. })));
  1105. }
  1106. else {
  1107. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }));
  1108. }
  1109. if (1 !== item.Order) {
  1110. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  1111. class: 'glyphicon glyphicon-arrow-up' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  1112. title: i18next.t('common.Up'),// ╠common.Up⇒上移╣
  1113. click: function () {
  1114. if ($(this).hasClass('disabled')) { return false; }
  1115. var sOrder = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  1116. iOrder = sOrder * 1;
  1117. $.each(oCurData.CheckOrder, function (idx, _data) {
  1118. if (iOrder === _data.Order) {
  1119. _data.Order--;
  1120. }
  1121. else if (iOrder - 1 === _data.Order) {
  1122. _data.Order++;
  1123. }
  1124. });
  1125. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  1126. $("#jsGrid").jsGrid("loadData");
  1127. }
  1128. })));
  1129. }
  1130. return oBtns;
  1131. }
  1132. }
  1133. ],
  1134. controller: {
  1135. loadData: function (args) {
  1136. return {
  1137. data: oCurData.CheckOrder,
  1138. itemsCount: oCurData.CheckOrder.length //data.length
  1139. };
  1140. },
  1141. insertItem: function (args) {
  1142. },
  1143. updateItem: function (args) {
  1144. },
  1145. deleteItem: function (args) {
  1146. }
  1147. },
  1148. onInit: function (args) {
  1149. oGrid = args.grid;
  1150. }
  1151. });
  1152. };
  1153. init();
  1154. };
  1155. require(['base', 'select2', 'jsgrid', 'filer', 'timepicker', 'common_eip', 'util'], fnPageInit, 'timepicker');