CheckARAccount.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.ars.CheckARAccount', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.BaseUtil'],
  5. views: ['fa.ars.CheckARAccount'],
  6. FormUtil: Ext.create('erp.util.FormUtil'),
  7. init:function(){
  8. var me = this;
  9. this.BaseUtil = Ext.create('erp.util.BaseUtil');
  10. this.control({
  11. 'button[id=check]': {
  12. click: function(btn) {
  13. var grid = btn.ownerCt.ownerCt;
  14. grid.store.each(function(r){
  15. r.set('check', '');
  16. });
  17. btn.hide();
  18. me.check(grid, 0, btn);
  19. }
  20. },
  21. '#allow' : {
  22. change : function(f) {
  23. if(!me.checked) {
  24. if(f.getValue()) {
  25. Ext.getCmp('accoutover').setDisabled(false);
  26. } else {
  27. Ext.getCmp('accoutover').setDisabled(true);
  28. }
  29. }
  30. }
  31. },
  32. 'button[id=close]': {
  33. click: function() {
  34. me.BaseUtil.getActiveTab().close();
  35. }
  36. },
  37. 'button[id=accoutover]': {
  38. click: function() {
  39. this.startAccount();
  40. }
  41. },
  42. 'button[id=resaccoutover]': {
  43. click: function() {
  44. this.overAccount();
  45. }
  46. },
  47. 'grid[id=account-check]': {
  48. itemclick: function(selModel, record) {
  49. var val = record.get('check');
  50. if(val == 'error') {
  51. me.showDetail(selModel.ownerCt, record);
  52. }
  53. }
  54. },
  55. 'tbtext[id=yearmonth]': {
  56. afterrender: function(f) {
  57. this.getCurrentMonth(f);
  58. }
  59. }
  60. });
  61. },
  62. startAccount: function(){
  63. var me = this;
  64. me.FormUtil.setLoading(true);
  65. Ext.Ajax.request({
  66. url : basePath + "fa/ars/startAccount.action",
  67. params:{
  68. date : me.currentMonth
  69. },
  70. timeout: 120000,
  71. method:'post',
  72. callback:function(options,success,response){
  73. me.FormUtil.setLoading(false);
  74. var localJson = new Ext.decode(response.responseText);
  75. if(localJson.success){
  76. endArSuccess(function(){
  77. window.location.reload();
  78. });
  79. } else {
  80. if(localJson.exceptionInfo){
  81. var str = localJson.exceptionInfo;
  82. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  83. str = str.replace('AFTERSUCCESS', '');
  84. showMessage('提示', str);
  85. window.location.reload();
  86. } else {
  87. showError(str);return;
  88. }
  89. }
  90. }
  91. }
  92. });
  93. },
  94. overAccount: function(){
  95. var me = this;
  96. me.FormUtil.setLoading(true);
  97. Ext.Ajax.request({
  98. url : basePath + "fa/ars/overAccount.action",
  99. params:{
  100. date : me.currentMonth
  101. },
  102. method:'post',
  103. callback:function(options,success,response){
  104. me.FormUtil.setLoading(false);
  105. var localJson = new Ext.decode(response.responseText);
  106. if(localJson.success){
  107. unEndArSuccess(function(){
  108. window.location.reload();
  109. });
  110. } else {
  111. if(localJson.exceptionInfo){
  112. var str = localJson.exceptionInfo;
  113. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  114. str = str.replace('AFTERSUCCESS', '');
  115. showMessage('提示', str);
  116. window.location.reload();
  117. } else {
  118. showError(str);return;
  119. }
  120. }
  121. }
  122. }
  123. });
  124. },
  125. check: function(grid, idx, btn) {
  126. var me =this,f = grid.store.getAt(idx);
  127. if(!f) {
  128. btn.setDisabled(false);
  129. return;
  130. }
  131. f.set('check', 'loading');
  132. var win = Ext.getCmp('win-' + f.get('type'));
  133. if(win) {
  134. win.destroy();
  135. }
  136. Ext.Ajax.request({
  137. url: basePath + f.get('action'),
  138. params: {
  139. type: f.get('type'),
  140. month: me.currentMonth,
  141. start: me.datestart,
  142. end: me.dateend
  143. },
  144. callback: function(opt, s, r) {
  145. me.check(grid, ++idx, btn);
  146. var rs = Ext.decode(r.responseText);
  147. if(rs.ok) {
  148. f.set('check', 'checked');
  149. } else {
  150. f.set('check', 'error');
  151. }
  152. if(idx == grid.store.data.length) {
  153. var ch = 0;
  154. grid.store.each(function(){
  155. if(this.get('check') == 'checked') {
  156. ch ++;
  157. }
  158. });
  159. if(idx == ch) {
  160. me.checked = true;
  161. Ext.getCmp('accoutover').setDisabled(false);
  162. } else {
  163. me.checked = false;
  164. Ext.getCmp('allow').show();
  165. }
  166. }
  167. }
  168. });
  169. },
  170. showDetail: function(grid, record) {
  171. var me = this, wid = 'win-' + record.get('type'),
  172. win = Ext.getCmp(wid);
  173. if(!win) {
  174. win = Ext.create('Ext.Window', {
  175. title: record.get('value'),
  176. id: wid,
  177. width: 800,
  178. height: 500,
  179. layout: 'anchor',
  180. items: [{
  181. xtype: 'gridpanel',
  182. anchor: '100% 100%',
  183. columnLines: true,
  184. cls: 'custom',
  185. columns: [{
  186. text: '单据',
  187. flex: 1,
  188. dataIndex: 'be_class'
  189. },{
  190. text: '编号',
  191. flex: 1.6,
  192. dataIndex: 'be_code'
  193. },{
  194. text: '检测时间',
  195. flex: 1,
  196. dataIndex: 'be_date',
  197. renderer: function(val) {return Ext.Date.format(new Date(val), 'Y-m-d');}
  198. },{
  199. text: '检测人',
  200. flex: .8,
  201. dataIndex: 'be_checker'
  202. },{
  203. text: '备注',
  204. flex: 3,
  205. dataIndex: 'be_remark'
  206. }],
  207. store: new Ext.data.Store({
  208. fields: ['be_class', 'be_code', 'be_date', 'be_checker', 'be_remark']
  209. })
  210. }],
  211. buttonAlign: 'center',
  212. buttons: [{
  213. text: $I18N.common.button.erpExportButton,
  214. iconCls: 'x-button-icon-excel',
  215. cls: 'x-btn-blue',
  216. handler: function(btn) {
  217. me.BaseUtil.exportGrid(btn.up('window').down('gridpanel'));
  218. }
  219. },{
  220. text: '导出全部',
  221. iconCls: 'x-button-icon-excel',
  222. cls: 'x-btn-blue',
  223. handler: function(btn) {
  224. me.getAll(grid, record);
  225. }
  226. },{
  227. text: $I18N.common.button.erpCloseButton,
  228. cls: 'x-btn-blue',
  229. handler: function(btn) {
  230. btn.ownerCt.ownerCt.close();
  231. }
  232. }]
  233. });
  234. this.getBillError(record.get('type'), win.down('gridpanel'));
  235. }
  236. win.show();
  237. },
  238. getCurrentMonth: function(f) {
  239. var me = this;
  240. Ext.Ajax.request({
  241. url: basePath + 'fa/getMonth.action',
  242. params: {
  243. type: 'MONTH-C'
  244. },
  245. callback: function(opt, s, r) {
  246. var rs = Ext.decode(r.responseText);
  247. if(rs.data) {
  248. me.currentMonth = rs.data.PD_DETNO;
  249. me.datestart = Ext.Date.format(new Date(rs.data.PD_STARTDATE), 'Ymd');
  250. me.dateend = Ext.Date.format(new Date(rs.data.PD_ENDDATE), 'Ymd');
  251. f.setText(rs.data.PD_DETNO + ' 从' + Ext.Date.format(new Date(rs.data.PD_STARTDATE), 'Y-m-d')
  252. + ' 到 ' + Ext.Date.format(new Date(rs.data.PD_ENDDATE), 'Y-m-d'));
  253. }
  254. }
  255. });
  256. },
  257. getBillError: function(type, grid) {
  258. Ext.Ajax.request({
  259. url: basePath + 'fa/getBillError.action',
  260. params: {
  261. type: type
  262. },
  263. callback: function(opt, s, r) {
  264. var rs = Ext.decode(r.responseText);
  265. if(rs.data) {
  266. grid.store.loadData(rs.data);
  267. } else if(rs.exceptionInfo) {
  268. showError(rs.exceptionInfo);
  269. }
  270. }
  271. });
  272. },
  273. getAll: function(grid, record) {
  274. var p = Ext.create('Ext.ProgressBar', {
  275. renderTo: Ext.getBody(),
  276. floating: true,
  277. width: 300,
  278. value: 0.4,
  279. text: '获取全部数据...'
  280. }).show();
  281. this.checkAll(grid, record);
  282. p.updateProgress(0.8, '正在下载...', true);
  283. this.exportExcel(record.get('type'));
  284. Ext.defer(function(){
  285. p.setVisible(false);
  286. }, 3000);
  287. },
  288. checkAll: function(grid, record) {
  289. var me =this;
  290. record.set('check', 'loading');
  291. Ext.Ajax.request({
  292. url: basePath + record.get('action'),
  293. params: {
  294. type: record.get('type'),
  295. month: me.currentMonth,
  296. start: me.datestart,
  297. end: me.dateend,
  298. all: true
  299. },
  300. async: false,
  301. callback: function(opt, s, r) {
  302. var rs = Ext.decode(r.responseText);
  303. if(rs.ok) {
  304. record.set('check', 'checked');
  305. } else {
  306. record.set('check', 'error');
  307. }
  308. }
  309. });
  310. },
  311. exportExcel: function(type) {
  312. var title = Ext.Date.format(new Date(), 'Y-m-d H:m:s');
  313. if (!Ext.fly('ext-grid-excel')) {
  314. var frm = document.createElement('form');
  315. frm.id = 'ext-grid-excel';
  316. frm.name = id;
  317. frm.className = 'x-hidden';
  318. document.body.appendChild(frm);
  319. }
  320. Ext.Ajax.request({
  321. url: basePath + ('fa/exportBillError.xls'),
  322. method: 'post',
  323. form: Ext.fly('ext-grid-excel'),
  324. isUpload: true,
  325. params: {
  326. type: type,
  327. title: title
  328. }
  329. });
  330. }
  331. });