MakeMaterialIssue.js 9.5 KB

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