Purchase.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.purchase.Purchase', {
  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: ['core.form.Panel', 'scm.purchase.Purchase', 'core.grid.Panel2', 'core.toolbar.Toolbar',
  8. 'core.form.MultiField', 'core.button.Save', 'core.button.Add', 'core.button.Submit',
  9. 'core.button.Print', 'core.button.PrintHK', 'core.button.PrintEn','core.button.Upload', 'core.button.ResAudit',
  10. 'core.button.Audit', 'core.button.Close', 'core.button.Delete', 'core.button.Update', 'core.button.B2B',
  11. 'core.button.DeleteDetail', 'core.button.ResSubmit', 'core.button.End','core.button.Printyestax', 'core.button.Printnotax',
  12. 'core.button.DeleteDetail', 'core.button.ResSubmit', 'core.button.End','core.button.AttendDataCom',
  13. 'core.button.ResEnd', 'core.button.GetPrice', 'core.button.Export', 'core.button.StandardPrice',
  14. 'core.trigger.DbfindTrigger', 'core.trigger.TextAreaTrigger', 'core.form.YnField',
  15. 'core.grid.YnColumn', 'core.form.StatusField', 'core.form.FileField', 'core.button.PrintA4',
  16. 'core.button.CopyAll', 'core.button.ResetSync', 'core.button.RefreshSync','core.button.RefreshQty','core.button.Split'],
  17. init: function() {
  18. var me = this;
  19. this.control({
  20. 'erpGridPanel2': {
  21. afterrender: function(grid) {
  22. var status = Ext.getCmp('pu_statuscode');
  23. if (status && status.value != 'ENTERING' && status.value != 'COMMITED') {
  24. Ext.each(grid.columns,
  25. function(c) {
  26. c.setEditor(null);
  27. });
  28. }
  29. },
  30. itemclick: this.onGridItemClick
  31. },
  32. 'erpSaveButton': {
  33. click: function(btn) {
  34. var form = me.getForm(btn), codeField = Ext.getCmp(form.codeField);
  35. if(codeField.value == null || codeField.value == ''){
  36. me.BaseUtil.getRandomNumber(caller);//自动添加编号
  37. var res = me.getLeadCode(Ext.getCmp('pu_kind').value);
  38. if(res != null && res != ''){
  39. codeField.setValue(res + codeField.getValue());
  40. }
  41. }
  42. //保存之前的一些前台的逻辑判定
  43. this.beforeSavePurchase();
  44. }
  45. },
  46. 'erpDeleteButton': {
  47. click: function(btn) {
  48. me.FormUtil.onDelete(Ext.getCmp('pu_id').value);
  49. }
  50. },
  51. 'erpAttendDataComButton':{
  52. beforerender:function(btn){
  53. btn.setText("计算");
  54. },
  55. click: function(btn){
  56. var id=Ext.getCmp('pu_id').value;
  57. grid = Ext.getCmp('grid');
  58. Ext.Ajax.request({
  59. url : basePath + "scm/purchase/purchasedataupdate.action",
  60. params: {
  61. id:id
  62. },
  63. method : 'post',
  64. async: false,
  65. callback : function(options,success,response){
  66. var res = new Ext.decode(response.responseText);
  67. if(res.exceptionInfo){
  68. showError(res.exceptionInfo);
  69. return;
  70. }
  71. grid.GridUtil.loadNewStore(grid,{
  72. caller:'Purchase',
  73. condition:gridCondition,
  74. _noc:1
  75. });
  76. showError("计算成功!");
  77. }
  78. });
  79. }
  80. },
  81. 'erpGetPriceButton': {
  82. afterrender: function(btn) {
  83. var status = Ext.getCmp('pu_statuscode');
  84. if (status && status.value != 'ENTERING') {
  85. btn.hide();
  86. }
  87. },
  88. click: function(btn) {
  89. id = Ext.getCmp('pu_id').value;
  90. Ext.Ajax.request({
  91. url: basePath + "scm/purchase/getPrice.action",
  92. params: {
  93. id: id
  94. },
  95. method: 'post',
  96. callback: function(options, success, response) {
  97. var res = new Ext.decode(response.responseText);
  98. if (res.exceptionInfo != null) {
  99. showError(res.exceptionInfo);
  100. return;
  101. }
  102. if (res.success) {
  103. updateSuccess(function(btn) {
  104. //update成功后刷新页面进入可编辑的页面
  105. window.location.reload();
  106. });
  107. }
  108. }
  109. });
  110. }
  111. },
  112. 'erpStandardPriceButton': {
  113. afterrender: function(btn) {
  114. var status = Ext.getCmp('pu_statuscode');
  115. if (status && status.value != 'ENTERING') {
  116. btn.hide();
  117. }
  118. },
  119. click: function(btn) {
  120. id = Ext.getCmp('pu_id').value;
  121. Ext.Ajax.request({
  122. url: basePath + "scm/purchase/getStandardPrice.action",
  123. params: {
  124. id: id
  125. },
  126. method: 'post',
  127. callback: function(options, success, response) {
  128. var res = new Ext.decode(response.responseText);
  129. if (res.exceptionInfo != null) {
  130. showError(res.exceptionInfo);
  131. return;
  132. }
  133. if (res.success) {
  134. updateSuccess(function(btn) {
  135. //update成功后刷新页面进入可编辑的页面
  136. window.location.reload();
  137. });
  138. }
  139. }
  140. });
  141. }
  142. },
  143. 'erpUpdateButton': {
  144. afterrender: function(btn) {
  145. var status = Ext.getCmp('pu_statuscode');
  146. if (status && status.value != 'ENTERING') {
  147. btn.hide();
  148. }
  149. },
  150. click: function(btn) {
  151. me.beforeUpdate();
  152. }
  153. },
  154. 'erpAddButton': {
  155. click: function() {
  156. me.FormUtil.onAdd('addPurchase', '新增采购单', 'jsps/scm/purchase/purchase.jsp');
  157. }
  158. },
  159. 'erpCloseButton': {
  160. click: function(btn) {
  161. me.FormUtil.beforeClose(me);
  162. }
  163. },
  164. 'erpSubmitButton': {
  165. afterrender: function(btn) {
  166. var status = Ext.getCmp('pu_statuscode');
  167. if (status && status.value != 'ENTERING') {
  168. btn.hide();
  169. }
  170. },
  171. click: function(btn) {
  172. var grid = Ext.getCmp('grid');
  173. var items = grid.store.data.items;
  174. var bool = true;
  175. //数量不能为空或0
  176. Ext.each(items,
  177. function(item) {
  178. if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
  179. if (item.data['pd_qty'] == null) {
  180. bool = false;
  181. showError('明细表第' + item.data['pd_detno'] + '行的数量为空');
  182. return;
  183. }
  184. }
  185. });
  186. //物料交货日期不能小于录入日期
  187. Ext.each(items,
  188. function(item) {
  189. if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
  190. if (item.data['pd_delivery'] == null) {
  191. bool = false;
  192. showError('明细表第' + item.data['pd_detno'] + '行的承诺日期为空');
  193. return;
  194. } else if (item.data['pd_delivery'] < Ext.getCmp('pu_indate').value) {
  195. bool = false;
  196. showError('明细表第' + item.data['pd_detno'] + '行的承诺日期小于单据录入日期');
  197. return;
  198. }
  199. }
  200. });
  201. if (bool) {
  202. me.FormUtil.onSubmit(Ext.getCmp('pu_id').value);
  203. }
  204. }
  205. },
  206. 'erpResSubmitButton': {
  207. afterrender: function(btn) {
  208. var status = Ext.getCmp('pu_statuscode');
  209. if (status && status.value != 'COMMITED') {
  210. btn.hide();
  211. }
  212. },
  213. click: function(btn) {
  214. me.FormUtil.onResSubmit(Ext.getCmp('pu_id').value);
  215. }
  216. },
  217. 'erpAuditButton': {
  218. afterrender: function(btn) {
  219. var status = Ext.getCmp('pu_statuscode');
  220. if (status && status.value != 'COMMITED') {
  221. btn.hide();
  222. }
  223. },
  224. click: function(btn) {
  225. me.FormUtil.onAudit(Ext.getCmp('pu_id').value);
  226. }
  227. },
  228. 'erpB2BButton': {
  229. afterrender: function(btn) {
  230. var status = Ext.getCmp('pu_statuscode');
  231. if (status && status.value != 'AUDITED') {
  232. btn.hide();
  233. }
  234. },
  235. click: function(btn) {
  236. me.FormUtil.onB2b(Ext.getCmp('pu_id').value);
  237. }
  238. },
  239. 'erpResAuditButton': {
  240. afterrender: function(btn) {
  241. var status = Ext.getCmp('pu_statuscode');
  242. if (status && status.value != 'AUDITED') {
  243. btn.hide();
  244. }
  245. },
  246. click: function(btn) {
  247. me.FormUtil.onResAudit(Ext.getCmp('pu_id').value);
  248. }
  249. },
  250. 'erpEndButton': {
  251. afterrender: function(btn) {
  252. var status = Ext.getCmp('pu_statuscode');
  253. if (status && status.value != 'AUDITED') {
  254. btn.hide();
  255. }
  256. },
  257. click: function(btn) {
  258. me.FormUtil.onEnd(Ext.getCmp('pu_id').value);
  259. }
  260. },
  261. 'erpResEndButton': {
  262. afterrender: function(btn) {
  263. var status = Ext.getCmp('pu_statuscode');
  264. if (status && status.value != 'FINISH') {
  265. btn.hide();
  266. }
  267. },
  268. click: function(btn) {
  269. me.FormUtil.onResEnd(Ext.getCmp('pu_id').value);
  270. }
  271. },
  272. /**
  273. * 更改供应商回复信息
  274. */
  275. '#updatevendorbackInfo': {
  276. click: function(btn) {
  277. var record = btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
  278. me.UpdateVendorInfo(record);
  279. }
  280. },
  281. /**
  282. * 更改采购回复信息
  283. */
  284. '#updatepurcbackInfo': {
  285. click: function(btn) {
  286. var record = btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
  287. me.UpdatePurcInfo(record);
  288. }
  289. },
  290. 'erpPrintA4Button':{
  291. click: function(btn) {
  292. var reportName = '';
  293. reportName = "PURCLIST_A4";
  294. var condition = '{Purchase.pu_id}=' + Ext.getCmp('pu_id').value + '';
  295. var id = Ext.getCmp('pu_id').value;
  296. me.FormUtil.onwindowsPrint(id, reportName, condition);
  297. }
  298. },
  299. 'erpPrintButton': {
  300. click: function(btn) {
  301. var reportName = '';
  302. reportName = "PURCLIST";
  303. var condition = '{Purchase.pu_id}=' + Ext.getCmp('pu_id').value + '';
  304. var id = Ext.getCmp('pu_id').value;
  305. me.FormUtil.onwindowsPrint(id, reportName, condition);
  306. }
  307. },
  308. 'erpPrintEnButton': {
  309. click: function(btn) {
  310. var reportName = '';
  311. reportName = "PURCLIST_EN";
  312. var condition = '{Purchase.pu_id}=' + Ext.getCmp('pu_id').value + '';
  313. var id = Ext.getCmp('pu_id').value;
  314. me.FormUtil.onwindowsPrint(id, reportName, condition);
  315. }
  316. },
  317. 'erpPrintHKButton': {
  318. click: function(btn) {
  319. var reportName = '';
  320. reportName = "PURCLIST_HK";
  321. var condition = '{Purchase.pu_id}=' + Ext.getCmp('pu_id').value + '';
  322. var id = Ext.getCmp('pu_id').value;
  323. me.FormUtil.onwindowsPrint(id, reportName, condition);
  324. }
  325. },
  326. 'erpPrintyestaxButton': {
  327. click: function(btn) {
  328. var reportName = '';
  329. reportName = "PURCLIST_yestax";
  330. var condition = '{Purchase.pu_id}=' + Ext.getCmp('pu_id').value + '';
  331. var id = Ext.getCmp('pu_id').value;
  332. me.FormUtil.onwindowsPrint(id, reportName, condition);
  333. }
  334. },
  335. 'erpPrintnotaxButton': {
  336. click: function(btn) {
  337. var reportName = '';
  338. reportName = "PURCLIST_notax";
  339. var condition = '{Purchase.pu_id}=' + Ext.getCmp('pu_id').value + '';
  340. var id = Ext.getCmp('pu_id').value;
  341. me.FormUtil.onwindowsPrint(id, reportName, condition);
  342. }
  343. },
  344. 'field[name=pu_vendcode]': {
  345. change: function(f) {
  346. if (f.value != null && f.value != '') {
  347. if (Ext.getCmp('pu_receivecode').value == null || Ext.getCmp('pu_receivecode').value.toString().trim() == '') {
  348. Ext.getCmp('pu_receivecode').setValue(f.value);
  349. }
  350. }
  351. }
  352. },
  353. 'field[name=pu_vendname]': {
  354. change: function(f) {
  355. if (f.value != null && f.value != '') {
  356. if (Ext.getCmp('pu_receivename').value == null || Ext.getCmp('pu_receivename').value.toString().trim() == '') {
  357. Ext.getCmp('pu_receivename').setValue(f.value);
  358. }
  359. }
  360. }
  361. },
  362. 'erpCopyButton': {
  363. click: function(btn) {
  364. me.copy();
  365. }
  366. },
  367. 'erpResetSyncButton': {
  368. afterrender: function(btn) {
  369. var form = btn.ownerCt.ownerCt,
  370. s = form.down('#pu_statuscode'),
  371. v = form.down('#pu_receivecode');
  372. if (s.getValue() != 'AUDITED' || v.getValue() != '02.01.028') {
  373. btn.hide();
  374. }
  375. },
  376. click: function(btn) {
  377. var form = btn.ownerCt.ownerCt,
  378. id = form.down('#pu_id').getValue();
  379. btn.resetSyncStatus(basePath + 'scm/purchase/syncstatus.action', id);
  380. }
  381. },
  382. 'erpRefreshSyncButton': {
  383. afterrender: function(btn) {
  384. var form = btn.ownerCt.ownerCt,
  385. s = form.down('#pu_statuscode'),
  386. v = form.down('#pu_sync');
  387. if (s.getValue() != 'AUDITED' || (v && v.getValue() == null)) {
  388. btn.hide();
  389. }
  390. }
  391. },
  392. 'erpRefreshQtyButton':{
  393. click: function(btn){
  394. var puid=Ext.getCmp('pu_id').value;
  395. Ext.Ajax.request({
  396. url : basePath + "scm/purchase/refreshqty.action",
  397. params:{
  398. id: puid
  399. },
  400. method:'post',
  401. callback:function(options,success,response){
  402. var localJson = new Ext.decode(response.responseText);
  403. if(localJson.success){
  404. Ext.Msg.alert("提示","刷新成功!");
  405. window.location.reload();
  406. } else {
  407. if(localJson.exceptionInfo){
  408. var str = localJson.exceptionInfo;
  409. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  410. str = str.replace('AFTERSUCCESS', '');
  411. showError(str);
  412. } else {
  413. showError(str);return;
  414. }
  415. }
  416. }
  417. }
  418. });
  419. }
  420. },
  421. /**
  422. * PO分拆
  423. */
  424. 'erpSplitButton': {
  425. beforerender: function(btn) {
  426. btn.text="拆分及交期回复";
  427. btn.width=130;
  428. },
  429. click: function(btn) {
  430. var record=btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
  431. me.PurchaseSplit(record);
  432. }
  433. }
  434. });
  435. },
  436. UpdatePurcInfo: function(record) {
  437. win = this.getPurcBackInfo(record);
  438. win.show();
  439. },
  440. getPurcBackInfo: function(record) {
  441. var me = this;
  442. return Ext.create('Ext.window.Window', {
  443. width: 430,
  444. height: 250,
  445. closeAction: 'destroy',
  446. cls: 'custom-blue',
  447. title: '<h1>更改采购回复信息</h1>',
  448. layout: {
  449. type: 'vbox'
  450. },
  451. items: [{
  452. width: '100%',
  453. html: '<div style="background:transparent;border:none;width:100%;height:30px;' + 'color:#036;vertical-align:middle;line-height:30px;font-size:14px;">' + '*注:修改采购单更多信息请制作采购变更单<a style="float:right" href="javascript:' + 'openTable(\'采购变更\',\'jsps/scm/purchase/purchaseChange.jsp\',\'PurchaseChange\');">进入</a></div>'
  454. },{
  455. margin: '5 0 0 5',
  456. xtype: 'datefield',
  457. fieldLabel: '采购回复时间',
  458. name: 'pd_purcbackdate',
  459. format: 'Y-m-d',
  460. value: record.data.pd_purcbackdate ? record.data.pd_purcbackdate : record.data.pd_deliveryreply,
  461. id: 'pd_purcbackdate'
  462. },{
  463. margin: '5 0 0 5',
  464. xtype: 'numberfield',
  465. fieldLabel: '采购回复数量',
  466. name: 'pd_purcbackqty',
  467. hideTrigger: true,
  468. value: record.data.pd_purcbackqty ? record.data.pd_purcbackqty : record.data.pd_qtyreply,
  469. id: 'pd_purcbackqty'
  470. },{
  471. margin: '5 0 0 5',
  472. xtype: 'textfield',
  473. columnidth: 0.4,
  474. fieldLabel: '采购回复明细',
  475. name: 'pd_purcbackremark',
  476. value:record.data.pd_purcbackremark,
  477. id: 'pd_purcbackremark'
  478. },{
  479. margin: '5 0 0 5',
  480. xtype: 'textfield',
  481. columnidth: 0.4,
  482. fieldLabel: '更新日期',
  483. name: 'pd_purcupdate',
  484. readOnly: true,
  485. value:record.data.pd_purcupdate,
  486. id: 'pd_purcupdate'
  487. }],
  488. buttonAlign: 'center',
  489. buttons: [{
  490. xtype: 'button',
  491. text: '保存',
  492. width: 60,
  493. iconCls: 'x-button-icon-save',
  494. handler: function(btn) {
  495. var w = btn.up('window');
  496. me.savePurcInfo(w);
  497. win.close();
  498. win.destroy();
  499. }
  500. },{
  501. xtype: 'button',
  502. columnWidth: 0.1,
  503. text: '关闭',
  504. width: 60,
  505. iconCls: 'x-button-icon-close',
  506. margin: '0 0 0 10',
  507. handler: function(btn) {
  508. var win = btn.up('window');
  509. win.close();
  510. win.destroy();
  511. }
  512. }]
  513. });
  514. },
  515. savePurcInfo: function(w) {
  516. var pd_purcbackdate = w.down('field[name=pd_purcbackdate]').getValue(),
  517. pd_purcbackqty = w.down('field[name=pd_purcbackqty]').getValue(),
  518. pd_purcbackremark = w.down('field[name=pd_purcbackremark]').getValue(),
  519. grid = Ext.getCmp('grid'),
  520. record = grid.getSelectionModel().getLastSelected();
  521. var dd = {
  522. pd_id : record.data.pd_id,
  523. pd_puid : record.data.pd_puid,
  524. pd_purcbackdate : Ext.Date.format(pd_purcbackdate, 'Y-m-d'),
  525. pd_purcbackqty : pd_purcbackqty,
  526. pd_purcbackremark : pd_purcbackremark,
  527. caller: caller
  528. };
  529. Ext.Ajax.request({
  530. url : basePath +'scm/purchase/updatePurcBackInfo.action',
  531. params : {
  532. _noc: 1,
  533. data: unescape(Ext.JSON.encode(dd))
  534. },
  535. method : 'post',
  536. callback : function(opt, s, res){
  537. var r = new Ext.decode(res.responseText);
  538. if(r.success){
  539. grid.GridUtil.loadNewStore(grid, {
  540. caller: caller,
  541. condition: 'pd_puid=' + record.data.pd_puid
  542. });
  543. showMessage('提示', '更新成功!', 1000);
  544. } else if(r.exceptionInfo){
  545. showError(r.exceptionInfo);
  546. } else{
  547. saveFailure();
  548. }
  549. }
  550. });
  551. },
  552. UpdateVendorInfo: function(record) {
  553. win = this.getVendorInfoWindow(record);
  554. win.show();
  555. },
  556. getVendorInfoWindow: function(record) {
  557. var me = this;
  558. var date = record.data.pd_deliveryreply;
  559. if (date != null) {
  560. date = Ext.Date.parse(date, "Y-m-d");
  561. }
  562. return Ext.create('Ext.window.Window', {
  563. width: 430,
  564. height: 250,
  565. closeAction: 'destroy',
  566. cls: 'custom-blue',
  567. title: '<h1>更改供应商回信息</h1>',
  568. layout: {
  569. type: 'vbox'
  570. },
  571. items: [{
  572. width: '100%',
  573. html: '<div style="background:transparent;border:none;width:100%;height:30px;' + 'color:#036;vertical-align:middle;line-height:30px;font-size:14px;">' + '*注:修改采购单更多信息请制作采购变更单<a style="float:right" href="javascript:' + 'openTable(\'采购变更\',\'jsps/scm/purchase/purchaseChange.jsp\',\'PurchaseChange\');">进入</a></div>'
  574. },
  575. {
  576. margin: '5 0 0 5',
  577. xtype: 'datefield',
  578. fieldLabel: '回复交期',
  579. name: 'DELIVERYREPLY',
  580. format: 'Y-m-d',
  581. value: date,
  582. id: 'DELIVERYREPLY'
  583. },
  584. {
  585. margin: '5 0 0 5',
  586. xtype: 'numberfield',
  587. fieldLabel: '回复数量',
  588. name: 'QTYREPLY',
  589. hideTrigger: true,
  590. value: record.data.pd_qtyreply,
  591. id: 'QTYREPLY'
  592. },{
  593. margin: '5 0 0 5',
  594. xtype: 'checkbox',
  595. columnidth: 0.4,
  596. fieldLabel: '能否按时交货',
  597. name: 'isok',
  598. value:(record.data.pd_isok && record.data.pd_isok=='是'),
  599. id: 'isok'
  600. },
  601. {
  602. margin: '5 0 0 5',
  603. xtype: 'textareatrigger',
  604. columnidth: 0.4,
  605. fieldLabel: '回复明细',
  606. name: 'replydetail',
  607. value:record.data.pd_replydetail,
  608. id: 'replydetail'
  609. }
  610. ],
  611. buttonAlign: 'center',
  612. buttons: [{
  613. xtype: 'button',
  614. text: '保存',
  615. width: 60,
  616. iconCls: 'x-button-icon-save',
  617. handler: function(btn) {
  618. var w = btn.up('window');
  619. me.saveVendorInfo(w);
  620. win.close();
  621. win.destroy();
  622. }
  623. },
  624. {
  625. xtype: 'button',
  626. columnWidth: 0.1,
  627. text: '关闭',
  628. width: 60,
  629. iconCls: 'x-button-icon-close',
  630. margin: '0 0 0 10',
  631. handler: function(btn) {
  632. var win = btn.up('window');
  633. win.close();
  634. win.destroy();
  635. }
  636. }]
  637. });
  638. },
  639. saveVendorInfo: function(w) {
  640. var deliveryreply = w.down('field[name=DELIVERYREPLY]').getValue();
  641. var qty = w.down('field[name=QTYREPLY]').getValue();
  642. grid = Ext.getCmp('grid'),
  643. record = grid.getSelectionModel().getLastSelected();
  644. if (!deliveryreply && !qty && !Ext.getCmp('replydetail').value) {
  645. showError('请先设置回复信息');
  646. return;
  647. } else {
  648. var isok = w.down('field[name=isok]').getValue();
  649. var dd = {
  650. pd_id: record.data.pd_id,
  651. pd_qtyreply: qty ? qty: 0,
  652. pd_deliveryreply: deliveryreply ? Ext.Date.format(deliveryreply, 'Y-m-d') : null,
  653. pd_isok: isok ? '是': '否',
  654. pd_replydetail:Ext.getCmp('replydetail').value
  655. };
  656. Ext.Ajax.request({
  657. url: basePath + 'scm/purchase/updateVendorBackInfo.action',
  658. params: {
  659. data: unescape(Ext.JSON.encode(dd)),
  660. caller: caller
  661. },
  662. method: 'post',
  663. callback: function(opt, s, res) {
  664. var r = new Ext.decode(res.responseText);
  665. if (r.success) {
  666. grid.GridUtil.loadNewStore(grid, {
  667. caller: caller,
  668. condition: gridCondition
  669. });
  670. showMessage('提示', '更新成功!', 1000);
  671. } else if (r.exceptionInfo) {
  672. showError(r.exceptionInfo);
  673. } else {
  674. saveFailure();
  675. }
  676. }
  677. });
  678. }
  679. },
  680. onGridItemClick: function(selModel, record) { //grid行选择
  681. if (record.data.pd_id != 0 && record.data.pd_id != null && record.data.pd_id != '') {
  682. var btn = Ext.getCmp('updatevendorbackInfo');
  683. btn && btn.setDisabled(false);
  684. btn = Ext.getCmp('erpSplitButton');
  685. btn && btn.setDisabled(false);
  686. btn = Ext.getCmp('updatepurcbackInfo');
  687. btn && btn.setDisabled(false);
  688. }
  689. this.GridUtil.onGridItemClick(selModel, record);
  690. },
  691. getForm: function(btn) {
  692. return btn.ownerCt.ownerCt;
  693. },
  694. beforeSavePurchase: function() {
  695. var grid = Ext.getCmp('grid'),
  696. items = grid.store.data.items,
  697. c = Ext.getCmp('pu_code').value;
  698. var vend = Ext.getCmp('pu_vendid').value,
  699. vendcode = Ext.getCmp('pu_vendcode').value,
  700. vendname = Ext.getCmp('pu_vendname').value;
  701. if (vend == null || vend == '' || vend == '0' || vend == 0) {
  702. showError('未选择供应商,或供应商编号无效!');
  703. return;
  704. }
  705. Ext.Array.each(items,
  706. function(item) {
  707. item.set('pd_code', c);
  708. item.set('pd_vendid', vend);
  709. item.set('pd_vendcode', vendcode);
  710. item.set('pd_vendname', vendname);
  711. });
  712. //手工录入采购单,合同类型不能为标准
  713. var pu_kind = Ext.getCmp('pu_kind').value;
  714. if (pu_kind == null || pu_kind == '') {
  715. showError('合同类型不能为空');
  716. return;
  717. }
  718. if (pu_kind == '标准' || pu_kind == 'normal' || pu_kind == '標準') {
  719. showError('手工录入采购单,合同类型不能为标准');
  720. return;
  721. }
  722. var items = grid.store.data.items;
  723. var bool = true;
  724. //数量不能为空或0
  725. Ext.each(items,
  726. function(item) {
  727. if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
  728. if (item.data['pd_qty'] == null) {
  729. bool = false;
  730. showError('明细表第' + item.data['pd_detno'] + '行的数量为空');
  731. return;
  732. }
  733. }
  734. });
  735. //物料交货日期不能小于录入日期
  736. Ext.each(items,
  737. function(item) {
  738. if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
  739. if (item.data['pd_delivery'] == null) {
  740. item.set('pd_delivery', Ext.getCmp('pu_delivery'));
  741. } else if (item.data['pd_delivery'] < Ext.getCmp('pu_indate').value) {
  742. bool = false;
  743. showError('明细表第' + item.data['pd_detno'] + '行的交货日期小于单据录入日期');
  744. return;
  745. }
  746. }
  747. });
  748. //保存purchase
  749. if (bool) this.FormUtil.beforeSave(this);
  750. },
  751. beforeUpdate: function() {
  752. var grid = Ext.getCmp('grid'),
  753. items = grid.store.data.items,
  754. c = Ext.getCmp('pu_code').value;
  755. var vend = Ext.getCmp('pu_vendid').value,
  756. vendcode = Ext.getCmp('pu_vendcode').value,
  757. vendname = Ext.getCmp('pu_vendname').value;
  758. if (vend == null || vend == '' || vend == '0' || vend == 0) {
  759. showError('未选择供应商,或供应商编号无效!');
  760. return;
  761. }
  762. Ext.Array.each(items,
  763. function(item) {
  764. item.set('pd_code', c);
  765. item.set('pd_vendid', vend);
  766. item.set('pd_vendcode', vendcode);
  767. item.set('pd_vendname', vendname);
  768. });
  769. var items = grid.store.data.items;
  770. var bool = true;
  771. //数量不能为空或0
  772. Ext.each(items,
  773. function(item) {
  774. if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
  775. if (item.data['pd_qty'] == null || item.data['pd_qty'] == '' || item.data['pd_qty'] == '0' || item.data['pd_qty'] == 0) {
  776. bool = false;
  777. showError('明细表第' + item.data['pd_detno'] + '行的数量为空');
  778. return;
  779. }
  780. }
  781. });
  782. /*//采购价格不能为0
  783. if (Ext.getCmp('pu_getprice').value == 0) { //是否自动获取单价
  784. Ext.each(items,
  785. function(item) {
  786. if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
  787. if (item.data['pd_price'] == null) {
  788. bool = false;
  789. showError('明细表第' + item.data['pd_detno'] + '行的价格为空');
  790. return;
  791. } else if (item.data['pd_price'] == 0 || item.data['pd_price'] == '0') {
  792. bool = false;
  793. showError('明细表第' + item.data['pd_detno'] + '行的价格为0');
  794. return;
  795. }
  796. }
  797. });
  798. }*/
  799. //物料交货日期不能小于录入日期
  800. Ext.each(items,
  801. function(item) {
  802. if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
  803. if (item.data['pd_delivery'] == null) {
  804. item.set('pd_delivery', Ext.getCmp('pu_delivery'));
  805. } else if (item.data['pd_delivery'] < Ext.getCmp('pu_indate').value) {
  806. bool = false;
  807. showError('明细表第' + item.data['pd_detno'] + '行的交货日期小于单据录入日期');
  808. return;
  809. }
  810. }
  811. });
  812. //更新
  813. if (bool) this.FormUtil.onUpdate(this);
  814. },
  815. /**
  816. * 复制采购单
  817. */
  818. copy: function() {
  819. var me = this,
  820. form = Ext.getCmp('form');
  821. var v = form.down('#pu_id').value;
  822. if (v > 0) {
  823. form.setLoading(true);
  824. Ext.Ajax.request({
  825. url: basePath + 'scm/purchase/copyPurchase.action',
  826. params: {
  827. caller: caller,
  828. id: v
  829. },
  830. callback: function(opt, s, r) {
  831. form.setLoading(false);
  832. var res = Ext.decode(r.responseText);
  833. if (res.data) {
  834. var url = 'jsps/scm/purchase/purchase.jsp?formCondition=pu_idIS' + res.data.id + '&gridCondition=pd_puidIS' + res.data.id;
  835. showMessage('提示', '复制成功', 2000);
  836. me.FormUtil.onAdd(null, '采购单', url);
  837. } else {
  838. showError(res.exceptionInfo);
  839. }
  840. }
  841. });
  842. }
  843. },
  844. /**
  845. *采购单拆分
  846. * */
  847. PurchaseSplit:function(record){
  848. var me=this,originaldetno=Number(record.data.pd_detno);
  849. var puid=record.data.pd_puid;
  850. var pdid=record.data.pd_id;
  851. Ext.create('Ext.window.Window',{
  852. width:850,
  853. height:'80%',
  854. iconCls:'x-grid-icon-partition',
  855. title:'<h1>采购单拆分</h1>',
  856. id:'win',
  857. items:[{
  858. xtype:'form',
  859. layout:'column',
  860. region:'north',
  861. frame:true,
  862. defaults:{
  863. xtype:'textfield',
  864. columnWidth:0.5,
  865. readOnly:true,
  866. fieldStyle:'background:#f0f0f0;border: 0px solid #8B8970;color:blue;'
  867. },
  868. items:[{
  869. fieldLabel:'采购单号',
  870. value:record.data.pd_code,
  871. id:'sacode'
  872. },{
  873. fieldLabel:'物流编号' ,
  874. value:record.data.pd_prodcode
  875. },{
  876. fieldLabel:'物料名称',
  877. value:record.data.pr_detail
  878. },{
  879. fieldLabel:'原序号' ,
  880. value:record.data.pd_detno
  881. },{
  882. fieldLabel:'原数量',
  883. value:record.data.pd_qty
  884. }],
  885. buttonAlign:'center',
  886. buttons:[{
  887. xtype:'button',
  888. columnWidth:0.12,
  889. text:'保存',
  890. width:60,
  891. iconCls: 'x-button-icon-save',
  892. margin:'0 0 0 30',
  893. handler:function(btn){
  894. var store=Ext.getCmp('smallgrid').getStore();
  895. var count=0;
  896. var jsonData=new Array();
  897. var dd;
  898. Ext.Array.each(store.data.items,function(item){
  899. if(item.data.pd_qty!=0&&item.data.pd_delivery!=null&&item.data.pd_qty>0){
  900. if(item.dirty){
  901. dd=new Object();
  902. //说明是新增批次
  903. dd['pd_qty']=item.data.pd_qty;
  904. dd['pd_id']=item.data.pd_id;
  905. dd['pd_detno']=item.data.pd_detno;
  906. dd['pd_delivery']=Ext.Date.format(item.data.pd_delivery, 'Y-m-d');
  907. dd['pd_replydetail']=item.data.pd_replydetail;
  908. dd['pd_isok']=item.data.pd_isok=='-1'?'是':'否';
  909. dd['pd_qtyreply']=item.data.pd_qtyreply;
  910. if(item.data.pd_deliveryreply){
  911. dd['pd_deliveryreply']=Ext.Date.format(item.data.pd_deliveryreply, 'Y-m-d');
  912. }else
  913. dd['pd_deliveryreply']=null;
  914. jsonData.push(Ext.JSON.encode(dd));
  915. }
  916. count+=Number(item.data.pd_qty);
  917. }
  918. });
  919. var assqty=Number(record.data.pd_qty);
  920. if(count!=assqty){
  921. showError('分拆数量必须等于原数量!') ;
  922. return;
  923. }else{
  924. var r=new Object();
  925. r['pd_id']=record.data.pd_id;
  926. r['pd_puid']=record.data.pd_puid;
  927. r['pd_detno']=record.data.pd_detno;
  928. var params=new Object();
  929. params.formdata = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  930. params.data = unescape(jsonData.toString().replace(/\\/g,"%"));
  931. Ext.Ajax.request({
  932. url : basePath +'scm/purchase/splitPurchase.action',
  933. params : params,
  934. waitMsg:'拆分中...',
  935. method : 'post',
  936. callback : function(options,success,response){
  937. var localJson = new Ext.decode(response.responseText);
  938. if(localJson.success){
  939. saveSuccess(function(){
  940. //add成功后刷新页面进入可编辑的页面
  941. Ext.getCmp('win').close();
  942. me.loadSplitData(originaldetno,puid,record);
  943. });
  944. } else if(localJson.exceptionInfo){
  945. var str = localJson.exceptionInfo;
  946. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  947. str = str.replace('AFTERSUCCESS', '');
  948. saveSuccess(function(){
  949. //add成功后刷新页面进入可编辑的页面
  950. me.loadSplitData(originaldetno,puid,record);
  951. });
  952. showError(str);
  953. } else {
  954. showError(str);
  955. return;
  956. }
  957. } else{
  958. saveFailure();
  959. }
  960. }
  961. });
  962. }
  963. }
  964. },{
  965. xtype:'button',
  966. columnWidth:0.1,
  967. text:'关闭',
  968. width:60,
  969. iconCls: 'x-button-icon-close',
  970. margin:'0 0 0 10',
  971. handler:function(btn){
  972. Ext.getCmp('win').close();
  973. }
  974. }]
  975. },{
  976. xtype:'gridpanel',
  977. region:'south',
  978. id:'smallgrid',
  979. layout:'fit',
  980. height:'80%',
  981. columnLines:true,
  982. store:Ext.create('Ext.data.Store',{
  983. fields:[{name:'pd_delivery',type:'date'},{name:'pd_qty',type:'int'},{name:'pd_deliveryreply',type:'date'},{name:'pd_qtyreply',type:'int'},{name:'pd_replydetail',type:'string'},{name:'pd_isok',type:'int'},{name:'pd_acceptqty',type:'int'},{name:'pd_yqty',type:'int'},{name:'pd_id',type:'int'}],
  984. data:[]
  985. }),
  986. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  987. clicksToEdit: 1,
  988. listeners:{
  989. 'edit':function(editor,e,Opts){
  990. var record=e.record;
  991. var version=record.data.ma_version;
  992. if(version){
  993. e.record.reject();
  994. Ext.Msg.alert('提示','不能修改已拆分明细!');
  995. }
  996. }
  997. }
  998. })],
  999. tbar: [{
  1000. tooltip: '添加批次',
  1001. iconCls: 'x-button-icon-add',
  1002. width:25,
  1003. handler : function() {
  1004. var store = Ext.getCmp('smallgrid').getStore();
  1005. var r = new Object();
  1006. r.pd_delivery=record.get('pd_delivery');
  1007. r.pd_qty=0;
  1008. r.pd_id=0;
  1009. r.pd_detno=store.getCount()+1;
  1010. store.insert(store.getCount(), r);
  1011. }
  1012. }, {
  1013. tooltip: '删除批次',
  1014. width:25,
  1015. itemId: 'delete',
  1016. iconCls: 'x-button-icon-delete',
  1017. handler: function(btn) {
  1018. var sm = Ext.getCmp('smallgrid').getSelectionModel();
  1019. var record=sm.getSelection();
  1020. var pd_id=record[0].data.pd_id;
  1021. if(pd_id&&pd_id!=0){
  1022. Ext.Msg.alert('提示','不能删除已拆批次或原始行号!');
  1023. return;
  1024. }
  1025. var store=Ext.getCmp('smallgrid').getStore();
  1026. store.remove(record);
  1027. if (store.getCount() > 0) {
  1028. sm.select(0);
  1029. }
  1030. },
  1031. disabled: true
  1032. }],
  1033. listeners:{
  1034. itemmousedown:function(selmodel, record){
  1035. selmodel.ownerCt.down('#delete').setDisabled(false);
  1036. }
  1037. },
  1038. columns:[{
  1039. dataIndex:'pd_detno',
  1040. header:'序号',
  1041. format:'0',
  1042. xtype:'numbercolumn'
  1043. },{
  1044. dataIndex:'pd_delivery',
  1045. header:'交货日期',
  1046. xtype:'datecolumn',
  1047. width:120,
  1048. editable:true,
  1049. renderer:function(val,meta,record){
  1050. if(record.data.ma_version){
  1051. meta.tdCls = "x-grid-cell-renderer-cl";
  1052. }
  1053. if(val)
  1054. return Ext.Date.format(val, 'Y-m-d');
  1055. else return null;
  1056. },
  1057. editor:{
  1058. xtype: 'datefield',
  1059. format:'Y-m-d'
  1060. }
  1061. },{
  1062. dataIndex:'pd_qty',
  1063. header:'数量',
  1064. width:120,
  1065. xtype:'numbercolumn',
  1066. editable:true,
  1067. renderer:function(val,meta,record){
  1068. if(record.data.ma_version){
  1069. meta.tdCls = "x-grid-cell-renderer-cl";
  1070. }
  1071. return val;
  1072. },
  1073. editor:{
  1074. xtype:'numberfield',
  1075. format:'0',
  1076. hideTrigger: true
  1077. }
  1078. },{
  1079. dataIndex:'pd_deliveryreply',
  1080. header:'回复交期',
  1081. xtype:'datecolumn',
  1082. width:120,
  1083. editable:true,
  1084. renderer:function(val,meta,record){
  1085. if(val)
  1086. return Ext.Date.format(val, 'Y-m-d');
  1087. else return null;
  1088. },
  1089. editor:{
  1090. xtype: 'datefield',
  1091. format:'Y-m-d'
  1092. }
  1093. },{
  1094. dataIndex:'pd_qtyreply',
  1095. header:'回复数量',
  1096. width:120,
  1097. xtype:'numbercolumn',
  1098. editable:true,
  1099. renderer:function(val,meta,record){
  1100. if(record.data.ma_version){
  1101. meta.tdCls = "x-grid-cell-renderer-cl";
  1102. }
  1103. return val;
  1104. },
  1105. editor:{
  1106. xtype:'numberfield',
  1107. format:'0',
  1108. hideTrigger: true
  1109. }
  1110. },{
  1111. dataIndex:'pd_isok',
  1112. header:'是否准时',
  1113. xtype:'yncolumn',
  1114. width:100,
  1115. editable:true
  1116. },{
  1117. dataIndex:'pd_replydetail',
  1118. header:'回复明细',
  1119. width:100,
  1120. renderer:function(val,meta,record){
  1121. if(record.data.originaldetno){
  1122. meta.tdCls = "x-grid-cell-renderer-cl";
  1123. }
  1124. return val;
  1125. } ,
  1126. editor:{
  1127. xtype:'textfield',
  1128. format:'0',
  1129. hideTrigger: true
  1130. },
  1131. editable:true
  1132. },{
  1133. dataIndex:'pd_yqty',
  1134. header:'已转收料数',
  1135. xtype:'numbercolumn',
  1136. width:100,
  1137. editable:false
  1138. },{
  1139. dataIndex:'pd_acceptqty',
  1140. header:'已转验收数',
  1141. xtype:'numbercolumn',
  1142. width:100,
  1143. editable:false
  1144. },{
  1145. dataIndex:'pd_id',
  1146. header:'pdid',
  1147. width:0,
  1148. xtype:'numbercolumn',
  1149. editable:true,
  1150. editor:{
  1151. xtype:'numberfield',
  1152. format:'0',
  1153. hideTrigger: true
  1154. }
  1155. }]
  1156. }] ,
  1157. listeners:{
  1158. 'beforeclose':function(view ,opt){
  1159. var grid = Ext.getCmp('grid');
  1160. var value = Ext.getCmp('pu_id').value;
  1161. var gridCondition = grid.mainField + '=' + value,
  1162. gridParam = {caller: caller, condition: gridCondition};
  1163. me.GridUtil.loadNewStore(grid, gridParam);
  1164. }
  1165. }
  1166. }).show();
  1167. this.loadSplitData(originaldetno,puid,record);
  1168. },
  1169. loadSplitData:function(detno,puid,record){
  1170. var grid=Ext.getCmp('smallgrid');
  1171. grid.setLoading(true);//loading...
  1172. Ext.Ajax.request({//拿到grid的columns
  1173. url : basePath + "common/loadNewGridStore.action",
  1174. params:{
  1175. caller:'PurchaseSplit',
  1176. condition:"pd_detno="+detno+" AND pd_puid="+puid+" order by pd_id asc"
  1177. },
  1178. method : 'post',
  1179. callback : function(options,success,response){
  1180. grid.setLoading(false);
  1181. var res = new Ext.decode(response.responseText);
  1182. if(res.exceptionInfo){
  1183. showError(res.exceptionInfo);return;
  1184. }
  1185. var data = res.data;
  1186. grid.store.loadData(data);
  1187. //自定义event
  1188. grid.addEvents({
  1189. storeloaded: true
  1190. });
  1191. grid.fireEvent('storeloaded', grid, data);
  1192. }
  1193. });
  1194. },
  1195. getLeadCode: function(type) {
  1196. var result = null;
  1197. Ext.Ajax.request({
  1198. url : basePath + 'common/getFieldData.action',
  1199. async: false,
  1200. params: {
  1201. caller: 'PurchaseKind',
  1202. field: 'pk_excode',
  1203. condition: 'pk_name=\'' + type + '\''
  1204. },
  1205. method : 'post',
  1206. callback : function(opt, s, res){
  1207. var r = new Ext.decode(res.responseText);
  1208. if(r.exceptionInfo){
  1209. showError(r.exceptionInfo);return;
  1210. } else if(r.success){
  1211. result = r.data;
  1212. }
  1213. }
  1214. });
  1215. return result;
  1216. }
  1217. });