MakeMaterialScrap.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. '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: 'MAKE'
  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. console.log(condition);
  146. Ext.Ajax.request({
  147. url : basePath + 'common/getFieldsDatas.action',
  148. params: {
  149. caller: 'MakeMaterialReplace left join MakeMaterial on mm_id=mp_mmid left join Product on mp_prodcode=pr_code' +
  150. ' left join WareHouse on wh_id=mp_warehouseid',
  151. fields: 'mp_mmid,mp_detno,mp_thisqty,mp_canuseqty,mp_repqty,mp_remark,mp_prodcode,pr_detail,pr_spec,pr_unit,wh_code',
  152. condition: condition + ' and (mp_thisqty > 0 and mp_haverepqty>0)'
  153. },
  154. async: false,
  155. method : 'post',
  156. callback : function(options,success,response){
  157. var localJson = new Ext.decode(response.responseText);
  158. if(localJson.exceptionInfo){
  159. showError(localJson.exceptionInfo);return;
  160. }
  161. if(localJson.success){
  162. var data = Ext.decode(localJson.data);
  163. if(data && data.length > 0) {
  164. var idx, store = grid.store, record;
  165. grid.lockrender = true;
  166. Ext.each(data, function(d){
  167. idx = store.find('mm_id', d.MP_MMID);
  168. record = store.getAt(idx);
  169. if(idx != null && idx >= 0) {
  170. store.insert(idx + 1, {
  171. mm_prodcode: d.MP_PRODCODE,
  172. mm_oneuseqty: record.data.mm_oneuseqty,
  173. mm_code: record.data.mm_code,
  174. pr_detail: d.PR_DETAIL,
  175. pr_spec: d.PR_SPEC,
  176. pr_unit: d.PR_UNIT,
  177. mm_canuserepqty: d.MP_CANUSEQTY,
  178. mm_thisqty: d.MP_THISQTY,
  179. mm_totaluseqty: d.MP_REPQTY,
  180. mm_ifrep: 1,
  181. mm_remark: d.MP_REMARK,
  182. mm_whcode: d.WH_CODE,
  183. mm_detno: d.MP_DETNO,
  184. mm_id: d.MP_MMID,
  185. isrep: true
  186. });
  187. }
  188. });
  189. grid.lockrender = false;
  190. }
  191. grid.store.fireEvent('load', grid.store);
  192. }
  193. }
  194. });
  195. },
  196. /**
  197. * 转报废前,校验报废套数与报废数
  198. */
  199. checkQty: function(a, b){
  200. var c = this.getMixedGroups(b.selModel.getSelection(), ['mm_code', 'mm_id']),
  201. code,count,q = 0,m = 0,err = '';
  202. a.store.each(function(d){
  203. code = d.get('ma_code');
  204. if(!Ext.isEmpty(code)) {
  205. q = d.get('ma_thisqty');
  206. if (q>0){
  207. Ext.Array.each(c, function(i) {
  208. if(i.keys.mm_code == code) {
  209. count = 0;
  210. m = 0;
  211. Ext.Array.each(i.groups, function(j){
  212. if(m == 0)
  213. detno = j.get('mm_detno');
  214. m = j.get('mm_oneuseqty');
  215. r = j.get('mm_onlineqty');
  216. count += j.get('mm_thisqty');
  217. });
  218. if(r < count ) {
  219. err += '\n报废数大于结存数,序号[' + detno + ']';
  220. }
  221. }
  222. });
  223. }
  224. }
  225. });
  226. return err;
  227. },
  228. getMixedGroups: function(items, fields) {
  229. var data = new Object(),k,o;
  230. Ext.Array.each(items, function(d){
  231. k = '';
  232. o = new Object();
  233. Ext.each(fields, function(f){
  234. k += f + ':' + d.get(f) + ',';
  235. o[f] = d.get(f);
  236. });
  237. if(k.length > 0) {
  238. if(!data[k]) {
  239. data[k] = {keys: o, groups: [d]};
  240. } else {
  241. data[k].groups.push(d);
  242. }
  243. }
  244. });
  245. return Ext.Object.getValues(data);
  246. },
  247. check: function(items) {
  248. var e = '';
  249. Ext.Array.each(items, function(item){
  250. if(Ext.isEmpty(item.get('mm_thisqty'))) {
  251. e += '\n工单[' + item.get('mm_code') + '],行号[' + item.get('mm_detno') + ']报废数未填写';
  252. }
  253. });
  254. return e;
  255. },
  256. getEffectData: function(items) {
  257. var d = new Array();
  258. Ext.Array.each(items, function(item){
  259. d.push({
  260. mm_detno: item.get('mm_detno'),
  261. mm_code: item.get('mm_code'),
  262. mm_id: item.get('isrep') == null ? item.get('mm_id') : -item.get('mm_id'),
  263. mm_thisqty: item.get('mm_thisqty'),
  264. mm_whcode: item.get('mm_whcode')
  265. });
  266. });
  267. return d;
  268. },
  269. getProductWh: function(grid) {
  270. var codes = [];
  271. grid.store.each(function(d){
  272. codes.push("'" + d.get('mm_prodcode') + "'");
  273. });
  274. Ext.Ajax.request({
  275. url: basePath + 'scm/product/getProductwh.action',
  276. params: {
  277. codes: codes.join(',')
  278. },
  279. callback: function (opt, s, r) {
  280. if(s) {
  281. var rs = Ext.decode(r.responseText);
  282. if(rs.data) {
  283. grid.productwh = rs.data;
  284. }
  285. }
  286. }
  287. });
  288. },
  289. getSetting : function(f) {
  290. Ext.Ajax.request({
  291. url : basePath + 'common/getFieldData.action',
  292. async: false,
  293. params: {
  294. caller: 'Setting',
  295. field: 'se_value',
  296. condition: 'se_what=\'GroupWarehouse\''
  297. },
  298. method : 'post',
  299. callback : function(opt, s, res){
  300. var r = new Ext.decode(res.responseText);
  301. if(r.exceptionInfo){
  302. showError(r.exceptionInfo);return;
  303. }
  304. if(r.success && r.data){
  305. if (r.data == 'false') {
  306. f.setValue(false);
  307. }
  308. }
  309. }
  310. });
  311. }
  312. });