CheckIVAccount.js 9.0 KB

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