MakeSendLS.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.make.MakeSendLS', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.FormUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil', 'erp.util.RenderUtil'],
  5. views:[
  6. 'pm.make.MakeSendLS','common.batchDeal.GridPanel','common.batchDeal.Form',
  7. 'core.form.ConDateField','core.button.Close','core.form.YnField','core.form.MultiField',
  8. 'core.trigger.TextAreaTrigger','core.trigger.DbfindTrigger','core.trigger.MultiDbfindTrigger'
  9. ],
  10. init:function(){
  11. var me = this;
  12. this.control({
  13. 'button[id=query]': {
  14. click: function(btn){
  15. if(Ext.getCmp('ma_code').value ==null||Ext.getCmp('ma_code').value ==''){
  16. showError('制造单号为空,请填写以后在筛选!');
  17. return;
  18. }
  19. this.onQuery();
  20. }
  21. },
  22. 'erpBatchDealGridPanel' : {
  23. storeloaded: function(grid) {
  24. me.getProductWh(grid);
  25. }
  26. },
  27. 'button[id=add]': {
  28. click: function(btn){
  29. if(Ext.getCmp('ma_departmentcode').value ==null||Ext.getCmp('ma_departmentcode').value ==''){
  30. showError('部门编号为空, 请重新填写!');
  31. return;
  32. }
  33. if(Ext.getCmp('ms_recordorcode').value ==null||Ext.getCmp('ms_recordorcode').value ==''){
  34. showError('人员编号为空, 请重新填写!');
  35. return;
  36. }
  37. var grid = Ext.getCmp('batchDealGridPanel');
  38. warnMsg("确定要发料吗?", function(btn){
  39. if(btn == 'yes'){
  40. me.create(grid);
  41. }
  42. });
  43. }
  44. }
  45. });
  46. },
  47. getProductWh: function(grid) {
  48. var codes = [];
  49. grid.store.each(function(d){
  50. codes.push("'" + d.get('mm_prodcode') + "'");
  51. });
  52. Ext.Ajax.request({
  53. url: basePath + 'scm/product/getProductwh.action',
  54. params: {
  55. codes: codes.join(',')
  56. },
  57. callback: function (opt, s, r) {
  58. if(s) {
  59. var rs = Ext.decode(r.responseText);
  60. if(rs.data) {
  61. grid.productwh = rs.data;
  62. }
  63. }
  64. }
  65. });
  66. },
  67. onQuery: function(){
  68. var grid = Ext.getCmp('grid');
  69. this.setQty();
  70. if(!grid){
  71. grid = Ext.getCmp('batchDealGridPanel');
  72. }
  73. grid.multiselected = new Array();
  74. var form = Ext.getCmp('dealform');
  75. var cond = form.getCondition();
  76. if(Ext.isEmpty(cond)) {
  77. cond = '1=1';
  78. }
  79. if(Ext.getCmp('pr_whmanname') && Ext.getCmp('pr_whmanname').value !=null && Ext.getCmp('pr_whmanname').value !=''){
  80. var conds=cond.split("pr_whmanname");
  81. if(Ext.getCmp('ma_blank').checked==true){
  82. cond = conds[0]+'pr_whmanname is null or pr_whmanname'+conds[1];
  83. }
  84. }
  85. if(Ext.getCmp('pr_location') && Ext.getCmp('pr_location').value !=null && Ext.getCmp('pr_location').value !=''){
  86. var conds=cond.split("pr_location");
  87. if(Ext.getCmp('ifnulllocation').checked==true){
  88. cond = conds[0]+'pr_location is null or pr_location'+conds[1];
  89. }
  90. }
  91. cond+=" and nvl(mm_materialstatus,' ')=' '";
  92. var autotype=getUrlParam('AutoType');
  93. if(caller!='MakeSendLS!Out' && autotype==null ){
  94. cond+=" and pr_supplytype='PULL'";
  95. }
  96. form.beforeQuery(caller, cond);//执行查询前逻辑
  97. grid.getGridColumnsAndStore(grid, 'common/singleGridPanel.action',{caller: caller, condition: cond, start: 1, end: 1000}, "",true);
  98. var condition = "1=1";
  99. if(Ext.getCmp('ma_id').value != null&&Ext.getCmp('ma_id').value !=''){
  100. condition="( mp_maid="+Ext.getCmp('ma_id').value+")";
  101. }
  102. condition+=" and nvl(mm_materialstatus,' ')=' '";
  103. if(autotype==null){
  104. condition+=" and pr_supplytype='PULL'";
  105. }
  106. this.showReplace(condition, grid);
  107. },
  108. showReplace: function(condition, grid){
  109. Ext.Ajax.request({
  110. url : basePath + 'common/getFieldsDatas.action',
  111. params: {
  112. caller: 'MakeMaterialReplace left join MakeMaterial on mm_id=mp_mmid left join Product on mp_prodcode=pr_code' ,
  113. fields: 'mp_mmid,mp_detno,mp_thisqty,mp_canuseqty,mp_repqty,mp_prodcode,mp_whcode,pr_detail,pr_spec,'+
  114. 'pr_unit,mp_haverepqty,mp_thisplanqty,mp_wipuseqty,mp_canuseqty,mm_level,mm_oneuseqty,pr_wiponhand,pr_location',
  115. condition: condition + ' and (mp_thisqty > 0) order by mp_mmid,mp_detno'
  116. },
  117. async: false,
  118. method : 'post',
  119. callback : function(options,success,response){
  120. var localJson = new Ext.decode(response.responseText);
  121. if(localJson.exceptionInfo){
  122. showError(localJson.exceptionInfo);return;
  123. }
  124. if(localJson.success){
  125. var data = Ext.decode(localJson.data);
  126. if(data && data.length > 0) {
  127. var idx=0, store = grid.store;
  128. grid.lockrender = true;
  129. Ext.each(data, function(d){
  130. console.log(store.data.items);
  131. Ext.Array.each(store.data.items,function(item,index){
  132. console.log(item.data.mm_id);
  133. console.log(item.data.mm_id==d.MP_MMID);
  134. if(item.data.mm_id==d.MP_MMID){
  135. idx=index;
  136. return;
  137. }
  138. });
  139. console.log(idx);
  140. record = store.getAt(idx);
  141. console.log(record);
  142. if(idx != null && idx >= 0) {
  143. store.insert(idx + 1, {
  144. mm_prodcode:d.MP_PRODCODE,
  145. mm_oneuseqty: d.MM_ONEUSEQTY,
  146. mm_qty: d.MP_CANUSEQTY,
  147. pr_detail: d.PR_DETAIL,
  148. pr_spec: d.PR_SPEC,
  149. pr_unit: d.PR_UNIT,
  150. mm_thisqty: d.MP_THISQTY,
  151. mm_totaluseqty: d.MP_REPQTY,
  152. mm_whcode: d.MP_WHCODE,
  153. mm_detno: d.MP_DETNO,
  154. mm_id: d.MP_MMID,
  155. havegetqty: d.MP_HAVEREPQTY,
  156. mm_level:d.MM_LEVEL,
  157. mm_thisplanqty:d.MP_THISPLANQTY,
  158. mm_wipuseqty:d.MP_WIPUSEQTY,
  159. pr_wiponhand:d.PR_WIPONHAND,
  160. isrep: true,
  161. pr_location:d.PR_LOCATION
  162. });
  163. }
  164. });
  165. grid.lockrender = false;
  166. }
  167. grid.store.fireEvent('load', grid.store);
  168. }
  169. }
  170. });
  171. },
  172. setQty: function(){
  173. var ma_id = Ext.getCmp('ma_id').value;
  174. var qty = Ext.getCmp('setqty').value;
  175. var wipwhcode = Ext.getCmp('ma_xbwhouse').value;
  176. if(qty==null || qty==''){
  177. qty = 0;
  178. }
  179. Ext.Ajax.request({
  180. url : basePath + 'pm/make/setLSThisQty.action',
  181. async: false,
  182. params: {
  183. caller:caller,
  184. ma_id:ma_id,
  185. qty:qty,
  186. wipwhcode:wipwhcode
  187. },
  188. callback: function(opt, s, r){
  189. var res = Ext.decode(r.responseText);
  190. if(res.exceptionInfo) {
  191. showError(res.exceptionInfo);
  192. }
  193. }
  194. });
  195. },
  196. create:function(grid){
  197. var me = this,
  198. material = this.getEffectData(grid.selModel.getSelection());
  199. var wipwhcode=Ext.getCmp('ma_xbwhouse').value;
  200. var pi_departmentcode="",pi_emcode="",pi_cgycode="";
  201. if (Ext.getCmp('ma_departmentcode')){
  202. pi_departmentcode=Ext.getCmp('ma_departmentcode').value;
  203. };
  204. if (Ext.getCmp('ms_recordorcode')){
  205. pi_emcode=Ext.getCmp('ms_recordorcode').value;
  206. };
  207. if (Ext.getCmp('pr_whmancode')){
  208. pi_cgycode=Ext.getCmp('pr_whmancode').value;
  209. };
  210. if(material.length > 0){
  211. grid.setLoading(true);//loading...
  212. Ext.Ajax.request({
  213. url : basePath + 'pm/make/turnlssend.action',
  214. params: {
  215. data: Ext.encode(material),
  216. bywhcode: Ext.getCmp('bywhcode').checked,
  217. wipwhcode: wipwhcode,
  218. maid:Ext.getCmp('ma_id').value,
  219. caller:caller,
  220. departmentcode:pi_departmentcode,
  221. emcode:pi_emcode,
  222. cgycode:pi_cgycode
  223. },
  224. method : 'post',
  225. callback : function(options,success,response){
  226. grid.setLoading(false);
  227. var localJson = new Ext.decode(response.responseText);
  228. if(localJson.exceptionInfo){
  229. showError(localJson.exceptionInfo);
  230. }
  231. if(localJson.log){
  232. showMessage('提示', localJson.log);
  233. }
  234. if(localJson.success){
  235. turnSuccess(function(){
  236. });
  237. }
  238. me.onQuery();
  239. }
  240. });
  241. }
  242. },
  243. getEffectData: function(items) {
  244. var d = new Array();
  245. var code = Ext.getCmp('ma_code').value;
  246. Ext.Array.each(items, function(item){
  247. if(item.get('mm_thisqty') > 0 || item.get('mm_thisplanqty') > 0) {
  248. d.push({
  249. mm_code: code,
  250. mm_id: item.get('isrep') == null ? item.get('mm_id') : -item.get('mm_id'),
  251. mm_detno: item.get('mm_detno'),
  252. mm_thisqty: item.get('mm_thisqty'),
  253. mm_thisplanqty: item.get('mm_thisplanqty'),
  254. mm_wipuseqty: item.get('mm_wipuseqty'),
  255. mm_whcode: item.get('mm_whcode'),
  256. mm_prodcode: item.get('mm_prodcode')
  257. });
  258. }
  259. });
  260. return d;
  261. }
  262. });