ARCheck.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.ars.ARCheck', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. BaseUtil: Ext.create('erp.util.BaseUtil'),
  7. views:[
  8. 'core.form.Panel','fa.ars.ARCheck','core.grid.Panel2','core.toolbar.Toolbar','core.form.MultiField',
  9. 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','core.button.ResAudit',
  10. 'core.button.Audit','core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail',
  11. 'core.button.ResSubmit','core.button.Flow','core.button.Post','core.button.ResPost','core.button.Confirm','core.button.Cancel',
  12. 'core.button.ConfirmBill','core.button.ResSubmitTurnSale','core.button.SubmitTurnSale','core.button.TurnRecBalanceNotice',
  13. 'core.trigger.MultiDbfindTrigger','core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField'
  14. ],
  15. init:function(){
  16. var me = this;
  17. this.control({
  18. 'erpGridPanel2': {
  19. itemclick: this.onGridItemClick
  20. },
  21. 'erpSaveButton': {
  22. click: function(btn){
  23. var form = me.getForm(btn);
  24. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  25. me.BaseUtil.getRandomNumber();//自动添加编号
  26. }
  27. this.getAmount();
  28. this.FormUtil.beforeSave(this);
  29. }
  30. },
  31. 'erpDeleteButton' : {
  32. click: function(btn){
  33. me.FormUtil.onDelete(Ext.getCmp('ac_id').value);
  34. }
  35. },
  36. 'erpUpdateButton': {
  37. click: function(btn){
  38. this.getAmount();
  39. this.FormUtil.onUpdate(this);
  40. }
  41. },
  42. 'erpAddButton': {
  43. click: function(){
  44. me.FormUtil.onAdd('addARCheck', '新增应收对账', 'jsps/fa/ars/arCheck.jsp');
  45. }
  46. },
  47. 'erpCloseButton': {
  48. click: function(btn){
  49. me.FormUtil.beforeClose(me);
  50. }
  51. },
  52. 'erpSubmitButton': {
  53. afterrender: function(btn){
  54. var status = Ext.getCmp('ac_statuscode');
  55. if(status && status.value != 'ENTERING'){
  56. btn.hide();
  57. }
  58. },
  59. click: function(btn){
  60. me.beforeSubmit(btn);
  61. }
  62. },
  63. 'erpResSubmitButton': {
  64. afterrender: function(btn){
  65. var status = Ext.getCmp('ac_statuscode');
  66. if(status && status.value != 'COMMITED'){
  67. btn.hide();
  68. }
  69. },
  70. click: function(btn){
  71. me.FormUtil.onResSubmit(Ext.getCmp('ac_id').value);
  72. }
  73. },
  74. 'erpAuditButton': {
  75. afterrender: function(btn){
  76. var status = Ext.getCmp('ac_statuscode');
  77. if(status && status.value != 'COMMITED'){
  78. btn.hide();
  79. }
  80. },
  81. click: function(btn){
  82. me.FormUtil.onAudit(Ext.getCmp('ac_id').value);
  83. }
  84. },
  85. 'erpResAuditButton': {
  86. afterrender: function(btn){
  87. var status = Ext.getCmp('ac_statuscode');
  88. if(status && status.value != 'AUDITED'){
  89. btn.hide();
  90. }
  91. },
  92. click: function(btn){
  93. me.FormUtil.onResAudit(Ext.getCmp('ac_id').value);
  94. }
  95. },
  96. 'erpPostButton': {
  97. afterrender: function(btn){
  98. var status = Ext.getCmp('ac_statuscode');
  99. if(status && status.value != 'AUDITED'){
  100. btn.hide();
  101. }
  102. },
  103. click: function(btn){
  104. me.FormUtil.onPost(Ext.getCmp('ac_id').value);
  105. }
  106. },
  107. 'erpResPostButton': {
  108. afterrender: function(btn){
  109. var status = Ext.getCmp('ac_statuscode');
  110. if(status && status.value != 'POSTED'){
  111. btn.hide();
  112. }
  113. },
  114. click: function(btn){
  115. me.FormUtil.onResPost(Ext.getCmp('ac_id').value);
  116. }
  117. },
  118. '#updateDetailInfo': {
  119. click: function(btn) {
  120. var record = btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
  121. me.UpdateDetailInfo(record);
  122. }
  123. },
  124. 'erpPrintButton': {
  125. click: function(btn){
  126. var reportName = '';
  127. reportName = "archeck_voice";
  128. var condition = '{archeck.ac_id}=' + Ext.getCmp('ac_id').value + '';
  129. var id = Ext.getCmp('ac_id').value;
  130. me.FormUtil.onwindowsPrint(id, reportName, condition);
  131. }
  132. },
  133. 'erpConfirmButton': {
  134. afterrender: function(btn){
  135. var confirmstatus = Ext.getCmp('ac_confirmstatus');
  136. if(confirmstatus && confirmstatus.value == '已确认' ){
  137. btn.hide();
  138. }
  139. var status = Ext.getCmp('ac_statuscode');
  140. if(status && status.value != 'AUDITED'){
  141. btn.hide();
  142. }
  143. },
  144. click: function(btn){
  145. warnMsg("确定对账吗?", function(btn){
  146. if(btn == 'yes'){
  147. me.FormUtil.getActiveTab().setLoading(true);//loading...
  148. Ext.Ajax.request({
  149. url : basePath + 'fa/ars/confirmARCheck.action',
  150. params: {
  151. id: Ext.getCmp('ac_id').value
  152. },
  153. method : 'post',
  154. callback : function(options,success,response){
  155. me.FormUtil.getActiveTab().setLoading(false);
  156. var localJson = new Ext.decode(response.responseText);
  157. if(localJson.exceptionInfo){
  158. showError(localJson.exceptionInfo);
  159. }
  160. if(localJson.success){
  161. window.location.reload();
  162. }
  163. }
  164. });
  165. }
  166. });
  167. }
  168. },
  169. 'erpCancelButton': {
  170. beforerender:function(btn){
  171. btn.setText('取消确认');
  172. btn.setWidth(100);
  173. },
  174. afterrender: function(btn){
  175. var confirmstatus = Ext.getCmp('ac_confirmstatus'), status = Ext.getCmp('ac_statuscode');
  176. if(confirmstatus && confirmstatus.value != '已确认' ){
  177. btn.hide();
  178. }
  179. if(status && status.value != 'AUDITED'){
  180. btn.hide();
  181. }
  182. },
  183. click: function(btn){
  184. warnMsg("确定取消确认吗?", function(btn){
  185. if(btn == 'yes'){
  186. me.FormUtil.getActiveTab().setLoading(true);//loading...
  187. Ext.Ajax.request({
  188. url : basePath + 'fa/ars/cancelARCheck.action',
  189. params: {
  190. id: Ext.getCmp('ac_id').value
  191. },
  192. method : 'post',
  193. callback : function(options,success,response){
  194. me.FormUtil.getActiveTab().setLoading(false);
  195. var localJson = new Ext.decode(response.responseText);
  196. if(localJson.exceptionInfo){
  197. showError(localJson.exceptionInfo);
  198. }
  199. if(localJson.success){
  200. window.location.reload();
  201. }
  202. }
  203. });
  204. }
  205. });
  206. }
  207. },
  208. 'erpConfirmBillButton':{
  209. afterrender: function(btn){
  210. var status = Ext.getCmp("ac_confirmstatus"), auditstatus = Ext.getCmp('ac_statuscode');
  211. if(status && status.value != '已确认'){
  212. btn.hide();
  213. }
  214. if(auditstatus && auditstatus.value != 'AUDITED'){
  215. btn.hide();
  216. }
  217. },
  218. click: function(m){
  219. me.batchdeal('ARCheck!ToBill!Deal', ' ad_acid=' + Ext.getCmp('ac_id').value +' and abs(nvl(ad_yqty,0)) < abs(nvl(ad_qty,0))', 'fa/ars/arCheckTurnBill.action');
  220. }
  221. },
  222. 'erpSubmitTurnSaleButton':{
  223. click:function(btn){
  224. Ext.Ajax.request({//拿到grid的columns
  225. url : basePath + "fa/ars/submitARCheckConfirm.action",
  226. params: {
  227. id : Ext.getCmp('ac_id').getValue()
  228. },
  229. method : 'post',
  230. callback : function(options,success,response){
  231. var res = new Ext.decode(response.responseText);
  232. if(res.exceptionInfo){
  233. var str = res.exceptionInfo;
  234. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  235. str = str.replace('AFTERSUCCESS', '');
  236. console.log(btn.ownerCt.ownerCt);
  237. me.FormUtil.getMultiAssigns(Ext.getCmp('ac_id').getValue(),'ARCheck!Confirm',btn.ownerCt.ownerCt);
  238. }
  239. showMessage("提示", str);return;
  240. } else if(res.success){
  241. me.FormUtil.getMultiAssigns(Ext.getCmp('ac_id').getValue(),'ARCheck!Confirm',btn.ownerCt.ownerCt);
  242. }
  243. }
  244. });
  245. },
  246. afterrender:function(btn){
  247. btn.setText("提交(确认)");
  248. var ac_confirmstatus=Ext.getCmp('ac_confirmstatus').getValue();
  249. var ac_statuscode=Ext.getCmp('ac_statuscode').getValue();
  250. var bool=true;
  251. if((Ext.isEmpty(ac_confirmstatus)||ac_confirmstatus=='未确认') && ac_statuscode=='AUDITED'){
  252. bool=false;
  253. }
  254. if(bool) btn.hide();
  255. }
  256. },
  257. 'erpResSubmitTurnSaleButton':{
  258. click:function(btn){
  259. Ext.Ajax.request({//拿到grid的columns
  260. url : basePath + "fa/ars/resSubmitARCheckConfirm.action",
  261. params: {
  262. id : Ext.getCmp('ac_id').getValue()
  263. },
  264. method : 'post',
  265. callback : function(options,success,response){
  266. var res = new Ext.decode(response.responseText);
  267. if(res.exceptionInfo){
  268. showError(res.exceptionInfo);return;
  269. }
  270. if(res.success){
  271. resSubmitSuccess();
  272. window.location.reload();
  273. }
  274. }
  275. });
  276. },
  277. afterrender:function(btn){
  278. btn.setText("反提交(确认)");
  279. var ac_confirmstatus = Ext.getCmp('ac_confirmstatus').getValue();
  280. if(ac_confirmstatus != '已提交'){
  281. btn.hide();
  282. }
  283. }
  284. },
  285. 'erpTurnRecBalanceNoticeButton':{
  286. afterrender: function(btn){
  287. var status = Ext.getCmp("ac_confirmstatus"), auditstatus = Ext.getCmp('ac_statuscode');
  288. if(status && status.value != '已确认'){
  289. btn.hide();
  290. }
  291. if(auditstatus && auditstatus.value != 'AUDITED'){
  292. btn.hide();
  293. }
  294. },
  295. click: function(m){
  296. warnMsg("确定生成回款通知单?", function(btn){
  297. if(btn == 'yes'){
  298. me.FormUtil.getActiveTab().setLoading(true);//loading...
  299. Ext.Ajax.request({
  300. url : basePath + 'fa/ars/turnRecBalanceNotice.action',
  301. params: {
  302. id: Ext.getCmp('ac_id').value,
  303. caller: caller
  304. },
  305. method : 'post',
  306. callback : function(options,success,response){
  307. me.FormUtil.getActiveTab().setLoading(false);
  308. var localJson = new Ext.decode(response.responseText);
  309. if(localJson.exceptionInfo){
  310. showError(localJson.exceptionInfo);
  311. }
  312. if(localJson.success){
  313. if(localJson.log){
  314. showMessage("localJson", localJson.log);
  315. }
  316. }
  317. }
  318. });
  319. }
  320. });
  321. }
  322. }
  323. });
  324. },
  325. //计算金额 并写入主表对账总额字段
  326. getAmount: function(){
  327. var grid = Ext.getCmp('grid');
  328. var items = grid.store.data.items;
  329. var amount = 0;
  330. Ext.each(items,function(item,index){
  331. if(!Ext.isEmpty(item.data['ad_amount'])){
  332. amount= amount + Number(item.data['ad_amount']);
  333. }
  334. });
  335. Ext.getCmp('ac_checkamount').setValue(Ext.Number.toFixed(amount, 2));
  336. },
  337. beforeSubmit:function(btn){
  338. var me = this;
  339. var grid = Ext.getCmp('grid'),items=grid.store.data.items;
  340. var amount = Number(Ext.getCmp('ac_checkamount').getValue());
  341. var detailamount = 0;
  342. me.FormUtil.onSubmit(Ext.getCmp('ac_id').value);
  343. },
  344. onGridItemClick: function(selModel, record){//grid行选择
  345. if (record.data.ad_id != 0 && record.data.ad_id != null && record.data.ad_qty != record.data.ad_confirmqty) {
  346. var btn = Ext.getCmp('updateDetailInfo');
  347. btn && btn.setDisabled(false);
  348. }else{
  349. var btn = Ext.getCmp('updateDetailInfo');
  350. btn && btn.setDisabled(true);
  351. }
  352. this.GridUtil.onGridItemClick(selModel, record);
  353. },
  354. getForm: function(btn){
  355. return btn.ownerCt.ownerCt;
  356. },
  357. UpdateDetailInfo: function(record) {
  358. win = this.getDetailInfoWindow(record);
  359. win.show();
  360. },
  361. getDetailInfoWindow: function(record) {
  362. var me = this;
  363. return Ext.create('Ext.window.Window', {
  364. width: 430,
  365. height: 250,
  366. closeAction: 'destroy',
  367. cls: 'custom-blue',
  368. title: '<h1>更改对账数量信息</h1>',
  369. layout: {
  370. type: 'vbox'
  371. },
  372. items: [{
  373. width: '100%',
  374. html: '<div style="background:transparent;border:none;width:100%;height:30px;' + 'color:#036;vertical-align:middle;line-height:30px;font-size:14px;">' + '*注:只能修改对账数量</div>'
  375. },
  376. {
  377. margin: '5 0 0 5',
  378. xtype: 'textfield',
  379. fieldLabel: '来源单号',
  380. name: 'sourcecode',
  381. value: record.data.ad_sourcecode,
  382. readOnly:true,
  383. id: 'sourcecode'
  384. },
  385. {
  386. margin: '5 0 0 5',
  387. xtype: 'numberfield',
  388. fieldLabel: '来源序号',
  389. name: 'sourcedetno',
  390. value: record.data.ad_sourcedetno,
  391. readOnly:true,
  392. id: 'sourcedetno'
  393. },{
  394. margin: '5 0 0 5',
  395. xtype: 'textfield',
  396. columnidth: 0.4,
  397. fieldLabel: '出入库单号',
  398. name: 'prodinoutno',
  399. readOnly:true,
  400. value:record.data.ad_inoutno,
  401. id: 'prodinoutno'
  402. },
  403. {
  404. margin: '5 0 0 5',
  405. xtype: 'numberfield',
  406. columnidth: 0.4,
  407. fieldLabel: '本次对账数量',
  408. name: 'thisqty',
  409. value:record.data.ad_qty,
  410. id: 'thisqty'
  411. }],
  412. buttonAlign: 'center',
  413. buttons: [{
  414. xtype: 'button',
  415. text: '保存',
  416. width: 60,
  417. iconCls: 'x-button-icon-save',
  418. handler: function(btn) {
  419. var w = btn.up('window');
  420. me.saveDetailInfo(w);
  421. win.close();
  422. win.destroy();
  423. }
  424. },
  425. {
  426. xtype: 'button',
  427. columnWidth: 0.1,
  428. text: '关闭',
  429. width: 60,
  430. iconCls: 'x-button-icon-close',
  431. margin: '0 0 0 10',
  432. handler: function(btn) {
  433. var win = btn.up('window');
  434. win.close();
  435. win.destroy();
  436. }
  437. }]
  438. });
  439. },
  440. saveDetailInfo: function(w) {
  441. var qty = w.down('field[name=thisqty]').getValue();
  442. grid = Ext.getCmp('grid'),record = grid.getSelectionModel().getLastSelected();
  443. if(typeof record.data.ad_yqty != "undefined" ) {
  444. if(!Ext.isEmpty(record.data.ad_yqty)){
  445. if(qty < record.data.ad_yqty){
  446. showError('新数量不能小于已转发票数量');
  447. return;
  448. }
  449. }
  450. }
  451. var dd = {
  452. ad_id: record.data.ad_id,
  453. ad_qty: qty ? qty: 0
  454. };
  455. Ext.Ajax.request({
  456. url: basePath + 'fa/ars/saveDetailInfo.action',
  457. params: {
  458. data: unescape(Ext.JSON.encode(dd)),
  459. caller: caller
  460. },
  461. method: 'post',
  462. callback: function(opt, s, res) {
  463. var r = new Ext.decode(res.responseText);
  464. if (r.success) {
  465. grid.GridUtil.loadNewStore(grid, {
  466. caller: caller,
  467. condition: gridCondition
  468. });
  469. showMessage('提示', '更新成功!', 1000);
  470. } else if (r.exceptionInfo) {
  471. showError(r.exceptionInfo);
  472. } else {
  473. saveFailure();
  474. }
  475. }
  476. });
  477. },
  478. batchdeal: function(nCaller, condition, url){
  479. var win = new Ext.window.Window({
  480. id : 'win',
  481. height: "100%",
  482. width: "80%",
  483. maximizable : true,
  484. buttonAlign : 'center',
  485. layout : 'anchor',
  486. items: [{
  487. tag : 'iframe',
  488. frame : true,
  489. anchor : '100% 100%',
  490. layout : 'fit',
  491. html : '<iframe id="iframe_' + caller + '" src="' + basePath + 'jsps/common/editorColumn.jsp?caller=' + nCaller
  492. + "&condition=" + condition +'" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  493. }],
  494. buttons : [{
  495. name: 'confirm',
  496. text : $I18N.common.button.erpConfirmButton,
  497. iconCls: 'x-button-icon-confirm',
  498. cls: 'x-btn-gray',
  499. listeners: {
  500. buffer: 500,
  501. click: function(btn) {
  502. var grid = Ext.getCmp('win').items.items[0].body.dom.getElementsByTagName('iframe')[0].contentWindow.Ext.getCmp("editorColumnGridPanel");
  503. btn.setDisabled(true);
  504. grid.updateAction(url);
  505. }
  506. }
  507. }, {
  508. text : $I18N.common.button.erpCloseButton,
  509. iconCls: 'x-button-icon-close',
  510. cls: 'x-btn-gray',
  511. handler : function(){
  512. Ext.getCmp('win').close();
  513. }
  514. }]
  515. });
  516. win.show();
  517. }
  518. });