APCheck.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.arp.APCheck', {
  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.arp.APCheck','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',
  12. 'core.button.Banned', 'core.button.ConfirmBill','core.button.TurnYHFKSQ','core.button.Cancel','core.button.ResSubmitTurnSale','core.button.SubmitTurnSale',
  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('addAPCheck', '新增应付对账', 'jsps/fa/arp/apCheck.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. var confirmstatus = Ext.getCmp('ac_confirmstatus');
  92. if(confirmstatus && confirmstatus.value == '已确认' ){
  93. btn.hide();
  94. }
  95. },
  96. click: function(btn){
  97. me.FormUtil.onResAudit(Ext.getCmp('ac_id').value);
  98. }
  99. },
  100. 'erpPostButton': {
  101. afterrender: function(btn){
  102. var status = Ext.getCmp('ac_statuscode');
  103. if(status && status.value != 'AUDITED'){
  104. btn.hide();
  105. }
  106. },
  107. click: function(btn){
  108. me.FormUtil.onPost(Ext.getCmp('ac_id').value);
  109. }
  110. },
  111. 'erpResPostButton': {
  112. afterrender: function(btn){
  113. var status = Ext.getCmp('ac_statuscode');
  114. if(status && status.value != 'POSTED'){
  115. btn.hide();
  116. }
  117. },
  118. click: function(btn){
  119. me.FormUtil.onResPost(Ext.getCmp('ac_id').value);
  120. }
  121. },
  122. 'erpPrintButton': {
  123. click: function(btn){
  124. var reportName = '';
  125. reportName = "apcheck_voice";
  126. var condition = '{apcheck.ac_id}=' + Ext.getCmp('ac_id').value + '';
  127. var id = Ext.getCmp('ac_id').value;
  128. me.FormUtil.onwindowsPrint(id, reportName, condition);
  129. }
  130. },
  131. 'erpBannedButton': {
  132. beforerender:function(btn){
  133. btn.setText('不同意');
  134. btn.setWidth(100);
  135. },
  136. afterrender: function(btn){
  137. var status = Ext.getCmp('ac_confirmstatus'), b2bid = Ext.getCmp('ac_b2bid');
  138. if(b2bid && !Ext.isEmpty(b2bid.value) && b2bid.value != 0 && status.value != '已确认'){
  139. btn.show();
  140. } else {
  141. btn.hide();
  142. }
  143. if(status && status.value == '已确认' ){
  144. btn.hide();
  145. }
  146. },
  147. click: function(btn){
  148. if (!confirm('确定不同意?')){
  149. return;
  150. }
  151. //me.FormUtil.onBanned(Ext.getCmp('pr_id').value);
  152. //zhongyl 2014 03 13
  153. var reason = Ext.getCmp('ac_reason');
  154. if(reason && (reason.value == null||reason.value=='')){
  155. showError('请填写不同意原因!');
  156. }else{
  157. Ext.Ajax.request({
  158. url : basePath + 'fa/arp/resConfirmAPCheck.action',
  159. params: {
  160. id: Ext.getCmp('ac_id').value,
  161. reason:Ext.getCmp('ac_reason').value
  162. },
  163. method : 'post',
  164. callback : function(options,success,response){
  165. me.FormUtil.getActiveTab().setLoading(false);
  166. var localJson = new Ext.decode(response.responseText);
  167. if(localJson.exceptionInfo){
  168. showError(localJson.exceptionInfo);
  169. }
  170. if(localJson.success){
  171. window.location.reload();
  172. }
  173. }
  174. });
  175. }
  176. }
  177. },
  178. 'field[name=ac_reason]':{
  179. beforerender:function(field){
  180. var status = Ext.getCmp('ac_confirmstatus');
  181. if(status && status.value != '已确认'){
  182. field.readOnly=false;
  183. }
  184. }
  185. },
  186. 'erpConfirmButton': {
  187. afterrender: function(btn){
  188. var confirmstatus = Ext.getCmp('ac_confirmstatus');
  189. if(confirmstatus && confirmstatus.value == '已确认' ){
  190. btn.hide();
  191. }
  192. var status = Ext.getCmp('ac_statuscode');
  193. if(status && status.value != 'AUDITED'){
  194. btn.hide();
  195. }
  196. },
  197. click: function(btn){
  198. warnMsg("确定对账吗?", function(btn){
  199. if(btn == 'yes'){
  200. me.FormUtil.getActiveTab().setLoading(true);//loading...
  201. Ext.Ajax.request({
  202. url : basePath + 'fa/arp/confirmAPCheck.action',
  203. params: {
  204. id: Ext.getCmp('ac_id').value
  205. },
  206. method : 'post',
  207. callback : function(options,success,response){
  208. me.FormUtil.getActiveTab().setLoading(false);
  209. var localJson = new Ext.decode(response.responseText);
  210. if(localJson.exceptionInfo){
  211. showError(localJson.exceptionInfo);
  212. }
  213. if(localJson.success){
  214. window.location.reload();
  215. }
  216. }
  217. });
  218. }
  219. });
  220. }
  221. },
  222. 'erpCancelButton': {
  223. beforerender:function(btn){
  224. btn.setText('取消确认');
  225. btn.setWidth(100);
  226. },
  227. afterrender: function(btn){
  228. var confirmstatus = Ext.getCmp('ac_confirmstatus'), status = Ext.getCmp('ac_statuscode');
  229. if(confirmstatus && confirmstatus.value != '已确认' ){
  230. btn.hide();
  231. }
  232. if(status && status.value != 'AUDITED'){
  233. btn.hide();
  234. }
  235. },
  236. click: function(btn){
  237. warnMsg("确定取消确认吗?", function(btn){
  238. if(btn == 'yes'){
  239. me.FormUtil.getActiveTab().setLoading(true);//loading...
  240. Ext.Ajax.request({
  241. url : basePath + 'fa/arp/cancelAPCheck.action',
  242. params: {
  243. id: Ext.getCmp('ac_id').value
  244. },
  245. method : 'post',
  246. callback : function(options,success,response){
  247. me.FormUtil.getActiveTab().setLoading(false);
  248. var localJson = new Ext.decode(response.responseText);
  249. if(localJson.exceptionInfo){
  250. showError(localJson.exceptionInfo);
  251. }
  252. if(localJson.success){
  253. window.location.reload();
  254. }
  255. }
  256. });
  257. }
  258. });
  259. }
  260. },
  261. 'erpConfirmBillButton':{
  262. afterrender: function(btn){
  263. var status = Ext.getCmp("ac_confirmstatus"), auditstatus = Ext.getCmp('ac_statuscode');
  264. if(status && status.value != '已确认'){
  265. btn.hide();
  266. }
  267. if(auditstatus && auditstatus.value != 'AUDITED'){
  268. btn.hide();
  269. }
  270. },
  271. click: function(m){
  272. me.batchdeal('APCheck!ToBill!Deal', ' ad_acid=' + Ext.getCmp('ac_id').value +' and abs(nvl(ad_yqty,0)) < abs(nvl(ad_qty,0)) and pd_piclass not in (\'不良品入库单\',\'不良品出库单\')', 'fa/arp/apCheckTurnBill.action');
  273. }
  274. },
  275. 'erpTurnYHFKSQButton':{
  276. afterrender: function(btn){
  277. var status = Ext.getCmp("ac_confirmstatus"), auditstatus = Ext.getCmp('ac_statuscode');
  278. if(status && status.value != '已确认'){
  279. btn.hide();
  280. }
  281. if(auditstatus && auditstatus.value != 'AUDITED'){
  282. btn.hide();
  283. }
  284. },
  285. click: function(m){
  286. warnMsg("确定生成付款申请?", function(btn){
  287. if(btn == 'yes'){
  288. me.FormUtil.getActiveTab().setLoading(true);//loading...
  289. Ext.Ajax.request({
  290. url : basePath + 'fa/arp/turnPayPlease.action',
  291. params: {
  292. id: Ext.getCmp('ac_id').value,
  293. caller: caller
  294. },
  295. method : 'post',
  296. callback : function(options,success,response){
  297. me.FormUtil.getActiveTab().setLoading(false);
  298. var localJson = new Ext.decode(response.responseText);
  299. if(localJson.exceptionInfo){
  300. showError(localJson.exceptionInfo);
  301. }
  302. if(localJson.success){
  303. if(localJson.log){
  304. showMessage("localJson", localJson.log);
  305. }
  306. }
  307. }
  308. });
  309. }
  310. });
  311. }
  312. },
  313. 'erpSubmitTurnSaleButton':{
  314. click:function(btn){
  315. Ext.Ajax.request({//拿到grid的columns
  316. url : basePath + "fa/arp/submitAPCheckConfirm.action",
  317. params: {
  318. id : Ext.getCmp('ac_id').getValue()
  319. },
  320. method : 'post',
  321. callback : function(options,success,response){
  322. var res = new Ext.decode(response.responseText);
  323. if(res.exceptionInfo){
  324. var str = res.exceptionInfo;
  325. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  326. str = str.replace('AFTERSUCCESS', '');
  327. me.FormUtil.getMultiAssigns(Ext.getCmp('ac_id').getValue(),'APCheck!Confirm',btn.ownerCt.ownerCt);
  328. }
  329. showMessage("提示", str);return;
  330. } else if(res.success){
  331. me.FormUtil.getMultiAssigns(Ext.getCmp('ac_id').getValue(),'APCheck!Confirm',btn.ownerCt.ownerCt);
  332. }
  333. }
  334. });
  335. },
  336. afterrender:function(btn){
  337. btn.setText("提交(确认)");
  338. var ac_confirmstatus=Ext.getCmp('ac_confirmstatus').getValue();
  339. var ac_statuscode=Ext.getCmp('ac_statuscode').getValue();
  340. var bool=true;
  341. if((Ext.isEmpty(ac_confirmstatus)||ac_confirmstatus=='未确认') && ac_statuscode=='AUDITED'){
  342. bool=false;
  343. }
  344. if(bool) btn.hide();
  345. }
  346. },
  347. 'erpResSubmitTurnSaleButton':{
  348. click:function(btn){
  349. Ext.Ajax.request({//拿到grid的columns
  350. url : basePath + "fa/arp/resSubmitAPCheckConfirm.action",
  351. params: {
  352. id : Ext.getCmp('ac_id').getValue()
  353. },
  354. method : 'post',
  355. callback : function(options,success,response){
  356. var res = new Ext.decode(response.responseText);
  357. if(res.exceptionInfo){
  358. showError(res.exceptionInfo);return;
  359. }
  360. if(res.success){
  361. resSubmitSuccess();
  362. window.location.reload();
  363. }
  364. }
  365. });
  366. },
  367. afterrender:function(btn){
  368. btn.setText("反提交(确认)");
  369. var ac_confirmstatus = Ext.getCmp('ac_confirmstatus').getValue();
  370. if(ac_confirmstatus != '已提交'){
  371. btn.hide();
  372. }
  373. }
  374. }
  375. });
  376. },
  377. //计算金额 并写入主表对账总额字段
  378. getAmount: function(){
  379. var grid = Ext.getCmp('grid');
  380. var items = grid.store.data.items;
  381. var amount = 0;
  382. Ext.each(items,function(item,index){
  383. if(!Ext.isEmpty(item.data['ad_amount'])){
  384. amount= amount + Number(item.data['ad_amount']);
  385. }
  386. });
  387. Ext.getCmp('ac_checkamount').setValue(Ext.Number.toFixed(amount, 2));
  388. },
  389. beforeSubmit:function(btn){
  390. var me = this;
  391. var grid = Ext.getCmp('grid'),items=grid.store.data.items;
  392. var amount = Number(Ext.getCmp('ac_checkamount').getValue());
  393. var detailamount = 0;
  394. me.FormUtil.onSubmit(Ext.getCmp('ac_id').value);
  395. },
  396. onGridItemClick: function(selModel, record){//grid行选择
  397. this.GridUtil.onGridItemClick(selModel, record);
  398. },
  399. getForm: function(btn){
  400. return btn.ownerCt.ownerCt;
  401. },
  402. batchdeal: function(nCaller, condition, url){
  403. var win = new Ext.window.Window({
  404. id : 'win',
  405. height: "100%",
  406. width: "80%",
  407. maximizable : true,
  408. buttonAlign : 'center',
  409. layout : 'anchor',
  410. items: [{
  411. tag : 'iframe',
  412. frame : true,
  413. anchor : '100% 100%',
  414. layout : 'fit',
  415. html : '<iframe id="iframe_' + caller + '" src="' + basePath + 'jsps/common/editorColumn.jsp?caller=' + nCaller
  416. + "&condition=" + condition +'" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  417. }],
  418. buttons : [{
  419. name: 'confirm',
  420. text : $I18N.common.button.erpConfirmButton,
  421. iconCls: 'x-button-icon-confirm',
  422. cls: 'x-btn-gray',
  423. listeners: {
  424. buffer: 500,
  425. click: function(btn) {
  426. var grid = Ext.getCmp('win').items.items[0].body.dom.getElementsByTagName('iframe')[0].contentWindow.Ext.getCmp("editorColumnGridPanel");
  427. btn.setDisabled(true);
  428. grid.updateAction(url);
  429. }
  430. }
  431. }, {
  432. text : $I18N.common.button.erpCloseButton,
  433. iconCls: 'x-button-icon-close',
  434. cls: 'x-btn-gray',
  435. handler : function(){
  436. Ext.getCmp('win').close();
  437. }
  438. }]
  439. });
  440. win.show();
  441. }
  442. });