ExchangeGl.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.gla.ExchangeGl', {
  3. extend: 'Ext.app.Controller',
  4. BaseUtil: Ext.create('erp.util.BaseUtil'),
  5. views: ['fa.gla.ExchangeGl', 'core.trigger.CateTreeDbfindTrigger', 'core.button.Close'],
  6. init: function(){
  7. this.control({
  8. 'displayfield[name=yearmonth]': {
  9. afterrender: function(f) {
  10. this.getCurrentMonth(f);
  11. }
  12. },
  13. 'cateTreeDbfindTrigger[name=ca_code]': {
  14. afterrender: function(f) {
  15. this.getDefaultCatecode(f);
  16. }
  17. },
  18. 'button[id=deal]': {
  19. click: function(btn) {
  20. var form = btn.ownerCt.ownerCt,
  21. ym = form.down('#yearmonth').value,
  22. cacode = form.down('#ca_code').value,
  23. account = form.down('#account').value,
  24. grid = form.ownerCt.down('gridpanel');
  25. var dd = new Array(), err = new Array();
  26. grid.store.each(function(){
  27. dd.push(this.data);
  28. if(this.get('cm_endrate') == 0) {
  29. err.push(this.get('cm_crname'));
  30. }
  31. });
  32. if(err.length > 0) {
  33. showError('汇率不能为空,币别:' + err.join(','));
  34. return;
  35. }
  36. this.deal(form, grid, ym, cacode, account, Ext.encode(dd));
  37. }
  38. }
  39. });
  40. },
  41. getCurrentMonth: function(f) {
  42. var me = this;
  43. Ext.Ajax.request({
  44. url: basePath + 'fa/getMonth.action',
  45. params: {
  46. type: 'MONTH-A'
  47. },
  48. callback: function(opt, s, r) {
  49. var rs = Ext.decode(r.responseText);
  50. if(rs.data) {
  51. f.setValue(rs.data.PD_DETNO);
  52. me.getCurrencyMonth(f.ownerCt.ownerCt.down('gridpanel'), f.value);
  53. }
  54. }
  55. });
  56. },
  57. getDefaultCatecode: function(f) {
  58. this.BaseUtil.getSetting('exchangeGl', 'exchangeCatecode', function(code){
  59. f.setValue(code);
  60. });
  61. },
  62. getCurrencyMonth: function(grid, ym) {
  63. Ext.Ajax.request({
  64. url : basePath + 'common/getFieldsDatas.action',
  65. async: false,
  66. params: {
  67. caller: 'CurrencysMonth',
  68. fields: 'cm_code,cm_crname,cm_endrate',
  69. condition: 'cm_yearmonth=' + ym
  70. },
  71. method : 'post',
  72. callback : function(opt, s, r){
  73. var rs = new Ext.decode(r.responseText);
  74. if(rs.exceptionInfo){
  75. showError(rs.exceptionInfo);return;
  76. }
  77. if(rs.success){
  78. var data = Ext.decode(rs.data), _data = new Array();
  79. Ext.each(data, function(d) {
  80. _data.push({
  81. cm_code: d.CM_CODE,
  82. cm_crname: d.CM_CRNAME,
  83. cm_endrate: d.CM_ENDRATE
  84. });
  85. });
  86. grid.store.loadData(_data);
  87. }
  88. }
  89. });
  90. },
  91. deal: function(form, grid, ym ,ca_code, account, data) {
  92. var me = this;
  93. Ext.Ajax.request({
  94. url: basePath + 'fa/gla/exchangegl.action',
  95. params: {
  96. yearmonth: ym,
  97. ca_code: ca_code,
  98. account: account,
  99. data: data
  100. },
  101. callback: function(opt, s, r) {
  102. var rs = Ext.decode(r.responseText);
  103. if(rs.success) {
  104. if(rs.data) {
  105. showMessage('提示', rs.data);
  106. }
  107. me.getCurrencyMonth(grid, ym);
  108. } else if(rs.exceptionInfo) {
  109. showError(rs.exceptionInfo);
  110. }
  111. }
  112. });
  113. }
  114. });