MakeMaterialIssue.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.outsource.MakeMaterialIssue', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.RenderUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil'],
  5. views:[
  6. 'pm.outsource.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[name=query]': {
  33. click: function(btn){
  34. me.onQuery();
  35. }
  36. },
  37. 'checkbox[id=whcode]' : {
  38. afterrender : function(f) {
  39. me.BaseUtil.getSetting('MakeMaterial!OS!issue', 'GroupWarehouse.OS', function(bool) {
  40. f.setValue(bool);
  41. });
  42. }
  43. },
  44. 'checkbox[id=set]' : {
  45. afterrender : function(f) {
  46. me.BaseUtil.getSetting('MakeMaterial!OS!issue', 'SetOfMaterial.OS', function(bool) {
  47. f.setValue(bool);
  48. });
  49. me.BaseUtil.getSetting('MakeMaterial!OS!issue', 'ifCanrepqty', function(v) {
  50. ifCanrepqty = v;
  51. });
  52. me.BaseUtil.getSetting('MakeMaterial!OS!issue', 'includingLoss', function(v) {//套料数发料是否包含损耗
  53. ifIncludingLoss = v;
  54. });
  55. }
  56. },
  57. 'combo[id=groupPurs]': {
  58. beforerender: function(f) {
  59. me.BaseUtil.getSetting('MakeMaterial!OS!issue', 'isGroupPurc', function(v) {
  60. if(v){
  61. f.show();
  62. }
  63. });
  64. }
  65. }
  66. });
  67. },
  68. turnOut: function(grid) {
  69. var me = this,
  70. material = this.getEffectData(grid.selModel.getSelection());
  71. if(material.length > 0){
  72. grid.setLoading(true);//loading...
  73. Ext.Ajax.request({
  74. url : basePath + 'pm/make/turnOut.action',
  75. params: {
  76. data: Ext.encode(material),
  77. wh: Ext.getCmp('whcode').checked,
  78. whman: Ext.getCmp('pr_whmancode').value,
  79. caller: caller,
  80. type: 'OS'
  81. },
  82. method : 'post',
  83. callback : function(options,success,response){
  84. grid.setLoading(false);
  85. var localJson = new Ext.decode(response.responseText);
  86. if(localJson.exceptionInfo){
  87. showError(localJson.exceptionInfo);
  88. }
  89. if(localJson.log.indexOf("转入成功") > -1){
  90. showMessage('提示', localJson.log);
  91. /*if(localJson.success){
  92. turnSuccess(function(){
  93. grid.multiselected = new Array();
  94. });
  95. }*/
  96. me.onQuery();
  97. }else{
  98. showError(localJson.log);
  99. }
  100. }
  101. });
  102. }
  103. },
  104. /**
  105. * 筛选
  106. */
  107. onQuery: function(){
  108. var me=this,grid = Ext.getCmp('grid');
  109. //计算thisqty
  110. this.calThisQty(grid);
  111. //Query
  112. var condition = null;
  113. Ext.each(grid.store.data.items, function(item){
  114. if(item.data['ma_code'] != null && item.data['ma_code'] != ''){
  115. if (item.data['ma_id']==null || item.data['ma_id']==''){
  116. showError('制造单号'+item.data['ma_code']+'必须从放大镜选择');
  117. }else{
  118. if(condition == null){
  119. condition = "(mm_code='" + item.data['ma_code'] + "'";
  120. } else {
  121. condition += " OR mm_code='" + item.data['ma_code'] + "'";
  122. }
  123. }
  124. }
  125. });
  126. if(condition == null){
  127. condition = " 1=2 ";//未录入有效工单,则不筛选任何数据
  128. }else{
  129. condition += ")";
  130. }
  131. if (Ext.getCmp('pr_whmancode')){
  132. var whmancode=Ext.getCmp('pr_whmancode');
  133. if (whmancode && whmancode.value!=''){
  134. if (Ext.getCmp('ifnullwhman').checked){
  135. condition+="and (pr_whmancode='"+whmancode.value+"' or NVL(pr_whmancode,' ')=' ')";
  136. }else{
  137. condition+="and pr_whmancode='"+whmancode.value+"'";
  138. }
  139. }
  140. }
  141. if (Ext.getCmp('pr_location')){
  142. var location=Ext.getCmp('pr_location');
  143. if (location && location.value!=''){
  144. if (Ext.getCmp('ifnulllocation').checked){
  145. condition+="and (pr_location like '%"+location.value+"%' or NVL(pr_location,' ')=' ')";
  146. }else{
  147. condition+="and pr_location like '%"+location.value+"%'";
  148. }
  149. }
  150. }
  151. if (Ext.getCmp('ma_wccode')){
  152. var wccode=Ext.getCmp('ma_wccode');
  153. if (wccode && !Ext.isEmpty(wccode.value)){
  154. condition+="and mm_wccode='"+wccode.value+"'";
  155. }
  156. }
  157. if(Ext.getCmp('groupPurs')){
  158. var grouppurs = Ext.getCmp('groupPurs');
  159. if(grouppurs && grouppurs.value != ''){
  160. condition += " and "+ grouppurs.value ;
  161. }
  162. }
  163. if(condition != null){
  164. grid.busy = true;
  165. grid.multiselected = new Array();
  166. var dg = Ext.getCmp('editorColumnGridPanel');
  167. dg.busy = true;
  168. condition += " AND (nvl(mm_materialstatus,' ')=' ') AND (mm_qty-(nvl(mm_havegetqty,0)+nvl(mm_returnmqty,0)-nvl(mm_addqty,0)) > 0)";
  169. this.BaseUtil.getSetting('MakeMaterial!OS!issue', 'ifDisplayPull', function(val){
  170. if(!val){
  171. condition=condition+" and NVL(pr_supplytype,' ')<>'PULL' ";
  172. }
  173. dg.getGridColumnsAndStore(condition + ' order by mm_maid,mm_detno');
  174. me.showReplace(condition, dg);
  175. setTimeout(function(){
  176. dg.busy = false;
  177. grid.busy = false;
  178. }, 1000);
  179. });
  180. }
  181. },
  182. /**
  183. * 计算可领料数
  184. **/
  185. calThisQty: function(grid){
  186. var items = grid.store.data.items, idx = new Array();
  187. Ext.each(items, function(item){
  188. if(item.data['ma_code'] != null && item.data['ma_code'] != ''){
  189. idx.push(item.data['ma_id']);
  190. }
  191. });
  192. if(idx.length > 0) {
  193. Ext.Ajax.request({
  194. url : basePath + 'pm/make/calThisQty.action',
  195. async: false,
  196. params: {
  197. ids: Ext.Array.concate(idx, ',')
  198. },
  199. callback: function(opt, s, r){
  200. var res = Ext.decode(r.responseText);
  201. if(res.exceptionInfo) {
  202. showError(res.exceptionInfo);
  203. }
  204. }
  205. });
  206. }
  207. },
  208. /**
  209. * 替代料
  210. */
  211. showReplace: function(condition, grid){
  212. Ext.Ajax.request({
  213. url : basePath + 'common/getFieldsDatas.action',
  214. params: {
  215. 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',
  216. 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',
  217. condition: condition + ' and (mp_thisqty > 0 or mm_thisqty>0)'
  218. },
  219. async: false,
  220. method : 'post',
  221. callback : function(options,success,response){
  222. var localJson = new Ext.decode(response.responseText);
  223. if(localJson.exceptionInfo){
  224. showError(localJson.exceptionInfo);return;
  225. }
  226. if(localJson.success){
  227. var data = Ext.decode(localJson.data);
  228. if(data && data.length > 0) {
  229. var idx, store = grid.store, record;
  230. grid.lockrender = true;
  231. Ext.each(data, function(d){
  232. idx = store.find('mm_id', d.MP_MMID);
  233. record = store.getAt(idx);
  234. if(idx != null && idx >= 0) {
  235. if(ifCanrepqty){//如果参数设置为不考虑可替代数
  236. store.insert(idx + 1, {
  237. mm_prodcode: d.MP_PRODCODE,
  238. mm_oneuseqty: record.data.mm_oneuseqty,
  239. mm_code: record.data.mm_code,
  240. pr_detail: d.PR_DETAIL,
  241. pr_spec: d.PR_SPEC,
  242. pr_unit: d.PR_UNIT,
  243. mm_canuserepqty: d.MP_CANUSEQTY,
  244. mm_qty: record.data.mm_qty,
  245. mm_thisqty: record.data.mm_thisqty,
  246. mm_totaluseqty: record.data.mm_totaluseqty,
  247. mm_havegetqty: record.data.mm_haverepqty,
  248. mm_returnmqty: record.data.mm_returnmqty,
  249. mm_addqty: record.data.mm_addqty,
  250. mm_repqty:record.data.mm_repqty,
  251. mm_ifrep: 1,
  252. mm_remark: d.MP_REMARK,
  253. mm_whcode: d.MP_WHCODE,
  254. mm_detno: d.MP_DETNO,
  255. mm_id: d.MP_MMID,
  256. ma_vendcode:record.data.ma_vendcode,
  257. isrep: true,
  258. pr_location: d.PR_LOCATION,
  259. pw_onhand:d.PW_ONHAND
  260. });
  261. }else{
  262. store.insert(idx + 1, {
  263. mm_prodcode: d.MP_PRODCODE,
  264. mm_oneuseqty: record.data.mm_oneuseqty,
  265. mm_code: record.data.mm_code,
  266. pr_detail: d.PR_DETAIL,
  267. pr_spec: d.PR_SPEC,
  268. pr_unit: d.PR_UNIT,
  269. mm_canuserepqty: d.MP_CANUSEQTY,
  270. mm_qty: d.MP_CANUSEQTY,
  271. mm_thisqty: d.MP_THISQTY,
  272. mm_totaluseqty: d.MP_REPQTY,
  273. mm_havegetqty: d.MP_HAVEREPQTY,
  274. mm_returnmqty: d.MP_RETURNMQTY,
  275. mm_addqty: d.MP_ADDQTY,
  276. mm_ifrep: 1,
  277. mm_remark: d.MP_REMARK,
  278. mm_whcode: d.MP_WHCODE,
  279. mm_detno: d.MP_DETNO,
  280. mm_id: d.MP_MMID,
  281. ma_vendcode:record.data.ma_vendcode,
  282. isrep: true,
  283. pr_location: d.PR_LOCATION,
  284. pw_onhand:d.PW_ONHAND
  285. });
  286. }
  287. }
  288. });
  289. grid.lockrender = false;
  290. }
  291. grid.store.fireEvent('load', grid.store);
  292. }
  293. }
  294. });
  295. },
  296. /**
  297. * 转领料前,校验发料套数与领料数
  298. */
  299. checkQty: function(a, b){
  300. var err='' ;
  301. var c = this.getMixedGroups(b.selModel.getSelection(), ['mm_code', 'mm_id']);
  302. /*//判断主料加替代料的和不能超过可领料数量
  303. Ext.Array.each(c,function(i) {
  304. var mainqty =0 ,totalqty = 0,detno;
  305. Ext.Array.each(i.groups,function(j) {
  306. if(!j.get('isrep')){//主料
  307. mainqty = j.get('mm_qty') - (j.get('mm_havegetqty') - j.get('mm_addqty') + j.get('mm_returnmqty') ) - j.get('mm_totaluseqty');
  308. }
  309. //计算该mm_id 领料之和
  310. totalqty +=j.get('mm_thisqty');
  311. detno = j.get('mm_detno');
  312. });
  313. if(totalqty > mainqty){
  314. err += "工单号["+i.keys.mm_code+"]序号["+detno+"]本次领料数超过可领数("+mainqty+")\n";
  315. }
  316. });*/
  317. if (((!Ext.getCmp('set').value) && err == '') || (Ext.getCmp('set').value && ifIncludingLoss && err == '')) {
  318. return '';
  319. }else if(!Ext.getCmp('set').value && err != ''){
  320. return err;
  321. }
  322. var code,count,q = 0,m = 0;
  323. a.store.each(function(d){
  324. code = d.get('ma_code');
  325. if(!Ext.isEmpty(code)) {
  326. q = d.get('ma_thisqty');
  327. Ext.Array.each(c, function(i) {
  328. if(i.keys.mm_code == code) {
  329. count = 0;
  330. m = 0;
  331. Ext.Array.each(i.groups, function(j){
  332. if(m == 0)
  333. m = j.get('mm_oneuseqty');
  334. count += j.get('mm_thisqty');
  335. });
  336. if(Math.round(count - Number(q * m) ,5 ) > 0.0001) {
  337. err += '\n领料数超出发料套数,工单号[' + code + ']';
  338. }
  339. }
  340. });
  341. }
  342. });
  343. return err;
  344. },
  345. getMixedGroups: function(items, fields) {
  346. var data = new Object(),k,o;
  347. Ext.Array.each(items, function(d){
  348. k = '';
  349. o = new Object();
  350. Ext.each(fields, function(f){
  351. k += f + ':' + d.get(f) + ',';
  352. o[f] = d.get(f);
  353. });
  354. if(k.length > 0) {
  355. if(!data[k]) {
  356. data[k] = {keys: o, groups: [d]};
  357. } else {
  358. data[k].groups.push(d);
  359. }
  360. }
  361. });
  362. return Ext.Object.getValues(data);
  363. },
  364. check: function(items) {
  365. var e = '';
  366. Ext.Array.each(items, function(item){
  367. if(Ext.isEmpty(item.get('mm_whcode'))) {
  368. e += '\n工单[' + item.get('mm_code') + '],主料序号-替代料序号[' + item.get('mm_detno') + ']仓库为空';
  369. }
  370. if(Ext.isEmpty(item.get('mm_thisqty'))) {
  371. e += '\n工单[' + item.get('mm_code') + '],主料序号-替代料序号[' + item.get('mm_detno') + ']领料数为空';
  372. }
  373. });
  374. return e;
  375. },
  376. getEffectData: function(items) {
  377. var d = new Array();
  378. Ext.Array.each(items, function(item){
  379. d.push({
  380. mm_detno: item.get('mm_detno'),
  381. mm_code: item.get('mm_code'),
  382. mm_id: item.get('isrep') == null ? item.get('mm_id') : -item.get('mm_id'),
  383. mm_thisqty: item.get('mm_thisqty'),
  384. mm_whcode: item.get('mm_whcode'),
  385. ma_vendcode: item.get('ma_vendcode'),
  386. mm_prodcode: item.get('mm_prodcode')
  387. });
  388. });
  389. return d;
  390. }
  391. });