VoucherCreate.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.VoucherCreate', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. views: ['fa.VoucherCreate', 'core.form.Panel', 'core.form.MonthDateField', 'core.form.ConDateField',
  7. 'core.form.MultiField', 'core.trigger.DbfindTrigger', 'core.button.Export',
  8. 'core.button.Close', 'core.button.Query', 'core.button.VoCreate','core.trigger.AddDbfindTrigger'],
  9. init:function(){
  10. var me = this;
  11. this.control({
  12. 'field[name=yearmonth]': {
  13. afterrender: function(f) {
  14. me.getMonth(f);
  15. },
  16. change: function(f) {
  17. if(!Ext.isEmpty(f.value)) {
  18. var d = Ext.ComponentQuery.query('condatefield');
  19. if(d && d.length > 0)
  20. d[0].setMonthValue(f.value);
  21. }
  22. }
  23. },
  24. 'condatefield[name=rb_date]': {
  25. afterrender: function(f) {
  26. f.hideScope(true);
  27. }
  28. },
  29. 'panel[id=vc-panel]': {
  30. afterrender: function(p) {
  31. me.getVsSet(p);
  32. }
  33. },
  34. 'erpQueryButton': {
  35. click: function(btn) {
  36. var condition = this.getCondition(btn.ownerCt.ownerCt);
  37. if(condition != null) {
  38. var grid = Ext.getCmp('grid');
  39. this.GridUtil.loadNewStore(grid, {caller: caller, condition: condition, start: 1, end: c_type == 'merge' ? 1000 : 200});
  40. }
  41. }
  42. },
  43. 'erpVoCreateButton': {
  44. afterrender: function(btn) {
  45. if(!isCreate) {
  46. btn.setText($I18N.common.button.erpVoUnCreateButton);
  47. } else if(c_type == 'single'){
  48. btn.ownerCt.insert(3, {
  49. xtype: 'button',
  50. iconCls: 'x-button-icon-add',
  51. cls: 'x-btn-gray',
  52. text: '合并生成',
  53. id: 'mergecreate'
  54. });
  55. }
  56. },
  57. click: function(btn) {
  58. var form = btn.ownerCt.ownerCt,
  59. ym = form.down('#yearmonth').value;
  60. var grid = Ext.getCmp('grid'),s = new Array(), c = null;
  61. if(c_type == 'single') {
  62. grid.store.each(function(item){
  63. c = item.get(grid.prikey);
  64. if(!Ext.isEmpty(c)) {
  65. if(grid.selModel.isSelected(item)) {
  66. s.push("'" + c + "'");
  67. }
  68. }
  69. });
  70. if(s.length > 0) {
  71. if(isCreate) {
  72. if(s.length > 40) {// 超过40条的,换成分批制作
  73. me.largeCreate(ym, cls, s);
  74. } else {
  75. me.create(ym, cls, s.join(','));
  76. }
  77. } else {
  78. me.unCreate(s.join(','));
  79. }
  80. }
  81. } else {// 合并制作的改为直接传递条件
  82. if(grid.store.data.length > 0) {
  83. var condition = this.getCondition(form);
  84. if(condition != null) {
  85. if(isCreate) {
  86. me.create(ym, cls, condition);
  87. } else {
  88. me.unCreate(condition);
  89. }
  90. }
  91. }
  92. }
  93. }
  94. },
  95. '#mergecreate': {
  96. click: function(btn) {
  97. var form = btn.ownerCt.ownerCt,
  98. ym = form.down('#yearmonth').value;
  99. var grid = Ext.getCmp('grid'),s = new Array(), c = null;
  100. grid.store.each(function(item){
  101. c = item.get(grid.prikey);
  102. if(!Ext.isEmpty(c)) {
  103. if(grid.selModel.isSelected(item)) {
  104. s.push("'" + c + "'");
  105. }
  106. }
  107. });
  108. if(s.length > 0) {
  109. var cond = grid.prikey + ' in (' + s.join(',') + ')';
  110. if(isCreate) {
  111. me.create(ym, cls, cond, 'merge');
  112. } else {
  113. me.unCreate(cond);
  114. }
  115. }
  116. }
  117. }
  118. });
  119. },
  120. getCondition: function(form, _get) {
  121. var items = form.items.items,
  122. val = null,value = new Array();
  123. Ext.each(items, function(item){
  124. if(item.logic != null) {
  125. val = item.value;
  126. if(!Ext.isEmpty(val)) {
  127. if(contains(val.toString(), 'BETWEEN', true)
  128. && contains(val.toString(), 'AND', true)){
  129. value.push('(' + item.logic + ' ' + val + ')');
  130. } else if(item.xtype == 'combo' && val == '$ALL'){
  131. var condition = '';
  132. if(item.store.data.length > 1) {
  133. item.store.each(function(d, idx){
  134. if(d.data.value != '$ALL') {
  135. if(condition == ''){
  136. condition += item.logic + "='" + d.data.value + "'";
  137. } else {
  138. condition += ' OR ' + item.logic + "='" + d.data.value + "'";
  139. }
  140. }
  141. });
  142. }
  143. if(condition != ''){
  144. value.push('(' + condition + ')');
  145. }
  146. } else if(item.xtype=='adddbfindtrigger' && item.value != null && item.value != ''){
  147. var condition = '';
  148. if(condition == ''){
  149. condition += item.logic + ' in (' ;
  150. }
  151. var str=item.value,constr="";
  152. for(var i=0;i<str.split("#").length;i++){
  153. if(i<str.split("#").length-1){
  154. constr+="'"+str.split("#")[i]+"',";
  155. }else constr+="'"+str.split("#")[i]+"'";
  156. }
  157. condition += constr;
  158. condition += ') ';
  159. if(condition != ''){
  160. value.push('(' + condition + ')');
  161. }
  162. } else {
  163. if(String(val).indexOf('%') > 0) {
  164. value.push('(' + item.logic + ' like \'' + val + '\')');
  165. } else {
  166. value.push('(' + item.logic + '=\'' + val + '\')');
  167. }
  168. }
  169. }
  170. }
  171. });
  172. if(value.length > 0) {
  173. var grid = Ext.getCmp('grid');
  174. var condition = value.join(' AND ');
  175. condition += ' AND (' + (('nvl(' + grid.voucfield + ',\' \')') + (isCreate && !_get ? '=' : '<>') + '\' \')');
  176. condition += Ext.isEmpty(grid.defaultCondition) ? '' : (' AND ' + grid.defaultCondition);
  177. if(!isCreate && c_type == 'merge') {
  178. condition += ' AND (' + grid.voucfield + ' IN (SELECT vo_code FROM Voucher WHERE ' +
  179. 'vo_createkind=\'合并制作\'))';
  180. }
  181. if (form.classfield && cls) {
  182. condition += ' AND (' + form.classfield + '=\'' + cls + '\')';
  183. }
  184. return condition;
  185. }
  186. return null;
  187. },
  188. /**
  189. * 根据VoucherStyle--vs_datalist取Grid配置
  190. */
  191. getVsSet: function(p) {
  192. var me = this;
  193. Ext.Ajax.request({
  194. url : basePath + 'common/getFieldsData.action',
  195. params: {
  196. caller: 'VoucherStyle',
  197. fields: 'vs_datalist,vs_classfield,vs_prikey1,vs_voucfield,vs_datacondition,vs_detailtable',
  198. condition: 'vs_code=\'' + vs_code + '\''
  199. },
  200. method : 'post',
  201. callback : function(options,success,response){
  202. var rs = new Ext.decode(response.responseText);
  203. if(rs.exceptionInfo){
  204. showError(rs.exceptionInfo);
  205. } else if(rs.success){
  206. if(rs.data != null){
  207. var form = Ext.getCmp('form');
  208. form.classfield = rs.data.vs_classfield;
  209. me.voucherSet = rs.data;
  210. me.getGridSet(p, rs.data.vs_datalist, rs.data.vs_prikey1,
  211. rs.data.vs_voucfield, rs.data.vs_datacondition);
  212. }
  213. }
  214. }
  215. });
  216. },
  217. getGridSet: function(p, cal, prikey, voucfield, condition) {
  218. var grid = Ext.create('Ext.grid.Panel', {
  219. anchor: '100% 100%',
  220. id: 'grid',
  221. columnLines: true,
  222. columns: [],
  223. store: [],
  224. prikey: prikey,
  225. voucfield: voucfield,
  226. defaultCondition: condition,
  227. caller: cal,
  228. listeners: {
  229. scrollershow: function(scroller) {
  230. if (scroller && scroller.scrollEl) {
  231. scroller.clearManagedListeners();
  232. scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
  233. }
  234. }
  235. },
  236. selModel: c_type == 'single' ? new Ext.selection.CheckboxModel() : new Ext.selection.Model()//单张制作时,有checkbox
  237. });
  238. p.add(grid);
  239. this.GridUtil.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', {caller: caller, condition: null});
  240. },
  241. /**
  242. * 制作凭证
  243. */
  244. create: function(ym, kind, data, mode) {
  245. var me = this, grid = Ext.getCmp('grid');
  246. grid.setLoading(true);
  247. Ext.Ajax.request({
  248. url: basePath + 'fa/vc/createVoucher.action',
  249. params: {
  250. vs_code: vs_code,
  251. yearmonth: ym,
  252. datas: data,
  253. mode: (mode || c_type),
  254. kind: kind,
  255. vomode: vo_type
  256. },
  257. timeout: 60000,
  258. callback: function(opt, s, r) {
  259. grid.setLoading(false);
  260. var rs = Ext.decode(r.responseText);
  261. if(rs.exceptionInfo) {
  262. showError(rs.exceptionInfo);
  263. } else if(rs.error) {
  264. showMessage('提示', rs.error);
  265. } else {
  266. alert('制作成功');
  267. // 这个code在合并制作成功后,取凭证号的时候用到
  268. var btn = Ext.getCmp('querybtn'), code = grid.store.first().get(grid.prikey);
  269. btn.fireEvent('click', btn);
  270. me.getVoucher(vs_code, kind, data, mode != null, grid.prikey + '=\'' + code + '\'');
  271. }
  272. }
  273. });
  274. },
  275. /**
  276. * 制作凭证
  277. */
  278. syncCreate: function(ym, kind, data) {
  279. var res = true;
  280. Ext.Ajax.request({
  281. url: basePath + 'fa/vc/createVoucher.action',
  282. params: {
  283. vs_code: vs_code,
  284. yearmonth: ym,
  285. datas: data,
  286. mode: c_type,
  287. kind: kind,
  288. vomode: vo_type
  289. },
  290. async: false,
  291. callback: function(opt, s, r) {
  292. var rs = Ext.decode(r.responseText);
  293. if(rs.exceptionInfo) {
  294. showError(rs.exceptionInfo);
  295. res = false;
  296. } else if(rs.error) {
  297. showMessage('提示', rs.error);
  298. res = false;
  299. }
  300. }
  301. });
  302. return res;
  303. },
  304. /**
  305. * 超过40条的制作
  306. */
  307. largeCreate: function(ym, kind, datas) {
  308. var size = 20, len = datas.length, t = Math.ceil(len / size), a = 0,
  309. grid = Ext.getCmp('grid'), res = true;
  310. grid.setLoading(true);
  311. for (var i = 0;i < t;i++ ) {
  312. var s = [], b = Math.min(a + size, len);
  313. for(;a < b;a++ ) {
  314. s.push(datas[a]);
  315. }
  316. res = this.syncCreate(ym, kind, s.join(','));
  317. if(!res)
  318. break;
  319. }
  320. grid.setLoading(false);
  321. if(res) {
  322. alert('制作成功');
  323. var btn = Ext.getCmp('querybtn');
  324. btn.fireEvent('click', btn);
  325. this.getVoucher(vs_code, kind, datas.join(','));
  326. }
  327. },
  328. /**
  329. * 取消凭证
  330. */
  331. unCreate: function(data) {
  332. Ext.Ajax.request({
  333. url: basePath + 'fa/vc/unCreateVoucher.action',
  334. params: {
  335. vs_code: vs_code,
  336. mode: c_type,
  337. kind: cls,
  338. datas: data
  339. },
  340. callback: function(opt, s, r) {
  341. var rs = Ext.decode(r.responseText);
  342. if(rs.exceptionInfo) {
  343. showError(rs.exceptionInfo);
  344. } else if(rs.error) {
  345. showMessage('提示', rs.error);
  346. } else {
  347. alert('取消成功');
  348. var btn = Ext.getCmp('querybtn');
  349. btn.fireEvent('click', btn);
  350. }
  351. }
  352. });
  353. },
  354. getMonth: function(f) {
  355. Ext.Ajax.request({
  356. url: basePath + 'fa/getMonth.action',
  357. params: {
  358. votype: 'GL'//vo_type//直接取总账期间
  359. },
  360. callback: function(opt, s, r) {
  361. var rs = Ext.decode(r.responseText);
  362. if(rs.data) {
  363. f.setValue(rs.data.PD_DETNO);
  364. }
  365. }
  366. });
  367. },
  368. getVoucher: function(vs, kind, data, singlemerge, codeStr) {
  369. var me = this, s = me.voucherSet, cond = '';
  370. if('merge' == c_type) {
  371. cond = this.getCondition(Ext.getCmp('form'), true);
  372. codeStr && (cond += ' and (' + codeStr + ')');
  373. } else if(singlemerge && s.vs_classfield) {
  374. cond = data + ' and ' + s.vs_classfield + '=\'' + kind + '\'';
  375. } else {
  376. cond = s.vs_prikey1 + ' in (' + data + ')';
  377. if (s.vs_classfield)
  378. cond += ' and ' + s.vs_classfield + '=\'' + kind + '\'';
  379. }
  380. Ext.Ajax.request({
  381. url : basePath + 'common/getFieldsDatas.action',
  382. params: {
  383. caller: s.vs_detailtable + ' left join voucher vo on vo.vo_code=' + s.vs_voucfield,
  384. fields: 'distinct vo.vo_id,' + s.vs_voucfield,
  385. condition: cond
  386. },
  387. method : 'post',
  388. callback : function(options,success,response){
  389. var rs = new Ext.decode(response.responseText);
  390. if(rs.exceptionInfo){
  391. showError(rs.exceptionInfo);
  392. } else if(rs.data){
  393. var msg = '凭证:<br>', json = Ext.decode(rs.data);
  394. var f = s.vs_voucfield.toUpperCase(), id = 0;
  395. for(var i in json) {
  396. id = json[i]['VO_ID'];
  397. msg += '<hr><a href="javascript:openUrl(\'jsps/fa/ars/voucher.jsp?formCondition=vo_idIS' +
  398. id + '&gridCondition=vd_voidIS' + id + '\')">' + json[i][f] + '</a>';
  399. }
  400. showMessage('提示', msg);
  401. }
  402. }
  403. });
  404. }
  405. });