CheckAccount.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.co.inventory.CheckAccount', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.BaseUtil'],
  5. views: ['co.inventory.CheckAccount'],
  6. init:function(){
  7. var me = this;
  8. this.BaseUtil = Ext.create('erp.util.BaseUtil');
  9. this.control({
  10. 'button[id=check]': {
  11. click: function(btn) {
  12. var grid = btn.ownerCt.ownerCt;
  13. grid.store.each(function(r){
  14. r.set('check', '');
  15. });
  16. btn.setDisabled(true);
  17. me.check(grid, 0, btn);
  18. }
  19. },
  20. 'button[id=close]': {
  21. click: function() {
  22. me.BaseUtil.getActiveTab().close();
  23. }
  24. },
  25. 'grid[id=account-check]': {
  26. itemclick: function(selModel, record) {
  27. var val = record.get('check');
  28. if(val == 'error') {
  29. me.showDetail(selModel.ownerCt, record);
  30. }
  31. }
  32. },
  33. 'tbtext[id=yearmonth]': {
  34. afterrender: function(f) {
  35. this.getCurrentMonth(f);
  36. }
  37. }
  38. });
  39. },
  40. check: function(grid, idx, btn) {
  41. var me =this,f = grid.store.getAt(idx);
  42. if(!f) {
  43. btn.setDisabled(false);
  44. return;
  45. }
  46. f.set('check', 'loading');
  47. var win = Ext.getCmp('win-' + f.get('type'));
  48. if(win) {
  49. win.destroy();
  50. }
  51. Ext.Ajax.request({
  52. url: basePath + f.get('action'),
  53. params: {
  54. type: f.get('type'),
  55. month: me.currentMonth,
  56. pmonth: me.preYearmonth,
  57. start: me.datestart,
  58. end: me.dateend
  59. },
  60. callback: function(opt, s, r) {
  61. me.check(grid, ++idx, btn);
  62. var rs = Ext.decode(r.responseText);
  63. if(rs.ok) {
  64. f.set('check', 'checked');
  65. } else {
  66. f.set('check', 'error');
  67. }
  68. }
  69. });
  70. },
  71. showDetail: function(grid, record) {
  72. var me = this, wid = 'win-' + record.get('type'),
  73. win = Ext.getCmp(wid);
  74. if(!win) {
  75. win = Ext.create('Ext.Window', {
  76. title: record.get('value'),
  77. id: wid,
  78. width: 800,
  79. height: 500,
  80. layout: 'anchor',
  81. items: [{
  82. xtype: 'gridpanel',
  83. anchor: '100% 100%',
  84. columnLines: true,
  85. cls: 'custom',
  86. columns: [{
  87. text: '单据',
  88. flex: 1,
  89. dataIndex: 'be_class'
  90. },{
  91. text: '编号',
  92. flex: 1.6,
  93. dataIndex: 'be_code'
  94. },{
  95. text: '检测时间',
  96. flex: 1,
  97. dataIndex: 'be_date',
  98. renderer: function(val) {return Ext.Date.format(new Date(val), 'Y-m-d');}
  99. },{
  100. text: '检测人',
  101. flex: .8,
  102. dataIndex: 'be_checker'
  103. },{
  104. text: '备注',
  105. flex: 3,
  106. dataIndex: 'be_remark'
  107. }],
  108. store: new Ext.data.Store({
  109. fields: ['be_class', 'be_code', 'be_date', 'be_checker', 'be_remark']
  110. })
  111. }],
  112. buttonAlign: 'center',
  113. buttons: [{
  114. text: $I18N.common.button.erpExportButton,
  115. iconCls: 'x-button-icon-excel',
  116. cls: 'x-btn-blue',
  117. handler: function(btn) {
  118. me.BaseUtil.exportGrid(btn.up('window').down('gridpanel'));
  119. }
  120. },{
  121. text: '导出全部',
  122. iconCls: 'x-button-icon-excel',
  123. cls: 'x-btn-blue',
  124. handler: function(btn) {
  125. me.getAll(grid, record);
  126. }
  127. },{
  128. text: $I18N.common.button.erpCloseButton,
  129. cls: 'x-btn-blue',
  130. handler: function(btn) {
  131. btn.ownerCt.ownerCt.close();
  132. }
  133. }]
  134. });
  135. this.getBillError(record.get('type'), win.down('gridpanel'));
  136. }
  137. win.show();
  138. },
  139. getCurrentMonth: function(f) {
  140. var me = this;
  141. Ext.Ajax.request({
  142. url: basePath + 'fa/getMonth.action',
  143. params: {
  144. type: 'MONTH-T'
  145. },
  146. callback: function(opt, s, r) {
  147. var rs = Ext.decode(r.responseText);
  148. if(rs.data) {
  149. me.currentMonth = rs.data.PD_DETNO;
  150. me.datestart = Ext.Date.format(new Date(rs.data.PD_STARTDATE), 'Ymd');
  151. me.dateend = Ext.Date.format(new Date(rs.data.PD_ENDDATE), 'Ymd');
  152. f.setText(rs.data.PD_DETNO + ' 从' + Ext.Date.format(new Date(rs.data.PD_STARTDATE), 'Y-m-d')
  153. + ' 到 ' + Ext.Date.format(new Date(rs.data.PD_ENDDATE), 'Y-m-d'));
  154. }
  155. }
  156. });
  157. },
  158. getBillError: function(type, grid) {
  159. Ext.Ajax.request({
  160. url: basePath + 'fa/getBillError.action',
  161. params: {
  162. type: type
  163. },
  164. callback: function(opt, s, r) {
  165. var rs = Ext.decode(r.responseText);
  166. if(rs.data) {
  167. grid.store.loadData(rs.data);
  168. } else if(rs.exceptionInfo) {
  169. showError(rs.exceptionInfo);
  170. }
  171. }
  172. });
  173. },
  174. getAll: function(grid, record) {
  175. var p = Ext.create('Ext.ProgressBar', {
  176. renderTo: Ext.getBody(),
  177. floating: true,
  178. width: 300,
  179. value: 0.4,
  180. text: '获取全部数据...'
  181. }).show();
  182. this.checkAll(grid, record);
  183. p.updateProgress(0.8, '正在下载...', true);
  184. this.exportExcel(record.get('type'));
  185. Ext.defer(function(){
  186. p.setVisible(false);
  187. }, 3000);
  188. },
  189. checkAll: function(grid, record) {
  190. var me =this;
  191. record.set('check', 'loading');
  192. Ext.Ajax.request({
  193. url: basePath + record.get('action'),
  194. params: {
  195. type: record.get('type'),
  196. month: me.currentMonth,
  197. start: me.datestart,
  198. end: me.dateend,
  199. all: true
  200. },
  201. async: false,
  202. callback: function(opt, s, r) {
  203. var rs = Ext.decode(r.responseText);
  204. if(rs.ok) {
  205. record.set('check', 'checked');
  206. } else {
  207. record.set('check', 'error');
  208. }
  209. }
  210. });
  211. },
  212. exportExcel: function(type) {
  213. var title = Ext.Date.format(new Date(), 'Y-m-d H:m:s');
  214. if (!Ext.fly('ext-grid-excel')) {
  215. var frm = document.createElement('form');
  216. frm.id = 'ext-grid-excel';
  217. frm.name = id;
  218. frm.className = 'x-hidden';
  219. document.body.appendChild(frm);
  220. }
  221. Ext.Ajax.request({
  222. url: basePath + ('fa/exportBillError.xls'),
  223. method: 'post',
  224. form: Ext.fly('ext-grid-excel'),
  225. isUpload: true,
  226. params: {
  227. type: type,
  228. title: title
  229. }
  230. });
  231. }
  232. });