Ext.QuickTips.init(); Ext.define('erp.controller.pm.make.MakeMaterialScrap', { extend: 'Ext.app.Controller', requires: ['erp.util.RenderUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil'], views:[ 'pm.make.MakeMaterialScrap', 'core.grid.Panel5', 'common.editorColumn.GridPanel', 'core.grid.YnColumn', 'core.button.CreateDetail', 'core.button.PrintDetail', 'core.trigger.DbfindTrigger' ], init:function(){ var me = this; me.GridUtil = Ext.create('erp.util.GridUtil'); me.BaseUtil = Ext.create('erp.util.BaseUtil'); this.control({ 'button[id=retreat]': { click: function(btn){ var grid = Ext.getCmp('editorColumnGridPanel'); var e = me.checkQty(Ext.getCmp('grid'), grid); if(e.length > 0) { showError(e);return; } e = me.check(grid.selModel.getSelection()); if(e.length > 0) { showError(e);return; } warnMsg("确定要生成报废单吗?", function(btn){ if(btn == 'yes'){ me.turnOut(grid); } }); } }, 'button[name=query]': { click: function(btn){ me.onQuery(); } }, 'checkbox[id=whcode]' : { afterrender : function(f) { me.BaseUtil.getSetting('MakeMaterial!Scrap', 'GroupWarehouse', function(bool) { f.setValue(bool); }); } }, 'combo[id=groupPurs]': { beforerender: function(f) { me.BaseUtil.getSetting('MakeMaterial!Scrap', 'isGroupPurc', function(v) { if(v){ f.show(); } }); } }, 'erpEditorColumnGridPanel':{ storeloaded:function(grid){ //zhouy 没有找到更好的解决 锁定列与normalview对不齐的方式 暂时这样处理 Ext.defer(function(){ var lockedView = grid.view.lockedView; if(lockedView){ var tableEl = lockedView.el.child('.x-grid-table'); if(tableEl){ tableEl.dom.style.marginBottom = '7px'; } } //lockedView.doLayout(); }, 100); } }, 'dbfindtrigger[name=ma_code]':{ aftertrigger:function(){ var record = Ext.getCmp('grid').selModel.getLastSelected(); record.set('ma_thisqty',0); } } }); }, turnOut: function(grid) { var me = this, material = this.getEffectData(grid.selModel.getSelection()); if(material.length > 0){ grid.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + 'pm/make/turnScrap.action', params: { data: Ext.encode(material), caller: caller, type: 'MAKE' }, method : 'post', callback : function(options,success,response){ grid.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); } if(localJson.log){ showMessage('提示', localJson.log); } if(localJson.success){ turnSuccess(function(){ grid.multiselected = new Array(); }); } me.onQuery(); } }); } }, /** * 筛选 */ onQuery: function(){ var grid = Ext.getCmp('grid'); //计算thisqty this.calOnlineQty(grid); //Query var condition = null,dirtyrecords=new Array(); Ext.each(grid.store.data.items,function(item) { if (item.data['ma_code'] != null && item.data['ma_code'] != '') { if (item.data['ma_id']==null || item.data['ma_id']==''){ showError('制造单号'+item.data['ma_code']+'必须从放大镜选择'); }else{ if (condition == null) { condition = "(mm_code='" + item.data['ma_code'] + "'"; } else { condition += " OR mm_code='" + item.data['ma_code'] + "'"; } } }else if(item.dirty){ dirtyrecords.push(item); } }); if(condition == null){ condition = " 1=2 ";//未录入有效工单,则不筛选任何数据 }else{ condition += ")"; } if(Ext.getCmp('groupPurs')){ var grouppurs = Ext.getCmp('groupPurs'); if(grouppurs && grouppurs.value != ''){ condition += " and "+ grouppurs.value ; } } if(dirtyrecords.length>0) grid.store.remove(dirtyrecords); if(condition != null){ grid.busy = true; grid.multiselected = new Array(); var dg = Ext.getCmp('editorColumnGridPanel'); dg.busy = true; condition += " AND (nvl(mm_materialstatus,' ')=' ') AND (mm_thisqty > 0)"; dg.getGridColumnsAndStore(condition + ' order by mm_maid,mm_detno'); this.showReplace(condition, dg); setTimeout(function(){ dg.busy = false; grid.busy = false; }, 1000); } }, /** * 更新工单用料在线结存数量 **/ calOnlineQty: function(grid){ var items = grid.store.data.items, idx = new Array(); Ext.each(items, function(item){ if(item.data['ma_code'] != null && item.data['ma_code'] != ''){ idx.push(item.data['ma_id']); if (item.data['ma_id']==null || item.data['ma_id']==''){ showError('制造单号'+item.data['ma_code']+'必须从放大镜选择'); return; } } }); if(idx.length > 0) { Ext.Ajax.request({ url : basePath + 'pm/make/calOnlineQty.action', async: false, params: { ids: Ext.Array.concate(idx, ',') }, callback: function(opt, s, r){ var res = Ext.decode(r.responseText); if(res.exceptionInfo) { showError(res.exceptionInfo); } } }); } }, /** * 替代料 */ showReplace: function(condition, grid){ condition += " and (mp_thisqty>0 and mp_haverepqty-NVL(mp_scrapqty,0)>0 )"; Ext.Ajax.request({ url : basePath + 'common/getFieldsDatas.action', params: { caller: 'MakeMaterialReplace left join MakeMaterial on mm_id=mp_mmid left join Product on mp_prodcode=pr_code' + ' left join WareHouse on wh_code=mp_whcode', fields: 'mp_mmid,mp_detno,mp_thisqty,mp_canuseqty,mp_repqty,mp_scrapqty,mp_turnscrapqty,mp_haverepqty,mp_addqty,mm_onlineqty,mp_remark,mp_prodcode,pr_detail,pr_spec,pr_unit,wh_code', condition: condition }, async: false, method : 'post', callback : function(options,success,response){ var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo);return; } if(localJson.success){ var data = Ext.decode(localJson.data); if(data && data.length > 0) { var idx, store = grid.store, record; grid.lockrender = true; Ext.each(data, function(d){ idx = store.find('mm_id', d.MP_MMID); record = store.getAt(idx); if(idx != null && idx >= 0) { store.insert(idx + 1, { mm_prodcode: d.MP_PRODCODE, mm_oneuseqty: record.data.mm_oneuseqty, mm_code: record.data.mm_code, pr_detail: d.PR_DETAIL, pr_spec: d.PR_SPEC, pr_unit: d.PR_UNIT, mm_canuserepqty: d.MP_CANUSEQTY, mm_thisqty: d.MP_THISQTY, mm_totaluseqty: d.MP_REPQTY, mm_scrapqty: d.MP_SCRAPQTY, mm_turnscrapqty: d.MP_TURNSCRAPQTY, mm_ifrep: 1, mm_remark: d.MP_REMARK, mm_whcode: d.WH_CODE, mm_detno: d.MP_DETNO, mm_id: d.MP_MMID, isrep: true, mm_havegetqty:d.MP_HAVEREPQTY, mm_onlineqty:d.MM_ONLINEQTY, mm_addqty: d.MP_ADDQTY, }); } }); grid.lockrender = false; } grid.store.fireEvent('load', grid.store); grid.fireEvent('storeloaded', grid); } } }); }, /** * 转报废前,校验报废套数与报废数 */ checkQty: function(a, b){ var c = this.getMixedGroups(b.selModel.getSelection(), ['mm_code', 'mm_id']), code,count,q = 0,m = 0,err = '',backqty=0; a.store.each(function(d){ code = d.get('ma_code'); if(!Ext.isEmpty(code)) { Ext.Array.each(c, function(i) { if(i.keys.mm_code == code) { count = 0; m = 0; backqty=0; Ext.Array.each(i.groups, function(j){ if(m == 0) detno = j.get('mm_detno'); m = j.get('mm_oneuseqty'); r = j.get('mm_onlineqty'); backqty = j.get('mm_backqty'); count += j.get('mm_thisqty'); }); if(r-backqty < count ) { err += '\n报废数大于结存数,序号[' + detno + ']'; } } }); } }); return err; }, getMixedGroups: function(items, fields) { var data = new Object(),k,o; Ext.Array.each(items, function(d){ k = ''; o = new Object(); Ext.each(fields, function(f){ k += f + ':' + d.get(f) + ','; o[f] = d.get(f); }); if(k.length > 0) { if(!data[k]) { data[k] = {keys: o, groups: [d]}; } else { data[k].groups.push(d); } } }); return Ext.Object.getValues(data); }, check: function(items) { var e = ''; Ext.Array.each(items, function(item){ if (item.get('mm_ifrep')==1){//替代料本次退料不能大于已领料数-报废数 if(item.get('mm_thisqty') > item.get('mm_havegetqty') - item.get('mm_scrapqty') ) { e += '\n工单[' + item.get('mm_code') + '],替代料[' + item.get('mm_prodcode') + ']本次数大于已领料数-已报废数'; } }else{ if(item.get('mm_thisqty') > item.get('mm_havegetqty') - item.get('mm_haverepqty') ) { e += '\n工单[' + item.get('mm_code') + '],行号[' + item.get('mm_detno') + ']本次数大于主料已领料数'; } } if(Ext.isEmpty(item.get('mm_thisqty')) || item.get('mm_thisqty') == 0) { e += '\n工单[' + item.get('mm_code') + '],行号[' + item.get('mm_detno') + ']报废数未填写或者为0'; } }); return e; }, getEffectData: function(items) { var d = new Array(); Ext.Array.each(items, function(item){ d.push({ mm_detno: item.get('mm_detno'), mm_code: item.get('mm_code'), mm_id: item.get('isrep') == null ? item.get('mm_id') : -item.get('mm_id'), mm_thisqty: item.get('mm_thisqty'), mm_whcode: item.get('mm_whcode') }); }); return d; } });