MakeMaterialGive.js 11 KB

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