MakeMaterialGive.js 9.3 KB

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