MakeMaterialGive.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.outsource.MakeMaterialGive', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.RenderUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil'],
  5. views:[
  6. 'pm.outsource.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. warnMsg("确定要生成补料单吗?", function(btn){
  17. if(btn == 'yes'){
  18. var grid = Ext.getCmp('editorColumnGridPanel');
  19. me.turnAdd(grid);
  20. }
  21. });
  22. }
  23. },
  24. 'button[name=query]': {
  25. click: function(btn){
  26. me.onQuery();
  27. }
  28. },
  29. 'checkbox[id=whcode]' : {
  30. afterrender : function(f) {
  31. me.BaseUtil.getSetting('MakeMaterial!OS!Give', 'GroupWarehouse.OS', function(bool) {
  32. f.setValue(bool);
  33. });
  34. }
  35. },
  36. 'combo[id=groupPurs]': {
  37. beforerender: function(f) {
  38. me.BaseUtil.getSetting('MakeMaterial!OS!Give', 'isGroupPurc', function(v) {
  39. if(v){
  40. f.show();
  41. }
  42. });
  43. }
  44. },
  45. 'dbfindtrigger[name=ma_code]':{
  46. aftertrigger:function(){
  47. var record = Ext.getCmp('grid').selModel.getLastSelected();
  48. record.set('ma_thisqty',0);
  49. }
  50. }
  51. });
  52. },
  53. onQuery: function(){
  54. var grid = Ext.getCmp('grid');
  55. //计算thisqty
  56. this.calAddQty(grid);
  57. var condition = null;
  58. Ext.each(grid.store.data.items, function(item){
  59. if(item.data['ma_code'] != null && item.data['ma_code'] != ''){
  60. if (item.data['ma_id']==null || item.data['ma_id']==''){
  61. showError('制造单号'+item.data['ma_code']+'必须从放大镜选择');
  62. }else{
  63. if(condition == null){
  64. condition = "(mm_code='" + item.data['ma_code'] + "'";
  65. } else {
  66. condition += " OR mm_code='" + item.data['ma_code'] + "'";
  67. }
  68. }
  69. }
  70. });
  71. if(condition == null){
  72. condition = " 1=2 ";//未录入有效工单,则不筛选任何数据
  73. }else{
  74. condition += ")";
  75. }
  76. if (Ext.getCmp('pr_location')){
  77. var location=Ext.getCmp('pr_location');
  78. if (location && location.value!=''){
  79. if (Ext.getCmp('ifnulllocation').checked){
  80. condition+="and (pr_location like '%"+location.value+"%' or NVL(pr_location,' ')=' ')";
  81. }else{
  82. condition+="and pr_location like '%"+location.value+"%' ";
  83. }
  84. }
  85. }
  86. if(Ext.getCmp('groupPurs')){
  87. var grouppurs = Ext.getCmp('groupPurs');
  88. if(grouppurs && grouppurs.value != ''){
  89. condition += " and "+ grouppurs.value ;
  90. }
  91. }
  92. if(condition != null){
  93. grid.multiselected = new Array();
  94. grid.busy = true;
  95. var dg = Ext.getCmp('editorColumnGridPanel');
  96. dg.busy = true;
  97. condition += " AND ( nvl(mm_scrapqty,0)+nvl(mm_returnmqty,0)-nvl(mm_balance,0)-nvl(mm_addqty,0)-NVL(mm_turnaddqty,0)>0)";
  98. dg.getGridColumnsAndStore(condition + ' order by mm_maid,mm_detno');
  99. this.showReplace(condition, dg);
  100. setTimeout(function(){
  101. dg.busy = false;
  102. grid.busy = false;
  103. }, 1000);
  104. }
  105. },
  106. /**
  107. * 计算可补料数
  108. **/
  109. calAddQty: function(grid){
  110. var items = grid.store.data.items, idx = new Array();
  111. Ext.each(items, function(item){
  112. if(item.data['ma_code'] != null && item.data['ma_code'] != ''){
  113. idx.push(item.data['ma_id']);
  114. }
  115. });
  116. if(idx.length > 0) {
  117. Ext.Ajax.request({
  118. url : basePath + 'pm/make/calAddQty.action',
  119. async: false,
  120. params: {
  121. ids: Ext.Array.concate(idx, ',')
  122. },
  123. callback: function(opt, s, r){
  124. var res = Ext.decode(r.responseText);
  125. if(res.exceptionInfo) {
  126. showError(res.exceptionInfo);
  127. }
  128. }
  129. });
  130. }
  131. },
  132. /**
  133. * 替代料
  134. */
  135. showReplace: function(condition, grid){
  136. Ext.Ajax.request({
  137. url : basePath + 'common/getFieldsDatas.action',
  138. params: {
  139. caller: 'MakeMaterialReplace left join MakeMaterial on mm_id=mp_mmid left join make on mm_maid=ma_id left join Product on mp_prodcode=pr_code' +
  140. ' left join productwh on pw_whcode=mp_whcode and pw_prodcode=mp_prodcode',
  141. 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,ma_vendcode,mp_whcode,pw_onhand',
  142. condition: condition + ' and ( nvl(mm_scrapqty,0)+nvl(mm_returnmqty,0)-nvl(mm_balance,0)-nvl(mm_addqty,0)-NVL(mm_turnaddqty,0)>0)'
  143. },
  144. async: false,
  145. method : 'post',
  146. callback : function(options,success,response){
  147. var localJson = new Ext.decode(response.responseText);
  148. if(localJson.exceptionInfo){
  149. showError(localJson.exceptionInfo);return;
  150. }
  151. if(localJson.success){
  152. var data = Ext.decode(localJson.data);
  153. if(data && data.length > 0) {
  154. var idx, store = grid.store, record;
  155. grid.lockrender = true;
  156. Ext.each(data, function(d){
  157. idx = store.find('mm_id', d.MP_MMID);
  158. record = store.getAt(idx);
  159. if(idx != null && idx >= 0) {
  160. store.insert(idx + 1, {
  161. mm_prodcode: d.MP_PRODCODE,
  162. mm_oneuseqty: record.data.mm_oneuseqty,
  163. mm_code: record.data.mm_code,
  164. pr_detail: d.PR_DETAIL,
  165. pr_spec: d.PR_SPEC,
  166. pr_unit: d.PR_UNIT,
  167. mm_canuserepqty: d.MP_CANUSEQTY,
  168. mm_thisqty: d.MP_THISQTY,
  169. mm_totaluseqty: d.MP_REPQTY,
  170. mm_havegetqty: d.MP_HAVEREPQTY,
  171. mm_qty: d.MP_CANUSEQTY,
  172. mm_turnaddqty: d.MM_TURNADDQTY,
  173. mm_ifrep: 1,
  174. mm_remark: d.MP_REMARK,
  175. mm_whcode: d.MP_WHCODE,
  176. mm_detno: d.MP_DETNO,
  177. mm_id: d.MP_MMID,
  178. isrep: true,
  179. pr_location:d.PR_LOCATION,
  180. ma_vendcode: d.MA_VENDCODE,
  181. pw_onhand:d.PW_ONHAND
  182. });
  183. }
  184. });
  185. grid.lockrender = false;
  186. }
  187. grid.store.fireEvent('load', grid.store);
  188. grid.fireEvent('storeloaded', grid);
  189. }
  190. }
  191. });
  192. },
  193. turnAdd: function(grid) {
  194. var me = this,
  195. material = me.getEffectData(grid.selModel.getSelection());
  196. if(material.length > 0){
  197. grid.setLoading(true);//loading...
  198. Ext.Ajax.request({
  199. url : basePath + 'pm/make/turnAdd.action',
  200. params: {
  201. data: Ext.encode(material),
  202. wh: Ext.getCmp('whcode').checked,
  203. caller: caller,
  204. type: 'OS'
  205. },
  206. method : 'post',
  207. callback : function(options,success,response){
  208. grid.setLoading(false);
  209. var localJson = new Ext.decode(response.responseText);
  210. if(localJson.exceptionInfo){
  211. showError(localJson.exceptionInfo);
  212. }
  213. if(localJson.log){
  214. showMessage('提示', localJson.log);
  215. }
  216. if(localJson.success){
  217. turnSuccess(function(){
  218. grid.multiselected = new Array();
  219. });
  220. }
  221. me.onQuery();
  222. }
  223. });
  224. }
  225. },
  226. getEffectData: function(items) {
  227. var d = new Array();
  228. Ext.Array.each(items, function(item){
  229. d.push({
  230. mm_detno: item.get('mm_detno'),
  231. mm_code: item.get('mm_code'),
  232. mm_id: item.get('isrep') == null ? item.get('mm_id') : -item.get('mm_id'),
  233. mm_thisqty: item.get('mm_thisqty'),
  234. mm_whcode: item.get('mm_whcode'),
  235. ma_vendcode:item.get('ma_vendcode')
  236. });
  237. });
  238. return d;
  239. }
  240. });