CarryPurc.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.gla.CarryPurc', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. views: ['fa.gla.CarryPurc', 'core.button.Close'],
  6. init: function(){
  7. this.control({
  8. 'displayfield[name=yearmonth]': {
  9. afterrender: function(f) {
  10. this.getCurrentMonth(f);
  11. }
  12. },
  13. 'button[id=deal]': {
  14. click: function(btn) {
  15. var form = btn.ownerCt.ownerCt,
  16. ym = form.down('#yearmonth').value,
  17. account = form.down('#account').value;
  18. if(btn.isUnCreate) {
  19. this.unCreate(form, ym);
  20. } else {
  21. this.create(form, ym, account);
  22. }
  23. }
  24. }
  25. });
  26. },
  27. getCurrentMonth: function(f) {
  28. var me = this;
  29. Ext.Ajax.request({
  30. url: basePath + 'fa/getMonth.action',
  31. params: {
  32. type: 'MONTH-A'
  33. },
  34. callback: function(opt, s, r) {
  35. var rs = Ext.decode(r.responseText);
  36. if(rs.data) {
  37. f.setValue(rs.data.PD_DETNO);
  38. me.getPurcVoucher(f.ownerCt.down('#vocode'), rs.data.PD_DETNO);
  39. }
  40. }
  41. });
  42. },
  43. getPurcVoucher: function(f, y) {
  44. Ext.Ajax.request({
  45. url : basePath + 'common/getFieldData.action',
  46. params: {
  47. caller: 'Voucher',
  48. field: 'vo_code',
  49. condition: 'vo_yearmonth=' + y + ' and instr(vo_explanation,\'结转采购费用\')>0'
  50. },
  51. method : 'post',
  52. callback : function(opt, s, res){
  53. var r = new Ext.decode(res.responseText);
  54. if(r.exceptionInfo){
  55. f.hide();
  56. showError(r.exceptionInfo);return;
  57. } else if(r.success && r.data) {
  58. f.setValue(r.data);
  59. var form = f.ownerCt;
  60. form.down('#account').hide();
  61. form.down('#deal').setText('取消凭证');
  62. form.down('#deal').isUnCreate = true;
  63. } else {
  64. f.hide();
  65. }
  66. }
  67. });
  68. },
  69. create: function(form, ym, account) {
  70. var tab = this.FormUtil.getActiveTab();
  71. tab.setLoading(true);
  72. Ext.Ajax.request({
  73. url: basePath + 'fa/vc/createVoucher.action',
  74. params: {
  75. vs_code: 'PurcFee',
  76. mode: 'merge',
  77. datas: 'pi_class in (\'采购验收单\',\'采购验退单\') and pi_statuscode=\'POSTED\' and nvl(pi_vouchercode, \' \')=\' \' and to_char(pi_date,\'yyyymm\')=' + ym,
  78. kind: '结转采购费用',
  79. yearmonth: ym,
  80. vomode: 'AP'
  81. },
  82. timeout: 4800000,
  83. callback: function(opt, s, r) {
  84. tab.setLoading(false);
  85. var rs = Ext.decode(r.responseText);
  86. if (rs.error) {
  87. showError(rs.error);
  88. } else if(rs.success) {
  89. if(rs.data) {
  90. showMessage('提示', rs.data);
  91. window.location.reload();
  92. } else {
  93. alert('结转采购费用成功!');
  94. }
  95. }
  96. }
  97. });
  98. },
  99. unCreate: function(form, ym) {
  100. var tab = this.FormUtil.getActiveTab();
  101. tab.setLoading(true);
  102. Ext.Ajax.request({
  103. url: basePath + 'fa/gla/unCreatePurcfee.action',
  104. params: {
  105. yearmonth: ym
  106. },
  107. callback: function(opt, s, r) {
  108. tab.setLoading(false);
  109. var rs = Ext.decode(r.responseText);
  110. if (rs.error) {
  111. showError(rs.error);
  112. } else if(rs.success) {
  113. showMessage('提示', '成功取消采购费用凭证!', 1000);
  114. window.location.reload();
  115. }
  116. }
  117. });
  118. }
  119. });