MakeMaterialScrap.js 9.8 KB

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