APBill.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.ars.APBill', {
  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.APBill','core.grid.Panel2','core.toolbar.Toolbar',
  9. 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','core.button.Upload','core.button.ResAudit',
  10. 'core.button.Audit','core.button.Close','core.button.Delete','core.button.Update','core.button.ResSubmit',
  11. 'core.button.Post','core.button.ResPost','core.button.AutoInvoice', 'core.button.Confirm', 'core.button.Cancel',
  12. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.form.MonthDateField',
  13. 'core.trigger.CateTreeDbfindTrigger','core.button.AssDetail','core.button.BillDateUpdate','core.form.SeparNumber',
  14. 'core.button.PrintVoucherCode', 'core.button.TicketTaxes'
  15. ],
  16. init:function(){
  17. var me = this;
  18. me.gridLastSelected = null;
  19. this.control({
  20. 'erpGridPanel2': {
  21. itemclick:function(selModel, record){
  22. me.onGridItemClick(selModel, record);
  23. if(caller =='APBill!OTDW'){
  24. var btn = Ext.getCmp('assdetail');
  25. var ass = record.data['ca_asstype'];
  26. if(!Ext.isEmpty(ass)){
  27. btn.setDisabled(false);
  28. } else {
  29. btn.setDisabled(true);
  30. }
  31. }
  32. },
  33. afterrender:function(grid){
  34. grid.plugins[0].on('afteredit',function(e){
  35. setTimeout(function(){
  36. var amount = grid.store.getSum(grid.store.data.items, 'abd_apamount');
  37. Ext.getCmp('ab_apamount').setValue(amount);
  38. },200);
  39. });
  40. }
  41. },
  42. 'erpDeleteDetailButton': {
  43. afterrender: function(btn){
  44. if(caller =='APBill!OTDW'){
  45. //辅助核算
  46. btn.ownerCt.add({
  47. xtype:'erpAssDetailButton',
  48. disabled:true
  49. });
  50. }
  51. }
  52. },
  53. 'field[name=ab_currency]': {
  54. beforetrigger: function(field) {
  55. var t = field.up('form').down('field[name=ab_date]'),
  56. value = t.getValue();
  57. if(value) {
  58. field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym');
  59. }
  60. }
  61. },
  62. 'erpSaveButton': {
  63. click: function(btn){
  64. var form = me.getForm(btn);
  65. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  66. me.BaseUtil.getRandomNumber();
  67. }
  68. //保存之前的一些前台的逻辑判定
  69. this.beforeSaveAPBill();
  70. }
  71. },
  72. 'erpDeleteButton' : {
  73. afterrender: function(btn){
  74. var poststatus = Ext.getCmp('ab_statuscode');
  75. if(poststatus && poststatus.value == 'POSTED'){
  76. btn.hide();
  77. }
  78. },
  79. click: function(btn){
  80. me.FormUtil.onDelete(Ext.getCmp('ab_id').value);
  81. }
  82. },
  83. 'erpUpdateButton': {
  84. afterrender: function(btn){
  85. var poststatus = Ext.getCmp('ab_statuscode');
  86. if(poststatus && poststatus.value == 'POSTED'){
  87. btn.hide();
  88. }
  89. },
  90. click: function(btn){
  91. me.beforeUpdateAPBill();
  92. }
  93. },
  94. 'erpAddButton': {
  95. click: function(){
  96. var form = Ext.getCmp('form');
  97. var title = '新增';
  98. if(form){
  99. if(form.title){
  100. title = title+form.title;
  101. }
  102. }
  103. me.FormUtil.onAdd('addAPBill', title, 'jsps/fa/ars/apbill.jsp?whoami='+caller);
  104. }
  105. },
  106. 'erpCloseButton': {
  107. click: function(btn){
  108. me.FormUtil.beforeClose(me);
  109. }
  110. },
  111. 'erpSubmitButton': {
  112. afterrender: function(btn){
  113. var auditStatus = Ext.getCmp(me.getForm(btn).auditStatusCode);
  114. if(auditStatus && auditStatus.value != 'ENTERING'){
  115. btn.hide();
  116. }
  117. var poststatus = Ext.getCmp('ab_statuscode');
  118. if(poststatus && poststatus.value == 'POSTED'){
  119. btn.hide();
  120. }
  121. },
  122. click: function(btn){
  123. me.FormUtil.onSubmit(Ext.getCmp('ab_id').value, false, me.beforeUpdateAPBill, me);
  124. }
  125. },
  126. 'erpResSubmitButton': {
  127. afterrender: function(btn){
  128. var auditStatus = Ext.getCmp(me.getForm(btn).auditStatusCode);
  129. if(auditStatus && auditStatus.value != 'COMMITED'){
  130. btn.hide();
  131. }
  132. var poststatus = Ext.getCmp('ab_statuscode');
  133. if(poststatus && poststatus.value == 'POSTED'){
  134. btn.hide();
  135. }
  136. },
  137. click: function(btn){
  138. me.FormUtil.onResSubmit(Ext.getCmp('ab_id').value);
  139. }
  140. },
  141. 'erpAuditButton': {
  142. afterrender: function(btn){
  143. var auditStatus = Ext.getCmp(me.getForm(btn).auditStatusCode);
  144. if(auditStatus && auditStatus.value != 'COMMITED'){
  145. btn.hide();
  146. }
  147. var poststatus = Ext.getCmp('ab_statuscode');
  148. if(poststatus && poststatus.value == 'POSTED'){
  149. btn.hide();
  150. }
  151. },
  152. click: function(btn){
  153. me.FormUtil.onAudit(Ext.getCmp('ab_id').value);
  154. }
  155. },
  156. 'erpResAuditButton': {
  157. afterrender: function(btn){
  158. var auditStatus = Ext.getCmp(me.getForm(btn).auditStatusCode);
  159. if(auditStatus && auditStatus.value != 'AUDITED'){
  160. btn.hide();
  161. }
  162. var poststatus = Ext.getCmp('ab_statuscode');
  163. if(poststatus && poststatus.value == 'POSTED'){
  164. btn.hide();
  165. }
  166. },
  167. click: function(btn){
  168. me.FormUtil.onResAudit(Ext.getCmp('ab_id').value);
  169. }
  170. },
  171. 'erpPrintButton': {
  172. click: function(btn){
  173. var reportName="PurcInvoice";
  174. var id=Ext.getCmp('ab_id').value;
  175. var condition = '{APBill.ab_id}=' + Ext.getCmp('ab_id').value;
  176. me.FormUtil.onwindowsPrint(id, reportName, condition);
  177. }
  178. },
  179. 'erpPrintVoucherCodeButton': {
  180. click: function(btn){
  181. if(Ext.getCmp('ab_vouchercode').value ==null || Ext.getCmp('ab_vouchercode').value ==''){
  182. showError('当前发票还没有制作凭证,不能打印');
  183. }else{
  184. var reportName = '';
  185. reportName = "PurcVCInvoice";
  186. var condition = '{APBill.ab_vouchercode}=\'' + Ext.getCmp('ab_vouchercode').value +'\'';
  187. var id=Ext.getCmp('ab_id').value;
  188. me.FormUtil.onwindowsPrint(id, reportName, condition);
  189. }
  190. }
  191. },
  192. 'erpPostButton': {
  193. afterrender: function(btn){
  194. var status = Ext.getCmp(me.getForm(btn).statusCode);
  195. if(status && status.value == 'UNPOST'){
  196. btn.show();
  197. }else{
  198. btn.hide();
  199. }
  200. },
  201. click: function(btn){
  202. me.FormUtil.onPost(Ext.getCmp('ab_id').value);
  203. }
  204. },
  205. 'erpResPostButton': {
  206. afterrender: function(btn){
  207. var status = Ext.getCmp(me.getForm(btn).statusCode);
  208. if(status && status.value == 'POSTED'){
  209. btn.show();
  210. }else{
  211. btn.hide();
  212. }
  213. },
  214. click: function(btn){
  215. me.FormUtil.onResPost(Ext.getCmp('ab_id').value);
  216. }
  217. },
  218. 'erpConfirmButton': {
  219. afterrender: function(btn){
  220. btn.setText( $I18N.common.button.erpConfirmCheckButton );
  221. btn.setWidth( 100 );
  222. var status = Ext.getCmp('ab_statuscode');
  223. if(status && status.value != 'POSTED'){
  224. btn.hide();
  225. }
  226. confirmstatus = Ext.getCmp('ab_confirmstatus');
  227. if(confirmstatus && confirmstatus.value == '已对账'){
  228. btn.hide();
  229. }
  230. },
  231. click: function(btn){
  232. warnMsg("确定对账吗?", function(btn){
  233. if(btn == 'yes'){
  234. me.FormUtil.getActiveTab().setLoading(true);//loading...
  235. Ext.Ajax.request({
  236. url : basePath + 'fa/arp/confirmAPBill.action',
  237. params: {
  238. id: Ext.getCmp('ab_id').value,
  239. caller : caller
  240. },
  241. method : 'post',
  242. callback : function(options,success,response){
  243. me.FormUtil.getActiveTab().setLoading(false);
  244. var localJson = new Ext.decode(response.responseText);
  245. if(localJson.exceptionInfo){
  246. showError(localJson.exceptionInfo);
  247. }
  248. if(localJson.success){
  249. window.location.reload();
  250. }
  251. }
  252. });
  253. }
  254. });
  255. }
  256. },
  257. 'erpCancelButton': {
  258. afterrender: function(btn){
  259. btn.setText( $I18N.common.button.erpCancelCheckButton );
  260. btn.setWidth( 100 );
  261. var status = Ext.getCmp('ab_confirmstatus');
  262. if(status && status.value != '已对账'){
  263. btn.hide();
  264. }
  265. },
  266. click: function(btn){
  267. warnMsg("取消对账吗?", function(btn){
  268. if(btn == 'yes'){
  269. me.FormUtil.getActiveTab().setLoading(true);//loading...
  270. Ext.Ajax.request({
  271. url : basePath + 'fa/arp/cancelAPBill.action',
  272. params: {
  273. id: Ext.getCmp('ab_id').value,
  274. caller : caller
  275. },
  276. method : 'post',
  277. callback : function(options,success,response){
  278. me.FormUtil.getActiveTab().setLoading(false);
  279. var localJson = new Ext.decode(response.responseText);
  280. if(localJson.exceptionInfo){
  281. showError(localJson.exceptionInfo);
  282. }
  283. if(localJson.success){
  284. window.location.reload();
  285. }
  286. }
  287. });
  288. }
  289. });
  290. }
  291. },
  292. 'erpAutoInvoiceButton': {
  293. click: function(btn){
  294. var abcode=Ext.getCmp('ab_code').value;
  295. var abdate=Ext.getCmp('ab_date').value;
  296. Ext.Ajax.request({
  297. url : basePath + 'fa/ars/createVoucherAPO.action',
  298. params: {
  299. abcode: abcode,
  300. abdate: abdate
  301. },
  302. method : 'post',
  303. callback : function(options,success,response){
  304. me.FormUtil.getActiveTab().setLoading(false);
  305. var localJson = new Ext.decode(response.responseText);
  306. if(localJson.exceptionInfo){
  307. showError(localJson.exceptionInfo);
  308. }
  309. if(localJson.success){
  310. turnSuccess(function(){
  311. //var id = localJson.id;
  312. //var url = "jsps/scm/purchase/purchasePrice.jsp?formCondition=pp_id=" + id +
  313. //"&gridCondition=ppd_ppid=" + id;
  314. //me.FormUtil.onAdd('PurchasePrice' + id, '物料核价单' + id, url);
  315. });
  316. }
  317. }
  318. });
  319. }
  320. },
  321. 'numberfield[name=ab_apamount]':{
  322. beforerender:function(num){
  323. num.minValue = Number.NEGATIVE_INFINITY;
  324. num.setMinValue(num.minValue);
  325. b = num.baseChars+"";
  326. b += num.decimalSeparator;
  327. b += "-";
  328. b = Ext.String.escapeRegex(b);
  329. num.maskRe = new RegExp("[" + b + "]");
  330. }
  331. },
  332. 'erpTicketTaxesButton': {
  333. click: function(btn){
  334. var me = this, win = Ext.getCmp('ticketTaxes-win');
  335. if(!win){
  336. var ab_refno = Ext.getCmp('ab_refno').value, ab_remark = Ext.getCmp('ab_remark').value,
  337. win = Ext.create('Ext.Window', {
  338. id: 'ticketTaxes-win',
  339. title: '更新税票信息',
  340. height: 200,
  341. width: 400,
  342. items: [{
  343. xtype: 'form',
  344. height: '100%',
  345. width: '100%',
  346. bodyStyle: 'background:#f1f2f5;',
  347. items: [{
  348. margin: '10 0 0 0',
  349. xtype: 'textfield',
  350. fieldLabel: '税票编号',
  351. name:'ab_refno',
  352. value: ab_refno
  353. },{
  354. margin: '10 0 0 0',
  355. xtype: 'textfield',
  356. fieldLabel: '备注',
  357. name:'ab_remark',
  358. value: ab_remark
  359. }],
  360. closeAction: 'hide',
  361. buttonAlign: 'center',
  362. layout: {
  363. type: 'vbox',
  364. align: 'center'
  365. },
  366. buttons: [{
  367. text: $I18N.common.button.erpConfirmButton,
  368. cls: 'x-btn-blue',
  369. handler: function(btn) {
  370. var form = btn.ownerCt.ownerCt,
  371. a = form.down('textfield[name=ab_refno]'),
  372. b = form.down('textfield[name=ab_remark]');
  373. if(form.getForm().isDirty()) {
  374. me.updateTaxcode(Ext.getCmp('ab_id').value, a.value, b.value);
  375. }
  376. }
  377. }, {
  378. text: $I18N.common.button.erpCloseButton,
  379. cls: 'x-btn-blue',
  380. handler: function(btn) {
  381. btn.up('window').hide();
  382. }
  383. }]
  384. }]
  385. });
  386. }
  387. win.show();
  388. }
  389. },
  390. 'field[name=ab_differ]':{/*
  391. change:function(field){
  392. if(Ext.getCmp('ab_differ')){
  393. var sum = 0;
  394. var v_differ = Ext.isNumber(Ext.getCmp('ab_differ').getValue())?Ext.getCmp('ab_differ').getValue():'0';
  395. var grid = Ext.getCmp('grid');
  396. Ext.each(grid.store.data.items,function(item,index){
  397. if(item.dirty && !me.GridUtil.isBlank(grid, item.data)){
  398. sum += Number(item.data['abd_taxamount']);
  399. }
  400. });
  401. sum += Number(v_differ);
  402. Ext.getCmp('ab_taxsum').setValue(sum);
  403. }
  404. }
  405. */}
  406. });
  407. },
  408. //此CALLER为 应收发票维护界面 删除单据需要把明细行中开票数据还原
  409. //在此做还原操作
  410. //此CALLER为 应收发票维护界面 修改单据需要把明细行中开票数据还原
  411. // //在此做还原操作
  412. onGridItemClick: function(selModel, record){//grid行选择
  413. this.gridLastSelected = record;
  414. var grid = Ext.getCmp('grid');
  415. if(record.data[grid.necessaryField] == null || record.data[grid.necessaryField] == ''){
  416. this.gridLastSelected.findable = true;//空数据可以在输入完code,并移开光标后,自动调出该条数据
  417. } else {
  418. this.gridLastSelected.findable = false;
  419. }
  420. this.GridUtil.onGridItemClick(selModel, record);
  421. },
  422. getForm: function(btn){
  423. return btn.ownerCt.ownerCt;
  424. },
  425. beforeSaveAPBill: function(){
  426. if(caller =='APBill!CWIM'){
  427. var date_s = Ext.getCmp('ab_date').rawValue;
  428. var date_str = date_s.replace("-","");
  429. if(date_str.length>=6){
  430. date_str = date_str.substring(0,6);
  431. }else{
  432. var myDate = new Date();
  433. var dateString = Ext.Date.format(myDate,'Ymd');
  434. date_str = dateString.substring(0,6);
  435. }
  436. Ext.getCmp('ab_yearmonth').setValue(date_str);
  437. }
  438. this.BaseUtil.getPaydate('ab_paymentsmethodid','ab_date','ab_paydate');
  439. //保存ARBill
  440. /*if(bool)*/
  441. this.beforeSave(this);
  442. },
  443. beforeSave: function(){
  444. var me = this;
  445. var form = Ext.getCmp('form');
  446. if(! me.FormUtil.checkForm()){
  447. return;
  448. }
  449. if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
  450. me.FormUtil.getSeqId(form);
  451. }
  452. var detail = Ext.getCmp('grid');
  453. var param2 = new Array();
  454. var param3 = new Array();
  455. if(Ext.getCmp('assdetail')){
  456. Ext.each(Ext.Object.getKeys(Ext.getCmp('assdetail').cacheStoreGrid), function(key){
  457. Ext.each(Ext.getCmp('assdetail').cacheStoreGrid[key], function(d){
  458. d['dass_condid'] = key;
  459. param2.push(d);
  460. });
  461. });
  462. }
  463. if(Ext.getCmp('assmainbutton')){
  464. // Ext.each(Ext.Object.getKeys(Ext.getCmp('assmainbutton').cacheStoreForm), function(key){
  465. // Ext.each(Ext.getCmp('assmainbutton').cacheStoreForm[key], function(d){
  466. // d['ass_conid'] = key;
  467. // param3.push(d);
  468. // });
  469. // }
  470. }
  471. Ext.each(detail.store.data.items, function(item){
  472. if(item.data.prd_id == null || item.data.prd_id == 0){
  473. item.data.prd_id = -item.index;
  474. }
  475. });
  476. var param1 = me.GridUtil.getGridStore(detail);
  477. me.onSave(form, param1, param2,param3);
  478. },
  479. onSave: function(form, param1, param2,param3){
  480. var me = this;
  481. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  482. param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
  483. param3 = param3 == null ? [] : Ext.encode(param3).replace(/\\/g,"%");
  484. if(form.getForm().isValid()){
  485. Ext.each(form.items.items, function(item){
  486. if(item.xtype == 'numberfield'){
  487. if(item.value == null || item.value == ''){
  488. item.setValue(0);
  489. }
  490. }
  491. });
  492. me.FormUtil.save(form.getValues(), param1, param2,param3);
  493. }else{
  494. me.FormUtil.checkForm();
  495. }
  496. },
  497. beforeUpdateAPBill: function(){
  498. var grid = Ext.getCmp('grid');
  499. if(caller =='APBill!CWIM'){
  500. var date_s = Ext.getCmp('ab_date').rawValue;
  501. var date_str = date_s.replace("-","");
  502. if(date_str.length>=6){
  503. date_str = date_str.substring(0,6);
  504. }else{
  505. var myDate = new Date();
  506. var dateString = Ext.Date.format(myDate,'Ymd');
  507. date_str = dateString.substring(0,6);
  508. }
  509. Ext.getCmp('ab_yearmonth').setValue(date_str);
  510. }
  511. this.BaseUtil.getPaydate('ab_paymentsmethodid','ab_date','ab_paydate');
  512. Ext.Array.each(grid.store.data.items, function(item){
  513. item.set('abd_abid',Ext.getCmp('ab_id').value);
  514. });
  515. var bool = true;
  516. //保存
  517. if(bool)
  518. this.beforeUpdate(this);
  519. },
  520. beforeUpdate: function(){
  521. var me = this;
  522. var form = Ext.getCmp('form');
  523. if(! me.FormUtil.checkForm()){
  524. return;
  525. }
  526. var detail = Ext.getCmp('grid');
  527. Ext.each(detail.store.data.items, function(item){
  528. if(item.data.prd_id == null || item.data.prd_id == 0){
  529. item.data.prd_id = -item.index;
  530. }
  531. });
  532. var param1 = me.GridUtil.getGridStore(detail);
  533. var param2 = new Array();
  534. var param3 = new Array();
  535. if(Ext.getCmp('assdetail')){
  536. Ext.each(Ext.Object.getKeys(Ext.getCmp('assdetail').cacheStoreGrid), function(key){
  537. Ext.each(Ext.getCmp('assdetail').cacheStoreGrid[key], function(d){
  538. d['dass_condid'] = key;
  539. param2.push(d);
  540. });
  541. });
  542. }
  543. if(Ext.getCmp('assmainbutton')){
  544. // Ext.each(Ext.Object.getKeys(Ext.getCmp('assmainbutton').cacheStoreForm), function(key){
  545. // Ext.each(Ext.getCmp('assmainbutton').cacheStoreForm[key], function(d){
  546. // d['ass_conid'] = key;
  547. // param3.push(d);
  548. // });
  549. // }
  550. }
  551. if(me.FormUtil.checkFormDirty(form) == '' && detail.necessaryField.length > 0 && (param1.length == 0)
  552. && param2.length == 0&& param3.length == 0){
  553. showError($I18N.common.grid.emptyDetail);
  554. return;
  555. } else {
  556. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  557. param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
  558. param3 = param3 == null ? [] : Ext.encode(param3).replace(/\\/g,"%");
  559. if(form.getForm().isValid()){
  560. Ext.each(form.items.items, function(item){
  561. if(item.xtype == 'numberfield'){
  562. if(item.value == null || item.value == ''){
  563. item.setValue(0);
  564. }
  565. }
  566. });
  567. me.FormUtil.update(form.getValues(), param1, param2,param3);
  568. }else{
  569. me.FormUtil.checkForm();
  570. }
  571. }
  572. },
  573. beforePostAPBill:function(){
  574. },
  575. updateTaxcode: function(abid, val1, val2) {
  576. var me = this;
  577. Ext.Ajax.request({
  578. url: basePath + 'fa/arp/updateAPBillTaxcode.action',
  579. params: {
  580. caller: caller,
  581. ab_id: abid,
  582. ab_refno: val1,
  583. ab_remark: val2
  584. },
  585. callback: function(opt, s, r) {
  586. var rs = Ext.decode(r.responseText);
  587. if(rs.exceptionInfo) {
  588. showError(rs.exceptionInfo);
  589. } else {
  590. alert('更新成功!');
  591. window.location.reload();
  592. }
  593. }
  594. });
  595. }
  596. });