MakeMaterialScrap.js 8.4 KB

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