FormPanelController.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. Ext.define('saas.view.money.payBalance.FormPanelController', {
  2. extend: 'saas.view.core.form.FormPanelController',
  3. alias: 'controller.money-paybalance-formpanel',
  4. init: function (form) {
  5. var me = this;
  6. this.control({
  7. // 供应商名称
  8. 'dbfindtrigger[name=pb_vendname]':{
  9. beforerender: function (f) {
  10. Ext.apply(f, {
  11. dbfinds: [{
  12. from: 've_code',
  13. to: 'pb_vendcode'
  14. }, {
  15. from: 've_name',
  16. to: 'pb_vendname'
  17. },{
  18. from: 've_leftamount',
  19. to: 've_leftamount'
  20. },{
  21. from: 'id',
  22. to: 'pb_vendid',
  23. ignore:true
  24. }],
  25. });
  26. }
  27. },
  28. 'multidbfindtrigger[name=pbd_slcode]': {
  29. beforerender: function (f) {
  30. Ext.apply(f, {
  31. dataUrl: '/api/money/subledger/list',
  32. addTitle: '源单资料',
  33. dbfinds: [{
  34. from: 'id',
  35. to: 'pbd_slid'
  36. }, {
  37. from: 'sl_code',
  38. to: 'pbd_slcode'
  39. },{
  40. from: 'sl_orderamount',
  41. to: 'pbd_amount'
  42. },{
  43. from: 'sl_yamount',
  44. to: 'sl_yamount'
  45. },{
  46. from: 'sl_namount',
  47. to: 'sl_namount'
  48. },{
  49. from:'sl_date',
  50. to:'pbd_sldate'
  51. },{
  52. from:'sl_kind',
  53. to:'pbd_slkind'
  54. },{
  55. from:'sl_namount',
  56. to:'pbd_nowbalance'
  57. }],
  58. dbtpls: [{
  59. field: 'sl_code',
  60. width: 100
  61. }],
  62. defaultCondition: "sl_vendid<>0 and sl_kind in ('期初余额','采购验收单','采购验退单') and sl_namount<>0" ,
  63. dbSearchFields:[{
  64. emptyText:'输入源单编号',
  65. xtype : "textfield",
  66. name : "search",
  67. getCondition: function(v) {
  68. return "(upper(sl_code) like '%"+v.toUpperCase()+"%')";
  69. },
  70. allowBlank : true,
  71. columnWidth : 0.25
  72. }],
  73. dbColumns:[{
  74. "text": "源单id",
  75. "hidden": true,
  76. "dataIndex": "id",
  77. "width": 100,
  78. "xtype": "numbercolumn"
  79. },{
  80. "text": "源单编号",
  81. "flex": 1,
  82. "dataIndex": "sl_code",
  83. "width": 100
  84. },{
  85. "text": "源单类型",
  86. "flex": 1,
  87. "dataIndex": "sl_kind",
  88. "width": 100
  89. }, {
  90. "text": "单据金额",
  91. "flex": 1,
  92. "dataIndex": "sl_orderamount",
  93. "width": 100,
  94. xtype: 'numbercolumn',
  95. align:'end'
  96. }, {
  97. "text": "已核销金额",
  98. "flex": 1,
  99. "dataIndex": "sl_yamount",
  100. "width": 150,
  101. xtype: 'numbercolumn',
  102. align:'end',
  103. "items": null
  104. }, {
  105. "text": "未核销金额",
  106. "flex": 1,
  107. "dataIndex": "sl_namount",
  108. "width": 100,
  109. xtype: 'numbercolumn',
  110. align:'end'
  111. },{
  112. "text": "单据日期",
  113. "flex": 1,
  114. "dataIndex": "sl_date",
  115. "width": 120,
  116. xtype: 'datecolumn',
  117. align:'end'
  118. }]
  119. });
  120. }
  121. },
  122. 'dbfindtrigger[name=pd_bankname]':{
  123. beforerender: function (f) {
  124. Ext.apply(f, {
  125. dbfinds: [{
  126. from: 'id',
  127. to: 'pd_bankid',ignore:true
  128. }, {
  129. from: 'bk_bankcode',
  130. to: 'pd_bankcode'
  131. },{
  132. from: 'bk_bankname',
  133. to: 'pd_bankname'
  134. }],
  135. });
  136. }
  137. }
  138. });
  139. },
  140. addCombo:function(){
  141. var combo=this.ownerCmp;
  142. Ext.create('Ext.window.Window',{
  143. layout:'vbox',
  144. bodyPadding: 15,
  145. width:500,
  146. items:[{
  147. fieldLabel:'实际值',
  148. xtype:'textfield'
  149. },{
  150. fieldLabel:'显示值',
  151. xtype:'textfield'
  152. }],
  153. buttons:[{
  154. text:'确认',
  155. handler:function(b){
  156. combo.setValue('ok');
  157. b.up('window').close();
  158. }
  159. }],
  160. renderTo:this.ownerCmp.ownerCt.getEl()
  161. }).show();
  162. },
  163. turnIn: function() {
  164. var me = this,
  165. form = me.getView(),
  166. id = form.getForm().findField(form._idField);
  167. saas.util.BaseUtil.request({
  168. url: form._turnInUrl+id.value,
  169. method: 'GET',
  170. })
  171. .then(function(localJson) {
  172. if(localJson.success){
  173. saas.util.BaseUtil.showSuccessToast('转单成功');
  174. }
  175. })
  176. .catch(function(res) {
  177. console.error(res);
  178. saas.util.BaseUtil.showErrorToast('转单失败: ' + res.message);
  179. });
  180. },
  181. onSave: function() {
  182. var me = this,
  183. form = me.getView(),
  184. viewModel = me.getViewModel(),
  185. store1 = viewModel.get('detail0').detailStore,
  186. store2 = viewModel.get('detail1').detailStore;
  187. var valid = form.isValid();
  188. if(!valid) {
  189. saas.util.BaseUtil.showErrorToast(form.invalidText);
  190. return false;
  191. }
  192. var sum_pd_amount = store1.sum('pd_amount'); // 付款金额合计
  193. var pb_discounts = viewModel.get('pb_discounts'); // 折扣金额
  194. var sum_pbd_nowbalance = store2.sum('pbd_nowbalance'); // 本次核销金额合计
  195. var flag = sum_pd_amount + pb_discounts - sum_pbd_nowbalance;
  196. viewModel.set("pb_preamount",flag);
  197. if(flag != 0) {
  198. var t = flag > 0 ? '大' : '小';
  199. saas.util.BaseUtil.showConfirm('提示', '付款金额' + t + '于本次折扣后核销金额,是否仍要保存?')
  200. .then(function(y) {
  201. if(y == 'yes') {
  202. me.save();
  203. }
  204. });
  205. }else {
  206. me.save();
  207. }
  208. },
  209. vendnamechange:function(dbfindtrigger){
  210. var me = this,
  211. viewModel = me.getViewModel();
  212. var c = viewModel.get('pb_vendname_change');
  213. if(c!=null&&c!=''){
  214. c = ' and sl_vendid='+c;
  215. }else{
  216. c ='';
  217. }
  218. dbfindtrigger.defaultCondition = "sl_vendid<>0 and sl_kind in ('期初余额','采购验收单','采购验退单') and sl_namount<>0" + c;
  219. }
  220. });