factory.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. starter.factory('workatd', function (cfg, global, formatFilter, Tool) {
  2. var _weeknames = ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
  3. var _today = new Date();
  4. var _current = {};
  5. var _urlbase = formatFilter('{0}workatd/settings/', cfg.api);
  6. return {
  7. titleArr: ['正常考勤', '上班迟到', '下班早退', '上班未签到', '下班未签退'],
  8. weeknames: _weeknames,
  9. todayweek: _weeknames[_today.getDay()],
  10. today: _today.getFullYear() + "年" + (_today.getMonth() + 1).toString() + "月" + _today.getDate() + "日",
  11. current: function (op) {
  12. op = op || 1;
  13. return op > 0 ? Tool.getTempData('workatddetail') : _current;
  14. },
  15. addnew: function () {
  16. _current = {
  17. "ischeckmonday": true,
  18. "ischecktuesday": true,
  19. "ischeckwednesday": true,
  20. "ischeckthursday": true,
  21. "ischeckfriday": true,
  22. "ischecksaturday": false,
  23. "ischecksunday": false,
  24. "am_ontime": null,
  25. "am_offtime": null,
  26. "pm_ontime": null,
  27. "pm_offtime": null,
  28. "isdoublecheck": 0,
  29. "workposition": null,
  30. "workaddress": null,
  31. "offset": 500,
  32. "ap_names": null,
  33. "isallowauto": 1,
  34. "isallcheck": 0,
  35. "tz": new Date().getTimezoneOffset(),
  36. "workatdreportusr": [],
  37. "workatddept": [],
  38. "workatdwithoutusr": []
  39. }
  40. return _current;
  41. },
  42. getSettings: function () {
  43. var url = formatFilter('{0}workatd/settings/', cfg.api);
  44. return Tool.get(url);
  45. },
  46. getDetail: function (id) {
  47. var url = formatFilter('{0}workatd/setting/{1}/', cfg.api, id);
  48. return Tool.get(url, true, 'workatddetail')
  49. },
  50. save: function (id, data) {
  51. var reportusr = data.workatdreportusr;
  52. var withoutusr = data.workatdwithoutusr;
  53. var dept = data.workatddept;
  54. data.workatdreportusr = [];
  55. data.workatdwithoutusr = [];
  56. data.workatddept = [];
  57. if (!data.isdoublecheck) {
  58. data.am_offtime = null;
  59. data.pm_ontime = null;
  60. }
  61. data = _.omit(data, 'am_ontime_view', 'am_offtime_view', 'pm_ontime_view', 'pm_offtime_view', 'ischeckpmoff', 'ischeckpmon', 'ischeckamon', 'ischeckamoff', "isdoublecheck");
  62. _.each(reportusr, function (item) {
  63. data.workatdreportusr.push(item.user_id);
  64. });
  65. _.each(withoutusr, function (item) {
  66. data.workatdwithoutusr.push(item.user_id);
  67. });
  68. _.each(dept, function (item) {
  69. if (item.dept__id) {
  70. item.id = item.dept__id;
  71. }
  72. data.workatddept.push(item.id);
  73. });
  74. if (id == '-1' || id == '0') {
  75. //新增
  76. var url = formatFilter('{0}workatd/setting/', cfg.api);
  77. return Tool.post(url, data);
  78. } else {
  79. //修改
  80. var url = formatFilter('{0}workatd/setting/{1}/', cfg.api, id);
  81. return Tool.put(url, data);
  82. }
  83. },
  84. delete: function (id) {
  85. //删除
  86. var url = formatFilter('{0}workatd/setting/{1}/', cfg.api, id);
  87. return Tool.delete(url);
  88. },
  89. getDateList: function (workatdsetid, type) {
  90. var url = formatFilter('{0}workatd/dailyreportdatelist/?workatdsetid={1}&type={2}', cfg.api, workatdsetid, type);
  91. if (workatdsetid == 0)
  92. url = formatFilter('{0}workatd/dailyreportdatelist/?type={1}', cfg.api, type);
  93. return Tool.get(url);
  94. },
  95. getReport: function (workatdsetid, date, deptid) {
  96. var url = formatFilter('{0}workatd/dailyreport/?workatdsetid={1}&check_dd={2}&deptid={3}', cfg.api, workatdsetid, date, deptid);
  97. return Tool.get(url);
  98. },
  99. getCountRoot: function () {
  100. var url = formatFilter('{0}workatdgetcountroot/?usrid={1}', cfg.api, global.user.usrid);
  101. return Tool.get(url);
  102. },
  103. getCountList: function () {
  104. var url = formatFilter('{0}workatd/settings/', cfg.api);
  105. return Tool.get(url);
  106. },
  107. getReportDetail: function (id, date, atdtype, type, deptid) {
  108. var url = formatFilter('{0}workatd/dailyreportdetail/?workatdsetid={1}&date={2}&atdtype={3}&type={4}&deptid={5}', cfg.api, id, date, atdtype, type, deptid);
  109. return Tool.get(url)
  110. },
  111. getWorkatdDeptCount: function (workatdsetid) {
  112. var url = formatFilter('{0}workatd/deptcount/?workatdsetid={1}', cfg.api, workatdsetid);
  113. return Tool.get(url)
  114. },
  115. getCheckinDetail: function (check_dd) {
  116. var url = formatFilter('{0}workatd/checkindetail/?check_dd={1}', cfg.api, check_dd);
  117. return Tool.get(url);
  118. },
  119. getPersonMonthCount: function (year, month) {
  120. var url = formatFilter('{0}workatd/personmonthcount/?year={1}&month={2}', cfg.api, year, month);
  121. return Tool.get(url);
  122. },
  123. getPersonMonthCountDetail: function (year, month, type) {
  124. var url = formatFilter('{0}workatd/personmonthcountdetail/?year={1}&month={2}&type={3}', cfg.api, year, month, type);
  125. return Tool.get(url);
  126. },
  127. getNextPage: function (url) {
  128. return Tool.get(url)
  129. },
  130. getMonthCount: function (year, month) {
  131. var url = formatFilter('{0}workatd/monthcount/?year={1}&month={2}', cfg.api, year, month);
  132. return Tool.get(url);
  133. },
  134. getMonthCountDetail: function (year, month, type) {
  135. var url = formatFilter('{0}workatd/monthcountdetail/?year={1}&month={2}&type={3}', cfg.api, year, month, type);
  136. return Tool.get(url);
  137. }
  138. }
  139. })
  140. .factory('workatdcheck', function ($http, $q, cfg, global, formatFilter, Tool) {
  141. var _workatdcheck = {};
  142. _workatdcheck.getCheckInfo = function () {
  143. var url = formatFilter('{0}workatd/checkin/?usrid={1}', cfg.api, global.user.usrid);
  144. return Tool.get(url);
  145. };
  146. _workatdcheck.getDeptSetId = function () {
  147. var url = formatFilter('{0}depts/{1}/', cfg.api, global.user.deptno);
  148. return Tool.get(url);
  149. };
  150. _workatdcheck.checkin = function (data) {
  151. var url = formatFilter('{0}workatd/checkin/', cfg.api);
  152. var data = {
  153. 'checktype': data.checktype,
  154. 'workatdsetid': data.workatdsetid,
  155. 'reason': !data.isoutside && data.content && data.isoutoftime ? data.content : null,
  156. 'outside': data.isoutside && data.content && data.isoutoftime ? data.content : null,
  157. 'isautocheck': false
  158. };
  159. return Tool.post(url, data);
  160. };
  161. _workatdcheck.getDeptWorkatdSet = function () {
  162. var url = formatFilter('{0}deptworkatdset/?usrid={1}&depid={2}', cfg.api, global.user.usrid, global.user.deptno);
  163. return Tool.get(url);
  164. };
  165. return _workatdcheck;
  166. });