MRPThrow.js 15 KB

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