MakeSendLS.js 9.9 KB

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