MRPThrow.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.mps.MRPThrow', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.FormUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil', 'erp.util.RenderUtil'],
  5. views:[
  6. 'common.batchDeal.Viewport','common.batchDeal.Form','pm.mps.MRPThrowGrid','core.button.ScanReplaceProd','pm.mps.MrpReplaceGrid','core.button.SupplyTurnNeed',
  7. 'core.trigger.DbfindTrigger','core.form.FtField','core.form.FtFindField','core.form.ConDateField','core.form.ConMonthDateField','core.form.YnField',
  8. 'core.button.VastDeal','core.button.VastPrint','core.button.VastAnalyse','core.button.GetVendor','core.form.FtDateField',
  9. 'core.button.VastTurnPurc','core.trigger.TextAreaTrigger','core.form.YnField','core.grid.YnColumn','core.button.DealMake','core.button.Close',
  10. 'core.button.MakeOccur','core.button.SaleOccur','core.button.AllThrow','core.button.SelectThrow','core.button.AvailableReplaceProd','core.form.MonthDateField',
  11. 'core.button.TurnGoodsUp'
  12. ],
  13. init:function(){
  14. var me = this;
  15. this.FormUtil = Ext.create('erp.util.FormUtil');
  16. this.control({
  17. 'erpBatchDealGridPanel': {
  18. afterrender: function(grid){
  19. var form = Ext.getCmp('dealform');
  20. if(form && form.items.items.length > 0){
  21. //根据form字段的多少来调节form所占高度
  22. var height = window.innerHeight;
  23. if(Ext.isIE){
  24. height = screen.height*0.75;
  25. }
  26. var cw = 0;
  27. Ext.each(form.items.items, function(){
  28. cw += this.columnWidth;
  29. });
  30. cw = Math.ceil(cw);
  31. if(cw == 0){
  32. cw = 5;
  33. } else if(cw > 2 && cw <= 5){
  34. cw -= 1;
  35. } else if(cw > 5 && cw < 8){
  36. cw = 4;
  37. }
  38. cw = Math.min(cw, 5);
  39. form.setHeight(height*cw/10 + 10);
  40. grid.setHeight(height*(10 - cw)/10 - 10);
  41. }
  42. grid.down('#storeCount').update({
  43. count: grid.store.totalCount
  44. });
  45. grid.store.on('datachanged',function(store){
  46. grid.selModel.select(grid.multiselected);
  47. });
  48. },
  49. storeloaded:function(grid){
  50. grid.down('#storeCount').update({
  51. count: grid.store.totalCount
  52. });
  53. grid.multiselected=[];
  54. }
  55. },
  56. 'erpSelectThrowButton': {
  57. click: function(btn){
  58. var gridStore = me.NeedSelectThrow();
  59. if(gridStore != null){
  60. me.NeedThrow(gridStore)
  61. };
  62. }
  63. },
  64. 'erpVastDealButton': {
  65. click: function(btn){
  66. var gridStore = me.NeedSelectThrow();
  67. if(gridStore != null){
  68. if(caller == 'MRPOnhandThrow'){
  69. me.GoodsUp(gridStore,btn);
  70. }else{
  71. me.NeedThrow(gridStore);
  72. }
  73. };
  74. }
  75. },
  76. 'condatefield[name=md_needdate]':{
  77. afterrender:function(field){
  78. field.combo.setValue(7);
  79. field.setDateFieldValue(7);
  80. }
  81. },
  82. 'dbfindtrigger[name=md_mpscode]':{
  83. afterrender:function(field){
  84. field.setValue(getUrlParam('mpscode'));
  85. }
  86. },
  87. 'erpAvailableReplaceProdButton': {
  88. click: function(btn){
  89. var urlcon=Ext.create('erp.util.BaseUtil').getUrlParam('urlcondition');
  90. if(urlcon){
  91. var array=urlcon.split('AND');
  92. var id=array[0].split('=')[1].trim().replace(/'/g,"");
  93. }
  94. var condition="md_mpsid='"+id+"'";
  95. me.FormUtil.onAdd('MRPNeedReplace','可用替代维护','/jsps/common/batchDeal.jsp?whoami=MRPNeedReplace&_noc=1&urlcondition='+condition);
  96. }
  97. },
  98. 'erpScanReplaceProdButton':{
  99. click:function(btn){
  100. var grid=Ext.getCmp('batchDealGridPanel');
  101. var selected = grid.getSelectionModel().getLastSelected( );
  102. var value=selected.data[grid.keyField];
  103. Ext.create('Ext.window.Window', {
  104. title: '查看替代料',
  105. height:400,
  106. width: 505,
  107. id:'win',
  108. layout: 'fit',
  109. items: {
  110. xtype: 'MrpReplaceGrid',
  111. border: false,
  112. caller:'MRPReplace',
  113. condition:"mr_mdid="+value
  114. },
  115. buttonAlign:'center',
  116. buttons:[{
  117. xtype:'button',
  118. text: $I18N.common.button.erpCloseButton,
  119. iconCls: 'x-button-icon-close',
  120. cls: 'x-btn-gray',
  121. width: 60,
  122. style: {
  123. marginLeft: '10px'
  124. },
  125. handler:function(btn){
  126. btn.ownerCt.ownerCt.close();
  127. }
  128. }]
  129. }).show();
  130. }
  131. },
  132. 'erpVastPrintButton':{
  133. beforerender:function(btn){
  134. btn.handler=function(){
  135. var kind=caller;
  136. var idStr='';
  137. var title='';
  138. var dateFW='';
  139. var mpscode=Ext.getCmp('md_mpscode').value;
  140. var reportName='MRPData';
  141. if(caller=="MPSNeed"){
  142. condition='{MRPData.md_mpscode}='+"'"+mpscode+"'"+' and '+'{MRPData.md_kind}='+"'NEED'"+' and '+'{PRODUCT.pr_supplytype}<>'+"'虚拟件'";
  143. }
  144. if(caller=="MPSSupply"){
  145. condition='{MRPData.md_mpscode}='+"'"+mpscode+"'"+' and '+'{MRPData.md_kind}='+"'SUPPLY'"+' and '+'{PRODUCT.pr_supplytype}<>'+"'虚拟件'";
  146. }
  147. me.FormUtil.batchPrint(idStr,reportName,condition,title,dateFW);
  148. };
  149. }
  150. },
  151. 'erpSupplyTurnNeedButton':{
  152. click:function(){
  153. me.SupplyTurnNeed();
  154. }
  155. },
  156. 'erpAllThrowButton':{
  157. afterrender:function(btn){
  158. //处理一些需要条件传回来赋值
  159. var urlcon=Ext.create('erp.util.BaseUtil').getUrlParam('urlcondition');
  160. if(urlcon){
  161. var array=urlcon.split('AND');
  162. for(var i=0;i<array.length;i++){
  163. var field=Ext.getCmp(array[i].split('=')[0].trim());
  164. if(field){
  165. field.setValue(array[i].split('=')[1].trim().replace(/'/g,""));
  166. }
  167. }
  168. }
  169. if(caller=='MPSSupply'){
  170. btn.hide();
  171. }
  172. } ,
  173. click: function(btn){
  174. warnMsg("确定要投放当前筛选结果的所有需求?", function(btn){
  175. me.NeedThrowBycondition();
  176. });
  177. }
  178. },
  179. 'combo[name=md_sourcekind]':{
  180. select :function(field){
  181. }
  182. }
  183. });
  184. },
  185. countGrid: function(){
  186. //重新计算合计栏值
  187. var grid = Ext.getCmp('batchDealGridPanel');
  188. Ext.each(grid.columns, function(column){
  189. if(column.summary){
  190. var sum = 0;
  191. Ext.each(grid.store.data.items, function(item){
  192. if(item.value != null && item.value != ''){
  193. sum += Number(item.value);
  194. }
  195. });
  196. Ext.getCmp(column.dataIndex + '_sum').setText(column.text + '(sum):' + sum);
  197. } else if(column.average) {
  198. var average = 0;
  199. Ext.each(grid.store.data.items, function(item){
  200. if(item.value != null && item.value != ''){
  201. average += Number(item.value);
  202. }
  203. });
  204. average = average/grid.store.data.items.length;
  205. Ext.getCmp(column.dataIndex + '_average').setText(column.text + '(average):' + average);
  206. } else if(column.count) {
  207. var count = 0;
  208. Ext.each(grid.store.data.items, function(item){
  209. if(item.value != null && item.value != ''){
  210. count++;
  211. }
  212. });
  213. Ext.getCmp(column.dataIndex + '_count').setText(column.text + '(count):' + count);
  214. }
  215. });
  216. },
  217. getCondition: function(){
  218. var grid = Ext.getCmp('batchDealGridPanel');
  219. //grid.multiselected = new Array();
  220. var form = Ext.getCmp('dealform');
  221. var condition = grid.defaultCondition || '';
  222. Ext.each(form.items.items, function(f){
  223. if(f.logic != null && f.logic != ''){
  224. if(f.xtype == 'checkbox' && f.value == true){
  225. if(condition == ''){
  226. condition += f.logic;
  227. } else {
  228. condition += ' AND ' + f.logic;
  229. }
  230. } else if(f.xtype == 'datefield' && f.value != null){
  231. var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
  232. if(condition == ''){
  233. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  234. } else {
  235. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  236. }
  237. } else if(f.xtype == 'datetimefield' && f.value != null){
  238. var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
  239. if(condition == ''){
  240. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  241. } else {
  242. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  243. }
  244. } else if(f.xtype == 'numberfield' && f.value != null && f.value != ''){
  245. if(condition == ''){
  246. condition += f.logic + '=' + f.value;
  247. } else {
  248. condition += ' AND ' + f.logic + '=' + f.value;
  249. }
  250. } else {
  251. //一般情况下,在执行批量处理时,是不需要把form的数据传回去,
  252. //但某些情况下,需要将form的某些字段的值也传回去
  253. //例如 请购批量转采购,如果指定了采购单号,就要把采购单号传回去
  254. if(contains(f.logic, 'to:', true)){
  255. if(!grid.toField){
  256. grid.toField = new Array();
  257. }
  258. grid.toField.push(f.logic.split(':')[1]);
  259. } else {
  260. if(f.value != null && f.value != ''){
  261. if(contains(f.value, 'BETWEEN', true) && contains(f.value, 'AND', true)){
  262. if(condition == ''){
  263. condition += f.logic + " " + f.value;
  264. } else {
  265. condition += ' AND (' + f.logic + " " + f.value + ")";
  266. }
  267. } else if(contains(f.value, '||', true)){
  268. var str = '';
  269. Ext.each(f.value.split('||'), function(v){
  270. if(v != null && v != ''){
  271. if(str == ''){
  272. str += f.logic + "='" + v + "'";
  273. } else {
  274. str += ' OR ' + f.logic + "='" + v + "'";
  275. }
  276. }
  277. });
  278. if(condition == ''){
  279. condition += "(" + str + ")";
  280. } else {
  281. condition += ' AND (' + str + ")";
  282. }
  283. } else {
  284. if(condition == ''){
  285. condition += f.logic + "='" + f.value + "'";
  286. } else {
  287. condition += ' AND (' + f.logic + "='" + f.value + "')";
  288. }
  289. }
  290. }
  291. }
  292. }
  293. }
  294. });
  295. return condition;
  296. },
  297. NeedSelectThrow: function(){ //获取选取的需要操作的明细
  298. var grid = Ext.getCmp('batchDealGridPanel');
  299. var count=0;
  300. if(grid.multiselected.length==0){
  301. var items = grid.selModel.getSelection();
  302. Ext.each(items, function(item, index){
  303. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  304. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  305. grid.multiselected.push(item);
  306. }
  307. });
  308. }
  309. var records = Ext.Array.unique(grid.multiselected);
  310. var gridStore = new Array();
  311. var dd;
  312. if(records.length>0){
  313. Ext.each(records, function(records, index){
  314. if(records.data.md_prodcode!=''){
  315. dd=new Object();
  316. dd['md_id']=records.data.md_id;
  317. gridStore[index] = Ext.JSON.encode(dd);
  318. count++;
  319. }
  320. });
  321. return gridStore;
  322. } else {
  323. showError("没有需要处理的数据!");
  324. return ;
  325. }
  326. },
  327. NeedThrow:function(store){
  328. if(this.throwing) {
  329. alert('正在执行...不要重复点击!');
  330. return;
  331. }
  332. var me = this, gridstore = store;
  333. var main = parent.Ext.getCmp("content-panel");
  334. main.getActiveTab().setLoading(true);//loading...
  335. var btn = Ext.getCmp('erpSelectThrowButton');
  336. if(btn) btn.setDisabled(true);
  337. this.throwing = true;
  338. Ext.Ajax.request({
  339. url : basePath + "pm/MPSMain/NeedThrow.action",
  340. params: {
  341. mainCode:Ext.getCmp('md_mpscode').value,
  342. caller:caller,
  343. gridStore:unescape(gridstore.toString().replace(/\\/g,"%")),
  344. toWhere:'AUTO',
  345. toCode:Ext.getCmp('md_ordercode').value,
  346. condition:''
  347. },
  348. timeout: 60000,
  349. method : 'post',
  350. callback : function(options,success,response){
  351. btn.setDisabled(false);
  352. me.throwing = false;
  353. main.getActiveTab().setLoading(false);
  354. var localJson = new Ext.decode(response.responseText);
  355. if(localJson.exceptionInfo){
  356. showError(localJson.exceptionInfo);
  357. return "";
  358. }
  359. if(localJson.success){
  360. if(localJson.log){
  361. showMessage("提示", localJson.log);
  362. }
  363. Ext.Msg.alert("提示", "处理成功!", function(){
  364. Ext.getCmp('dealform').onQuery();
  365. });
  366. }
  367. }
  368. });
  369. },
  370. NeedThrowBycondition:function(){
  371. var condition="";
  372. condition=this.getCondition();
  373. var main = parent.Ext.getCmp("content-panel");
  374. if (Ext.getCmp('pr_manutype').value!='PURCHASE'){
  375. showMessage("提示", "全部投放必须选择生产类型[外购]的物料");
  376. return;
  377. }
  378. main.getActiveTab().setLoading(true);//loading...
  379. Ext.Ajax.request({
  380. url : basePath + "pm/MPSMain/NeedThrow.action",
  381. params: {
  382. mainCode:Ext.getCmp('md_mpscode').value,
  383. caller:"MpsNeed",
  384. gridStore:null,
  385. toWhere:'AUTO',
  386. toCode:Ext.getCmp('md_ordercode').value,
  387. condition:condition
  388. },
  389. method : 'post',
  390. timeout: 60000,
  391. callback : function(options,success,response){
  392. main.getActiveTab().setLoading(false);
  393. var localJson = new Ext.decode(response.responseText);
  394. if(localJson.exceptionInfo){
  395. showError(localJson.exceptionInfo);
  396. return "";
  397. }
  398. if(localJson.success){
  399. if(localJson.log){
  400. showMessage("提示", localJson.log);
  401. }
  402. Ext.Msg.alert("提示", "处理成功!", function(){
  403. Ext.getCmp('dealform').onQuery();
  404. });
  405. }
  406. }
  407. });
  408. },
  409. SupplyTurnNeed:function(){
  410. var grid = Ext.getCmp('batchDealGridPanel');
  411. var count=0;
  412. if(grid.multiselected.length==0){
  413. var items = grid.selModel.getSelection();
  414. Ext.each(items, function(item, index){
  415. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  416. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  417. grid.multiselected.push(item);
  418. }
  419. });
  420. }
  421. var records = Ext.Array.unique(grid.multiselected);
  422. var gridStore = new Array();
  423. var dd;
  424. if(records.length>0){
  425. Ext.each(records, function(records, index){
  426. if(records.data.md_prodcode!=''){
  427. dd=new Object();
  428. dd['md_id']=records.data.md_id;
  429. gridStore[index] = Ext.JSON.encode(dd);
  430. count++;
  431. }
  432. });
  433. var main = parent.Ext.getCmp("content-panel");
  434. main.getActiveTab().setLoading(true);//loading...
  435. Ext.Ajax.request({
  436. url : basePath + "pm/mps/turnsupplytoneed.action",
  437. params: {
  438. mainCode:Ext.getCmp('md_mpscode').value,
  439. gridStore:unescape(gridStore.toString().replace(/\\/g,"%"))
  440. },
  441. method : 'post',
  442. callback : function(options,success,response){
  443. main.getActiveTab().setLoading(false);
  444. var localJson = new Ext.decode(response.responseText);
  445. if(localJson.exceptionInfo){
  446. showError(localJson.exceptionInfo);
  447. return "";
  448. }
  449. if(localJson.success){
  450. if(localJson.log){
  451. showMessage("提示", localJson.log);
  452. }
  453. Ext.Msg.alert("提示", "处理成功!", function(){
  454. Ext.getCmp('dealform').onQuery();
  455. });
  456. }
  457. }
  458. });
  459. } else {
  460. showError("没有需要处理的数据!");
  461. }
  462. }
  463. });