| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222 |
- Ext.QuickTips.init();
- Ext.define('erp.controller.scm.purchase.Purchase', {
- extend: 'Ext.app.Controller',
- FormUtil: Ext.create('erp.util.FormUtil'),
- GridUtil: Ext.create('erp.util.GridUtil'),
- BaseUtil: Ext.create('erp.util.BaseUtil'),
- views: ['core.form.Panel', 'scm.purchase.Purchase', 'core.grid.Panel2', 'core.toolbar.Toolbar',
- 'core.form.MultiField', 'core.button.Save', 'core.button.Add', 'core.button.Submit',
- 'core.button.Print', 'core.button.PrintHK', 'core.button.PrintEn','core.button.Upload', 'core.button.ResAudit',
- 'core.button.Audit', 'core.button.Close', 'core.button.Delete', 'core.button.Update', 'core.button.B2B',
- 'core.button.DeleteDetail', 'core.button.ResSubmit', 'core.button.End','core.button.Printyestax', 'core.button.Printnotax',
- 'core.button.DeleteDetail', 'core.button.ResSubmit', 'core.button.End','core.button.AttendDataCom',
- 'core.button.ResEnd', 'core.button.GetPrice', 'core.button.Export', 'core.button.StandardPrice',
- 'core.trigger.DbfindTrigger', 'core.trigger.TextAreaTrigger', 'core.form.YnField',
- 'core.grid.YnColumn', 'core.form.StatusField', 'core.form.FileField', 'core.button.PrintA4',
- 'core.button.CopyAll', 'core.button.ResetSync', 'core.button.RefreshSync','core.button.RefreshQty','core.button.Split'],
- init: function() {
- var me = this;
- this.control({
- 'erpGridPanel2': {
- afterrender: function(grid) {
- var status = Ext.getCmp('pu_statuscode');
- if (status && status.value != 'ENTERING' && status.value != 'COMMITED') {
- Ext.each(grid.columns,
- function(c) {
- c.setEditor(null);
- });
- }
- },
- itemclick: this.onGridItemClick
- },
- 'erpSaveButton': {
- click: function(btn) {
- var form = me.getForm(btn), codeField = Ext.getCmp(form.codeField);
- if(codeField.value == null || codeField.value == ''){
- me.BaseUtil.getRandomNumber(caller);//自动添加编号
- var res = me.getLeadCode(Ext.getCmp('pu_kind').value);
- if(res != null && res != ''){
- codeField.setValue(res + codeField.getValue());
- }
- }
- //保存之前的一些前台的逻辑判定
- this.beforeSavePurchase();
- }
- },
- 'erpDeleteButton': {
- click: function(btn) {
- me.FormUtil.onDelete(Ext.getCmp('pu_id').value);
- }
- },
- 'erpAttendDataComButton':{
- beforerender:function(btn){
- btn.setText("计算");
- },
- click: function(btn){
- var id=Ext.getCmp('pu_id').value;
- grid = Ext.getCmp('grid');
- Ext.Ajax.request({
- url : basePath + "scm/purchase/purchasedataupdate.action",
- params: {
- id:id
- },
- method : 'post',
- async: false,
- callback : function(options,success,response){
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo){
- showError(res.exceptionInfo);
- return;
- }
- grid.GridUtil.loadNewStore(grid,{
- caller:'Purchase',
- condition:gridCondition,
- _noc:1
- });
- showError("计算成功!");
-
- }
- });
- }
- },
- 'erpGetPriceButton': {
- afterrender: function(btn) {
- var status = Ext.getCmp('pu_statuscode');
- if (status && status.value != 'ENTERING') {
- btn.hide();
- }
- },
- click: function(btn) {
- id = Ext.getCmp('pu_id').value;
- Ext.Ajax.request({
- url: basePath + "scm/purchase/getPrice.action",
- params: {
- id: id
- },
- method: 'post',
- callback: function(options, success, response) {
- var res = new Ext.decode(response.responseText);
- if (res.exceptionInfo != null) {
- showError(res.exceptionInfo);
- return;
- }
- if (res.success) {
- updateSuccess(function(btn) {
- //update成功后刷新页面进入可编辑的页面
- window.location.reload();
- });
- }
- }
- });
- }
- },
- 'erpStandardPriceButton': {
- afterrender: function(btn) {
- var status = Ext.getCmp('pu_statuscode');
- if (status && status.value != 'ENTERING') {
- btn.hide();
- }
- },
- click: function(btn) {
- id = Ext.getCmp('pu_id').value;
- Ext.Ajax.request({
- url: basePath + "scm/purchase/getStandardPrice.action",
- params: {
- id: id
- },
- method: 'post',
- callback: function(options, success, response) {
- var res = new Ext.decode(response.responseText);
- if (res.exceptionInfo != null) {
- showError(res.exceptionInfo);
- return;
- }
- if (res.success) {
- updateSuccess(function(btn) {
- //update成功后刷新页面进入可编辑的页面
- window.location.reload();
- });
- }
- }
- });
- }
- },
- 'erpUpdateButton': {
- afterrender: function(btn) {
- var status = Ext.getCmp('pu_statuscode');
- if (status && status.value != 'ENTERING') {
- btn.hide();
- }
- },
- click: function(btn) {
- me.beforeUpdate();
- }
- },
- 'erpAddButton': {
- click: function() {
- me.FormUtil.onAdd('addPurchase', '新增采购单', 'jsps/scm/purchase/purchase.jsp');
- }
- },
- 'erpCloseButton': {
- click: function(btn) {
- me.FormUtil.beforeClose(me);
- }
- },
- 'erpSubmitButton': {
- afterrender: function(btn) {
- var status = Ext.getCmp('pu_statuscode');
- if (status && status.value != 'ENTERING') {
- btn.hide();
- }
- },
- click: function(btn) {
- var grid = Ext.getCmp('grid');
- var items = grid.store.data.items;
- var bool = true;
- //数量不能为空或0
- Ext.each(items,
- function(item) {
- if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
- if (item.data['pd_qty'] == null) {
- bool = false;
- showError('明细表第' + item.data['pd_detno'] + '行的数量为空');
- return;
- }
- }
- });
- //物料交货日期不能小于录入日期
- Ext.each(items,
- function(item) {
- if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
- if (item.data['pd_delivery'] == null) {
- bool = false;
- showError('明细表第' + item.data['pd_detno'] + '行的承诺日期为空');
- return;
- } else if (item.data['pd_delivery'] < Ext.getCmp('pu_indate').value) {
- bool = false;
- showError('明细表第' + item.data['pd_detno'] + '行的承诺日期小于单据录入日期');
- return;
- }
- }
- });
- if (bool) {
- me.FormUtil.onSubmit(Ext.getCmp('pu_id').value);
- }
- }
- },
- 'erpResSubmitButton': {
- afterrender: function(btn) {
- var status = Ext.getCmp('pu_statuscode');
- if (status && status.value != 'COMMITED') {
- btn.hide();
- }
- },
- click: function(btn) {
- me.FormUtil.onResSubmit(Ext.getCmp('pu_id').value);
- }
- },
- 'erpAuditButton': {
- afterrender: function(btn) {
- var status = Ext.getCmp('pu_statuscode');
- if (status && status.value != 'COMMITED') {
- btn.hide();
- }
- },
- click: function(btn) {
- me.FormUtil.onAudit(Ext.getCmp('pu_id').value);
- }
- },
- 'erpB2BButton': {
- afterrender: function(btn) {
- var status = Ext.getCmp('pu_statuscode');
- if (status && status.value != 'AUDITED') {
- btn.hide();
- }
- },
- click: function(btn) {
- me.FormUtil.onB2b(Ext.getCmp('pu_id').value);
- }
- },
- 'erpResAuditButton': {
- afterrender: function(btn) {
- var status = Ext.getCmp('pu_statuscode');
- if (status && status.value != 'AUDITED') {
- btn.hide();
- }
- },
- click: function(btn) {
- me.FormUtil.onResAudit(Ext.getCmp('pu_id').value);
- }
- },
- 'erpEndButton': {
- afterrender: function(btn) {
- var status = Ext.getCmp('pu_statuscode');
- if (status && status.value != 'AUDITED') {
- btn.hide();
- }
- },
- click: function(btn) {
- me.FormUtil.onEnd(Ext.getCmp('pu_id').value);
- }
- },
- 'erpResEndButton': {
- afterrender: function(btn) {
- var status = Ext.getCmp('pu_statuscode');
- if (status && status.value != 'FINISH') {
- btn.hide();
- }
- },
- click: function(btn) {
- me.FormUtil.onResEnd(Ext.getCmp('pu_id').value);
- }
- },
- /**
- * 更改供应商回复信息
- */
- '#updatevendorbackInfo': {
- click: function(btn) {
- var record = btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
- me.UpdateVendorInfo(record);
- }
- },
- /**
- * 更改采购回复信息
- */
- '#updatepurcbackInfo': {
- click: function(btn) {
- var record = btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
- me.UpdatePurcInfo(record);
- }
- },
- 'erpPrintA4Button':{
- click: function(btn) {
- var reportName = '';
- reportName = "PURCLIST_A4";
- var condition = '{Purchase.pu_id}=' + Ext.getCmp('pu_id').value + '';
- var id = Ext.getCmp('pu_id').value;
- me.FormUtil.onwindowsPrint(id, reportName, condition);
- }
- },
- 'erpPrintButton': {
- click: function(btn) {
- var reportName = '';
- reportName = "PURCLIST";
- var condition = '{Purchase.pu_id}=' + Ext.getCmp('pu_id').value + '';
- var id = Ext.getCmp('pu_id').value;
- me.FormUtil.onwindowsPrint(id, reportName, condition);
- }
- },
- 'erpPrintEnButton': {
- click: function(btn) {
- var reportName = '';
- reportName = "PURCLIST_EN";
- var condition = '{Purchase.pu_id}=' + Ext.getCmp('pu_id').value + '';
- var id = Ext.getCmp('pu_id').value;
- me.FormUtil.onwindowsPrint(id, reportName, condition);
- }
- },
- 'erpPrintHKButton': {
- click: function(btn) {
- var reportName = '';
- reportName = "PURCLIST_HK";
- var condition = '{Purchase.pu_id}=' + Ext.getCmp('pu_id').value + '';
- var id = Ext.getCmp('pu_id').value;
- me.FormUtil.onwindowsPrint(id, reportName, condition);
- }
- },
- 'erpPrintyestaxButton': {
- click: function(btn) {
- var reportName = '';
- reportName = "PURCLIST_yestax";
- var condition = '{Purchase.pu_id}=' + Ext.getCmp('pu_id').value + '';
- var id = Ext.getCmp('pu_id').value;
- me.FormUtil.onwindowsPrint(id, reportName, condition);
- }
- },
- 'erpPrintnotaxButton': {
- click: function(btn) {
- var reportName = '';
- reportName = "PURCLIST_notax";
- var condition = '{Purchase.pu_id}=' + Ext.getCmp('pu_id').value + '';
- var id = Ext.getCmp('pu_id').value;
- me.FormUtil.onwindowsPrint(id, reportName, condition);
- }
- },
- 'field[name=pu_vendcode]': {
- change: function(f) {
- if (f.value != null && f.value != '') {
- if (Ext.getCmp('pu_receivecode').value == null || Ext.getCmp('pu_receivecode').value.toString().trim() == '') {
- Ext.getCmp('pu_receivecode').setValue(f.value);
- }
- }
- }
- },
- 'field[name=pu_vendname]': {
- change: function(f) {
- if (f.value != null && f.value != '') {
- if (Ext.getCmp('pu_receivename').value == null || Ext.getCmp('pu_receivename').value.toString().trim() == '') {
- Ext.getCmp('pu_receivename').setValue(f.value);
- }
- }
- }
- },
- 'erpCopyButton': {
- click: function(btn) {
- me.copy();
- }
- },
- 'erpResetSyncButton': {
- afterrender: function(btn) {
- var form = btn.ownerCt.ownerCt,
- s = form.down('#pu_statuscode'),
- v = form.down('#pu_receivecode');
- if (s.getValue() != 'AUDITED' || v.getValue() != '02.01.028') {
- btn.hide();
- }
- },
- click: function(btn) {
- var form = btn.ownerCt.ownerCt,
- id = form.down('#pu_id').getValue();
- btn.resetSyncStatus(basePath + 'scm/purchase/syncstatus.action', id);
- }
- },
- 'erpRefreshSyncButton': {
- afterrender: function(btn) {
- var form = btn.ownerCt.ownerCt,
- s = form.down('#pu_statuscode'),
- v = form.down('#pu_sync');
- if (s.getValue() != 'AUDITED' || (v && v.getValue() == null)) {
- btn.hide();
- }
- }
- },
- 'erpRefreshQtyButton':{
- click: function(btn){
- var puid=Ext.getCmp('pu_id').value;
- Ext.Ajax.request({
- url : basePath + "scm/purchase/refreshqty.action",
- params:{
- id: puid
- },
- method:'post',
- callback:function(options,success,response){
- var localJson = new Ext.decode(response.responseText);
- if(localJson.success){
- Ext.Msg.alert("提示","刷新成功!");
- window.location.reload();
- } else {
- if(localJson.exceptionInfo){
- var str = localJson.exceptionInfo;
- if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
- str = str.replace('AFTERSUCCESS', '');
- showError(str);
- } else {
- showError(str);return;
- }
- }
- }
- }
- });
- }
- },
- /**
- * PO分拆
- */
- 'erpSplitButton': {
- beforerender: function(btn) {
- btn.text="拆分及交期回复";
- btn.width=130;
- },
- click: function(btn) {
- var record=btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
- me.PurchaseSplit(record);
- }
- }
- });
- },
- UpdatePurcInfo: function(record) {
- win = this.getPurcBackInfo(record);
- win.show();
- },
- getPurcBackInfo: function(record) {
- var me = this;
- return Ext.create('Ext.window.Window', {
- width: 430,
- height: 250,
- closeAction: 'destroy',
- cls: 'custom-blue',
- title: '<h1>更改采购回复信息</h1>',
- layout: {
- type: 'vbox'
- },
- items: [{
- width: '100%',
- 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>'
- },{
- margin: '5 0 0 5',
- xtype: 'datefield',
- fieldLabel: '采购回复时间',
- name: 'pd_purcbackdate',
- format: 'Y-m-d',
- value: record.data.pd_purcbackdate ? record.data.pd_purcbackdate : record.data.pd_deliveryreply,
- id: 'pd_purcbackdate'
- },{
- margin: '5 0 0 5',
- xtype: 'numberfield',
- fieldLabel: '采购回复数量',
- name: 'pd_purcbackqty',
- hideTrigger: true,
- value: record.data.pd_purcbackqty ? record.data.pd_purcbackqty : record.data.pd_qtyreply,
- id: 'pd_purcbackqty'
- },{
- margin: '5 0 0 5',
- xtype: 'textfield',
- columnidth: 0.4,
- fieldLabel: '采购回复明细',
- name: 'pd_purcbackremark',
- value:record.data.pd_purcbackremark,
- id: 'pd_purcbackremark'
- },{
- margin: '5 0 0 5',
- xtype: 'textfield',
- columnidth: 0.4,
- fieldLabel: '更新日期',
- name: 'pd_purcupdate',
- readOnly: true,
- value:record.data.pd_purcupdate,
- id: 'pd_purcupdate'
- }],
- buttonAlign: 'center',
- buttons: [{
- xtype: 'button',
- text: '保存',
- width: 60,
- iconCls: 'x-button-icon-save',
- handler: function(btn) {
- var w = btn.up('window');
- me.savePurcInfo(w);
- win.close();
- win.destroy();
- }
- },{
- xtype: 'button',
- columnWidth: 0.1,
- text: '关闭',
- width: 60,
- iconCls: 'x-button-icon-close',
- margin: '0 0 0 10',
- handler: function(btn) {
- var win = btn.up('window');
- win.close();
- win.destroy();
- }
- }]
- });
- },
- savePurcInfo: function(w) {
- var pd_purcbackdate = w.down('field[name=pd_purcbackdate]').getValue(),
- pd_purcbackqty = w.down('field[name=pd_purcbackqty]').getValue(),
- pd_purcbackremark = w.down('field[name=pd_purcbackremark]').getValue(),
- grid = Ext.getCmp('grid'),
- record = grid.getSelectionModel().getLastSelected();
- var dd = {
- pd_id : record.data.pd_id,
- pd_puid : record.data.pd_puid,
- pd_purcbackdate : Ext.Date.format(pd_purcbackdate, 'Y-m-d'),
- pd_purcbackqty : pd_purcbackqty,
- pd_purcbackremark : pd_purcbackremark,
- caller: caller
- };
- Ext.Ajax.request({
- url : basePath +'scm/purchase/updatePurcBackInfo.action',
- params : {
- _noc: 1,
- data: unescape(Ext.JSON.encode(dd))
- },
- method : 'post',
- callback : function(opt, s, res){
- var r = new Ext.decode(res.responseText);
- if(r.success){
- grid.GridUtil.loadNewStore(grid, {
- caller: caller,
- condition: 'pd_puid=' + record.data.pd_puid
- });
- showMessage('提示', '更新成功!', 1000);
- } else if(r.exceptionInfo){
- showError(r.exceptionInfo);
- } else{
- saveFailure();
- }
- }
- });
- },
- UpdateVendorInfo: function(record) {
- win = this.getVendorInfoWindow(record);
- win.show();
- },
- getVendorInfoWindow: function(record) {
- var me = this;
- var date = record.data.pd_deliveryreply;
- if (date != null) {
- date = Ext.Date.parse(date, "Y-m-d");
- }
- return Ext.create('Ext.window.Window', {
- width: 430,
- height: 250,
- closeAction: 'destroy',
- cls: 'custom-blue',
- title: '<h1>更改供应商回信息</h1>',
- layout: {
- type: 'vbox'
- },
- items: [{
- width: '100%',
- 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>'
- },
- {
- margin: '5 0 0 5',
- xtype: 'datefield',
- fieldLabel: '回复交期',
- name: 'DELIVERYREPLY',
- format: 'Y-m-d',
- value: date,
- id: 'DELIVERYREPLY'
- },
- {
- margin: '5 0 0 5',
- xtype: 'numberfield',
- fieldLabel: '回复数量',
- name: 'QTYREPLY',
- hideTrigger: true,
- value: record.data.pd_qtyreply,
- id: 'QTYREPLY'
- },{
- margin: '5 0 0 5',
- xtype: 'checkbox',
- columnidth: 0.4,
- fieldLabel: '能否按时交货',
- name: 'isok',
- value:(record.data.pd_isok && record.data.pd_isok=='是'),
- id: 'isok'
- },
- {
- margin: '5 0 0 5',
- xtype: 'textareatrigger',
- columnidth: 0.4,
- fieldLabel: '回复明细',
- name: 'replydetail',
- value:record.data.pd_replydetail,
- id: 'replydetail'
- }
- ],
- buttonAlign: 'center',
- buttons: [{
- xtype: 'button',
- text: '保存',
- width: 60,
- iconCls: 'x-button-icon-save',
- handler: function(btn) {
- var w = btn.up('window');
- me.saveVendorInfo(w);
- win.close();
- win.destroy();
- }
- },
- {
- xtype: 'button',
- columnWidth: 0.1,
- text: '关闭',
- width: 60,
- iconCls: 'x-button-icon-close',
- margin: '0 0 0 10',
- handler: function(btn) {
- var win = btn.up('window');
- win.close();
- win.destroy();
- }
- }]
- });
- },
- saveVendorInfo: function(w) {
- var deliveryreply = w.down('field[name=DELIVERYREPLY]').getValue();
- var qty = w.down('field[name=QTYREPLY]').getValue();
- grid = Ext.getCmp('grid'),
- record = grid.getSelectionModel().getLastSelected();
- if (!deliveryreply && !qty && !Ext.getCmp('replydetail').value) {
- showError('请先设置回复信息');
- return;
- } else {
- var isok = w.down('field[name=isok]').getValue();
- var dd = {
- pd_id: record.data.pd_id,
- pd_qtyreply: qty ? qty: 0,
- pd_deliveryreply: deliveryreply ? Ext.Date.format(deliveryreply, 'Y-m-d') : null,
- pd_isok: isok ? '是': '否',
- pd_replydetail:Ext.getCmp('replydetail').value
- };
- Ext.Ajax.request({
- url: basePath + 'scm/purchase/updateVendorBackInfo.action',
- params: {
- data: unescape(Ext.JSON.encode(dd)),
- caller: caller
- },
- method: 'post',
- callback: function(opt, s, res) {
- var r = new Ext.decode(res.responseText);
- if (r.success) {
- grid.GridUtil.loadNewStore(grid, {
- caller: caller,
- condition: gridCondition
- });
- showMessage('提示', '更新成功!', 1000);
- } else if (r.exceptionInfo) {
- showError(r.exceptionInfo);
- } else {
- saveFailure();
- }
- }
- });
- }
- },
- onGridItemClick: function(selModel, record) { //grid行选择
- if (record.data.pd_id != 0 && record.data.pd_id != null && record.data.pd_id != '') {
- var btn = Ext.getCmp('updatevendorbackInfo');
- btn && btn.setDisabled(false);
- btn = Ext.getCmp('erpSplitButton');
- btn && btn.setDisabled(false);
- btn = Ext.getCmp('updatepurcbackInfo');
- btn && btn.setDisabled(false);
- }
- this.GridUtil.onGridItemClick(selModel, record);
- },
- getForm: function(btn) {
- return btn.ownerCt.ownerCt;
- },
- beforeSavePurchase: function() {
- var grid = Ext.getCmp('grid'),
- items = grid.store.data.items,
- c = Ext.getCmp('pu_code').value;
- var vend = Ext.getCmp('pu_vendid').value,
- vendcode = Ext.getCmp('pu_vendcode').value,
- vendname = Ext.getCmp('pu_vendname').value;
- if (vend == null || vend == '' || vend == '0' || vend == 0) {
- showError('未选择供应商,或供应商编号无效!');
- return;
- }
- Ext.Array.each(items,
- function(item) {
- item.set('pd_code', c);
- item.set('pd_vendid', vend);
- item.set('pd_vendcode', vendcode);
- item.set('pd_vendname', vendname);
- });
- //手工录入采购单,合同类型不能为标准
- var pu_kind = Ext.getCmp('pu_kind').value;
- if (pu_kind == null || pu_kind == '') {
- showError('合同类型不能为空');
- return;
- }
- if (pu_kind == '标准' || pu_kind == 'normal' || pu_kind == '標準') {
- showError('手工录入采购单,合同类型不能为标准');
- return;
- }
- var items = grid.store.data.items;
- var bool = true;
- //数量不能为空或0
- Ext.each(items,
- function(item) {
- if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
- if (item.data['pd_qty'] == null) {
- bool = false;
- showError('明细表第' + item.data['pd_detno'] + '行的数量为空');
- return;
- }
- }
- });
- //物料交货日期不能小于录入日期
- Ext.each(items,
- function(item) {
- if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
- if (item.data['pd_delivery'] == null) {
- item.set('pd_delivery', Ext.getCmp('pu_delivery'));
- } else if (item.data['pd_delivery'] < Ext.getCmp('pu_indate').value) {
- bool = false;
- showError('明细表第' + item.data['pd_detno'] + '行的交货日期小于单据录入日期');
- return;
- }
- }
- });
- //保存purchase
- if (bool) this.FormUtil.beforeSave(this);
- },
- beforeUpdate: function() {
- var grid = Ext.getCmp('grid'),
- items = grid.store.data.items,
- c = Ext.getCmp('pu_code').value;
- var vend = Ext.getCmp('pu_vendid').value,
- vendcode = Ext.getCmp('pu_vendcode').value,
- vendname = Ext.getCmp('pu_vendname').value;
- if (vend == null || vend == '' || vend == '0' || vend == 0) {
- showError('未选择供应商,或供应商编号无效!');
- return;
- }
- Ext.Array.each(items,
- function(item) {
- item.set('pd_code', c);
- item.set('pd_vendid', vend);
- item.set('pd_vendcode', vendcode);
- item.set('pd_vendname', vendname);
- });
- var items = grid.store.data.items;
- var bool = true;
- //数量不能为空或0
- Ext.each(items,
- function(item) {
- if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
- if (item.data['pd_qty'] == null || item.data['pd_qty'] == '' || item.data['pd_qty'] == '0' || item.data['pd_qty'] == 0) {
- bool = false;
- showError('明细表第' + item.data['pd_detno'] + '行的数量为空');
- return;
- }
- }
- });
- /*//采购价格不能为0
- if (Ext.getCmp('pu_getprice').value == 0) { //是否自动获取单价
- Ext.each(items,
- function(item) {
- if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
- if (item.data['pd_price'] == null) {
- bool = false;
- showError('明细表第' + item.data['pd_detno'] + '行的价格为空');
- return;
- } else if (item.data['pd_price'] == 0 || item.data['pd_price'] == '0') {
- bool = false;
- showError('明细表第' + item.data['pd_detno'] + '行的价格为0');
- return;
- }
- }
- });
- }*/
- //物料交货日期不能小于录入日期
- Ext.each(items,
- function(item) {
- if (item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != "") {
- if (item.data['pd_delivery'] == null) {
- item.set('pd_delivery', Ext.getCmp('pu_delivery'));
- } else if (item.data['pd_delivery'] < Ext.getCmp('pu_indate').value) {
- bool = false;
- showError('明细表第' + item.data['pd_detno'] + '行的交货日期小于单据录入日期');
- return;
- }
- }
- });
- //更新
- if (bool) this.FormUtil.onUpdate(this);
- },
- /**
- * 复制采购单
- */
- copy: function() {
- var me = this,
- form = Ext.getCmp('form');
- var v = form.down('#pu_id').value;
- if (v > 0) {
- form.setLoading(true);
- Ext.Ajax.request({
- url: basePath + 'scm/purchase/copyPurchase.action',
- params: {
- caller: caller,
- id: v
- },
- callback: function(opt, s, r) {
- form.setLoading(false);
- var res = Ext.decode(r.responseText);
- if (res.data) {
- var url = 'jsps/scm/purchase/purchase.jsp?formCondition=pu_idIS' + res.data.id + '&gridCondition=pd_puidIS' + res.data.id;
- showMessage('提示', '复制成功', 2000);
- me.FormUtil.onAdd(null, '采购单', url);
- } else {
- showError(res.exceptionInfo);
- }
- }
- });
- }
- },
- /**
- *采购单拆分
- * */
- PurchaseSplit:function(record){
- var me=this,originaldetno=Number(record.data.pd_detno);
- var puid=record.data.pd_puid;
- var pdid=record.data.pd_id;
- Ext.create('Ext.window.Window',{
- width:850,
- height:'80%',
- iconCls:'x-grid-icon-partition',
- title:'<h1>采购单拆分</h1>',
- id:'win',
- items:[{
- xtype:'form',
- layout:'column',
- region:'north',
- frame:true,
- defaults:{
- xtype:'textfield',
- columnWidth:0.5,
- readOnly:true,
- fieldStyle:'background:#f0f0f0;border: 0px solid #8B8970;color:blue;'
- },
- items:[{
- fieldLabel:'采购单号',
- value:record.data.pd_code,
- id:'sacode'
- },{
- fieldLabel:'物流编号' ,
- value:record.data.pd_prodcode
- },{
- fieldLabel:'物料名称',
- value:record.data.pr_detail
- },{
- fieldLabel:'原序号' ,
- value:record.data.pd_detno
- },{
- fieldLabel:'原数量',
- value:record.data.pd_qty
- }],
- buttonAlign:'center',
- buttons:[{
- xtype:'button',
- columnWidth:0.12,
- text:'保存',
- width:60,
- iconCls: 'x-button-icon-save',
- margin:'0 0 0 30',
- handler:function(btn){
- var store=Ext.getCmp('smallgrid').getStore();
- var count=0;
- var jsonData=new Array();
- var dd;
- Ext.Array.each(store.data.items,function(item){
- if(item.data.pd_qty!=0&&item.data.pd_delivery!=null&&item.data.pd_qty>0){
- if(item.dirty){
- dd=new Object();
- //说明是新增批次
- dd['pd_qty']=item.data.pd_qty;
- dd['pd_id']=item.data.pd_id;
- dd['pd_detno']=item.data.pd_detno;
- dd['pd_delivery']=Ext.Date.format(item.data.pd_delivery, 'Y-m-d');
- dd['pd_replydetail']=item.data.pd_replydetail;
- dd['pd_isok']=item.data.pd_isok=='-1'?'是':'否';
- dd['pd_qtyreply']=item.data.pd_qtyreply;
- if(item.data.pd_deliveryreply){
- dd['pd_deliveryreply']=Ext.Date.format(item.data.pd_deliveryreply, 'Y-m-d');
- }else
- dd['pd_deliveryreply']=null;
- jsonData.push(Ext.JSON.encode(dd));
- }
- count+=Number(item.data.pd_qty);
- }
- });
- var assqty=Number(record.data.pd_qty);
- if(count!=assqty){
- showError('分拆数量必须等于原数量!') ;
- return;
- }else{
- var r=new Object();
- r['pd_id']=record.data.pd_id;
- r['pd_puid']=record.data.pd_puid;
- r['pd_detno']=record.data.pd_detno;
- var params=new Object();
- params.formdata = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
- params.data = unescape(jsonData.toString().replace(/\\/g,"%"));
- Ext.Ajax.request({
- url : basePath +'scm/purchase/splitPurchase.action',
- params : params,
- waitMsg:'拆分中...',
- method : 'post',
- callback : function(options,success,response){
- var localJson = new Ext.decode(response.responseText);
- if(localJson.success){
- saveSuccess(function(){
- //add成功后刷新页面进入可编辑的页面
- Ext.getCmp('win').close();
- me.loadSplitData(originaldetno,puid,record);
- });
- } else if(localJson.exceptionInfo){
- var str = localJson.exceptionInfo;
- if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
- str = str.replace('AFTERSUCCESS', '');
- saveSuccess(function(){
- //add成功后刷新页面进入可编辑的页面
- me.loadSplitData(originaldetno,puid,record);
- });
- showError(str);
- } else {
- showError(str);
- return;
- }
-
- } else{
- saveFailure();
- }
- }
- });
-
- }
- }
- },{
- xtype:'button',
- columnWidth:0.1,
- text:'关闭',
- width:60,
- iconCls: 'x-button-icon-close',
- margin:'0 0 0 10',
- handler:function(btn){
- Ext.getCmp('win').close();
- }
- }]
- },{
- xtype:'gridpanel',
- region:'south',
- id:'smallgrid',
- layout:'fit',
- height:'80%',
- columnLines:true,
- store:Ext.create('Ext.data.Store',{
- 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'}],
- data:[]
- }),
- plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
- clicksToEdit: 1,
- listeners:{
- 'edit':function(editor,e,Opts){
- var record=e.record;
- var version=record.data.ma_version;
- if(version){
- e.record.reject();
- Ext.Msg.alert('提示','不能修改已拆分明细!');
- }
- }
- }
- })],
- tbar: [{
- tooltip: '添加批次',
- iconCls: 'x-button-icon-add',
- width:25,
- handler : function() {
- var store = Ext.getCmp('smallgrid').getStore();
- var r = new Object();
- r.pd_delivery=record.get('pd_delivery');
- r.pd_qty=0;
- r.pd_id=0;
- r.pd_detno=store.getCount()+1;
- store.insert(store.getCount(), r);
- }
- }, {
- tooltip: '删除批次',
- width:25,
- itemId: 'delete',
- iconCls: 'x-button-icon-delete',
- handler: function(btn) {
- var sm = Ext.getCmp('smallgrid').getSelectionModel();
- var record=sm.getSelection();
- var pd_id=record[0].data.pd_id;
- if(pd_id&&pd_id!=0){
- Ext.Msg.alert('提示','不能删除已拆批次或原始行号!');
- return;
- }
- var store=Ext.getCmp('smallgrid').getStore();
- store.remove(record);
- if (store.getCount() > 0) {
- sm.select(0);
- }
- },
- disabled: true
- }],
- listeners:{
- itemmousedown:function(selmodel, record){
- selmodel.ownerCt.down('#delete').setDisabled(false);
- }
- },
- columns:[{
- dataIndex:'pd_detno',
- header:'序号',
- format:'0',
- xtype:'numbercolumn'
- },{
- dataIndex:'pd_delivery',
- header:'交货日期',
- xtype:'datecolumn',
- width:120,
- editable:true,
- renderer:function(val,meta,record){
- if(record.data.ma_version){
- meta.tdCls = "x-grid-cell-renderer-cl";
- }
- if(val)
- return Ext.Date.format(val, 'Y-m-d');
- else return null;
- },
- editor:{
- xtype: 'datefield',
- format:'Y-m-d'
- }
- },{
- dataIndex:'pd_qty',
- header:'数量',
- width:120,
- xtype:'numbercolumn',
- editable:true,
- renderer:function(val,meta,record){
- if(record.data.ma_version){
- meta.tdCls = "x-grid-cell-renderer-cl";
- }
- return val;
- },
- editor:{
- xtype:'numberfield',
- format:'0',
- hideTrigger: true
- }
- },{
- dataIndex:'pd_deliveryreply',
- header:'回复交期',
- xtype:'datecolumn',
- width:120,
- editable:true,
- renderer:function(val,meta,record){
- if(val)
- return Ext.Date.format(val, 'Y-m-d');
- else return null;
- },
- editor:{
- xtype: 'datefield',
- format:'Y-m-d'
- }
- },{
- dataIndex:'pd_qtyreply',
- header:'回复数量',
- width:120,
- xtype:'numbercolumn',
- editable:true,
- renderer:function(val,meta,record){
- if(record.data.ma_version){
- meta.tdCls = "x-grid-cell-renderer-cl";
- }
- return val;
- },
- editor:{
- xtype:'numberfield',
- format:'0',
- hideTrigger: true
- }
- },{
- dataIndex:'pd_isok',
- header:'是否准时',
- xtype:'yncolumn',
- width:100,
- editable:true
- },{
- dataIndex:'pd_replydetail',
- header:'回复明细',
- width:100,
- renderer:function(val,meta,record){
- if(record.data.originaldetno){
- meta.tdCls = "x-grid-cell-renderer-cl";
- }
- return val;
- } ,
- editor:{
- xtype:'textfield',
- format:'0',
- hideTrigger: true
- },
- editable:true
- },{
- dataIndex:'pd_yqty',
- header:'已转收料数',
- xtype:'numbercolumn',
- width:100,
- editable:false
- },{
- dataIndex:'pd_acceptqty',
- header:'已转验收数',
- xtype:'numbercolumn',
- width:100,
- editable:false
- },{
- dataIndex:'pd_id',
- header:'pdid',
- width:0,
- xtype:'numbercolumn',
- editable:true,
- editor:{
- xtype:'numberfield',
- format:'0',
- hideTrigger: true
- }
- }]
- }] ,
- listeners:{
- 'beforeclose':function(view ,opt){
- var grid = Ext.getCmp('grid');
- var value = Ext.getCmp('pu_id').value;
- var gridCondition = grid.mainField + '=' + value,
- gridParam = {caller: caller, condition: gridCondition};
- me.GridUtil.loadNewStore(grid, gridParam);
- }
- }
- }).show();
- this.loadSplitData(originaldetno,puid,record);
- },
- loadSplitData:function(detno,puid,record){
- var grid=Ext.getCmp('smallgrid');
- grid.setLoading(true);//loading...
- Ext.Ajax.request({//拿到grid的columns
- url : basePath + "common/loadNewGridStore.action",
- params:{
- caller:'PurchaseSplit',
- condition:"pd_detno="+detno+" AND pd_puid="+puid+" order by pd_id asc"
- },
- method : 'post',
- callback : function(options,success,response){
- grid.setLoading(false);
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo){
- showError(res.exceptionInfo);return;
- }
- var data = res.data;
- grid.store.loadData(data);
- //自定义event
- grid.addEvents({
- storeloaded: true
- });
- grid.fireEvent('storeloaded', grid, data);
- }
- });
- },
- getLeadCode: function(type) {
- var result = null;
- Ext.Ajax.request({
- url : basePath + 'common/getFieldData.action',
- async: false,
- params: {
- caller: 'PurchaseKind',
- field: 'pk_excode',
- condition: 'pk_name=\'' + type + '\''
- },
- method : 'post',
- callback : function(opt, s, res){
- var r = new Ext.decode(res.responseText);
- if(r.exceptionInfo){
- showError(r.exceptionInfo);return;
- } else if(r.success){
- result = r.data;
- }
- }
- });
- return result;
- }
- });
|