| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469 |
- Ext.QuickTips.init();
- Ext.define('erp.controller.plm.scm.Sale', {
- 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','plm.scm.Sale','core.grid.Panel2','core.toolbar.Toolbar','core.form.FileField','core.form.MultiField',
- 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','core.button.Upload','core.button.ResAudit',
- 'core.button.Audit','core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail','core.button.ResSubmit',
- 'core.button.Consign','core.button.End','core.button.ResEnd','core.button.TurnNotify','core.button.FeatureDefinition','core.button.FeatureView',
- 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.form.SpecialContainField'
- ],
- init:function(){
- var me = this;
- this.control({
- 'erpGridPanel2': {
- itemclick: function(selModel, record){
- if(record.data.sd_id != 0 && record.data.sd_id != null && record.data.sd_id != ''){
- Ext.getCmp('featuredefinition').setDisabled(false);
- Ext.getCmp('featureview').setDisabled(false);
- Ext.getCmp('bomopen').setDisabled(false);
- }
- if(!Ext.getCmp('grid').readOnly){
- this.onGridItemClick(selModel, record);
- }
- }
- },
- 'erpSaveButton': {
- click: function(btn){
- var form = me.getForm(btn), s=Ext.getCmp('sa_source');
- if(s) {
- var source = s.value;
- if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
- me.getSetting(function(s){
- if(s) {
- if(source == 'TBNOTIFY'){
- me.BaseUtil.getRandomNumber('Sale!PLM!TB');//自动添加编号
- } else if(source == 'MAKENOTIFY'){
- me.BaseUtil.getRandomNumber('Sale!PLM!ZZ');//自动添加编号
- } else if(source == 'TRIAL'){
- me.BaseUtil.getRandomNumber('Sale!PLM!BL');//自动添加编号
- } else if(source == 'EVTFAC'){
- me.BaseUtil.getRandomNumber('Sale!PLM!ES');//自动添加编号
- } else if(source == 'EVTPROJECT'){
- me.BaseUtil.getRandomNumber('Sale!PLM!ES');//自动添加编号
- } else if(source == 'DVT'){
- me.BaseUtil.getRandomNumber('Sale!PLM!DS');//自动添加编号
- } else {
- me.BaseUtil.getRandomNumber(caller);
- }
- } else {
- me.BaseUtil.getRandomNumber();
- }
- });
- }
- } else {
- if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
- me.BaseUtil.getRandomNumber();
- }
- }
- this.beforeSaveSale();
- }
- },
- 'erpDeleteButton' : {
- click: function(btn){
- me.FormUtil.onDelete({id: Number(Ext.getCmp('sa_id').value)});
- }
- },
- 'erpUpdateButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('sa_statuscode');
- if(status && status.value != 'ENTERING'){
- btn.hide();
- }
- },
- click: function(btn){
- me.beforeUpdate();
- }
- },
- 'erpAddButton': {
- click: function(){
- me.FormUtil.onAdd('addSale', '试产订单', 'jsps/plm/scm/sale.jsp');
- }
- },
- 'erpDeleteDetailButton': {
- afterrender: function(btn){
- btn.ownerCt.add({
- xtype: 'erpFeatureDefinitionButton'
- });
- btn.ownerCt.add({
- xtype: 'erpFeatureViewButton'
- });
- btn.ownerCt.add({
- xtype:'button',
- text:'BOM多级展开',
- width:120,
- iconCls: 'x-button-icon-check',
- cls: 'x-btn-gray',
- id:'bomopen',
- style: {
- marginLeft: '10px'
- },
- disabled:true,
- handler:function(){
- var record=btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
- var pr_code=record.data.sd_prodcode;
- var url="jsps/pm/bom/BOMStructQuery.jsp?whoami=BOMStruct!Struct!Query";
- var condition="";
- if(pr_code){
- condition+="pr_codeIS'"+pr_code+"'";
- }
- me.FormUtil.onAdd('BOMStruct'+ pr_code, 'BOM多级展开', url+"&condition="+condition);
- }
- });
- }
- },
- 'erpCloseButton': {
- click: function(btn){
- me.FormUtil.beforeClose(me);
- }
- },
- 'erpSubmitButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('sa_statuscode');
- if(status && status.value != 'ENTERING'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onSubmit(Ext.getCmp('sa_id').value);
- }
- },
- 'erpResSubmitButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('sa_statuscode');
- if(status && status.value != 'COMMITED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onResSubmit(Ext.getCmp('sa_id').value);
- }
- },
- 'erpAuditButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('sa_statuscode');
- if(status && status.value != 'COMMITED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onAudit(Ext.getCmp('sa_id').value);
- }
- },
- 'erpResAuditButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('sa_statuscode');
- if(status && status.value != 'AUDITED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onResAudit(Ext.getCmp('sa_id').value);
- }
- },
- 'erpEndButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('sa_statuscode');
- if(status && status.value != 'AUDITED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onEnd(Ext.getCmp('sa_id').value);
- }
- },
- 'combo[name=sa_source]':{
- change:function (field){
- var href=window.location.href;
- var arrstr=href.split("?");
- if(formCondition!=""){
- window.location.href =arrstr[0]+'?whoami=Sale!PLM!'+field.value+ '&formCondition=' +
- formCondition + '&gridCondition=' + gridCondition+'&source='+field.value;
- }else window.location.href =arrstr[0]+'?whoami=Sale!PLM!'+field.value+ '&source='+field.value;
-
- }
- },
- 'erpResEndButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('sa_statuscode');
- if(status && status.value != 'FINISH'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onResEnd(Ext.getCmp('sa_id').value);
- }
- },
- 'erpPrintButton': {
- click: function(btn){
- me.FormUtil.onPrint(Ext.getCmp('sa_id').value);
- }
- },
- 'field[name=sa_statuscode]': {
- change: function(f){
- var grid = Ext.getCmp('grid');
- if(grid && f.value != 'ENTERING' && f.value != 'COMMITED'){
- grid.setReadOnly(true);//只有未审核的订单,grid才能编辑
- }
- }
- },
- 'erpConsignButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('sa_statuscode');
- if(status && status.value != 'AUDITED'){
- btn.hide();
- }
- }
- },
- 'dbfindtrigger[name=sd_batchcode]': {
- focus: function(t){
- t.setHideTrigger(false);
- t.setReadOnly(false);//用disable()可以,但enable()无效
- var record = Ext.getCmp('grid').selModel.getLastSelected();
- var pr = record.data['sd_prodcode'];
- if(pr == null || pr == ''){
- showError("请先选择料号!");
- t.setHideTrigger(true);
- t.setReadOnly(true);
- } else {
- var id = record.data['sd_warehouseid'];
- if(id == null || id == ''){
- id = Ext.getCmp('sd_warehouseid');
- if(id == null || id == '' || id== 0 ){
- showError("请先选择仓库!");
- t.setHideTrigger(true);
- t.setReadOnly(true);
- }
- } else {
- t.dbBaseCondition = "ba_warehouseid='" + id + "' AND ba_prodcode='" + pr + "'";
- }
- }
- }
- },
- 'erpFeatureDefinitionButton':{
- click: function(btn){
- var grid = Ext.getCmp('grid');
- var record = grid.selModel.lastSelected;
- if(record.data.sd_prodcode != null){
- Ext.Ajax.request({//拿到grid的columns
- url : basePath + "pm/bom/getDescription.action",
- params: {
- tablename: 'Product',
- field: 'pr_specvalue',
- condition: "pr_code='" + record.data.sd_prodcode + "'"
- },
- method : 'post',
- async: false,
- callback : function(options,success,response){
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo){
- showError(res.exceptionInfo);return;
- }
- if(res.success){
- if(res.description != '' && res.description != null && res.description == 'NOTSPECIFIC'){
- var win = new Ext.window.Window({
- id : 'win',
- title: '生成特征料号',
- height: "90%",
- width: "70%",
- maximizable : true,
- buttonAlign : 'center',
- layout : 'anchor',
- items: [{
- tag : 'iframe',
- frame : true,
- anchor : '100% 100%',
- layout : 'fit',
- html : '<iframe id="iframe_' + record.data.sd_id + '" src="' + basePath +
- "jsps/pm/bom/FeatureValueSet.jsp?fromwhere=SaleDetail&condition=formidIS" + record.data.sd_id + ' AND pr_codeIS' + record.data.sd_prodcode + ' AND pr_nameIS' + record.data.pr_detail +'" height="100%" width="100%" frameborder="0" scrolling="yes"></iframe>'
- }]
- });
- win.show();
- } else {
- showError('物料特征必须为虚拟特征件');return;
- }
- }
- }
- });
- }
- }
- },
- 'erpFeatureViewButton':{
- click: function(btn){
- var grid = Ext.getCmp('grid');
- var record = grid.selModel.lastSelected;
- if(record.data.sd_prodcode != null){
- Ext.Ajax.request({//拿到grid的columns
- url : basePath + "pm/bom/getDescription.action",
- params: {
- tablename: 'Product',
- field: 'pr_specvalue',
- condition: "pr_code='" + record.data.sd_prodcode + "'"
- },
- method : 'post',
- async: false,
- callback : function(options,success,response){
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo){
- showError(res.exceptionInfo);return;
- }
- if(res.success){
- if(res.description != '' && res.description != null && res.description == 'SPECIFIC'){
- var win = new Ext.window.Window({
- id : 'win' + record.data.sd_id,
- title: '特征查看',
- height: "90%",
- width: "70%",
- maximizable : true,
- buttonAlign : 'center',
- layout : 'anchor',
- items: [{
- tag : 'iframe',
- frame : true,
- anchor : '100% 100%',
- layout : 'fit',
- html : '<iframe id="iframe_' + record.data.sd_id + '" src="' + basePath +
- "jsps/pm/bom/FeatureValueView.jsp?fromwhere=SaleDetail&formid=" + record.data.sd_id + '&pr_code=' + record.data.sd_prodcode +'" height="100%" width="100%" frameborder="0" scrolling="yes"></iframe>'
- }]
- });
- win.show();
- } else {
- showError('物料特征必须为 虚拟特征件');return;
- }
- }
- }
- });
- }
- }
- },
- });
- },
- getSetting : function(fn) {
- var me = this;
- Ext.Ajax.request({
- url : basePath + 'common/getFieldData.action',
- async: false,
- params: {
- caller: 'Setting',
- field: 'se_value',
- condition: 'se_what=\'SalePLMType\''
- },
- method : 'post',
- callback : function(opt, s, res){
- var r = new Ext.decode(res.responseText);
- var t = false;
- if(r.exceptionInfo){
- showError(r.exceptionInfo);return;
- }
- if(r.success && r.data){
- t = r.data == 'true';
- }
- fn.call(me, t);
- }
- });
- },
- onGridItemClick: function(selModel, record){//grid行选择
- this.GridUtil.onGridItemClick(selModel, record);
- },
- getRecordByPrCode: function(){
- if(this.gridLastSelected && this.gridLastSelected.findable){
- var data = Ext.getCmp('grid').store.data.items[this.gridLastSelected.index].data;
- var code = data.pd_prodcode;
- if(code != null && code!= ''){//看用户输入了编号没有
- var str = "sd_prodcode='" + code + "'";
- this.GridUtil.getRecordByCode({caller: 'Sale', condition: str});
- }
- }
- },
- getForm: function(btn){
- return btn.ownerCt.ownerCt;
- },
- beforeSaveSale: function(){
- var grid = Ext.getCmp('grid');
- var items = grid.store.data.items,sacode=Ext.getCmp('sa_code').value;
- var bool = true;
- //数量不能为空或0
- var recorddate = Ext.Date.format(Ext.getCmp('sa_recorddate').value, 'Ymd');
- Ext.each(items, function(item){
- item.set('sd_code', sacode);
- if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
- if(item.data['sd_qty'] == null || item.data['sd_qty'] == '' || item.data['sd_qty'] == '0'
- || item.data['sd_qty'] == 0){
- bool = false;
- showError('明细表第' + item.data['sd_detno'] + '行的数量为空');return;
- }
- }
- });
- var basedate=null,index=0;
- Ext.each(items, function(item){
- item.set('sd_code',sacode);
- if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
- if(item.data['sd_delivery'] == null){
- if(index!=0){
- item.set('sd_delivery',basedate);
- }else {
- bool=false;
- showError('明细行第'+item.data['sd_detno']+'行交货日期为空 不能更新!');
- return ;
- }
-
- } else if(Ext.Date.format(item.data['sd_delivery'], 'Ymd') < recorddate){
- bool = false;
- showError('明细表第' + item.data['sd_detno'] + '行的交货日期小于单据录入日期');return;
- }else {
- basedate=item.data['sd_delivery'];
- }
- index++;
- }
- });
- //保存sale
- if(bool)
- this.FormUtil.beforeSave(this);
- },
- beforeUpdate: function(){
- var grid = Ext.getCmp('grid');
- var sacode = Ext.getCmp('sa_code').value;
- var items = grid.store.data.items;
- var bool = true;
- var recorddate = Ext.Date.format(Ext.getCmp('sa_recorddate').value, 'Ymd');
- //数量不能为空或0
- Ext.each(items, function(item){
- if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
- if(item.data['sd_qty'] == null || item.data['sd_qty'] == '' || item.data['sd_qty'] == '0'
- || item.data['sd_qty'] == 0){
- bool = false;
- showError('明细表第' + item.data['sd_detno'] + '行的数量为空');return;
- }
- }
- });
- var recorddate = Ext.Date.format(Ext.getCmp('sa_date').value, 'Ymd');
- var basedate=null,index=0;
- Ext.each(items, function(item){
- item.set('sd_code',sacode);
- if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
- if(item.data['sd_delivery'] == null){
- if(index!=0){
- item.set('sd_delivery',basedate);
- }else {
- bool=false;
- showError('明细行第'+item.data['sd_detno']+'行交货日期为空 不能更新!');
- return ;
- }
-
- } else if(Ext.Date.format(item.data['sd_delivery'], 'Ymd') < recorddate){
- bool = false;
- showError('明细表第' + item.data['sd_detno'] + '行的交货日期小于单据录入日期');return;
- }else {
- basedate=item.data['sd_delivery'];
- }
- index++;
- }
- });
- //保存
- if(bool)
- this.FormUtil.onUpdate(this);
- }
- });
|