MakeMaterialScrap.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.outsource.MakeMaterialScrap', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.RenderUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil'],
  5. views:[
  6. 'pm.outsource.MakeMaterialScrap', '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=retreat]': {
  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!Scrap', 'GroupWarehouse.OS', function(bool) {
  40. f.setValue(bool);
  41. });
  42. }
  43. },
  44. 'combo[id=groupPurs]': {
  45. beforerender: function(f) {
  46. me.BaseUtil.getSetting('MakeMaterial!OS!Scrap', 'isGroupPurc', function(v) {
  47. if(v){
  48. f.show();
  49. }
  50. });
  51. }
  52. },
  53. 'dbfindtrigger[name=ma_code]':{
  54. aftertrigger:function(){
  55. var record = Ext.getCmp('grid').selModel.getLastSelected();
  56. record.set('ma_thisqty',0);
  57. }
  58. }
  59. });
  60. },
  61. turnOut: function(grid) {
  62. var me = this,
  63. material = this.getEffectData(grid.selModel.getSelection());
  64. if(material.length > 0){
  65. grid.setLoading(true);//loading...
  66. Ext.Ajax.request({
  67. url : basePath + 'pm/make/turnScrap.action',
  68. params: {
  69. data: Ext.encode(material),
  70. caller: caller,
  71. type: 'OS'
  72. },
  73. method : 'post',
  74. callback : function(options,success,response){
  75. grid.setLoading(false);
  76. var localJson = new Ext.decode(response.responseText);
  77. if(localJson.exceptionInfo){
  78. showError(localJson.exceptionInfo);
  79. }
  80. if(localJson.log){
  81. showMessage('提示', localJson.log);
  82. }
  83. if(localJson.success){
  84. turnSuccess(function(){
  85. grid.multiselected = new Array();
  86. });
  87. }
  88. me.onQuery();
  89. }
  90. });
  91. }
  92. },
  93. /**
  94. * 筛选
  95. */
  96. onQuery: function(){
  97. var grid = Ext.getCmp('grid');
  98. //计算thisqty
  99. this.calOnlineQty(grid);
  100. //Query
  101. var condition = null;
  102. Ext.each(grid.store.data.items, function(item){
  103. if(item.data['ma_code'] != null && item.data['ma_code'] != ''){
  104. if (item.data['ma_id']==null || item.data['ma_id']==''){
  105. showError('制造单号'+item.data['ma_code']+'必须从放大镜选择');
  106. }else{
  107. if(condition == null){
  108. condition = "(mm_code='" + item.data['ma_code'] + "'";
  109. } else {
  110. condition += " OR mm_code='" + item.data['ma_code'] + "'";
  111. }
  112. }
  113. }
  114. });
  115. if(condition == null){
  116. condition = " 1=2 ";//未录入有效工单,则不筛选任何数据
  117. }else{
  118. condition += ")";
  119. }
  120. if(Ext.getCmp('groupPurs')){
  121. var grouppurs = Ext.getCmp('groupPurs');
  122. if(grouppurs && grouppurs.value != ''){
  123. condition += " and "+ grouppurs.value ;
  124. }
  125. }
  126. if(condition != null){
  127. grid.busy = true;
  128. grid.multiselected = new Array();
  129. var dg = Ext.getCmp('editorColumnGridPanel');
  130. dg.busy = true;
  131. condition += " AND (nvl(mm_materialstatus,' ')=' ') AND (mm_thisqty > 0)";
  132. dg.getGridColumnsAndStore(condition + ' order by mm_maid,mm_detno');
  133. this.showReplace(condition, dg);
  134. setTimeout(function(){
  135. dg.busy = false;
  136. grid.busy = false;
  137. }, 1000);
  138. }
  139. },
  140. /**
  141. * 更新工单用料在线结存数量
  142. **/
  143. calOnlineQty: function(grid){
  144. var items = grid.store.data.items, idx = new Array();
  145. Ext.each(items, function(item){
  146. if(item.data['ma_code'] != null && item.data['ma_code'] != ''){
  147. idx.push(item.data['ma_id']);
  148. if (item.data['ma_id']==null || item.data['ma_id']==''){
  149. showError('制造单号'+item.data['ma_code']+'必须从放大镜选择');
  150. return;
  151. }
  152. }
  153. });
  154. if(idx.length > 0) {
  155. Ext.Ajax.request({
  156. url : basePath + 'pm/make/calOnlineQty.action',
  157. async: false,
  158. params: {
  159. ids: Ext.Array.concate(idx, ',')
  160. },
  161. callback: function(opt, s, r){
  162. var res = Ext.decode(r.responseText);
  163. if(res.exceptionInfo) {
  164. showError(res.exceptionInfo);
  165. }
  166. }
  167. });
  168. }
  169. },
  170. /**
  171. * 替代料
  172. */
  173. showReplace: function(condition, grid){
  174. condition += " and (mp_thisqty>0 and mp_haverepqty-NVL(mp_scrapqty,0)>0 )";
  175. Ext.Ajax.request({
  176. url : basePath + 'common/getFieldsDatas.action',
  177. params: {
  178. caller: 'MakeMaterialReplace left join MakeMaterial on mm_id=mp_mmid left join Product on mp_prodcode=pr_code' +
  179. ' left join WareHouse on wh_code=mp_whcode',
  180. fields: 'mp_mmid,mp_detno,mp_thisqty,mp_canuseqty,mp_repqty,mp_haverepqty,mp_scrapqty,mp_turnscrapqty,mm_onlineqty,mm_backqty,mp_remark,mp_prodcode,pr_detail,pr_spec,pr_unit,wh_code',
  181. condition: condition
  182. },
  183. async: false,
  184. method : 'post',
  185. callback : function(options,success,response){
  186. var localJson = new Ext.decode(response.responseText);
  187. if(localJson.exceptionInfo){
  188. showError(localJson.exceptionInfo);return;
  189. }
  190. if(localJson.success){
  191. var data = Ext.decode(localJson.data);
  192. if(data && data.length > 0) {
  193. var idx, store = grid.store, record;
  194. grid.lockrender = true;
  195. Ext.each(data, function(d){
  196. idx = store.find('mm_id', d.MP_MMID);
  197. record = store.getAt(idx);
  198. if(idx != null && idx >= 0) {
  199. store.insert(idx + 1, {
  200. mm_prodcode: d.MP_PRODCODE,
  201. mm_oneuseqty: record.data.mm_oneuseqty,
  202. mm_code: record.data.mm_code,
  203. pr_detail: d.PR_DETAIL,
  204. pr_spec: d.PR_SPEC,
  205. pr_unit: d.PR_UNIT,
  206. mm_canuserepqty: d.MP_CANUSEQTY,
  207. mm_thisqty: d.MP_THISQTY,
  208. mm_totaluseqty: d.MP_REPQTY,
  209. mm_ifrep: 1,
  210. mm_remark: d.MP_REMARK,
  211. mm_whcode: d.WH_CODE,
  212. mm_detno: d.MP_DETNO,
  213. mm_id: d.MP_MMID,
  214. isrep: true,
  215. mm_havegetqty:d.MP_HAVEREPQTY,
  216. mm_backqty:d.MM_BACKQTY,
  217. mm_onlineqty:d.MM_ONLINEQTY,
  218. mm_scrap:d.MP_SCRAPQTY,
  219. mm_turnscrapqty: d.MP_TURNSCRAPQTY
  220. });
  221. }
  222. });
  223. grid.lockrender = false;
  224. }
  225. grid.store.fireEvent('load', grid.store);
  226. }
  227. }
  228. });
  229. },
  230. /**
  231. * 转领料前,校验发料套数与领料数
  232. */
  233. checkQty: function(a, b){
  234. var c = this.getMixedGroups(b.selModel.getSelection(), ['mm_code', 'mm_id']),
  235. code,count,q = 0,m = 0,err = '',backqty=0;
  236. a.store.each(function(d){
  237. code = d.get('ma_code');
  238. if(!Ext.isEmpty(code)) {
  239. Ext.Array.each(c, function(i) {
  240. if(i.keys.mm_code == code) {
  241. count = 0;
  242. m = 0;
  243. backqty=0;
  244. Ext.Array.each(i.groups, function(j){
  245. if(m == 0)
  246. detno = j.get('mm_detno');
  247. m = j.get('mm_oneuseqty');
  248. r = j.get('mm_onlineqty');
  249. backqty = j.get('mm_backqty');
  250. count += j.get('mm_thisqty');
  251. });
  252. if(r-backqty < count ) {
  253. err += '\n报废数大于结存数,序号[' + detno + ']';
  254. }
  255. }
  256. });
  257. }
  258. });
  259. return err;
  260. },
  261. getMixedGroups: function(items, fields) {
  262. var data = new Object(),k,o;
  263. Ext.Array.each(items, function(d){
  264. k = '';
  265. o = new Object();
  266. Ext.each(fields, function(f){
  267. k += f + ':' + d.get(f) + ',';
  268. o[f] = d.get(f);
  269. });
  270. if(k.length > 0) {
  271. if(!data[k]) {
  272. data[k] = {keys: o, groups: [d]};
  273. } else {
  274. data[k].groups.push(d);
  275. }
  276. }
  277. });
  278. return Ext.Object.getValues(data);
  279. },
  280. check: function(items) {
  281. var e = '';
  282. Ext.Array.each(items, function(item){
  283. if (item.get('mm_ifrep')==1){//替代料本次退料不能大于已领料数-报废数
  284. if(item.get('mm_thisqty') > item.get('mm_havegetqty') ) {
  285. e += '\n工单[' + item.get('mm_code') + '],替代料[' + item.get('mm_prodcode') + ']本次数大于已领料数';
  286. }
  287. }else{
  288. if(item.get('mm_thisqty') > item.get('mm_havegetqty') - item.get('mm_haverepqty') ) {
  289. e += '\n工单[' + item.get('mm_code') + '],行号[' + item.get('mm_detno') + ']本次数大于主料已领料数';
  290. }
  291. }
  292. if(Ext.isEmpty(item.get('mm_thisqty')) || item.get('mm_thisqty') == 0) {
  293. e += '\n工单[' + item.get('mm_code') + '],行号[' + item.get('mm_detno') + ']报废数未填写或者为0';
  294. }
  295. });
  296. return e;
  297. },
  298. getEffectData: function(items) {
  299. var d = new Array();
  300. Ext.Array.each(items, function(item){
  301. d.push({
  302. mm_detno: item.get('mm_detno'),
  303. mm_code: item.get('mm_code'),
  304. mm_id: item.get('isrep') == null ? item.get('mm_id') : -item.get('mm_id'),
  305. mm_thisqty: item.get('mm_thisqty'),
  306. mm_whcode: item.get('mm_whcode')
  307. });
  308. });
  309. return d;
  310. }
  311. });