| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611 |
- Ext.QuickTips.init();
- Ext.define('erp.controller.pm.make.MakeMaterialIssue', {
- extend: 'Ext.app.Controller',
- requires: ['erp.util.RenderUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil'],
- views: ['pm.make.MakeMaterialIssue', '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=create]': {
- 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[id=createbc]': {
- 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.turnProdIOBC(grid);
- }
- });
- },
- beforerender:function(btn){
- me.BaseUtil.getSetting('MakeMaterial!issue', 'ifShowTurnOutButton', function(v) {
- if(v){
- btn.show();
- }
- });
- }
- },
- 'button[name=query]': {
- click: function(btn) {
- me.onQuery();
- }
- },
- 'checkbox[id=whcode]': {
- afterrender: function(f) {
- me.BaseUtil.getSetting('MakeMaterial!issue', 'groupWarehouse', function(v) {
- f.setValue(v);
- });
- }
- },
- 'checkbox[id=set]': {
- afterrender: function(f) {
- me.BaseUtil.getSetting('MakeMaterial!issue', 'setOfMaterial', function(v) {
- f.setValue(v);
- });
- me.BaseUtil.getSetting('MakeMaterial!issue', 'ifCanrepqty', function(v) {
- ifCanrepqty = v;
- });
- me.BaseUtil.getSetting('MakeMaterial!issue', 'includingLoss', function(v) {//套料数发料是否包含损耗
- ifIncludingLoss = v;
- });
- }
- },
- 'checkbox[id=ifnullwhman]': {
- afterrender: function(f) {
- me.BaseUtil.getSetting('MakeMaterial!issue', 'ifnullwhman', function(v) {
- f.setValue(v);
- });
- }
- },
- 'checkbox[id=ifnulllocation]': {
- afterrender: function(f) {
- me.BaseUtil.getSetting('MakeMaterial!issue', 'ifnulllocation', function(v) {
- f.setValue(v);
- });
- }
- },
- 'dbfindtrigger[id=st_code]':{
- beforerender: function(f) {
- me.BaseUtil.getSetting('MakeMaterial!issue', 'supportStepFilter', function(v) {
- if(v){
- f.show();
- }
- });
- }
- },
- 'textfield[id=pr_location]': {
- specialkey: function(field, e) {
- if (e.getKey() == Ext.EventObject.ENTER) {
- me.onQuery();
- }
- }
- },
- 'textfield[id=ma_wccode]': {
- specialkey: function(field, e) {
- if (e.getKey() == Ext.EventObject.ENTER) {
- me.onQuery();
- }
- }
- },
- 'combo[id=groupPurs]': {
- beforerender: function(f) {
- me.BaseUtil.getSetting('MakeMaterial!issue', '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);
- }
- }
- });
- },
- 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/turnOut.action',
- params: {
- data: Ext.encode(material),
- wh: Ext.getCmp('whcode').checked,
- whman: Ext.getCmp('pr_whmancode').value,
- 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.indexOf("转入成功") > -1){
- showMessage('提示', localJson.log);
- me.onQuery();
- if (localJson.success) {
- turnSuccess(function() {
- grid.selModel.deselectAll(true);
- grid.multiselected = new Array();
- });
- }
- }else{
- showError(localJson.log);
- }
- }
- });
- }
- },
- turnProdIOBC: function(grid) {
- var me = this,
- material = this.getEffectData(grid.selModel.getSelection());
- if (material.length > 0) {
- Ext.create('Ext.window.Window', {
- width: 350,
- height: 185,
- id: 'win',
- title: '<h1>生成拨出单</h1>',
- layout: 'column',
- items: [{
- margin: '10 0 0 0',
- xtype: 'dbfindtrigger',
- fieldLabel: '拨入仓库编号',
- name: 'wh_code',
- value: '',
- listeners: {
- aftertrigger: function(t, d) {
- t.ownerCt.down('textfield[name=wh_code]').setValue(d.get('wh_code'));
- t.ownerCt.down('textfield[name=inwhname]').setValue(d.get('wh_description'));
- }
- }
- },
- {
- margin: '3 0 0 0',
- xtype: 'textfield',
- fieldLabel: '拨入仓库名称',
- readOnly: true,
- name: 'inwhname',
- value: ''
- }],
- buttonAlign: 'center',
- buttons: [{
- xtype: 'button',
- columnWidth: 0.12,
- text: '确定',
- width: 60,
- iconCls: 'x-button-icon-save',
- handler: function(btn) {
- var inwhcode = btn.ownerCt.ownerCt.down('dbfindtrigger[name=wh_code]').value;
- if (!inwhcode) {
- showError('请先填写拨入的仓库编号!');
- return;
- } else {
- grid.setLoading(true); //loading...
- Ext.Ajax.request({
- url: basePath + 'pm/make/turnProdIOBC.action',
- params: {
- data: Ext.encode(material),
- inwhcode: inwhcode,
- whmancode: Ext.getCmp('pr_whmancode').value
- },
- 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);
- return;
- }
- if (localJson.success) {
- turnSuccess(function() {
- grid.selModel.deselectAll(true);
- grid.multiselected = new Array();
- });
- }
- Ext.getCmp('win').close();
- me.onQuery();
- }
- });
- }
- }
- },
- {
- xtype: 'button',
- columnWidth: 0.1,
- text: '取消',
- width: 60,
- iconCls: 'x-button-icon-close',
- margin: '0 0 0 10',
- handler: function(btn) {
- Ext.getCmp('win').close();
- }
- }]
- }).show();
- }
- },
- /**
- * 筛选
- */
- onQuery: function() {
- var me = this, grid = Ext.getCmp('grid');
- var c = this.getMixedGroups(grid.getStore().data.items, ['ma_code','ma_id']);
- if(grid.getStore().getCount() != 0 && (c.length != grid.getStore().getCount())){
- showError('筛选的单据编号重复');
- return ;
- }
-
- grid.selModel.deselectAll(true);
- grid.multiselected = new Array();
- //计算thisqty
- var bool = this.calThisQty(grid);
- if (!bool) return;
- //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(dirtyrecords.length>0) grid.store.remove(dirtyrecords);
- if (Ext.getCmp('pr_whmancode')) {
- var whmancode = Ext.getCmp('pr_whmancode');
- if (whmancode && whmancode.value != '') {
- if (Ext.getCmp('ifnullwhman').checked) {
- condition += "and (pr_whmancode='" + whmancode.value + "' or NVL(pr_whmancode,' ')=' ')";
- } else {
- condition += "and pr_whmancode='" + whmancode.value + "'";
- }
- }
- }
- if (Ext.getCmp('pr_location')) {
- var location = Ext.getCmp('pr_location');
- if (location && location.value != '') {
- if (Ext.getCmp('ifnulllocation').checked) {
- condition += "and (pr_location like '%" + location.value + "%' or NVL(pr_location,' ')=' ')";
- } else {
- condition += "and pr_location like '%" + location.value + "%'";
- }
- }
- }
- if (Ext.getCmp('wccode')) {
- var wccode = Ext.getCmp('wccode');
- if (wccode && wccode.value != '') {
- condition += " and mm_wccode like '%" + wccode.value + "%' ";
- }
- }
- if(Ext.getCmp('groupPurs')){
- var grouppurs = Ext.getCmp('groupPurs');
- if(grouppurs && grouppurs.value != ''){
- condition += " and "+ grouppurs.value;
- }
- }
- if(Ext.getCmp('st_code')){
- var stepcode = Ext.getCmp('st_code');
- if(stepcode && stepcode.value != ''){
- condition += " and mm_stepcode like '%"+ stepcode.value+"%' " ;
- }
- }
- if (condition != null) {
- grid.busy = true;
- var dg = Ext.getCmp('editorColumnGridPanel');
- dg.busy = true;
- condition += " AND (nvl(mm_materialstatus,' ')=' ') AND (mm_qty-(nvl(mm_havegetqty,0)+nvl(mm_returnmqty,0)-nvl(mm_addqty,0)) > 0)";
- var urlcondition = getUrlParam('urlcondition');
- condition = urlcondition != null ? condition + " and " + urlcondition: condition;
- this.BaseUtil.getSetting('MakeMaterial!issue', 'ifDisplayPull', function(val){
- if(!val){
- condition=condition+" and NVL(pr_supplytype,' ')<>'PULL' ";
- }
- dg.getGridColumnsAndStore(condition + ' order by mm_maid,mm_detno');
- me.showReplace(condition, dg);
- setTimeout(function() {
- dg.busy = false;
- grid.busy = false;
- },
- 1000);
- });
- }
- },
- /**
- * 计算可领料数
- **/
- calThisQty: 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']);
- }
- });
- var bool = true;
- if (idx.length > 0) {
- Ext.Ajax.request({
- url: basePath + 'pm/make/calThisQty.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);
- bool = false;
- }
- }
- });
- }
- return bool;
- },
- /**
- * 替代料
- */
- showReplace: function(condition, grid) {
- 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 productwh on pw_whcode=mp_whcode and pw_prodcode=mp_prodcode',
- fields: 'mp_mmid,mp_detno,mp_thisqty,mp_canuseqty,mp_repqty,mp_haverepqty,mp_addqty,mp_returnmqty,mp_remark,mp_prodcode,pr_detail,pr_spec,pr_unit,pr_location,mp_whcode,pw_onhand',
- condition: condition + ' and (mp_thisqty > 0 or mm_thisqty>0)'
- },
- 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) {
- if(ifCanrepqty){//如果参数设置为不考虑可替代数
- 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_qty: record.data.mm_qty,
- mm_thisqty: record.data.mm_thisqty,
- mm_totaluseqty: record.data.mm_totaluseqty,
- mm_havegetqty: record.data.mm_haverepqty,
- mm_returnmqty: record.data.mm_returnmqty,
- mm_addqty: record.data.mm_addqty,
- mm_repqty:record.data.mm_repqty,
- mm_ifrep: 1,
- mm_remark: d.MP_REMARK,
- mm_whcode: d.MP_WHCODE,
- mm_detno: d.MP_DETNO,
- mm_id: d.MP_MMID,
- isrep: true,
- pr_location: d.PR_LOCATION,
- pw_onhand:d.PW_ONHAND
- });
- }else{
- 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_qty: d.MP_CANUSEQTY,
- mm_thisqty: d.MP_THISQTY,
- mm_totaluseqty: d.MP_REPQTY,
- mm_havegetqty: d.MP_HAVEREPQTY,
- mm_returnmqty: d.MP_RETURNMQTY,
- mm_addqty: d.MP_ADDQTY,
- mm_ifrep: 1,
- mm_remark: d.MP_REMARK,
- mm_whcode: d.MP_WHCODE,
- mm_detno: d.MP_DETNO,
- mm_id: d.MP_MMID,
- isrep: true,
- pr_location: d.PR_LOCATION,
- pw_onhand:d.PW_ONHAND
- });
- }
- }
- });
- grid.lockrender = false;
- }
- grid.store.fireEvent('load', grid.store);
- grid.fireEvent('storeloaded', grid);
- }
- }
- });
- },
- /**
- * 转领料前,校验发料套数与领料数
- */
- checkQty: function(a, b) {
- var err='' ;
- var c = this.getMixedGroups(b.selModel.getSelection(), ['mm_code', 'mm_id']);
- /*//判断主料加替代料的和不能超过可领料数量
- Ext.Array.each(c,function(i) {
- var mainqty =0 ,totalqty = 0,detno;
- Ext.Array.each(i.groups,function(j) {
- if(!j.get('isrep')){//主料
- mainqty = j.get('mm_qty') - (j.get('mm_havegetqty') - j.get('mm_addqty') + j.get('mm_returnmqty') ) - j.get('mm_totaluseqty');
- }
- //计算该mm_id 领料之和
- totalqty +=j.get('mm_thisqty');
- detno = j.get('mm_detno');
- });
- if(totalqty > mainqty){
- err += "工单号["+i.keys.mm_code+"]序号["+detno+"]本次领料数超过可领数("+mainqty+")\n";
- }
- });*/
- if ((!Ext.getCmp('set').value && err == '') || (Ext.getCmp('set').value && ifIncludingLoss && err == '')) {
- return '';
- }else if(!Ext.getCmp('set').value && err != ''){
- return err;
- }
- var code,
- count,
- q = 0,
- m = 0;
- a.store.each(function(d) {
- code = d.get('ma_code');
- if (!Ext.isEmpty(code)) {
- q = d.get('ma_thisqty');
- Ext.Array.each(c,
- function(i) {
- if (i.keys.mm_code == code) {
- count = 0;
- m = 0;
- Ext.Array.each(i.groups,
- function(j) {
- if (m == 0) m = j.get('mm_oneuseqty');
- count += j.get('mm_thisqty');
- });
- if (Math.round(count - Number(q * m), 5) > 0.0001) {
- err += '领料数超出发料套数,工单号[' + code + ']';
- }
- }
- });
- }
- });
- //判断主料加替代料总数是否
- 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) {
- if(d.get(f) != " " && d.get(f) != 0){
- 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 (Ext.isEmpty(item.get('mm_whcode'))) {
- e += '\n工单[' + item.get('mm_code') + '],行号[' + item.get('mm_detno') + ']仓库为空';
- }
- if (Ext.isEmpty(item.get('mm_thisqty'))) {
- e += '\n工单[' + item.get('mm_code') + '],行号[' + item.get('mm_detno') + ']领料数为空';
- }
- });
- return e;
- },
- getEffectData: function(items) {
- var d = new Array();
- Ext.Array.each(items,
- function(item) {
- if (item.get('mm_thisqty') == 0) {
- showError('本次数量不允许为0!');
- return [];
- }
- 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'),
- mm_prodcode: item.get('mm_prodcode')
- });
- });
- return d;
- }
- });
|