MakeMaterialIssue.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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: ['pm.make.MakeMaterialIssue', 'core.grid.Panel5', 'common.editorColumn.GridPanel', 'core.grid.YnColumn', 'core.button.CreateDetail', 'core.button.PrintDetail', 'core.trigger.DbfindTrigger'],
  6. init: function() {
  7. var me = this;
  8. me.GridUtil = Ext.create('erp.util.GridUtil');
  9. me.BaseUtil = Ext.create('erp.util.BaseUtil');
  10. this.control({
  11. 'button[id=create]': {
  12. click: function(btn) {
  13. var grid = Ext.getCmp('editorColumnGridPanel');
  14. var e = me.checkQty(Ext.getCmp('grid'), grid);
  15. if (e.length > 0) {
  16. showError(e);
  17. return;
  18. }
  19. e = me.check(grid.selModel.getSelection());
  20. if (e.length > 0) {
  21. showError(e);
  22. return;
  23. }
  24. warnMsg("确定要生成领料单吗?",
  25. 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);
  38. return;
  39. }
  40. e = me.check(grid.selModel.getSelection());
  41. if (e.length > 0) {
  42. showError(e);
  43. return;
  44. }
  45. warnMsg("确定要生成拨出单吗?",
  46. function(btn) {
  47. if (btn == 'yes') {
  48. me.turnProdIOBC(grid);
  49. }
  50. });
  51. },
  52. beforerender:function(btn){
  53. me.BaseUtil.getSetting('MakeMaterial!issue', 'ifShowTurnOutButton', function(v) {
  54. if(v){
  55. btn.show();
  56. }
  57. });
  58. }
  59. },
  60. 'button[name=query]': {
  61. click: function(btn) {
  62. me.onQuery();
  63. }
  64. },
  65. 'checkbox[id=whcode]': {
  66. afterrender: function(f) {
  67. me.BaseUtil.getSetting('MakeMaterial!issue', 'groupWarehouse', function(v) {
  68. f.setValue(v);
  69. });
  70. }
  71. },
  72. 'checkbox[id=set]': {
  73. afterrender: function(f) {
  74. me.BaseUtil.getSetting('MakeMaterial!issue', 'setOfMaterial', function(v) {
  75. f.setValue(v);
  76. });
  77. me.BaseUtil.getSetting('MakeMaterial!issue', 'ifCanrepqty', function(v) {
  78. ifCanrepqty = v;
  79. });
  80. me.BaseUtil.getSetting('MakeMaterial!issue', 'includingLoss', function(v) {//套料数发料是否包含损耗
  81. ifIncludingLoss = v;
  82. });
  83. }
  84. },
  85. 'checkbox[id=ifnullwhman]': {
  86. afterrender: function(f) {
  87. me.BaseUtil.getSetting('MakeMaterial!issue', 'ifnullwhman', function(v) {
  88. f.setValue(v);
  89. });
  90. }
  91. },
  92. 'checkbox[id=ifnulllocation]': {
  93. afterrender: function(f) {
  94. me.BaseUtil.getSetting('MakeMaterial!issue', 'ifnulllocation', function(v) {
  95. f.setValue(v);
  96. });
  97. }
  98. },
  99. 'dbfindtrigger[id=st_code]':{
  100. beforerender: function(f) {
  101. me.BaseUtil.getSetting('MakeMaterial!issue', 'supportStepFilter', function(v) {
  102. if(v){
  103. f.show();
  104. }
  105. });
  106. }
  107. },
  108. 'textfield[id=pr_location]': {
  109. specialkey: function(field, e) {
  110. if (e.getKey() == Ext.EventObject.ENTER) {
  111. me.onQuery();
  112. }
  113. }
  114. },
  115. 'textfield[id=ma_wccode]': {
  116. specialkey: function(field, e) {
  117. if (e.getKey() == Ext.EventObject.ENTER) {
  118. me.onQuery();
  119. }
  120. }
  121. },
  122. 'combo[id=groupPurs]': {
  123. beforerender: function(f) {
  124. me.BaseUtil.getSetting('MakeMaterial!issue', 'isGroupPurc', function(v) {
  125. if(v){
  126. f.show();
  127. }
  128. });
  129. }
  130. },
  131. 'erpEditorColumnGridPanel':{
  132. storeloaded:function(grid){
  133. //zhouy 没有找到更好的解决 锁定列与normalview对不齐的方式 暂时这样处理
  134. Ext.defer(function(){
  135. var lockedView = grid.view.lockedView;
  136. if(lockedView){
  137. var tableEl = lockedView.el.child('.x-grid-table');
  138. if(tableEl){
  139. tableEl.dom.style.marginBottom = '7px';
  140. }
  141. }
  142. //lockedView.doLayout();
  143. }, 100);
  144. }
  145. }
  146. });
  147. },
  148. turnOut: function(grid) {
  149. var me = this,
  150. material = this.getEffectData(grid.selModel.getSelection());
  151. if (material.length > 0) {
  152. grid.setLoading(true); //loading...
  153. Ext.Ajax.request({
  154. url: basePath + 'pm/make/turnOut.action',
  155. params: {
  156. data: Ext.encode(material),
  157. wh: Ext.getCmp('whcode').checked,
  158. whman: Ext.getCmp('pr_whmancode').value,
  159. caller: caller,
  160. type: 'MAKE'
  161. },
  162. method: 'post',
  163. callback: function(options, success, response) {
  164. grid.setLoading(false);
  165. var localJson = new Ext.decode(response.responseText);
  166. if (localJson.exceptionInfo) {
  167. showError(localJson.exceptionInfo);
  168. }
  169. if(localJson.log.indexOf("转入成功") > -1){
  170. showMessage('提示', localJson.log);
  171. me.onQuery();
  172. if (localJson.success) {
  173. turnSuccess(function() {
  174. grid.selModel.deselectAll(true);
  175. grid.multiselected = new Array();
  176. });
  177. }
  178. }else{
  179. showError(localJson.log);
  180. }
  181. }
  182. });
  183. }
  184. },
  185. turnProdIOBC: function(grid) {
  186. var me = this,
  187. material = this.getEffectData(grid.selModel.getSelection());
  188. if (material.length > 0) {
  189. Ext.create('Ext.window.Window', {
  190. width: 350,
  191. height: 185,
  192. id: 'win',
  193. title: '<h1>生成拨出单</h1>',
  194. layout: 'column',
  195. items: [{
  196. margin: '10 0 0 0',
  197. xtype: 'dbfindtrigger',
  198. fieldLabel: '拨入仓库编号',
  199. name: 'wh_code',
  200. value: '',
  201. listeners: {
  202. aftertrigger: function(t, d) {
  203. t.ownerCt.down('textfield[name=wh_code]').setValue(d.get('wh_code'));
  204. t.ownerCt.down('textfield[name=inwhname]').setValue(d.get('wh_description'));
  205. }
  206. }
  207. },
  208. {
  209. margin: '3 0 0 0',
  210. xtype: 'textfield',
  211. fieldLabel: '拨入仓库名称',
  212. readOnly: true,
  213. name: 'inwhname',
  214. value: ''
  215. }],
  216. buttonAlign: 'center',
  217. buttons: [{
  218. xtype: 'button',
  219. columnWidth: 0.12,
  220. text: '确定',
  221. width: 60,
  222. iconCls: 'x-button-icon-save',
  223. handler: function(btn) {
  224. var inwhcode = btn.ownerCt.ownerCt.down('dbfindtrigger[name=wh_code]').value;
  225. if (!inwhcode) {
  226. showError('请先填写拨入的仓库编号!');
  227. return;
  228. } else {
  229. grid.setLoading(true); //loading...
  230. Ext.Ajax.request({
  231. url: basePath + 'pm/make/turnProdIOBC.action',
  232. params: {
  233. data: Ext.encode(material),
  234. inwhcode: inwhcode,
  235. whmancode: Ext.getCmp('pr_whmancode').value
  236. },
  237. method: 'post',
  238. callback: function(options, success, response) {
  239. grid.setLoading(false);
  240. var localJson = new Ext.decode(response.responseText);
  241. if (localJson.exceptionInfo) {
  242. showError(localJson.exceptionInfo);
  243. }
  244. if (localJson.log) {
  245. showMessage('提示', localJson.log);
  246. return;
  247. }
  248. if (localJson.success) {
  249. turnSuccess(function() {
  250. grid.selModel.deselectAll(true);
  251. grid.multiselected = new Array();
  252. });
  253. }
  254. Ext.getCmp('win').close();
  255. me.onQuery();
  256. }
  257. });
  258. }
  259. }
  260. },
  261. {
  262. xtype: 'button',
  263. columnWidth: 0.1,
  264. text: '取消',
  265. width: 60,
  266. iconCls: 'x-button-icon-close',
  267. margin: '0 0 0 10',
  268. handler: function(btn) {
  269. Ext.getCmp('win').close();
  270. }
  271. }]
  272. }).show();
  273. }
  274. },
  275. /**
  276. * 筛选
  277. */
  278. onQuery: function() {
  279. var me = this, grid = Ext.getCmp('grid');
  280. var c = this.getMixedGroups(grid.getStore().data.items, ['ma_code','ma_id']);
  281. if(grid.getStore().getCount() != 0 && (c.length != grid.getStore().getCount())){
  282. showError('筛选的单据编号重复');
  283. return ;
  284. }
  285. grid.selModel.deselectAll(true);
  286. grid.multiselected = new Array();
  287. //计算thisqty
  288. var bool = this.calThisQty(grid);
  289. if (!bool) return;
  290. //Query
  291. var condition = null,dirtyrecords=new Array();
  292. Ext.each(grid.store.data.items,function(item) {
  293. if (item.data['ma_code'] != null && item.data['ma_code'] != '') {
  294. if (item.data['ma_id']==null || item.data['ma_id']==''){
  295. showError('制造单号'+item.data['ma_code']+'必须从放大镜选择');
  296. }else{
  297. if (condition == null) {
  298. condition = "(mm_code='" + item.data['ma_code'] + "'";
  299. } else {
  300. condition += " OR mm_code='" + item.data['ma_code'] + "'";
  301. }
  302. }
  303. }else if(item.dirty){
  304. dirtyrecords.push(item);
  305. }
  306. });
  307. if(condition == null){
  308. condition = " 1=2 ";//未录入有效工单,则不筛选任何数据
  309. }else{
  310. condition += ")";
  311. }
  312. if(dirtyrecords.length>0) grid.store.remove(dirtyrecords);
  313. if (Ext.getCmp('pr_whmancode')) {
  314. var whmancode = Ext.getCmp('pr_whmancode');
  315. if (whmancode && whmancode.value != '') {
  316. if (Ext.getCmp('ifnullwhman').checked) {
  317. condition += "and (pr_whmancode='" + whmancode.value + "' or NVL(pr_whmancode,' ')=' ')";
  318. } else {
  319. condition += "and pr_whmancode='" + whmancode.value + "'";
  320. }
  321. }
  322. }
  323. if (Ext.getCmp('pr_location')) {
  324. var location = Ext.getCmp('pr_location');
  325. if (location && location.value != '') {
  326. if (Ext.getCmp('ifnulllocation').checked) {
  327. condition += "and (pr_location like '%" + location.value + "%' or NVL(pr_location,' ')=' ')";
  328. } else {
  329. condition += "and pr_location like '%" + location.value + "%'";
  330. }
  331. }
  332. }
  333. if (Ext.getCmp('wccode')) {
  334. var wccode = Ext.getCmp('wccode');
  335. if (wccode && wccode.value != '') {
  336. condition += " and mm_wccode like '%" + wccode.value + "%' ";
  337. }
  338. }
  339. if(Ext.getCmp('groupPurs')){
  340. var grouppurs = Ext.getCmp('groupPurs');
  341. if(grouppurs && grouppurs.value != ''){
  342. condition += " and "+ grouppurs.value;
  343. }
  344. }
  345. if(Ext.getCmp('st_code')){
  346. var stepcode = Ext.getCmp('st_code');
  347. if(stepcode && stepcode.value != ''){
  348. condition += " and mm_stepcode like '%"+ stepcode.value+"%' " ;
  349. }
  350. }
  351. if (condition != null) {
  352. grid.busy = true;
  353. var dg = Ext.getCmp('editorColumnGridPanel');
  354. dg.busy = true;
  355. condition += " AND (nvl(mm_materialstatus,' ')=' ') AND (mm_qty-(nvl(mm_havegetqty,0)+nvl(mm_returnmqty,0)-nvl(mm_addqty,0)) > 0)";
  356. var urlcondition = getUrlParam('urlcondition');
  357. condition = urlcondition != null ? condition + " and " + urlcondition: condition;
  358. this.BaseUtil.getSetting('MakeMaterial!issue', 'ifDisplayPull', function(val){
  359. if(!val){
  360. condition=condition+" and NVL(pr_supplytype,' ')<>'PULL' ";
  361. }
  362. dg.getGridColumnsAndStore(condition + ' order by mm_maid,mm_detno');
  363. me.showReplace(condition, dg);
  364. setTimeout(function() {
  365. dg.busy = false;
  366. grid.busy = false;
  367. },
  368. 1000);
  369. });
  370. }
  371. },
  372. /**
  373. * 计算可领料数
  374. **/
  375. calThisQty: function(grid) {
  376. var items = grid.store.data.items,
  377. idx = new Array();
  378. Ext.each(items,
  379. function(item) {
  380. if (item.data['ma_code'] != null && item.data['ma_code'] != '') {
  381. idx.push(item.data['ma_id']);
  382. }
  383. });
  384. var bool = true;
  385. if (idx.length > 0) {
  386. Ext.Ajax.request({
  387. url: basePath + 'pm/make/calThisQty.action',
  388. async: false,
  389. params: {
  390. ids: Ext.Array.concate(idx, ',')
  391. },
  392. callback: function(opt, s, r) {
  393. var res = Ext.decode(r.responseText);
  394. if (res.exceptionInfo) {
  395. showError(res.exceptionInfo);
  396. bool = false;
  397. }
  398. }
  399. });
  400. }
  401. return bool;
  402. },
  403. /**
  404. * 替代料
  405. */
  406. showReplace: function(condition, grid) {
  407. Ext.Ajax.request({
  408. url: basePath + 'common/getFieldsDatas.action',
  409. params: {
  410. 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',
  411. 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',
  412. condition: condition + ' and (mp_thisqty > 0 or mm_thisqty>0)'
  413. },
  414. async: false,
  415. method: 'post',
  416. callback: function(options, success, response) {
  417. var localJson = new Ext.decode(response.responseText);
  418. if (localJson.exceptionInfo) {
  419. showError(localJson.exceptionInfo);
  420. return;
  421. }
  422. if (localJson.success) {
  423. var data = Ext.decode(localJson.data);
  424. if (data && data.length > 0) {
  425. var idx, store = grid.store,
  426. record;
  427. grid.lockrender = true;
  428. Ext.each(data,
  429. function(d) {
  430. idx = store.find('mm_id', d.MP_MMID);
  431. record = store.getAt(idx);
  432. if (idx != null && idx >= 0) {
  433. if(ifCanrepqty){//如果参数设置为不考虑可替代数
  434. store.insert(idx + 1, {
  435. mm_prodcode: d.MP_PRODCODE,
  436. mm_oneuseqty: record.data.mm_oneuseqty,
  437. mm_code: record.data.mm_code,
  438. pr_detail: d.PR_DETAIL,
  439. pr_spec: d.PR_SPEC,
  440. pr_unit: d.PR_UNIT,
  441. mm_canuserepqty: d.MP_CANUSEQTY,
  442. mm_qty: record.data.mm_qty,
  443. mm_thisqty: record.data.mm_thisqty,
  444. mm_totaluseqty: record.data.mm_totaluseqty,
  445. mm_havegetqty: record.data.mm_haverepqty,
  446. mm_returnmqty: record.data.mm_returnmqty,
  447. mm_addqty: record.data.mm_addqty,
  448. mm_repqty:record.data.mm_repqty,
  449. mm_ifrep: 1,
  450. mm_remark: d.MP_REMARK,
  451. mm_whcode: d.MP_WHCODE,
  452. mm_detno: d.MP_DETNO,
  453. mm_id: d.MP_MMID,
  454. isrep: true,
  455. pr_location: d.PR_LOCATION,
  456. pw_onhand:d.PW_ONHAND
  457. });
  458. }else{
  459. store.insert(idx + 1, {
  460. mm_prodcode: d.MP_PRODCODE,
  461. mm_oneuseqty: record.data.mm_oneuseqty,
  462. mm_code: record.data.mm_code,
  463. pr_detail: d.PR_DETAIL,
  464. pr_spec: d.PR_SPEC,
  465. pr_unit: d.PR_UNIT,
  466. mm_canuserepqty: d.MP_CANUSEQTY,
  467. mm_qty: d.MP_CANUSEQTY,
  468. mm_thisqty: d.MP_THISQTY,
  469. mm_totaluseqty: d.MP_REPQTY,
  470. mm_havegetqty: d.MP_HAVEREPQTY,
  471. mm_returnmqty: d.MP_RETURNMQTY,
  472. mm_addqty: d.MP_ADDQTY,
  473. mm_ifrep: 1,
  474. mm_remark: d.MP_REMARK,
  475. mm_whcode: d.MP_WHCODE,
  476. mm_detno: d.MP_DETNO,
  477. mm_id: d.MP_MMID,
  478. isrep: true,
  479. pr_location: d.PR_LOCATION,
  480. pw_onhand:d.PW_ONHAND
  481. });
  482. }
  483. }
  484. });
  485. grid.lockrender = false;
  486. }
  487. grid.store.fireEvent('load', grid.store);
  488. grid.fireEvent('storeloaded', grid);
  489. }
  490. }
  491. });
  492. },
  493. /**
  494. * 转领料前,校验发料套数与领料数
  495. */
  496. checkQty: function(a, b) {
  497. var err='' ;
  498. var c = this.getMixedGroups(b.selModel.getSelection(), ['mm_code', 'mm_id']);
  499. /*//判断主料加替代料的和不能超过可领料数量
  500. Ext.Array.each(c,function(i) {
  501. var mainqty =0 ,totalqty = 0,detno;
  502. Ext.Array.each(i.groups,function(j) {
  503. if(!j.get('isrep')){//主料
  504. mainqty = j.get('mm_qty') - (j.get('mm_havegetqty') - j.get('mm_addqty') + j.get('mm_returnmqty') ) - j.get('mm_totaluseqty');
  505. }
  506. //计算该mm_id 领料之和
  507. totalqty +=j.get('mm_thisqty');
  508. detno = j.get('mm_detno');
  509. });
  510. if(totalqty > mainqty){
  511. err += "工单号["+i.keys.mm_code+"]序号["+detno+"]本次领料数超过可领数("+mainqty+")\n";
  512. }
  513. });*/
  514. if ((!Ext.getCmp('set').value && err == '') || (Ext.getCmp('set').value && ifIncludingLoss && err == '')) {
  515. return '';
  516. }else if(!Ext.getCmp('set').value && err != ''){
  517. return err;
  518. }
  519. var code,
  520. count,
  521. q = 0,
  522. m = 0;
  523. a.store.each(function(d) {
  524. code = d.get('ma_code');
  525. if (!Ext.isEmpty(code)) {
  526. q = d.get('ma_thisqty');
  527. Ext.Array.each(c,
  528. function(i) {
  529. if (i.keys.mm_code == code) {
  530. count = 0;
  531. m = 0;
  532. Ext.Array.each(i.groups,
  533. function(j) {
  534. if (m == 0) m = j.get('mm_oneuseqty');
  535. count += j.get('mm_thisqty');
  536. });
  537. if (Math.round(count - Number(q * m), 5) > 0.0001) {
  538. err += '领料数超出发料套数,工单号[' + code + ']';
  539. }
  540. }
  541. });
  542. }
  543. });
  544. //判断主料加替代料总数是否
  545. return err;
  546. },
  547. getMixedGroups: function(items, fields) {
  548. var data = new Object(),
  549. k,
  550. o;
  551. Ext.Array.each(items,
  552. function(d) {
  553. k = '';
  554. o = new Object();
  555. Ext.each(fields,
  556. function(f) {
  557. if(d.get(f) != " " && d.get(f) != 0){
  558. k += f + ':' + d.get(f) + ',';
  559. o[f] = d.get(f);
  560. }
  561. });
  562. if (k.length > 0) {
  563. if (!data[k]) {
  564. data[k] = {
  565. keys: o,
  566. groups: [d]
  567. };
  568. } else {
  569. data[k].groups.push(d);
  570. }
  571. }
  572. });
  573. return Ext.Object.getValues(data);
  574. },
  575. check: function(items) {
  576. var e = '';
  577. Ext.Array.each(items,
  578. function(item) {
  579. if (Ext.isEmpty(item.get('mm_whcode'))) {
  580. e += '\n工单[' + item.get('mm_code') + '],行号[' + item.get('mm_detno') + ']仓库为空';
  581. }
  582. if (Ext.isEmpty(item.get('mm_thisqty'))) {
  583. e += '\n工单[' + item.get('mm_code') + '],行号[' + item.get('mm_detno') + ']领料数为空';
  584. }
  585. });
  586. return e;
  587. },
  588. getEffectData: function(items) {
  589. var d = new Array();
  590. Ext.Array.each(items,
  591. function(item) {
  592. if (item.get('mm_thisqty') == 0) {
  593. showError('本次数量不允许为0!');
  594. return [];
  595. }
  596. d.push({
  597. mm_detno: item.get('mm_detno'),
  598. mm_code: item.get('mm_code'),
  599. mm_id: item.get('isrep') == null ? item.get('mm_id') : -item.get('mm_id'),
  600. mm_thisqty: item.get('mm_thisqty'),
  601. mm_whcode: item.get('mm_whcode'),
  602. mm_prodcode: item.get('mm_prodcode')
  603. });
  604. });
  605. return d;
  606. }
  607. });