MakeMaterialIssue.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.make.MakeMaterialIssue', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.RenderUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil'],
  5. views:[
  6. 'pm.make.MakeMaterialIssue', 'core.grid.Panel5', 'common.editorColumn.GridPanel', 'core.grid.YnColumn',
  7. 'core.button.CreateDetail', 'core.button.PrintDetail', 'core.trigger.DbfindTrigger'
  8. ],
  9. init:function(){
  10. var me = this;
  11. me.GridUtil = Ext.create('erp.util.GridUtil');
  12. me.BaseUtil = Ext.create('erp.util.BaseUtil');
  13. this.control({
  14. 'button[id=create]': {
  15. click: function(btn){
  16. var grid = Ext.getCmp('editorColumnGridPanel');
  17. var e = me.checkQty(Ext.getCmp('grid'), grid);
  18. if(e.length > 0) {
  19. showError(e);return;
  20. }
  21. e = me.check(grid.selModel.getSelection());
  22. if(e.length > 0) {
  23. showError(e);return;
  24. }
  25. warnMsg("确定要生成领料单吗?", function(btn){
  26. if(btn == 'yes'){
  27. me.turnOut(grid);
  28. }
  29. });
  30. }
  31. },
  32. 'button[id=createbc]': {
  33. click: function(btn){
  34. var grid = Ext.getCmp('editorColumnGridPanel');
  35. var e = me.checkQty(Ext.getCmp('grid'), grid);
  36. if(e.length > 0) {
  37. showError(e);return;
  38. }
  39. e = me.check(grid.selModel.getSelection());
  40. if(e.length > 0) {
  41. showError(e);return;
  42. }
  43. warnMsg("确定要生成拨出单吗?", function(btn){
  44. if(btn == 'yes'){
  45. me.turnProdIOBC(grid);
  46. }
  47. });
  48. }
  49. },
  50. 'button[name=query]': {
  51. click: function(btn){
  52. me.onQuery();
  53. }
  54. },
  55. 'erpEditorColumnGridPanel' : {
  56. afterlayout: function(grid) {
  57. grid.store.on('load', function(store){
  58. me.getProductWh(grid);
  59. });
  60. }
  61. },
  62. 'checkbox[id=whcode]' : {
  63. afterrender : function(f) {
  64. me.getSetting(f, 'GroupWarehouse');
  65. }
  66. },
  67. 'checkbox[id=set]' : {
  68. afterrender : function(f) {
  69. me.getSetting(f, 'SetOfMaterial');
  70. }
  71. },
  72. 'textfield[id=pr_location]':{
  73. specialkey:function(field,e){
  74. if (e.getKey()==Ext.EventObject.ENTER){
  75. me.onQuery();
  76. }
  77. }
  78. }
  79. });
  80. },
  81. turnOut: function(grid) {
  82. var me = this,
  83. material = this.getEffectData(grid.selModel.getSelection());
  84. if(material.length > 0){
  85. grid.setLoading(true);//loading...
  86. Ext.Ajax.request({
  87. url : basePath + 'pm/make/turnOut.action',
  88. params: {
  89. data: Ext.encode(material),
  90. wh: Ext.getCmp('whcode').checked,
  91. whman: Ext.getCmp('pr_whmancode').value,
  92. caller: caller,
  93. type: 'MAKE'
  94. },
  95. method : 'post',
  96. callback : function(options,success,response){
  97. grid.setLoading(false);
  98. var localJson = new Ext.decode(response.responseText);
  99. if(localJson.exceptionInfo){
  100. showError(localJson.exceptionInfo);
  101. }
  102. if(localJson.log){
  103. showMessage('提示', localJson.log);
  104. }
  105. if(localJson.success){
  106. turnSuccess(function(){
  107. grid.selModel.deselectAll(true);
  108. grid.multiselected = new Array();
  109. });
  110. }
  111. me.onQuery();
  112. }
  113. });
  114. }
  115. },
  116. turnProdIOBC: function(grid) {
  117. var me = this,
  118. material = this.getEffectData(grid.selModel.getSelection());
  119. if(material.length > 0){
  120. Ext.create('Ext.window.Window',{
  121. width:350,
  122. height:185,
  123. id:'win',
  124. title:'<h1>生成拨出单</h1>',
  125. layout:'column',
  126. items:[{
  127. margin: '10 0 0 0',
  128. xtype: 'dbfindtrigger',
  129. fieldLabel: '拨入仓库编号',
  130. name:'wh_code',
  131. value: '',
  132. listeners:{
  133. aftertrigger:function(t, d){
  134. t.ownerCt.down('textfield[name=wh_code]').setValue(d.get('wh_code'));
  135. t.ownerCt.down('textfield[name=inwhname]').setValue(d.get('wh_description'));
  136. }
  137. }
  138. },{
  139. margin: '3 0 0 0',
  140. xtype: 'textfield',
  141. fieldLabel: '拨入仓库名称',
  142. readOnly:true,
  143. name:'inwhname',
  144. value: ''
  145. }],
  146. buttonAlign:'center',
  147. buttons:[{
  148. xtype:'button',
  149. columnWidth:0.12,
  150. text:'确定',
  151. width:60,
  152. iconCls: 'x-button-icon-save',
  153. handler:function(btn){
  154. var inwhcode=btn.ownerCt.ownerCt.down('dbfindtrigger[name=wh_code]').value;
  155. if(!inwhcode){
  156. showError('请先填写拨入的仓库编号!') ;
  157. return;
  158. }else{
  159. grid.setLoading(true);//loading...
  160. Ext.Ajax.request({
  161. url : basePath + 'pm/make/turnProdIOBC.action',
  162. params: {
  163. data: Ext.encode(material),
  164. inwhcode: inwhcode ,
  165. whmancode:Ext.getCmp('pr_whmancode').value
  166. },
  167. method : 'post',
  168. callback : function(options,success,response){
  169. grid.setLoading(false);
  170. var localJson = new Ext.decode(response.responseText);
  171. if(localJson.exceptionInfo){
  172. showError(localJson.exceptionInfo);
  173. }
  174. if(localJson.log){
  175. showMessage('提示', localJson.log);
  176. }
  177. if(localJson.success){
  178. turnSuccess(function(){
  179. grid.selModel.deselectAll(true);
  180. grid.multiselected = new Array();
  181. });
  182. }
  183. Ext.getCmp('win').close();
  184. me.onQuery();
  185. }
  186. });
  187. }
  188. }
  189. },{
  190. xtype:'button',
  191. columnWidth:0.1,
  192. text:'取消',
  193. width:60,
  194. iconCls: 'x-button-icon-close',
  195. margin:'0 0 0 10',
  196. handler:function(btn){
  197. Ext.getCmp('win').close();
  198. }
  199. }]
  200. }).show();
  201. }
  202. },
  203. /**
  204. * 筛选
  205. */
  206. onQuery: function(){
  207. var grid = Ext.getCmp('grid');
  208. grid.selModel.deselectAll(true);
  209. grid.multiselected = new Array();
  210. //计算thisqty
  211. var bool=this.calThisQty(grid);
  212. if(!bool) return;
  213. //Query
  214. var condition = null;
  215. Ext.each(grid.store.data.items, function(item){
  216. if(item.data['ma_code'] != null && item.data['ma_code'] != ''){
  217. if(condition == null){
  218. condition = "(mm_code='" + item.data['ma_code'] + "'";
  219. } else {
  220. condition += " OR mm_code='" + item.data['ma_code'] + "'";
  221. }
  222. }
  223. });
  224. if (Ext.getCmp('pr_whmancode')){
  225. var whmancode=Ext.getCmp('pr_whmancode');
  226. if (whmancode && whmancode.value!=''){
  227. if (Ext.getCmp('ifnullwhman').checked){
  228. condition+="and (pr_whmancode='"+whmancode.value+"' or NVL(pr_whmancode,' ')=' ')";
  229. }else{
  230. condition+="and pr_whmancode='"+whmancode.value+"'";
  231. }
  232. }
  233. }
  234. if (Ext.getCmp('pr_location')){
  235. var location=Ext.getCmp('pr_location');
  236. if (location && location.value!=''){
  237. if (Ext.getCmp('ifnulllocation').checked){
  238. condition+="and (pr_location like '%"+location.value+"%' or NVL(pr_location,' ')=' ')";
  239. }else{
  240. condition+="and pr_location like '%"+location.value+"%'";
  241. }
  242. }
  243. }
  244. if(condition != null){
  245. grid.busy = true;
  246. var dg = Ext.getCmp('editorColumnGridPanel');
  247. dg.busy = true;
  248. condition += ") AND (nvl(mm_materialstatus,' ')=' ') AND (mm_qty-(nvl(mm_havegetqty,0)+nvl(mm_returnmqty,0)-nvl(mm_addqty,0)) > 0)";
  249. var urlcondition=getUrlParam('urlcondition');
  250. condition=urlcondition!=null?condition+" and "+urlcondition:condition;
  251. dg.getGridColumnsAndStore(condition + ' order by mm_maid,mm_detno');
  252. this.showReplace(condition, dg);
  253. setTimeout(function(){
  254. dg.busy = false;
  255. grid.busy = false;
  256. }, 1000);
  257. }
  258. },
  259. /**
  260. * 计算可领料数
  261. **/
  262. calThisQty: function(grid){
  263. var items = grid.store.data.items, idx = new Array();
  264. Ext.each(items, function(item){
  265. if(item.data['ma_code'] != null && item.data['ma_code'] != ''){
  266. idx.push(item.data['ma_id']);
  267. }
  268. });
  269. var bool=true;
  270. if(idx.length > 0) {
  271. Ext.Ajax.request({
  272. url : basePath + 'pm/make/calThisQty.action',
  273. async: false,
  274. params: {
  275. ids: Ext.Array.concate(idx, ',')
  276. },
  277. callback: function(opt, s, r){
  278. var res = Ext.decode(r.responseText);
  279. if(res.exceptionInfo) {
  280. showError(res.exceptionInfo);
  281. bool=false;
  282. }
  283. }
  284. });
  285. }
  286. return bool;
  287. },
  288. /**
  289. * 替代料
  290. */
  291. showReplace: function(condition, grid){
  292. Ext.Ajax.request({
  293. url : basePath + 'common/getFieldsDatas.action',
  294. params: {
  295. caller: 'MakeMaterialReplace left join MakeMaterial on mm_id=mp_mmid left join Product on mp_prodcode=pr_code' +
  296. ' left join WareHouse on wh_id=mp_warehouseid',
  297. fields: 'mp_mmid,mp_detno,mp_thisqty,mp_canuseqty,mp_repqty,mp_remark,mp_prodcode,pr_detail,pr_spec,pr_unit,pr_location,wh_code',
  298. condition: condition + ' and (mp_thisqty > 0 or mm_thisqty>0)'
  299. },
  300. async: false,
  301. method : 'post',
  302. callback : function(options,success,response){
  303. var localJson = new Ext.decode(response.responseText);
  304. if(localJson.exceptionInfo){
  305. showError(localJson.exceptionInfo);return;
  306. }
  307. if(localJson.success){
  308. var data = Ext.decode(localJson.data);
  309. if(data && data.length > 0) {
  310. var idx, store = grid.store, record;
  311. grid.lockrender = true;
  312. Ext.each(data, function(d){
  313. idx = store.find('mm_id', d.MP_MMID);
  314. record = store.getAt(idx);
  315. if(idx != null && idx >= 0) {
  316. store.insert(idx + 1, {
  317. mm_prodcode: d.MP_PRODCODE,
  318. mm_oneuseqty: record.data.mm_oneuseqty,
  319. mm_code: record.data.mm_code,
  320. pr_detail: d.PR_DETAIL,
  321. pr_spec: d.PR_SPEC,
  322. pr_unit: d.PR_UNIT,
  323. mm_canuserepqty: d.MP_CANUSEQTY,
  324. mm_thisqty: d.MP_THISQTY,
  325. mm_totaluseqty: d.MP_REPQTY,
  326. mm_ifrep: 1,
  327. mm_remark: d.MP_REMARK,
  328. mm_whcode: d.WH_CODE,
  329. mm_detno: d.MP_DETNO,
  330. mm_id: d.MP_MMID,
  331. isrep: true,
  332. pr_location:d.PR_LOCATION
  333. });
  334. }
  335. });
  336. grid.lockrender = false;
  337. }
  338. grid.store.fireEvent('load', grid.store);
  339. }
  340. }
  341. });
  342. },
  343. /**
  344. * 转领料前,校验发料套数与领料数
  345. */
  346. checkQty: function(a, b){
  347. if(!Ext.getCmp('set').value) {
  348. return '';
  349. }
  350. var c = this.getMixedGroups(b.selModel.getSelection(), ['mm_code', 'mm_id']),
  351. code,count,q = 0,m = 0,err = '';
  352. a.store.each(function(d){
  353. code = d.get('ma_code');
  354. if(!Ext.isEmpty(code)) {
  355. q = d.get('ma_thisqty');
  356. Ext.Array.each(c, function(i) {
  357. if(i.keys.mm_code == code) {
  358. count = 0;
  359. m = 0;
  360. Ext.Array.each(i.groups, function(j){
  361. if(m == 0)
  362. m = j.get('mm_oneuseqty');
  363. count += j.get('mm_thisqty');
  364. });
  365. if(Math.round(count - Number(q * m) ,5 ) > 0.0001) {
  366. err += '\n领料数超出发料套数,工单号[' + code + ']';
  367. }
  368. }
  369. });
  370. }
  371. });
  372. return err;
  373. },
  374. getMixedGroups: function(items, fields) {
  375. var data = new Object(),k,o;
  376. Ext.Array.each(items, function(d){
  377. k = '';
  378. o = new Object();
  379. Ext.each(fields, function(f){
  380. k += f + ':' + d.get(f) + ',';
  381. o[f] = d.get(f);
  382. });
  383. if(k.length > 0) {
  384. if(!data[k]) {
  385. data[k] = {keys: o, groups: [d]};
  386. } else {
  387. data[k].groups.push(d);
  388. }
  389. }
  390. });
  391. return Ext.Object.getValues(data);
  392. },
  393. check: function(items) {
  394. var e = '';
  395. Ext.Array.each(items, function(item){
  396. if(Ext.isEmpty(item.get('mm_whcode'))) {
  397. e += '\n工单[' + item.get('mm_code') + '],行号[' + item.get('mm_detno') + ']仓库为空';
  398. }
  399. if(Ext.isEmpty(item.get('mm_thisqty'))) {
  400. e += '\n工单[' + item.get('mm_code') + '],行号[' + item.get('mm_detno') + ']领料数为空';
  401. }
  402. });
  403. return e;
  404. },
  405. getEffectData: function(items) {
  406. var d = new Array();
  407. Ext.Array.each(items, function(item){
  408. if (item.get('mm_thisqty') == 0) {
  409. showError('本次数量不允许为0!');
  410. return [];
  411. }
  412. d.push({
  413. mm_detno: item.get('mm_detno'),
  414. mm_code: item.get('mm_code'),
  415. mm_id: item.get('isrep') == null ? item.get('mm_id') : -item.get('mm_id'),
  416. mm_thisqty: item.get('mm_thisqty'),
  417. mm_whcode: item.get('mm_whcode'),
  418. mm_prodcode:item.get('mm_prodcode')
  419. });
  420. });
  421. return d;
  422. },
  423. getProductWh: function(grid) {
  424. var codes = [];
  425. grid.store.each(function(d){
  426. codes.push("'" + d.get('mm_prodcode') + "'");
  427. });
  428. Ext.Ajax.request({
  429. url: basePath + 'scm/product/getProductwh.action',
  430. params: {
  431. codes: codes.join(',')
  432. },
  433. callback: function (opt, s, r) {
  434. if(s) {
  435. var rs = Ext.decode(r.responseText);
  436. if(rs.data) {
  437. grid.productwh = rs.data;
  438. }
  439. }
  440. }
  441. });
  442. },
  443. getSetting : function(f, type) {
  444. Ext.Ajax.request({
  445. url : basePath + 'common/getFieldData.action',
  446. async: false,
  447. params: {
  448. caller: 'Setting',
  449. field: 'se_value',
  450. condition: 'se_what=\'' + type + '\''
  451. },
  452. method : 'post',
  453. callback : function(opt, s, res){
  454. var r = new Ext.decode(res.responseText);
  455. if(r.exceptionInfo){
  456. showError(r.exceptionInfo);return;
  457. }
  458. if(r.success && r.data){
  459. if (r.data == 'false') {
  460. f.setValue(false);
  461. } else {
  462. f.setValue(true);
  463. }
  464. }
  465. }
  466. });
  467. }
  468. });