Inquiry.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.purchase.Inquiry', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. BaseUtil: Ext.create('erp.util.BaseUtil'),
  7. views:[
  8. 'core.form.Panel','scm.purchase.Inquiry','core.grid.Panel2','core.toolbar.Toolbar','core.form.FileField',
  9. 'core.button.Save','core.button.Update','core.button.Add','core.button.Submit','core.button.Print','core.button.Upload',
  10. 'core.button.Audit','core.button.Close','core.button.Delete','core.button.DeleteDetail','core.button.ResSubmit',
  11. 'core.button.ResAudit','core.button.HistoryQuotation','core.button.HistoryInPrice','core.button.UpdateMaxlimitInfo',
  12. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.button.TurnPurcPrice','core.button.AgreePrice','core.grid.YnColumn'
  13. ],
  14. init:function(){
  15. var me = this;
  16. me.alloweditor = true;
  17. this.control({
  18. 'erpGridPanel2': {
  19. afterrender: function(grid){
  20. var status = Ext.getCmp('in_statuscode');
  21. if(status && status.value != 'ENTERING' && status.value != 'COMMITED'){
  22. Ext.each(grid.columns, function(c){
  23. c.setEditor(null);
  24. });
  25. }
  26. },
  27. itemclick: this.onGridItemClick
  28. },
  29. 'erpSaveButton': {
  30. click: function(btn){
  31. var form = me.getForm(btn);
  32. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  33. me.BaseUtil.getRandomNumber();//自动添加编号
  34. }
  35. var bool = true;
  36. //供应商必填
  37. var grid = Ext.getCmp('grid'), start = Ext.getCmp('in_recorddate').value,
  38. end = Ext.getCmp('in_enddate').value;
  39. grid.getStore().each(function(item){
  40. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  41. if(item.data['id_vendcode'] == null || item.data['id_vendcode'] == ''){
  42. bool = false;
  43. showError('明细表第' + item.data['id_detno'] + '行的供应商为空');return;
  44. }
  45. if(item.data['id_fromdate'] ==null){
  46. item.set('id_fromdate', start);
  47. }
  48. if(item.data['id_todate'] ==null){
  49. item.set('id_todate', end);
  50. }
  51. if(Ext.Date.format(item.data['id_fromdate'],'Y-m-d') > Ext.Date.format(item.data['id_todate'],'Y-m-d')){
  52. bool=false;
  53. showError('明细有效开始日期大于截止日期,不能保存!');return;
  54. }
  55. if(Ext.Date.format(item.data['id_fromdate'],'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){
  56. bool=false;
  57. showError('明细有效开始日期小于当前日期,不能保存!');return;
  58. }
  59. }
  60. });
  61. if(bool){
  62. this.FormUtil.beforeSave(this);
  63. }
  64. }
  65. },
  66. 'erpUpdateButton': {
  67. click: function(btn){
  68. var bool = true;
  69. //供应商必填
  70. var grid = Ext.getCmp('grid'),
  71. fromDate = Ext.getCmp('in_recorddate').value,
  72. toDate = Ext.getCmp('in_enddate').value;
  73. grid.getStore().each(function(item){
  74. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  75. if(item.data['id_vendcode'] == null || item.data['id_vendcode'] == ''){
  76. bool = false;
  77. showError('明细表第' + item.data['id_detno'] + '行的供应商为空');return;
  78. }
  79. if(item.data['id_fromdate'] ==null ){
  80. item.set('id_fromdate',fromDate);
  81. }
  82. if(item.data['id_todate'] ==null){
  83. item.set('id_todate',toDate);
  84. }
  85. if(Ext.Date.format(item.data['id_fromdate'],'Y-m-d') > Ext.Date.format(item.data['id_todate'],'Y-m-d')){
  86. bool = false;
  87. showError('明细有效开始日期大于截止日期,不能保存!');return;
  88. }
  89. console.log(Ext.Date.format(item.data['id_fromdate'],'Y-m-d'));
  90. if(Ext.Date.format(item.data['id_fromdate'],'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){
  91. bool = false;
  92. showError('明细有效开始日期小于当前日期,不能保存!');return;
  93. }
  94. }
  95. });
  96. if(bool){
  97. this.FormUtil.onUpdate(this);
  98. }
  99. }
  100. },
  101. 'erpDeleteButton' : {
  102. click: function(btn){
  103. me.FormUtil.onDelete(Ext.getCmp('in_id').value);
  104. }
  105. },
  106. 'erpAddButton': {
  107. click: function(){
  108. me.FormUtil.onAdd('addInquiry', '新增询价单', 'jsps/scm/purchase/inquiry.jsp');
  109. }
  110. },
  111. 'erpUpdateMaxlimitInfoButton':{
  112. afterrender:function(btn){
  113. btn.setDisabled(true);
  114. },
  115. click: function(btn){
  116. var id=btn.ownerCt.ownerCt.ownerCt.items.items[1].selModel.selected.items[0].data["id_id"];
  117. var idstatus=btn.ownerCt.ownerCt.ownerCt.items.items[1].selModel.selected.items[0].data["id_status"];
  118. if(idstatus!='已报价'){
  119. showError("只能针对已报价的询价做限购");
  120. }else{
  121. var formCondition="id_id IS"+id;
  122. var linkCaller='InquiryMaxlimit';
  123. var win = new Ext.window.Window({
  124. id : 'win',
  125. height : '90%',
  126. width : '95%',
  127. maximizable : true,
  128. buttonAlign : 'center',
  129. layout : 'anchor',
  130. items : [ {
  131. tag : 'iframe',
  132. frame : true,
  133. anchor : '100% 100%',
  134. layout : 'fit',
  135. html : '<iframe id="iframe_'+linkCaller+'" src="'+basePath+'jsps/scm/purchase/inquiryMaxlimit.jsp?_noc=1&whoami='+linkCaller+'&formCondition='+formCondition+'" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
  136. } ],
  137. listeners:{
  138. 'beforeclose':function(view ,opt){
  139. //grid 刷新一次
  140. var grid=Ext.getCmp('grid');
  141. var gridParam = {caller: caller, condition: gridCondition};
  142. grid.GridUtil.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', gridParam, "");
  143. Ext.getCmp('updateMaxlimitInfo').setDisabled(true);
  144. }
  145. }
  146. });
  147. win.show();
  148. }
  149. }
  150. },
  151. 'erpCloseButton': {
  152. click: function(btn){
  153. me.FormUtil.beforeClose(me);
  154. }
  155. },
  156. 'erpSubmitButton': {
  157. afterrender: function(btn){
  158. var status = Ext.getCmp('in_statuscode');
  159. var checkstatus = Ext.getCmp('in_checkstatuscode').value;
  160. if(status && status.value != 'AUDITED'){
  161. btn.hide();
  162. }else if(checkstatus&&checkstatus!=null&&checkstatus!='ENTERING'){
  163. btn.hide();
  164. }
  165. },
  166. click: function(btn){
  167. /*Ext.getCmp('in_kind').setValue = 'ss';
  168. Ext.getCmp('in_enddate').setValue= 'ss';
  169. console.log('ce');
  170. me.FormUtil.onSubmit(Ext.getCmp('in_id').value);*/
  171. var inclass = Ext.getCmp('in_class');
  172. if(inclass&&inclass.value=='主动报价'){
  173. me.FormUtil.getActiveTab().setLoading(true);
  174. Ext.Ajax.request({
  175. url : basePath + 'scm/purchase/submitInquiry.action',
  176. params: {
  177. id: Ext.getCmp('in_id').value
  178. },
  179. method : 'post',
  180. callback : function(options,success,response){
  181. me.FormUtil.getActiveTab().setLoading(false);
  182. var localJson = new Ext.decode(response.responseText);
  183. if(localJson.exceptionInfo){
  184. showError(localJson.exceptionInfo);
  185. }
  186. if(localJson.success){
  187. window.location.reload();
  188. }
  189. }
  190. });
  191. }else{
  192. me.FormUtil.onSubmit(Ext.getCmp('in_id').value);
  193. }
  194. }
  195. },
  196. 'erpResSubmitButton': {
  197. afterrender: function(btn){
  198. var status = Ext.getCmp('in_checkstatuscode');
  199. if(status && status.value != 'COMMITED'){
  200. btn.hide();
  201. }
  202. },
  203. click: function(btn){
  204. me.FormUtil.onResSubmit(Ext.getCmp('in_id').value);
  205. }
  206. },
  207. 'erpAuditButton': {
  208. afterrender: function(btn){
  209. var status = Ext.getCmp('in_statuscode');
  210. if(status && status.value != 'ENTERING'){
  211. btn.hide();
  212. }
  213. },
  214. click: function(btn){
  215. me.FormUtil.onAudit(Ext.getCmp('in_id').value);
  216. }
  217. },
  218. 'erpResAuditButton': {
  219. afterrender: function(btn){
  220. var status = Ext.getCmp('in_statuscode');
  221. if(status && status.value != 'AUDITED'){
  222. btn.hide();
  223. }
  224. },
  225. click: function(btn){
  226. me.FormUtil.onResAudit(Ext.getCmp('in_id').value);
  227. }
  228. },
  229. 'erpPrintButton': {
  230. click: function(btn){
  231. me.FormUtil.onPrint(Ext.getCmp('in_id').value);
  232. }
  233. },
  234. 'erpAgreePriceButton': {
  235. afterrender: function(btn){
  236. var status = Ext.getCmp('in_statuscode');
  237. if(status && status.value != 'AUDITED'){
  238. btn.hide();
  239. }
  240. },
  241. click: function(btn){
  242. var appstatus = Ext.getCmp('in_checkstatuscode');
  243. if(appstatus && appstatus.value == 'APPROVED'){
  244. showError('审批完成的询价单不能进行最终判定!');return;
  245. }else{
  246. inid=Ext.getCmp('in_id').value;
  247. var url = basePath+'jsps/common/vastDatalist.jsp?_noc=1&whoami=ToPrice&urlcondition=id_inid='+inid+' and nvl(id_price,0)>0';
  248. var main = parent.parent.Ext.getCmp("content-panel");
  249. var panelId='Inquiry' + id;
  250. var title='采购询价转核价' + id;
  251. if(main){
  252. panelId = panelId == main.getActiveTab().id ? Math.random() : panelId;
  253. var panel = Ext.getCmp(panelId);
  254. if(!panel){
  255. var value = "";
  256. if (title.toString().length>5) {
  257. value = title.toString().substring(0,5);
  258. } else {
  259. value = title;
  260. }
  261. if(!contains(url, 'http://', true) && !contains(url, basePath, true)){
  262. url = basePath + url;
  263. }
  264. panel = {
  265. title : value,
  266. tag : 'iframe',
  267. tabConfig:{tooltip:title},
  268. frame : true,
  269. border : false,
  270. layout : 'fit',
  271. iconCls : 'x-tree-icon-tab-tab',
  272. html : '<iframe id="iframe_add_'+panelId+'" src="' + url+'" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>',
  273. closable : true
  274. };
  275. me.FormUtil.openTab(panel, panelId);
  276. } else {
  277. main.setActiveTab(panel);
  278. }
  279. } else {
  280. if(!contains(url, basePath, true)){
  281. url = basePath + url;
  282. }
  283. window.open(url);
  284. }
  285. }
  286. //me.FormUtil.onPrint(Ext.getCmp('in_id').value);
  287. }
  288. },
  289. 'erpTurnPurcPriceButton': {
  290. afterrender: function(btn){
  291. var status = Ext.getCmp('in_statuscode');
  292. if(status && status.value != 'AUDITED'){
  293. btn.hide();
  294. }
  295. },
  296. click: function(btn){
  297. warnMsg("确定要转入物料核价单吗?", function(btn){
  298. if(btn == 'yes'){
  299. me.FormUtil.getActiveTab().setLoading(true);//loading...
  300. Ext.Ajax.request({
  301. url : basePath + 'scm/purchase/turnPurcPrice.action',
  302. params: {
  303. id: Ext.getCmp('in_id').value
  304. },
  305. method : 'post',
  306. callback : function(options,success,response){
  307. me.FormUtil.getActiveTab().setLoading(false);
  308. var localJson = new Ext.decode(response.responseText);
  309. if(localJson.exceptionInfo){
  310. showError(localJson.exceptionInfo);
  311. }
  312. if(localJson.success){
  313. turnSuccess(function(){
  314. var id = localJson.id;
  315. var url = "jsps/scm/purchase/purchasePrice.jsp?formCondition=pp_id=" + id +
  316. "&gridCondition=ppd_ppid=" + id;
  317. me.FormUtil.onAdd('PurchasePrice' + id, '物料核价单' + id, url);
  318. });
  319. }
  320. }
  321. });
  322. }
  323. });
  324. }
  325. },
  326. /**
  327. * 查看历史入库价
  328. */
  329. 'button[id=historyin]': {
  330. click: function(){
  331. var record = Ext.getCmp('grid').selModel.lastSelected;
  332. if(record){
  333. var prod = record.data['id_prodcode'];
  334. var win = Ext.getCmp('in-win');
  335. if(win == null){
  336. win = Ext.create('Ext.window.Window', {
  337. id: 'in-win',
  338. width: '80%',
  339. height: '100%',
  340. maximizable : true,
  341. layout: 'anchor',
  342. closeAction: 'hide',
  343. items: [Ext.create('erp.view.core.grid.Panel2', {
  344. id: 'inhistory',
  345. anchor: '100% 100%',
  346. caller: 'ProdInOut!In!History',
  347. condition: "pd_prodcode='" + prod + "' order by pd_prodmadedate desc",
  348. bbar: null
  349. })],
  350. setMyTitle: function(code){//@param code 料号
  351. this.setTitle('编号:<font color=blue>' + code + '</font>&nbsp;的历史入库价&nbsp;&nbsp;' +
  352. '<input type="button" value="上一条" onClick="javascript:Ext.getCmp(\'in-win\').prev();" style="cursor: pointer;color:gray;font-size:13px;"/>' +
  353. '<input type="button" value="下一条" onClick="javascript:Ext.getCmp(\'in-win\').next();" style="cursor: pointer;color:gray;font-size:13px;"/>');
  354. },
  355. reload: function(code){//@param code 料号
  356. var g = this.down('grid[id=inhistory]');
  357. g.GridUtil.loadNewStore(g, {
  358. caller: g.caller,
  359. condition: "pd_prodcode='" + code + "' order by pd_prodmadedate desc"
  360. });
  361. this.setMyTitle(code);
  362. },
  363. prev: function(){//查看上一条
  364. var item = Ext.getCmp('grid').prev();
  365. if(item != null){
  366. this.reload(item.data['id_prodcode']);
  367. }
  368. },
  369. next: function(){//查看下一条
  370. var item = Ext.getCmp('grid').next();
  371. if(item != null){
  372. this.reload(item.data['id_prodcode']);
  373. }
  374. }
  375. });
  376. win.setMyTitle(prod);
  377. win.show();
  378. } else {
  379. win.reload(prod);
  380. win.show();
  381. }
  382. } else {
  383. alert("请先选择明细!");
  384. }
  385. }
  386. },
  387. /**
  388. * 查看历史报价
  389. */
  390. 'button[id=historyquo]': {
  391. click: function(){
  392. var record = Ext.getCmp('grid').selModel.lastSelected;
  393. if(record){
  394. var prod = record.data['id_prodcode'];
  395. var win = Ext.getCmp('history-win');
  396. if(win == null){
  397. win = Ext.create('Ext.window.Window', {
  398. id: 'history-win',
  399. width: '80%',
  400. height: '100%',
  401. maximizable : true,
  402. layout: 'anchor',
  403. closeAction: 'hide',
  404. setMyTitle: function(code){//@param code 料号
  405. this.setTitle('编号:<font color=blue>' + code + '</font>&nbsp;的报价历史&nbsp;&nbsp;' +
  406. '<input type="button" value="上一条" onClick="javascript:Ext.getCmp(\'history-win\').prev();" style="cursor: pointer;color:gray;font-size:13px;"/>' +
  407. '<input type="button" value="下一条" onClick="javascript:Ext.getCmp(\'history-win\').next();" style="cursor: pointer;color:gray;font-size:13px;"/>');
  408. },
  409. reload: function(code){//@param code 料号
  410. var g = this.down('grid[id=history]');
  411. g.GridUtil.loadNewStore(g, {
  412. caller: g.caller,
  413. condition: "id_prodcode='" + code + "'"
  414. });
  415. g = this.down('grid[id=invid]');
  416. g.GridUtil.loadNewStore(g, {
  417. caller: g.caller,
  418. condition: "ppd_prodcode='" + code + "' AND ppd_statuscode='VALID'"
  419. });
  420. this.setMyTitle(code);
  421. },
  422. prev: function(){//查看上一条
  423. var item = Ext.getCmp('grid').prev();
  424. if(item != null){
  425. this.reload(item.data['id_prodcode']);
  426. }
  427. },
  428. next: function(){//查看下一条
  429. var item = Ext.getCmp('grid').next();
  430. if(item != null){
  431. this.reload(item.data['id_prodcode']);
  432. }
  433. }
  434. });
  435. win.setMyTitle(prod);
  436. win.show();
  437. win.add(Ext.create('erp.view.core.grid.Panel2', {
  438. id: 'history',
  439. anchor: '100% 60%',
  440. caller: 'Inquiry!History',
  441. condition: "id_prodcode='" + prod + "'",
  442. bbar: null,
  443. listeners: {
  444. reconfigure: function(){
  445. win.add(Ext.create('erp.view.core.grid.Panel2', {
  446. id: 'invid',
  447. title: '现有效价格',
  448. anchor: '100% 40%',
  449. caller: 'PurchasePrice!Invid',
  450. condition: "ppd_prodcode='" + prod + "' AND ppd_statuscode='VALID'",
  451. bbar: null
  452. }));
  453. }
  454. }
  455. }));
  456. } else {
  457. win.reload(prod);
  458. win.show();
  459. }
  460. } else {
  461. alert("请先选择明细!");
  462. }
  463. }
  464. }
  465. });
  466. },
  467. onGridItemClick: function(selModel, record){//grid行选择
  468. this.GridUtil.onGridItemClick(selModel, record);
  469. var grid=selModel.ownerCt;
  470. var show=0;
  471. Ext.Array.each(grid.necessaryFields, function(field) {
  472. var fieldValue=record.data[field];
  473. if(fieldValue==undefined||fieldValue==""||fieldValue==null){
  474. show=1;
  475. return;
  476. }
  477. });
  478. if(show==1){
  479. Ext.getCmp('updateMaxlimitInfo').setDisabled(true);
  480. }else {
  481. Ext.getCmp('updateMaxlimitInfo').setDisabled(false);
  482. }
  483. },
  484. getForm: function(btn){
  485. return btn.ownerCt.ownerCt;
  486. }
  487. });