Ext.QuickTips.init(); Ext.define('erp.controller.fa.VoucherCreate', { extend: 'Ext.app.Controller', FormUtil: Ext.create('erp.util.FormUtil'), GridUtil: Ext.create('erp.util.GridUtil'), views: ['fa.VoucherCreate', 'core.form.Panel', 'core.form.MonthDateField', 'core.form.ConDateField', 'core.form.MultiField', 'core.trigger.DbfindTrigger', 'core.button.Export', 'core.button.Close', 'core.button.Query', 'core.button.VoCreate','core.trigger.AddDbfindTrigger'], init:function(){ var me = this; this.control({ 'field[name=yearmonth]': { afterrender: function(f) { me.getMonth(f); }, change: function(f) { if(!Ext.isEmpty(f.value)) { var d = Ext.ComponentQuery.query('condatefield'); if(d && d.length > 0) d[0].setMonthValue(f.value); } } }, 'condatefield[name=rb_date]': { afterrender: function(f) { f.hideScope(true); } }, 'panel[id=vc-panel]': { afterrender: function(p) { me.getVsSet(p); } }, 'erpQueryButton': { click: function(btn) { var condition = this.getCondition(btn.ownerCt.ownerCt); if(condition != null) { var grid = Ext.getCmp('grid'); this.GridUtil.loadNewStore(grid, {caller: caller, condition: condition, start: 1, end: c_type == 'merge' ? 1000 : 200}); } } }, 'erpVoCreateButton': { afterrender: function(btn) { if(!isCreate) { btn.setText($I18N.common.button.erpVoUnCreateButton); } else if(c_type == 'single'){ btn.ownerCt.insert(3, { xtype: 'button', iconCls: 'x-button-icon-add', cls: 'x-btn-gray', text: '合并生成', id: 'mergecreate' }); } }, click: function(btn) { var form = btn.ownerCt.ownerCt, ym = form.down('#yearmonth').value; var grid = Ext.getCmp('grid'),s = new Array(), c = null; if(c_type == 'single') { grid.store.each(function(item){ c = item.get(grid.prikey); if(!Ext.isEmpty(c)) { if(grid.selModel.isSelected(item)) { s.push("'" + c + "'"); } } }); if(s.length > 0) { if(isCreate) { if(s.length > 40) {// 超过40条的,换成分批制作 me.largeCreate(ym, cls, s); } else { me.create(ym, cls, s.join(',')); } } else { me.unCreate(s.join(',')); } } } else {// 合并制作的改为直接传递条件 if(grid.store.data.length > 0) { var condition = this.getCondition(form); if(condition != null) { if(isCreate) { me.create(ym, cls, condition); } else { me.unCreate(condition); } } } } } }, '#mergecreate': { click: function(btn) { var form = btn.ownerCt.ownerCt, ym = form.down('#yearmonth').value; var grid = Ext.getCmp('grid'),s = new Array(), c = null; grid.store.each(function(item){ c = item.get(grid.prikey); if(!Ext.isEmpty(c)) { if(grid.selModel.isSelected(item)) { s.push("'" + c + "'"); } } }); if(s.length > 0) { var cond = grid.prikey + ' in (' + s.join(',') + ')'; if(isCreate) { me.create(ym, cls, cond, 'merge'); } else { me.unCreate(cond); } } } } }); }, getCondition: function(form, _get) { var items = form.items.items, val = null,value = new Array(); Ext.each(items, function(item){ if(item.logic != null) { val = item.value; if(!Ext.isEmpty(val)) { if(contains(val.toString(), 'BETWEEN', true) && contains(val.toString(), 'AND', true)){ value.push('(' + item.logic + ' ' + val + ')'); } else if(item.xtype == 'combo' && val == '$ALL'){ var condition = ''; if(item.store.data.length > 1) { item.store.each(function(d, idx){ if(d.data.value != '$ALL') { if(condition == ''){ condition += item.logic + "='" + d.data.value + "'"; } else { condition += ' OR ' + item.logic + "='" + d.data.value + "'"; } } }); } if(condition != ''){ value.push('(' + condition + ')'); } } else if(item.xtype=='adddbfindtrigger' && item.value != null && item.value != ''){ var condition = ''; if(condition == ''){ condition += item.logic + ' in (' ; } var str=item.value,constr=""; for(var i=0;i 0) { value.push('(' + item.logic + ' like \'' + val + '\')'); } else { value.push('(' + item.logic + '=\'' + val + '\')'); } } } } }); if(value.length > 0) { var grid = Ext.getCmp('grid'); var condition = value.join(' AND '); condition += ' AND (' + (('nvl(' + grid.voucfield + ',\' \')') + (isCreate && !_get ? '=' : '<>') + '\' \')'); condition += Ext.isEmpty(grid.defaultCondition) ? '' : (' AND ' + grid.defaultCondition); if(!isCreate && c_type == 'merge') { condition += ' AND (' + grid.voucfield + ' IN (SELECT vo_code FROM Voucher WHERE ' + 'vo_createkind=\'合并制作\'))'; } if (form.classfield && cls) { condition += ' AND (' + form.classfield + '=\'' + cls + '\')'; } return condition; } return null; }, /** * 根据VoucherStyle--vs_datalist取Grid配置 */ getVsSet: function(p) { var me = this; Ext.Ajax.request({ url : basePath + 'common/getFieldsData.action', params: { caller: 'VoucherStyle', fields: 'vs_datalist,vs_classfield,vs_prikey1,vs_voucfield,vs_datacondition,vs_detailtable', condition: 'vs_code=\'' + vs_code + '\'' }, method : 'post', callback : function(options,success,response){ var rs = new Ext.decode(response.responseText); if(rs.exceptionInfo){ showError(rs.exceptionInfo); } else if(rs.success){ if(rs.data != null){ var form = Ext.getCmp('form'); form.classfield = rs.data.vs_classfield; me.voucherSet = rs.data; me.getGridSet(p, rs.data.vs_datalist, rs.data.vs_prikey1, rs.data.vs_voucfield, rs.data.vs_datacondition); } } } }); }, getGridSet: function(p, cal, prikey, voucfield, condition) { var grid = Ext.create('Ext.grid.Panel', { anchor: '100% 100%', id: 'grid', columnLines: true, columns: [], store: [], prikey: prikey, voucfield: voucfield, defaultCondition: condition, caller: cal, listeners: { scrollershow: function(scroller) { if (scroller && scroller.scrollEl) { scroller.clearManagedListeners(); scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller); } } }, selModel: c_type == 'single' ? new Ext.selection.CheckboxModel() : new Ext.selection.Model()//单张制作时,有checkbox }); p.add(grid); this.GridUtil.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', {caller: caller, condition: null}); }, /** * 制作凭证 */ create: function(ym, kind, data, mode) { var me = this, grid = Ext.getCmp('grid'); grid.setLoading(true); Ext.Ajax.request({ url: basePath + 'fa/vc/createVoucher.action', params: { vs_code: vs_code, yearmonth: ym, datas: data, mode: (mode || c_type), kind: kind, vomode: vo_type }, timeout: 60000, callback: function(opt, s, r) { grid.setLoading(false); var rs = Ext.decode(r.responseText); if(rs.exceptionInfo) { showError(rs.exceptionInfo); } else if(rs.error) { showMessage('提示', rs.error); } else { alert('制作成功'); // 这个code在合并制作成功后,取凭证号的时候用到 var btn = Ext.getCmp('querybtn'), code = grid.store.first().get(grid.prikey); btn.fireEvent('click', btn); me.getVoucher(vs_code, kind, data, mode != null, grid.prikey + '=\'' + code + '\''); } } }); }, /** * 制作凭证 */ syncCreate: function(ym, kind, data) { var res = true; Ext.Ajax.request({ url: basePath + 'fa/vc/createVoucher.action', params: { vs_code: vs_code, yearmonth: ym, datas: data, mode: c_type, kind: kind, vomode: vo_type }, async: false, callback: function(opt, s, r) { var rs = Ext.decode(r.responseText); if(rs.exceptionInfo) { showError(rs.exceptionInfo); res = false; } else if(rs.error) { showMessage('提示', rs.error); res = false; } } }); return res; }, /** * 超过40条的制作 */ largeCreate: function(ym, kind, datas) { var size = 20, len = datas.length, t = Math.ceil(len / size), a = 0, grid = Ext.getCmp('grid'), res = true; grid.setLoading(true); for (var i = 0;i < t;i++ ) { var s = [], b = Math.min(a + size, len); for(;a < b;a++ ) { s.push(datas[a]); } res = this.syncCreate(ym, kind, s.join(',')); if(!res) break; } grid.setLoading(false); if(res) { alert('制作成功'); var btn = Ext.getCmp('querybtn'); btn.fireEvent('click', btn); this.getVoucher(vs_code, kind, datas.join(',')); } }, /** * 取消凭证 */ unCreate: function(data) { Ext.Ajax.request({ url: basePath + 'fa/vc/unCreateVoucher.action', params: { vs_code: vs_code, mode: c_type, kind: cls, datas: data }, callback: function(opt, s, r) { var rs = Ext.decode(r.responseText); if(rs.exceptionInfo) { showError(rs.exceptionInfo); } else if(rs.error) { showMessage('提示', rs.error); } else { alert('取消成功'); var btn = Ext.getCmp('querybtn'); btn.fireEvent('click', btn); } } }); }, getMonth: function(f) { Ext.Ajax.request({ url: basePath + 'fa/getMonth.action', params: { votype: 'GL'//vo_type//直接取总账期间 }, callback: function(opt, s, r) { var rs = Ext.decode(r.responseText); if(rs.data) { f.setValue(rs.data.PD_DETNO); } } }); }, getVoucher: function(vs, kind, data, singlemerge, codeStr) { var me = this, s = me.voucherSet, cond = ''; if('merge' == c_type) { cond = this.getCondition(Ext.getCmp('form'), true); codeStr && (cond += ' and (' + codeStr + ')'); } else if(singlemerge && s.vs_classfield) { cond = data + ' and ' + s.vs_classfield + '=\'' + kind + '\''; } else { cond = s.vs_prikey1 + ' in (' + data + ')'; if (s.vs_classfield) cond += ' and ' + s.vs_classfield + '=\'' + kind + '\''; } Ext.Ajax.request({ url : basePath + 'common/getFieldsDatas.action', params: { caller: s.vs_detailtable + ' left join voucher vo on vo.vo_code=' + s.vs_voucfield, fields: 'distinct vo.vo_id,' + s.vs_voucfield, condition: cond }, method : 'post', callback : function(options,success,response){ var rs = new Ext.decode(response.responseText); if(rs.exceptionInfo){ showError(rs.exceptionInfo); } else if(rs.data){ var msg = '凭证:
', json = Ext.decode(rs.data); var f = s.vs_voucfield.toUpperCase(), id = 0; for(var i in json) { id = json[i]['VO_ID']; msg += '
' + json[i][f] + ''; } showMessage('提示', msg); } } }); } });