Ext.QuickTips.init(); Ext.define('erp.controller.oa.fee.feePlease', { extend: 'Ext.app.Controller', FormUtil: Ext.create('erp.util.FormUtil'), GridUtil: Ext.create('erp.util.GridUtil'), BaseUtil: Ext.create('erp.util.BaseUtil'), views:[ 'oa.fee.feePlease','core.form.Panel','core.grid.Panel2','core.toolbar.Toolbar','core.button.Scan','core.form.FileField', 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','core.button.Upload','core.button.ResAudit', 'core.button.Audit','core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail','core.form.DateHourMinuteField', 'core.button.ResSubmit','core.button.TurnCLFBX','core.button.TurnFYBX','core.button.TurnYHFKSQ','core.button.VoCreate', 'core.button.TurnYWZDBX','core.button.End','core.button.ResEnd','core.button.Confirm','core.trigger.MultiDbfindTrigger', 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.button.TurnBankRegister','core.form.MultiField','oa.fee.FeeBackGrid', 'erp.view.core.button.AddDetail','erp.view.core.button.DeleteDetail','erp.view.core.button.Copy','erp.view.core.button.Paste','erp.view.core.button.Up', 'erp.view.core.button.Down','erp.view.core.button.UpExcel','common.datalist.Toolbar','oa.fee.feePleaseFYBX' ], init:function(){ var me = this; this.control({ 'erpGridPanel2': { itemclick: function(selModel, record){ if(record.data.fpd_id != 0 && record.data.fpd_id != null && record.data.fpd_id != ''){ var btn = Ext.getCmp('factdays'); btn && btn.setDisabled(false); } this.onGridItemClick(selModel, record); } }, 'FeeBackGrid': { itemclick: this.onGridItemClick2 }, 'erpFormPanel' : { afterload : function(form) { this.hidecolumns(true); } }, 'dbfindtrigger[name=fpd_d1]': { afterrender:function(trigger){ trigger.dbKey='fp_department'; trigger.mappingKey='fcs_departmentname'; trigger.dbMessage='请先选择申请部门'; } }, 'dbfindtrigger[name=fp_pleaseman]':{ aftertrigger:function(trigger,record){ Ext.Ajax.request({ url:basePath+'oa/fee/getFeeAccount.action', method:'POST', params:{ emcode:trigger.value }, async:false, callback:function(opts,success,res){ var r = new Ext.decode(res.responseText); trigger.up('form').getForm().setValues(r.info); } }); } }, 'erpSaveButton': { click: function(btn){ var form = me.getForm(btn); if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){ if(caller=='FeePlease!CLFBX'){ me.BaseUtil.getRandomNumber('FeePlease!FYBX');//差旅费报销取费用报销同样的caller取编号 }else{ me.BaseUtil.getRandomNumber(caller);//自动添加编号 } } if(caller == 'FeePlease!CZCFSQ'|| caller == 'FeePlease!FYBX'){ this.getamount(); } this.beforeSave(); } }, 'erpCloseButton': { click: function(btn){ this.FormUtil.beforeClose(this); } }, 'erpAddButton': { click: function(btn){ if(caller=='FeePlease!FYBX'){ me.FormUtil.onAdd('add' + caller, '新增费用申请', "jsps/oa/fee/feePlease.jsp?whoami=" + caller); }else{ me.FormUtil.onAdd('add' + caller, '新增单据', "jsps/oa/fee/feePleaseFYBX.jsp?whoami=" + caller); } } }, 'erpUpdateButton': { click: function(btn){ if(caller == 'FeePlease!CZCFSQ'){ this.getamount(); } this.beforeUpdate(); } }, 'erpDeleteButton': { afterrender: function(btn){ var status = Ext.getCmp('fp_statuscode'); if(status && status.value != 'ENTERING'){ btn.hide(); } }, click: function(btn){ me.FormUtil.onDelete((Ext.getCmp('fp_id').value)); } }, 'erpAuditButton': { afterrender: function(btn){ var status = Ext.getCmp('fp_statuscode'); if(status && status.value != 'COMMITED'){ btn.hide(); } }, click: function(btn){ this.FormUtil.onAudit(Ext.getCmp('fp_id').value); } }, 'erpResAuditButton': { afterrender: function(btn){ var status = Ext.getCmp('fp_statuscode'); if(status && status.value != 'AUDITED'){ btn.hide(); } }, click: function(btn){ this.FormUtil.onResAudit(Ext.getCmp('fp_id').value); } }, 'erpSubmitButton': { afterrender: function(btn){ var status = Ext.getCmp('fp_statuscode'); if(status && status.value != 'ENTERING'){ btn.hide(); } }, click: function(btn){ this.FormUtil.onSubmit(Ext.getCmp('fp_id').value); } }, 'erpResSubmitButton': { afterrender: function(btn){ var status = Ext.getCmp('fp_statuscode'); if(status && status.value != 'COMMITED'){ btn.hide(); } }, click: function(btn){ this.FormUtil.onResSubmit(Ext.getCmp('fp_id').value); } }, 'erpPrintButton': { click:function(btn){ var reportName=''; var kind=Ext.getCmp('fp_kind'); if(kind&&kind.value=="借款申请单"){ reportName="AccountRegZW2"; }else{ reportName="AccountRegZW"; } var condition='{FeePlease.fp_id}='+Ext.getCmp('fp_id').value+''; var id=Ext.getCmp('fp_id').value; me.FormUtil.onwindowsPrint(id,reportName,condition); } }, 'erpEndButton': { afterrender: function(btn){ var status = Ext.getCmp('fp_statuscode'); if(status && status.value == 'FINISH'){ btn.hide(); } }, click: function(btn){ this.FormUtil.onEnd(Ext.getCmp('fp_id').value); } }, 'combo[name=fp_object]': { delay: 200, change: function(m){ this.hidecolumns(false); } }, 'erpResEndButton': { afterrender: function(btn){ var status = Ext.getCmp('fp_statuscode'); if(status && status.value != 'FINISH'){ btn.hide(); } }, click: function(btn){ this.FormUtil.onResEnd(Ext.getCmp('fp_id').value); } }, 'erpConfirmButton': {afterrender: function(btn){ var statu = Ext.getCmp('fp_statuscode'); if(statu && statu.value != 'AUDITED'){ btn.hide(); } }, click: function(btn){ me.onConfirm(Ext.getCmp('fp_id').value); } } , 'erpVoCreateButton':{//业务招待费转费用报销 beforerender:function(btn){ btn.setWidth(100); btn.setText("转费用报销"); }, afterrender: function(btn){ var status = Ext.getCmp('fp_statuscode'); var turnStatus=Ext.getCmp('fp_v11'); if(status && status.value != 'AUDITED'&&turnStatus||turnStatus.value!='未转费用申请'){ btn.hide(); } }, click:function(){ this.turnFYBX(me); } }, //转银行登记 'erpTurnBankRegisterButton':{ click:function(btn){ me.turnBankRegister(); }, afterrender: function(btn){ var status = Ext.getCmp('fp_statuscode'); if(status && status.value != 'AUDITED'){ btn.hide(); } } }, /** * 更改实际天数 */ '#factdays': { click: function(btn) { var record=btn.ownerCt.ownerCt.getSelectionModel().getLastSelected(); me.UpdateFactdays(record); } }, 'field[name=fp_v11]':{ beforerender:function(field){ var status = Ext.getCmp('fp_statuscode'); if(status && status.value == 'AUDITED'){ field.readOnly=false; } } }, 'field[name=fp_n2]':{ beforerender:function(field){ var status = Ext.getCmp('fp_statuscode'); if(status && status.value == 'AUDITED'){ field.readOnly=false; } } }, 'field[name=fp_sourcecode]': { afterrender:function(f){ if(caller=='FeePlease!CLFBX'|| caller=='FeePlease!FYBX'||caller=='FeePlease!HKSQ'){ f.setFieldStyle({ 'color': 'blue' }); f.focusCls = 'mail-attach'; var c = Ext.Function.bind(me.openRelative, me); Ext.EventManager.on(f.inputEl, { mousedown : c, scope: f, buffer : 100 }); } } }, 'erpTurnCLFBXButton':{ afterrender: function(btn){ var status = Ext.getCmp('fp_statuscode'); if(status && status.value != 'AUDITED'){ btn.hide(); } }, click: function(btn){ warnMsg("确定要转入差旅费报销单吗?", function(btn){ if(btn == 'yes'){ me.FormUtil.getActiveTab().setLoading(true);//loading... Ext.Ajax.request({ url : basePath + 'oa/feeplease/turnCLFBX.action', params: { caller: caller, id: Ext.getCmp('fp_id').value }, method : 'post', callback : function(options,success,response){ me.FormUtil.getActiveTab().setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); } if(localJson.success){ turnSuccess(function(){ var id = localJson.id; var url = "jsps/oa/fee/feePlease.jsp?whoami=FeePlease!CLFBX&formCondition=fp_id=" + id + "&gridCondition=fpd_fpid=" + id; me.FormUtil.onAdd('FeePlease' + id, '差旅费报销单' + id, url); }); } } }); } }); } }, 'erpTurnFYBXButton':{ afterrender: function(btn){ var status = Ext.getCmp('fp_statuscode'); if(status && status.value != 'AUDITED'){ btn.hide(); } }, click: function(btn){ warnMsg("确定要转入费用报销单吗?", function(btn){ if(btn == 'yes'){ me.FormUtil.getActiveTab().setLoading(true);//loading... Ext.Ajax.request({ url : basePath + 'oa/feeplease/turnFYBX.action', params: { caller: caller, id: Ext.getCmp('fp_id').value }, method : 'post', callback : function(options,success,response){ me.FormUtil.getActiveTab().setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); } if(localJson.success){ turnSuccess(function(){ var id = localJson.id; var url = "jsps/oa/fee/feePlease.jsp?whoami=FeePlease!FYBX&formCondition=fp_id=" + id + "&gridCondition=fpd_fpid=" + id; me.FormUtil.onAdd('FeePlease' + id, '费用报销单' + id, url); }); } } }); } }); } }, 'erpTurnYHFKSQButton':{ afterrender: function(btn){ var status = Ext.getCmp('fp_statuscode'); if(status && status.value != 'AUDITED'){ btn.hide(); } }, click: function(btn){ warnMsg("确定要转入银行付款申请单吗?", function(btn){ if(btn == 'yes'){ me.FormUtil.getActiveTab().setLoading(true);//loading... Ext.Ajax.request({ url : basePath + 'oa/feeplease/turnYHFKSQ.action', params: { caller: caller, id: Ext.getCmp('fp_id').value }, method : 'post', callback : function(options,success,response){ me.FormUtil.getActiveTab().setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); } if(localJson.success){ turnSuccess(function(){ var id = localJson.id; var url = "jsps/oa/fee/feePlease.jsp?whoami=FeePlease!YHFKSQ&formCondition=fp_id=" + id + "&gridCondition=fpd_fpid=" + id; me.FormUtil.onAdd('FeePlease' + id, '银行付款申请单' + id, url); }); } } }); } }); } }, 'erpTurnYWZDBXButton':{ afterrender: function(btn){ var status = Ext.getCmp('fp_statuscode'); if(status && status.value != 'AUDITED'){ btn.hide(); } }, click: function(btn){ warnMsg("确定要转入业务招待费报销单吗?", function(btn){ if(btn == 'yes'){ me.FormUtil.getActiveTab().setLoading(true);//loading... Ext.Ajax.request({ url : basePath + 'oa/feeplease/turnYWZDBX.action', params: { caller: caller, id: Ext.getCmp('fp_id').value }, method : 'post', callback : function(options,success,response){ me.FormUtil.getActiveTab().setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); } if(localJson.success){ turnSuccess(function(){ var id = localJson.id; var url = "jsps/oa/fee/feePlease.jsp?whoami=FeePlease!YWZDBX&formCondition=fp_id=" + id + "&gridCondition=fpd_fpid=" + id; me.FormUtil.onAdd('FeePlease' + id, '业务招待费报销单' + id, url); }); } } }); } }); } } }); }, getamount: function(){ var grid = Ext.getCmp('grid'); var items = grid.store.data.items; var amount = 0; Ext.each(items,function(item,index){ if(item.data['fpd_date1']!=null&&item.data['fpd_date1']!=""){ amount= amount + Number(item.data['fpd_total']); } }); Ext.getCmp('fp_pleaseamount').setValue(amount); }, onGridItemClick: function(selModel, record){//grid行选择 this.GridUtil.onGridItemClick(selModel, record); }, getForm: function(btn){ return btn.ownerCt.ownerCt; }, onConfirm: function(id){ var form = Ext.getCmp('form'); Ext.Ajax.request({ url : basePath + form.confirmUrl, params: { id: id, caller:caller }, method : 'post', callback : function(options,success,response){ //me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ //audit成功后刷新页面进入可编辑的页面 //auditSuccess(function(){ window.location.reload(); //}); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showMessage("提示", '确认成功'); //auditSuccess(function(){ window.location.reload(); //}); } else { showError(str);return; } } } } }); }, openRelative:function(e, el, obj){ var f = obj.scope; var name=''; var cal=''; var field='' var conField='' var type=Ext.getCmp('fp_sourcekind').value; if(type=='客户拜访记录'){ name='VisitRecord'; cal='visitrecord'; field='vr_id'; conField='vr_class=\'OfficeClerk\' and vr_code'; }else if(type=='原厂拜访记录'){ name='VisitRecord'; cal='visitrecord'; field='vr_id'; conField='vr_class=\'VisitRecord!Vender\' and vr_code'; }else if(type=='业务招待费申请单'){ name='FeePlease'; cal='FeePlease'; field='fp_id'; conField='fp_kind=\'业务招待费申请单\' and fp_code'; }else if(type=='出差申请单'){ name='FeePlease'; cal='FeePlease'; field='fp_id'; conField='fp_kind=\'出差申请单\' and fp_code'; }else if(type=='资源开发记录'){ name='VisitRecord'; cal='visitrecord'; field='vr_id'; conField='vr_class=\'VisitRecord!Resource\' and vr_code'; }else if(type=='借款申请单'){ name='FeePlease'; cal='FeePlease'; field='fp_id'; conField='fp_kind=\'借款申请单\' and fp_code'; } else if(type=='费用申请'){ name='PreFeePlease'; cal='PreFeePlease'; field='fp_id'; conField=' fp_code'; }else if(type=='资产维修'){ name='Propertyrepair'; cal='Propertyrepair'; field='pr_id'; conField=' pr_code'; }else if(type=='车辆维修'){ name='vehiclearchivesdetail'; cal='vehiclearchivesdetail'; field='vd_id'; conField=' vd_code'; }else if(type=='市场调研立项'){ name='MarketTaskReport'; cal='MarketTaskReport'; field='mr_id'; conField='mr_code'; } if(type=='市场调研立项'||type=='客户拜访记录' || type=='原厂拜访记录' || type=='业务招待费申请单'||type=='出差申请单'||type=='资源开发记录'||type=='借款申请单'||type=='费用申请'||type=='资产维修'||type=='车辆维修') { var code = Ext.getCmp('fp_sourcecode').value; if(code.indexOf('(')>-1){//来自其他的单据 this.turnOtherSob(code,field,conField,cal); }else{ var url=this.getRelativeUrl(code,field,conField,cal); this.FormUtil.onAdd(name, Ext.getCmp('fp_sourcekind').value, url); } } }, getRelativeUrl:function(code,field,conField,cal){ var id = 0; Ext.Ajax.request({ url : basePath + 'common/getFieldData.action', async: false, params: { caller: cal, field: field, condition: conField+'=\'' + code + '\'' }, method : 'post', callback : function(o, s, r){ var rs = new Ext.decode(r.responseText); if(rs.exceptionInfo){ showError(rs.exceptionInfo);return; } if(rs.success){ if(rs.data != null){ id = rs.data; } } } }); var url='#'; var type=Ext.getCmp('fp_sourcekind').value; if(type=='客户拜访记录'){ url='jsps/crm/customermgr/customervisit/visitRecord.jsp?formCondition=vr_idIS'+id+'&gridCondition=vrd_vridIS'+id; }else if(type=='原厂拜访记录'){ url='jsps/crm/customermgr/customervisit/visitRecord3.jsp?formCondition=vr_idIS'+id+'&gridCondition=vrd_vridIS'+id; }else if(type=='业务招待费申请单'){ url='jsps/oa/fee/feePlease.jsp?whoami=FeePlease!YWZDSQ&formCondition=fp_idIS'+id+'&gridCondition=fpd_fpidIS'+id; }else if(type=='出差申请单'){ url='jsps/oa/fee/feePlease.jsp?whoami=FeePlease!CCSQ&formCondition=fp_idIS'+id+'&gridCondition=fpd_fpidIS'+id; }else if(type=='资源开发记录'){ url='jsps/crm/customermgr/customervisit/visitRecord4.jsp?formCondition=vr_idIS'+id+'&gridCondition=vrd_vridIS'+id; }else if(type=='借款申请单'){ url='jsps/oa/fee/feePlease.jsp?whoami=FeePlease!JKSQ&formCondition=fp_idIS'+id+'&gridCondition=fpd_fpidIS'+id; }else if(type=='费用申请'){ url='jsps/oa/fee/preFeePlease.jsp?formCondition=fp_idIS'+id+'&gridCondition=fpd_fpidIS'+id; }else if(type=='资产维修'){ url='jsps/oa/storage/propertyrepair.jsp?formCondition=pr_idIS'+id+'&gridCondition=prd_pridIS'+id; }else if(type=='车辆维修'){ url='jsps/oa/vehicle/vehiclemaintain.jsp?formCondition=vd_idIS'+id; }else if(type=='市场调研立项'){ var c=Ext.getCmp('fp_v14')?Ext.getCmp('fp_v14').value:'MarketTaskReport#0';//调研模板caller#任务id var a=c.split('#'); url='jsps/crm/marketmgr/marketresearch/researchReport.jsp?'+ 'whoami='+a[0]+'&cond=idIS' +a[1]+'&formCondition=mr_idIS'+id+'&gridCondition=mrd_mridIS'+id; } return url; }, turnOtherSob:function(code,field,conField,cal){ var newSob=null;//code形如:2015040052(资料中心) Ext.Ajax.request({//去资料中心寻找括号内的帐套 url : basePath + 'common/getFieldData.action', async: false, params: { caller: 'DataCenter.MASTER', field: 'ma_user', condition: 'ma_function=\'' + code.split('(')[1].slice(0,-1) + '\'' }, method : 'post', callback : function(o, s, r){ var rs = new Ext.decode(r.responseText); if(rs.exceptionInfo){ showError(rs.exceptionInfo);return; } if(rs.success){ if(rs.data != null){ newSob = rs.data; } } } }); if(newSob==null){ showError('没有找到要转的帐套!'); return; }else{ var url=this.getRelativeUrl(code.split('(')[0],field,conField,newSob+'.'+cal); var currentMaster = parent.sob?parent.sob:parent.parent.sob; url=parent.location.href.split('jsps')[0]+url;//防止因为父页面url的改变,而找不到页面 Ext.Ajax.request({ url: basePath + 'common/changeMaster.action', params: { to: newSob }, callback: function(opt, s, r) { if (s) { var win = parent.Ext.create('Ext.Window', { width: '100%', height: '100%', draggable: false, closable: false, modal: true, id:'modalwindow', historyMaster:currentMaster, title: '创建到帐套' + code.split('(')[1].slice(0,-1) + '的临时会话', html : '', buttonAlign: 'center', buttons: [{ text: $I18N.common.button.erpCloseButton, cls: 'x-btn-blue', id: 'close', handler: function(b) { Ext.Ajax.request({ url: basePath + 'common/changeMaster.action', params: { to: currentMaster }, callback: function(opt, s, r) { if (s) { b.up('window').close(); } else { alert('切换到原帐套失败!'); } } }); } }] }); win.show(); } else { alert('无法创建到帐套' + code.split('(')[1].slice(0,-1) + '的临时会话!'); } } }); } }, turnFYBX:function(me){ warnMsg("确定要转入费用报销单吗?", function(btn){ if(btn == 'yes'){ me.FormUtil.getActiveTab().setLoading(true);//loading... Ext.Ajax.request({ url : basePath + 'oa/feeplease/turnFYBX2.action', params: { caller: caller, id: Ext.getCmp('fp_id').value }, method : 'post', callback : function(options,success,response){ me.FormUtil.getActiveTab().setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); } if(localJson.success){ //turnSuccess(function(){ showMessage("提示", '转入成功'); window.location.reload(); var id = localJson.id; var url = "jsps/oa/fee/feePlease.jsp?whoami=FeePlease!FYBX&formCondition=fp_id=" + id + "&gridCondition=fpd_fpid=" + id; me.FormUtil.onAdd('FeePlease' + id, '费用报销单' + id, url); //}); } } }); } }); }, turnBankRegister:function(){ var catecode = Ext.getCmp('fp_v11').value; if(catecode == null || catecode == ''){ showMessage("警告", '请填写需要转银行登记的付款方信息!'); return; } var thispayamount=Ext.getCmp('fp_n2').value; /*if(Ext.getCmp('fp_n2').value==0){ showMessage("警告", '本次转金额不能为0!'); return; }*/ /*if(Ext.getCmp('fp_n2').value<0){ showMessage("警告", '本次转金额不能小于0!'); return; }*/ var back=0;//还款金额 if(Ext.getCmp('fp_n6')&&Ext.getCmp('fp_n6').value!=null&&Ext.getCmp('fp_n6').value!=''){ back=Ext.getCmp('fp_n6').value; } if(((thispayamount+Ext.getCmp('fp_n1').value).toFixed(3)-0)>((Ext.getCmp('fp_pleaseamount').value-back).toFixed(3)-0)){ showMessage("警告", '本次转金额超出剩余金额!'); return; } var main = parent.Ext.getCmp("content-panel"); main.getActiveTab().setLoading(true);//loading... Ext.Ajax.request({ url : basePath + 'oa/fee/turnBankRegister.action', params: { id:Ext.getCmp("fp_id").value, paymentcode:Ext.getCmp('fp_v11').value, payment:Ext.getCmp('fp_v10').value, thispayamount:Ext.getCmp('fp_n2').value, caller:caller }, method : 'post', callback : function(options,success,response){ main.getActiveTab().setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); return ""; } if(localJson.success){ if(localJson.log){ showMessage("提示", localJson.log); window.location.reload(); } } } }); }, UpdateFactdays:function(record){ var win = this.factdayswindow; if (!win) { win = this.getFactdaysWindow(); } win.show(); }, getFactdaysWindow : function() { var me = this; return Ext.create('Ext.window.Window',{ width: 330, height: 180, closeAction: 'hide', cls: 'custom-blue', title:'