VoucherStyle.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.VoucherStyle', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. views: ['fa.VoucherStyle', 'core.form.Panel', 'core.grid.Panel2', 'core.grid.YnColumn', 'core.trigger.TextAreaTrigger',
  7. 'core.trigger.DbfindTrigger','core.button.Sync',
  8. 'core.button.Close', 'core.button.Save', 'core.button.Update'],
  9. init:function(){
  10. var me = this;
  11. this.control({
  12. 'erpGridPanel2': {
  13. itemclick: function(selModel, record) {
  14. me.GridUtil.onGridItemClick(selModel, record);
  15. var btn = Ext.getCmp('assdetail');
  16. var ass = record.data['ca_asstype'],
  17. check = record.data['vd_checkitem'];
  18. if(!Ext.isEmpty(ass) || check == -1){
  19. btn.setDisabled(false);
  20. } else {
  21. btn.setDisabled(true);
  22. }
  23. }
  24. },
  25. 'erpDeleteDetailButton': {
  26. afterrender: function(btn){
  27. //辅助核算
  28. btn.ownerCt.add({
  29. text: '辅助核算',
  30. width: 85,
  31. disabled: true,
  32. cls: 'x-btn-blue',
  33. id: 'assdetail'
  34. });
  35. }
  36. },
  37. 'erpSaveButton': {
  38. click: function(btn){
  39. me._beforeSave();
  40. me.beforeSave();
  41. }
  42. },
  43. 'erpUpdateButton': {
  44. click: function(btn){
  45. me._beforeSave();
  46. me.beforeUpdate();
  47. }
  48. },
  49. 'button[id=assdetail]': {
  50. click: function(btn){
  51. var grid = btn.ownerCt.ownerCt;
  52. var record = grid.selModel.lastSelected;
  53. if(record){
  54. var id = record.get('vd_id') || (-grid.store.indexOf(record));
  55. var win = Ext.getCmp('ass-' + id);
  56. if(win) {
  57. win.show();
  58. } else {
  59. var grid = Ext.create('Ext.grid.Panel', {
  60. anchor: '100% 100%',
  61. columns: [{
  62. text: 'ID',
  63. hidden: true,
  64. dataIndex: 'vsa_id'
  65. },{
  66. text: 'VD_ID',
  67. hidden: true,
  68. dataIndex: 'vsa_vdid'
  69. },{
  70. text: '核算项',
  71. dataIndex: 'vsa_assname',
  72. flex: 1,
  73. editor: {
  74. xtype: 'dbfindtrigger'
  75. },
  76. dbfind: 'AssKind|ak_name'
  77. },{
  78. text: '编号表达式',
  79. dataIndex: 'vsa_codefield',
  80. flex: 1,
  81. editor: {
  82. xtype: 'textfield'
  83. }
  84. },{
  85. text: '名称表达式',
  86. dataIndex: 'vsa_namefield',
  87. flex: 1,
  88. editor: {
  89. xtype: 'textfield'
  90. }
  91. }],
  92. store: new Ext.data.Store({
  93. fields: [{name: 'vsa_id', type: 'number'}, {name: 'vsa_vdid', type: 'number'},
  94. {name: 'vsa_assname', type: 'string'}, {name: 'vsa_codefield', type: 'string'},
  95. {name: 'vsa_namefield', type: 'string'}]
  96. }),
  97. columnLines: true,
  98. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  99. clicksToEdit: 1
  100. })],
  101. dbfinds: [{
  102. field: 'vsa_assname',
  103. dbGridField: 'ak_name'
  104. }],
  105. listeners: {
  106. itemclick: function(selModel, record) {
  107. var grid = selModel.ownerCt,
  108. store = grid.store,
  109. idx = store.indexOf(record),
  110. len = store.getCount();
  111. if(idx == len - 1) {
  112. store.add({}, {}, {}, {}, {});
  113. }
  114. }
  115. }
  116. });
  117. win = Ext.create('Ext.Window', {
  118. width: 500,
  119. height: 360,
  120. layout: 'anchor',
  121. title: '辅助核算公式',
  122. items: [grid],
  123. buttonAlign: 'center',
  124. modal: true,
  125. buttons: [{
  126. text: $I18N.common.button.erpConfirmButton,
  127. cls: 'x-btn-blue',
  128. handler: function(btn) {
  129. var win = btn.ownerCt.ownerCt,
  130. grid = Ext.getCmp('grid'),
  131. record = grid.selModel.lastSelected,
  132. ass = win.down('gridpanel');
  133. var data = new Array();
  134. ass.store.each(function(item){
  135. data.push(item.data);
  136. });
  137. if(data.length > 0){
  138. me.cacheStore[record.data[grid.keyField] || (-record.index)] = data;
  139. }
  140. win.hide();
  141. }
  142. },{
  143. text: $I18N.common.button.erpOffButton,
  144. cls: 'x-btn-blue',
  145. handler: function(btn) {
  146. btn.ownerCt.ownerCt.hide();
  147. }
  148. }]
  149. }).show();
  150. }
  151. me.getAss(win.down('gridpanel'), id, record.get('ca_assname'));
  152. }
  153. }
  154. },
  155. 'field[name=vd_catecode]': {
  156. aftertrigger: function(f, d) {
  157. var record = f.record,
  158. ass = d.get('ca_asstype');
  159. if(!Ext.isEmpty(ass)) {
  160. record.set('vd_checkitem', -1);
  161. } else {
  162. record.set('vd_checkitem', 0);
  163. }
  164. }
  165. }
  166. });
  167. },
  168. _beforeSave: function() {
  169. var grid = Ext.getCmp('grid'),
  170. code = Ext.getCmp('vs_code').value;
  171. // Ext.each(grid.store.data.items,function(item,index){
  172. //
  173. // if(item.data['vd_class']==''){
  174. // item.data['vd_code']=code;
  175. // }
  176. //
  177. // });
  178. grid.store.each(function(d){
  179. if(!Ext.isEmpty(d.get('vd_class'))) {
  180. d.set('vd_code', code);
  181. }
  182. });
  183. },
  184. cacheStore: new Array(),
  185. getAss: function(grid, id, assname) {
  186. var me = this;
  187. if(!me.cacheStore[id]){
  188. if(id == null || id <= 0){
  189. var data = new Array(),r = assname.join('#');
  190. for(var i=0;i<r.length;i++){
  191. var o = new Object();
  192. o.vsa_vdid = id;
  193. o.vsa_assname = r[i];
  194. data.push(o);
  195. }
  196. grid.store.loadData(data);
  197. } else {
  198. var condition = "vsa_vdid=" + id;
  199. Ext.Ajax.request({
  200. url : basePath + 'common/getFieldsDatas.action',
  201. params: {
  202. caller: "VoucherStyleAss",
  203. fields: 'vsa_id,vsa_vdid,vsa_assname,vsa_codefield,vsa_namefield',
  204. condition: condition
  205. },
  206. method : 'post',
  207. callback : function(options,success,response){
  208. var res = new Ext.decode(response.responseText);
  209. if(res.exception || res.exceptionInfo){
  210. showError(res.exceptionInfo);
  211. return;
  212. }
  213. var data = Ext.decode(res.data);
  214. var dd = new Array(),r = assname.split('#');
  215. Ext.Array.each(data, function(d){
  216. var o = new Object();
  217. o.vsa_id = d.VSA_ID;
  218. o.vsa_vdid = d.VSA_VDID;
  219. o.vsa_assname = d.VSA_ASSNAME;
  220. o.vsa_codefield = d.VSA_CODEFIELD;
  221. o.vsa_namefield = d.VSA_NAMEFIELD;
  222. dd.push(o);
  223. });
  224. for(var i = 0; i < r.length; i++){
  225. if(!Ext.isEmpty(r[i])) {
  226. var bool = false;
  227. Ext.Array.each(data, function(d){
  228. if(d.VSA_ASSNAME == r[i]) {
  229. bool = true;
  230. }
  231. });
  232. if(!bool) {
  233. var o = new Object();
  234. o.vsa_vdid = id;
  235. o.vsa_assname = r[i];
  236. dd.push(o);
  237. }
  238. }
  239. }
  240. if(dd.length == 0) {
  241. dd = [{}, {}, {}, {}, {}];
  242. }
  243. grid.store.loadData(dd);
  244. }
  245. });
  246. }
  247. } else {
  248. grid.store.loadData(me.cacheStore[id]);
  249. }
  250. },
  251. beforeSave: function(){
  252. var me = this;
  253. var form = Ext.getCmp('form');
  254. if(! me.FormUtil.checkForm()){
  255. return;
  256. }
  257. if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
  258. me.FormUtil.getSeqId(form);
  259. }
  260. var detail = Ext.getCmp('grid');
  261. var param2 = new Array();
  262. Ext.each(Ext.Object.getKeys(me.cacheStore), function(key){
  263. Ext.each(me.cacheStore[key], function(d){
  264. d['vsa_vdid'] = key;
  265. param2.push(d);
  266. });
  267. });
  268. Ext.each(detail.store.data.items, function(item){
  269. if(item.data.vd_id == null || item.data.vd_id == 0){
  270. item.data.vd_id = -item.index;
  271. }
  272. });
  273. var param1 = me.GridUtil.getGridStore(detail);
  274. if(detail.necessaryField.length > 0 && (param1.length == 0)){
  275. showError($I18N.common.grid.emptyDetail);
  276. return;
  277. }
  278. me.onSave(form, param1, param2);
  279. },
  280. onSave: function(form, param1, param2) {
  281. var me = this;
  282. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  283. param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
  284. // param3 = param3 == null ? [] : param3.toString().replace(/\\/g,"%");
  285. if(form.getForm().isValid()){
  286. Ext.each(form.items.items, function(item){
  287. if(item.xtype == 'numberfield'){
  288. if(item.value == null || item.value == ''){
  289. item.setValue(0);
  290. }
  291. }
  292. });
  293. me.FormUtil.save(form.getValues(), param1, param2);
  294. }else{
  295. me.FormUtil.checkForm();
  296. }
  297. },
  298. beforeUpdate: function(){
  299. var me = this;
  300. var form = Ext.getCmp('form');
  301. if(! me.FormUtil.checkForm()){
  302. return;
  303. }
  304. var detail = Ext.getCmp('grid');
  305. Ext.each(detail.store.data.items, function(item){
  306. if(item.data.vd_id == null || item.data.vd_id == 0){
  307. item.data.vd_id = -item.index;
  308. }
  309. });
  310. var param1 = me.GridUtil.getGridStore(detail);
  311. var param2 = new Array();
  312. Ext.each(Ext.Object.getKeys(me.cacheStore), function(key){
  313. Ext.each(me.cacheStore[key], function(d){
  314. d['vsa_vdid'] = key;
  315. param2.push(d);
  316. });
  317. });
  318. if(me.FormUtil.checkFormDirty(form) == '' && detail.necessaryField.length > 0 && (param1.length == 0)
  319. && param2.length == 0){
  320. showError($I18N.common.grid.emptyDetail);
  321. return;
  322. } else {
  323. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  324. param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
  325. if(form.getForm().isValid()){
  326. Ext.each(form.items.items, function(item){
  327. if(item.xtype == 'numberfield'){
  328. if(item.value == null || item.value == ''){
  329. item.setValue(0);
  330. }
  331. }
  332. });
  333. me.FormUtil.update(form.getValues(), param1, param2);
  334. }else{
  335. me.FormUtil.checkForm();
  336. }
  337. }
  338. }
  339. });