Ext.QuickTips.init(); Ext.define('erp.controller.scm.purchase.Inquiry', { extend: 'Ext.app.Controller', FormUtil: Ext.create('erp.util.FormUtil'), GridUtil: Ext.create('erp.util.GridUtil'), BaseUtil: Ext.create('erp.util.BaseUtil'), views:[ 'core.form.Panel','scm.purchase.Inquiry','core.grid.Panel2','core.toolbar.Toolbar','core.form.FileField', 'core.button.Save','core.button.Update','core.button.Add','core.button.Submit','core.button.Print','core.button.Upload', 'core.button.Audit','core.button.Close','core.button.Delete','core.button.DeleteDetail','core.button.ResSubmit', 'core.button.ResAudit','core.button.HistoryQuotation','core.button.HistoryInPrice','core.button.UpdateMaxlimitInfo','core.button.UpdatePurcVendor', 'core.button.UpdateInfo','core.button.Nullify','core.button.CopyAll', 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.button.TurnPurcPrice','core.button.AgreePrice','core.grid.YnColumn' ], init:function(){ var me = this; me.alloweditor = true; this.control({ 'field[name=in_purpose]':{ beforerender: function(field){ field.setReadOnly(false); } }, 'field[name=in_remark]':{ beforerender: function(field){ field.setReadOnly(false); } }, 'erpUpdateInfoButton':{ afterrender: function(btn){ var status = Ext.getCmp('in_statuscode'); if(status && status.value == 'NULLIFIED'){ btn.hide(); } }, click:function(){ var purpose= Ext.getCmp('in_purpose'), remark= Ext.getCmp('in_remark'); if(purpose && remark){ me.updateInfo(purpose.value, remark.value, Ext.getCmp('in_id').value); } } }, 'erpNullifyButton':{ afterrender: function(btn){ var status = Ext.getCmp('in_statuscode'), checkstatuscode = Ext.getCmp('in_checkstatuscode'); if(status && status.value != 'AUDITED'){ btn.hide(); } if(checkstatuscode && checkstatuscode.value == 'APPROVED'){ btn.hide(); } }, click: function(btn){ me.FormUtil.onNullify(Ext.getCmp('in_id').value); } }, 'erpGridPanel2': { afterrender: function(grid){ var status = Ext.getCmp('in_statuscode'); if(status && status.value != 'ENTERING' && status.value != 'COMMITED'){ Ext.each(grid.columns, function(c){ c.setEditor(null); }); } Ext.defer(function(){ var f = Ext.getCmp('in_id'); if(f && f.value > 0) me.getStepWise(f.value, function(data){ grid.store.each(function(d){ var dets = [], id = d.get('id_id'); if(id && id > 0) { Ext.Array.each(data, function(t){ if(t.idd_idid == id) dets.push(t); }); d.set('dets', dets); } }); }); }, 50); }, itemclick: this.onGridItemClick }, 'gridcolumn[dataIndex=id_purcvendcode]':{ beforerender:function(c){ c.autoEdit=true; } }, 'gridcolumn[dataIndex=id_purcvendname]':{ beforerender:function(c){ c.autoEdit=true; } }, 'gridcolumn[dataIndex=id_purccurrency]':{ beforerender:function(c){ c.autoEdit=true; } }, 'gridcolumn[dataIndex=id_purctaxrate]':{ beforerender:function(c){ c.autoEdit=true; } }, 'gridcolumn[dataIndex=id_purcprice]':{ beforerender:function(c){ c.autoEdit=true; } }, 'gridcolumn[dataIndex=id_remark]':{ beforerender:function(c){ c.autoEdit=true; } }, 'field[name=in_currency]': { beforetrigger: function(field) { var t = field.up('form').down('field[name=in_date]'), value = t.getValue(); if(value) { field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym'); } } }, 'erpSaveButton': { click: function(btn){ var form = me.getForm(btn); if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){ me.BaseUtil.getRandomNumber();//自动添加编号 } var bool = true; //供应商必填 var grid = Ext.getCmp('grid'), start = Ext.getCmp('in_recorddate').value, end = Ext.getCmp('in_enddate').value; if(!Ext.isEmpty(end)){ if(Ext.Date.format(end,'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){ bool=false; showError('有效期小于当前日期,不能保存!');return; } } grid.getStore().each(function(item){ if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){ if(item.data['id_vendcode'] == null || item.data['id_vendcode'] == ''){ bool = false; showError('明细表第' + item.data['id_detno'] + '行的供应商为空');return; } if(item.data['id_myfromdate'] ==null){ item.set('id_myfromdate', start); } if(!Ext.isEmpty(end)){ if(item.data['id_mytodate'] == null){ item.set('id_mytodate', end); } } } }); if(bool){ this.beforeSave(); } } }, 'erpUpdateButton': { click: function(btn){ var bool = true; //供应商必填 var grid = Ext.getCmp('grid'), fromDate = Ext.getCmp('in_recorddate').value, end = Ext.getCmp('in_enddate').value; if(!Ext.isEmpty(end)){ if(Ext.Date.format(end,'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){ bool=false; showError('有效期小于当前日期,不能更新!');return; } } grid.getStore().each(function(item){ if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){ if(item.data['id_vendcode'] == null || item.data['id_vendcode'] == ''){ bool = false; showError('明细表第' + item.data['id_detno'] + '行的供应商为空');return; } if(item.data['id_myfromdate'] ==null ){ item.set('id_myfromdate',fromDate); } if(!Ext.isEmpty(end)){ if(item.data['id_mytodate'] ==null){ item.set('id_mytodate',end); } } } }); if(bool){ this.beforeUpdate(); } } }, 'erpUpdatePurcVendorButton': { afterrender: function(btn){ var status = Ext.getCmp('in_statuscode'); var checkstatus = Ext.getCmp('in_checkstatus').value; if((status && status.value != 'AUDITED')||(checkstatus&&checkstatus=="已批准")){ btn.hide(); } }, click: function(btn){ this.beforeUpdate(); } }, 'erpDeleteButton' : { click: function(btn){ me.FormUtil.onDelete(Ext.getCmp('in_id').value); } }, 'erpAddButton': { click: function(){ me.FormUtil.onAdd('addInquiry', '新增询价单', 'jsps/scm/purchase/inquiry.jsp'); } }, 'erpUpdateMaxlimitInfoButton':{ afterrender:function(btn){ btn.setDisabled(true); }, click: function(btn){ var id=btn.ownerCt.ownerCt.ownerCt.items.items[1].selModel.selected.items[0].data["id_id"]; var idstatus=btn.ownerCt.ownerCt.ownerCt.items.items[1].selModel.selected.items[0].data["id_status"]; if(idstatus!='已报价'){ showError("只能针对已报价的询价做限购"); }else{ var formCondition="id_id IS"+id; var linkCaller='InquiryMaxlimit'; var win = new Ext.window.Window({ id : 'win', height : '90%', width : '95%', maximizable : true, buttonAlign : 'center', layout : 'anchor', items : [ { tag : 'iframe', frame : true, anchor : '100% 100%', layout : 'fit', html : '' } ], listeners:{ 'beforeclose':function(view ,opt){ //grid 刷新一次 var grid=Ext.getCmp('grid'); var gridParam = {caller: caller, condition: gridCondition}; grid.GridUtil.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', gridParam, ""); Ext.getCmp('updateMaxlimitInfo').setDisabled(true); } } }); win.show(); } } }, 'erpCloseButton': { click: function(btn){ me.FormUtil.beforeClose(me); } }, 'erpSubmitButton': { afterrender: function(btn){ var status = Ext.getCmp('in_statuscode'); var checkstatus = Ext.getCmp('in_checkstatuscode').value; if(status && status.value != 'AUDITED'){ btn.hide(); }else if(checkstatus&&checkstatus!=null&&checkstatus!='ENTERING'){ btn.hide(); } }, click: function(btn){ /*var end = Ext.getCmp('in_enddate').value; if(!Ext.isEmpty(end)){ if(Ext.Date.format(end,'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){ bool=false; showError('有效期小于当前日期,不能提交!');return; } }*/ var inclass = Ext.getCmp('in_class'); if(inclass&&inclass.value=='主动报价'){ me.FormUtil.getActiveTab().setLoading(true); Ext.Ajax.request({ url : basePath + 'scm/purchase/submitInquiry.action', params: { id: Ext.getCmp('in_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){ window.location.reload(); } } }); }else{ me.FormUtil.onSubmit(Ext.getCmp('in_id').value); } } }, 'erpResSubmitButton': { afterrender: function(btn){ var status = Ext.getCmp('in_checkstatuscode'); if(status && status.value != 'COMMITED'){ btn.hide(); } }, click: function(btn){ me.FormUtil.onResSubmit(Ext.getCmp('in_id').value); } }, 'erpAuditButton': { afterrender: function(btn){ var status = Ext.getCmp('in_statuscode'); if(status && status.value != 'ENTERING'){ btn.hide(); } }, click: function(btn){ var end = Ext.getCmp('in_enddate').value; if(!Ext.isEmpty(end)){ if(Ext.Date.format(end,'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){ bool=false; showError('有效期小于当前日期,不能审核!');return; } } me.FormUtil.onAudit(Ext.getCmp('in_id').value); } }, 'erpResAuditButton': { afterrender: function(btn){ var status = Ext.getCmp('in_statuscode'); if(status && status.value != 'AUDITED'){ btn.hide(); } }, click: function(btn){ me.FormUtil.onResAudit(Ext.getCmp('in_id').value); } }, 'erpPrintButton': { click: function(btn){ me.FormUtil.onPrint(Ext.getCmp('in_id').value); } }, 'erpAgreePriceButton': { afterrender: function(btn){ var status = Ext.getCmp('in_statuscode'); if(status && status.value != 'AUDITED'){ btn.hide(); } }, click: function(btn){ inid=Ext.getCmp('in_id').value; var url = basePath+'jsps/common/vastDatalist.jsp?_noc=1&whoami=ToPrice&urlcondition=id_inid='+inid+' and nvl(id_price,0)>0'; var main = parent.parent.Ext.getCmp("content-panel"); var panelId='Inquiry' + id; var title='采购询价转核价' + id; if(main){ panelId = panelId == main.getActiveTab().id ? Math.random() : panelId; var panel = Ext.getCmp(panelId); if(!panel){ var value = ""; if (title.toString().length>5) { value = title.toString().substring(0,5); } else { value = title; } if(!contains(url, 'http://', true) && !contains(url, basePath, true)){ url = basePath + url; } panel = { title : value, tag : 'iframe', tabConfig:{tooltip:title}, frame : true, border : false, layout : 'fit', iconCls : 'x-tree-icon-tab-tab', html : '', closable : true }; me.FormUtil.openTab(panel, panelId); } else { main.setActiveTab(panel); } } else { if(!contains(url, basePath, true)){ url = basePath + url; } window.open(url); } //me.FormUtil.onPrint(Ext.getCmp('in_id').value); } }, 'erpTurnPurcPriceButton': { afterrender: function(btn){ var status = Ext.getCmp('in_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 + 'scm/purchase/turnPurcPrice.action', params: { id: Ext.getCmp('in_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/scm/purchase/purchasePrice.jsp?formCondition=pp_id=" + id + "&gridCondition=ppd_ppid=" + id; me.FormUtil.onAdd('PurchasePrice' + id, '物料核价单' + id, url); }); } } }); } }); } }, /** * 查看历史入库价 */ 'button[id=historyin]': { click: function(){ var record = Ext.getCmp('grid').selModel.lastSelected; if(record){ var prod = record.data['id_prodcode']; var win = Ext.getCmp('in-win'); if(win == null){ win = Ext.create('Ext.window.Window', { id: 'in-win', width: '80%', height: '100%', maximizable : true, layout: 'anchor', closeAction: 'hide', items: [Ext.create('erp.view.core.grid.Panel2', { id: 'inhistory', anchor: '100% 100%', caller: 'ProdInOut!In!History', condition: "pd_prodcode='" + prod + "' order by pd_prodmadedate desc", bbar: null })], setMyTitle: function(code){//@param code 料号 this.setTitle('编号:' + code + ' 的历史入库价  ' + '' + ''); }, reload: function(code){//@param code 料号 var g = this.down('grid[id=inhistory]'); g.GridUtil.loadNewStore(g, { caller: g.caller, condition: "pd_prodcode='" + code + "' order by pd_prodmadedate desc" }); this.setMyTitle(code); }, prev: function(){//查看上一条 var item = Ext.getCmp('grid').prev(); if(item != null){ this.reload(item.data['id_prodcode']); } }, next: function(){//查看下一条 var item = Ext.getCmp('grid').next(); if(item != null){ this.reload(item.data['id_prodcode']); } } }); win.setMyTitle(prod); win.show(); } else { win.reload(prod); win.show(); } } else { alert("请先选择明细!"); } } }, /** * 查看历史报价 */ 'button[id=historyquo]': { click: function(){ var record = Ext.getCmp('grid').selModel.lastSelected; if(record){ var prod = record.data['id_prodcode']; var win = Ext.getCmp('history-win'); if(win == null){ win = Ext.create('Ext.window.Window', { id: 'history-win', width: '80%', height: '100%', maximizable : true, layout: 'anchor', closeAction: 'hide', setMyTitle: function(code){//@param code 料号 this.setTitle('编号:' + code + ' 的报价历史  ' + '' + ''); }, reload: function(code){//@param code 料号 var g = this.down('grid[id=history]'); g.GridUtil.loadNewStore(g, { caller: g.caller, condition: "id_prodcode='" + code + "'" }); g = this.down('grid[id=invid]'); g.GridUtil.loadNewStore(g, { caller: g.caller, condition: "ppd_prodcode='" + code + "' AND ppd_statuscode='VALID'" }); this.setMyTitle(code); }, prev: function(){//查看上一条 var item = Ext.getCmp('grid').prev(); if(item != null){ this.reload(item.data['id_prodcode']); } }, next: function(){//查看下一条 var item = Ext.getCmp('grid').next(); if(item != null){ this.reload(item.data['id_prodcode']); } } }); win.setMyTitle(prod); win.show(); win.add(Ext.create('erp.view.core.grid.Panel2', { id: 'history', anchor: '100% 60%', caller: 'Inquiry!History', condition: "id_prodcode='" + prod + "'", bbar: null, listeners: { reconfigure: function(){ win.add(Ext.create('erp.view.core.grid.Panel2', { id: 'invid', title: '现有效价格', anchor: '100% 40%', caller: 'PurchasePrice!Invid', condition: "ppd_prodcode='" + prod + "' AND ppd_statuscode='VALID'", bbar: null })); } } })); } else { win.reload(prod); win.show(); } } else { alert("请先选择明细!"); } } }, /** * 分段询价按钮 */ '#stepWiseInquiry' : { afterrender: function(b) { Ext.defer(function(){ var f = Ext.getCmp('in_statuscode'); if(f && f.value != 'ENTERING') b.hide(); }, 100); }, click: function(b) { var record = b.ownerCt.ownerCt.selModel.lastSelected; if(record) me.onStepWiseClick(record); } }, 'erpCopyButton': { click: function(btn) { me.copy(); } } }); }, onGridItemClick: function(selModel, record){//grid行选择 this.GridUtil.onGridItemClick(selModel, record); var grid=selModel.ownerCt; var show = false; Ext.Array.each(grid.necessaryFields, function(field) { var fieldValue=record.data[field]; if(fieldValue==undefined||fieldValue==""||fieldValue==null){ show = true; return; } }); if(show){ var btn = Ext.getCmp('updateMaxlimitInfo'); btn && btn.setDisabled(true); btn = Ext.getCmp('stepWiseInquiry'); btn && btn.setDisabled(true); btn = Ext.getCmp('historyquo'); btn && btn.setDisabled(true); btn = Ext.getCmp('historyin'); btn && btn.setDisabled(true); } else { var btn = Ext.getCmp('updateMaxlimitInfo'); btn && btn.setDisabled(false); btn = Ext.getCmp('stepWiseInquiry'); btn && btn.setDisabled(false); btn = Ext.getCmp('historyquo'); btn && btn.setDisabled(false); btn = Ext.getCmp('historyin'); btn && btn.setDisabled(false); } }, getForm: function(btn){ return btn.ownerCt.ownerCt; }, /** * 复制 */ copy: function() { var me = this, form = Ext.getCmp('form'); var v = Ext.getCmp('in_id').value; if (v > 0) { form.setLoading(true); Ext.Ajax.request({ url: basePath + 'scm/purchase/copyInquiry.action', params: { caller: caller, id: v }, callback: function(opt, s, r) { form.setLoading(false); var res = Ext.decode(r.responseText); if (res.data) { var url = 'jsps/scm/purchase/inquiry.jsp?formCondition=in_idIS' + res.data.id + '&gridCondition=id_inidIS' + res.data.id; showMessage('提示', '复制成功', 2000); me.FormUtil.onAdd(null, '询价单', url); } else { showError(res.exceptionInfo); } } }); } }, /** * 分段询价 */ onStepWiseClick: function(record) { var fields = this.getStepFields(record.get('dets')), me = this; Ext.create('Ext.window.Window', { autoShow: true, title: '分段询价', width: 300, height: 400, layout: 'anchor', items: [{ anchor: '100% 100%', xtype: 'form', items: fields, bodyStyle: 'background: #f1f2f5;', defaults: { margin: '5' } }], buttonAlign: 'center', buttons: [{ text: '确定', handler: function(b) { me.onStepConfirm(record, b.ownerCt.ownerCt.down('form'), function(){ b.ownerCt.ownerCt.close(); }); } }, { text: '取消', handler: function(b) { b.ownerCt.ownerCt.close(); } }] }); }, getStepFields: function(dets) { if(!dets || dets.length == 0) dets = [{idd_lapqty: 0},{},{},{},{}]; var fields = [], me = this; Ext.Array.each(dets, function(d){ fields.push({ xtype: 'numberfield', fieldLabel: '数量 ≥ ', labelWidth: 60, hideTrigger: true, name: 'idd_lapqty', value: d.idd_lapqty, dataId: d.idd_id, editable: (d.idd_lapqty == null || d.idd_lapqty > 0), flex: 1 }); }); fields.push({ xtype: 'button', iconCls: 'x-button-icon-add', handler: function(b) { me.onStepAdd(b.ownerCt); } }); return fields; }, onStepAdd: function(form) { var fields = form.items.items; if(fields.length > 11){ showError('最多支持10个分段!'); } else { form.insert(fields.length - 1, { xtype: 'numberfield', fieldLabel: '数量 ≥ ', labelWidth: 60, hideTrigger: true, name: 'idd_lapqty', flex: 1 }); } }, onStepConfirm: function(record, form, callback) { var dets = [], steps = [], err = []; form.getForm().getFields().each(function(field){ if('idd_lapqty' == field.name && field.value != null) { dets.push({idd_lapqty: field.value, idd_id: field.dataId}); if(steps.indexOf(field.value) == -1) steps.push(field.value); else err.push('数量:' + field.value); } }); if(err.length > 0) { showError('分段数量填写重复!
' + err.join('
')); return; } Ext.Array.sort(dets, function(a, b){ return a.idd_lapqty > b.idd_lapqty; }); record.set('dets', dets); record.dirty = true; record.modified = record.modified || {}; record.modified['id_lapqty'] = true; callback.call(null); }, beforeSave: function(){ var me = this; var form = Ext.getCmp('form'), id = Ext.getCmp(form.keyField).value; if(! me.FormUtil.checkForm()){ return; } if(Ext.isEmpty(id) || id == 0 || id == '0'){ me.FormUtil.getSeqId(form); } var detail = Ext.getCmp('grid'); var dets = []; detail.store.each(function(record, i){ if(!me.GridUtil.isBlank(detail, record.data)) { if(record.get('id_id') == null || record.get('id_id') == 0){ record.set('id_id', -1 * i); } var s = record.get('dets') || []; Ext.Array.each(s, function(t, i){ t.idd_id = t.idd_id || 0; t.idd_idid = String(record.get('id_id')); dets.push(t); }); } }); me.FormUtil.beforeSave(me, Ext.encode(dets)); }, beforeUpdate: function(){ var me = this; var form = Ext.getCmp('form'); if(! me.FormUtil.checkForm()){ return; } var detail = Ext.getCmp('grid'); var dets = []; detail.store.each(function(record, i){ if(!me.GridUtil.isBlank(detail, record.data)) { if(record.get('id_id') == null || record.get('id_id') == 0){ record.set('id_id', -1 * i); } var s = record.get('dets') || []; Ext.Array.each(s, function(t, i){ t.idd_id = t.idd_id || 0; t.idd_idid = String(record.get('id_id')); dets.push(t); }); } }); me.FormUtil.onUpdate(me, false, null, Ext.encode(dets)); }, getStepWise: function(in_id, callback) { Ext.Ajax.request({ url: basePath + 'scm/purchase/inquiry/det.action', params: { in_id: in_id }, callback: function(opt, s, r) { if(s) { var rs = Ext.decode(r.responseText); callback.call(null, rs); } } }); }, updateInfo:function(purpose, remark, id){ Ext.Ajax.request({ url : basePath + 'scm/purchase/inquiry/updateInfo.action', params: { purpose: purpose, remark: remark, id: id, caller: caller }, method : 'post', async:false, callback : function(options,success,response){ var res = new Ext.decode(response.responseText); if(res.exceptionInfo != null){ showError(res.exceptionInfo);return; } showMessage("提示", '更新成功!'); window.location.reload(); } }); } });