| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- Ext.QuickTips.init();
- Ext.define('erp.controller.pm.outsource.MakeMaterialGive', {
- extend: 'Ext.app.Controller',
- requires: ['erp.util.RenderUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil'],
- views:[
- 'pm.outsource.MakeMaterialGive', '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){
- warnMsg("确定要生成补料单吗?", function(btn){
- if(btn == 'yes'){
- var grid = Ext.getCmp('editorColumnGridPanel');
- var material = grid.getEffectData();
- if(material != null){
- grid.setLoading(true);//loading...
- Ext.Ajax.request({
- url : basePath + 'pm/make/turnAdd.action',
- params: {
- data: Ext.encode(material),
- wh: Ext.getCmp('whcode').checked,
- caller: caller,
- type: 'OS'
- },
- 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();
- });
- }
- }
- });
- }
- }
- });
- }
- },
- 'button[name=query]': {
- click: function(btn){
- var grid = Ext.getCmp('grid');
- //计算thisqty
- this.calAddQty(grid);
- //Query
- var condition = null;
- Ext.each(grid.store.data.items, function(item){
- if(item.data['ma_code'] != null && item.data['ma_code'] != ''){
- if(condition == null){
- condition = "(mm_code='" + item.data['ma_code'] + "'";
- } else {
- condition += " OR mm_code='" + item.data['ma_code'] + "'";
- }
- }
- });
- 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(condition != null){
- grid.multiselected = new Array();
- grid.busy = true;
- 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);
- }
- }
- },
- 'checkbox[id=whcode]' : {
- afterrender : function(f) {
- me.getSetting(f);
- }
- },
- 'erpEditorColumnGridPanel' : {
- afterlayout: function(grid) {
- grid.store.on('load', function(store){
- me.getProductWh(grid);
- });
- }
- }
- });
- },
- /**
- * 计算可补料数
- **/
- calAddQty: 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(idx.length > 0) {
- Ext.Ajax.request({
- url : basePath + 'pm/make/calAddQty.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){
- 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 make on ma_id=mm_maid' +
- ' left join WareHouse on wh_id=mp_warehouseid',
- fields: 'mp_mmid,mp_detno,mm_thisqty as mp_thisqty,mp_canuseqty,mp_repqty,mp_remark,mp_prodcode,pr_detail,pr_spec,pr_unit,pr_location,wh_code,ma_vendcode',
- condition: condition + ' and ( 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) {
- 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_ifrep: 1,
- mm_remark: d.MP_REMARK,
- mm_whcode: d.WH_CODE,
- mm_detno: d.MP_DETNO,
- mm_id: d.MP_MMID,
- isrep: true,
- pr_location:d.PR_LOCATION,
- ma_vendcode: d.MA_VENDCODE
-
- });
- }
- });
- grid.lockrender = false;
- }
- grid.store.fireEvent('load', grid.store);
- }
- }
- });
- },
- getProductWh: function(grid) {
- var codes = [];
- grid.store.each(function(d){
- codes.push("'" + d.get('mm_prodcode') + "'");
- });
- Ext.Ajax.request({
- url: basePath + 'scm/product/getProductwh.action',
- params: {
- codes: codes.join(',')
- },
- callback: function (opt, s, r) {
- if(s) {
- var rs = Ext.decode(r.responseText);
- if(rs.data) {
- grid.productwh = rs.data;
- }
- }
- }
- });
- },
- getSetting : function(f) {
- Ext.Ajax.request({
- url : basePath + 'common/getFieldData.action',
- async: false,
- params: {
- caller: 'Setting',
- field: 'se_value',
- condition: 'se_what=\'GroupWarehouse.OS\''
- },
- method : 'post',
- callback : function(opt, s, res){
- var r = new Ext.decode(res.responseText);
- if(r.exceptionInfo){
- showError(r.exceptionInfo);return;
- }
- if(r.success && r.data){
- if (r.data == 'false') {
- f.setValue(false);
- }
- }
- }
- });
- }
- });
|