| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450 |
- Ext.QuickTips.init();
- Ext.define('erp.controller.scm.purchase.Application', {
- 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.Application','core.grid.Panel2','core.toolbar.Toolbar','core.form.MultiField',
- 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','core.button.ResAudit',
- 'core.button.Audit','core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail','core.button.ResSubmit',
- 'core.button.TurnPurc','core.button.Flow','core.button.ImportExcel', 'core.button.UpdateRemark','core.button.ProduceBatch',
- 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.grid.YnColumn','core.form.FileField','core.button.MRPResourceScan'
- ],
- init:function(){
- var me = this;
- me.gridLastSelected = null;
- this.control({
- 'field[name=ap_remark]':{
- afterrender: function(field){
- Ext.defer(function(){
- field.setReadOnly(false);
- }, 200);
- }
- },
- 'erpGridPanel2': {
- itemclick: function(selModel, record){
- if(record.data.ad_prodcode != null && record.data.ad_prodcode != ''){
- var btn = Ext.getCmp('erpMRPResourceScan_button');
- if(btn){
- btn.setDisabled(false);
- btn._ad_prodcode = record.data.ad_prodcode;
- }
- }
- this.onGridItemClick(selModel, record);
-
- }
- },
- '#erpMRPResourceScan_button':{
- click:function(btn){
- var refcode = Ext.getCmp('ap_refcode').getValue();
- var prodcode = btn._ad_prodcode;
- if(Ext.isEmpty(refcode)){
- showError("[MRP单号]为空,不能查看MRP来源!");
- return;
- }
- if (!Ext.isEmpty(refcode)&&!Ext.isEmpty(prodcode)){
- var win = new Ext.window.Window({
- id : 'win_Resource',
- height : '90%',
- width : '95%',
- maximizable : true,
- buttonAlign : 'center',
- layout : 'anchor',
- items : [ {
- tag : 'iframe',
- frame : true,
- anchor : '100% 100%',
- layout : 'fit',
- html : '<iframe id="iframe_MRPResourceScanWin'+refcode+'" src="'+basePath+'jsps/common/datalist.jsp?_noc=1&whoami=Desk!MrpResultDetail&urlcondition=md_mrpcode=\''+refcode+'\' and md_prodcode=\''+prodcode+'\'" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
- } ]
- });
- win.show();
- }
- }
- },
- 'field[name=ap_currency]': {
- beforetrigger: function(field) {
- var t = field.up('form').down('field[name=ap_date]'),
- value = t.getValue();
- if(value) {
- field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym');
- }
- }
- },
- '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('ap_kind').value);
- if(res != null && res != ''){
- codeField.setValue(res + codeField.getValue());
- }
- }
- var bool = true;
- //数量不能为空或0
- //给从表赋值:vendcode、vendname
- var grid = Ext.getCmp('grid'),
- items = grid.store.data.items,
- recorddate = Ext.getCmp('ap_recorddate').value;
- Ext.each(items, function(item){
- if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
- if(item.data['ad_qty'] == null || item.data['ad_qty'] == '' || item.data['ad_qty'] == '0'
- || item.data['pd_qty'] == 0){
- bool = false;
- showError('明细表第' + item.data['ad_detno'] + '行的数量为空');return;
- }
- if(Ext.isEmpty(item.data['ad_delivery'])){
- bool = false;
- showError('明细表第' + item.data['ad_detno'] + '行的需求日期不能为空');return;
- }
- if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(recorddate,'Y-m-d')){
- bool = false;
- showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据录入日期');return;
- }
- if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){
- bool = false;
- showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据当前日期');return;
- }
- }
- });
- if(bool){
- this.FormUtil.beforeSave(this);
- }
- }
- },
- 'erpDeleteButton' : {
- click: function(btn){
- me.FormUtil.onDelete(Ext.getCmp('ap_id').value);
- }
- },
- 'erpProduceBatchButton':{
- beforerender:function(btn){
- btn.setText("计 算");
- },
- click: function(btn){
- var id=Ext.getCmp('ap_id').value;
- grid = Ext.getCmp('grid');
- Ext.Ajax.request({
- url : basePath + "scm/purchase/applicationdataupdate.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:'Application',
- condition:gridCondition,
- _noc:1
- });
- showError("计算成功!");
- }
- });
- }
- },
- 'erpImportExcelButton':{
- afterrender:function(btn){
- var statuscode=Ext.getCmp('ap_statuscode').getValue();
- if(statuscode&&statuscode!='ENTERING'){
- btn.hide();
- }
- }
- },
- 'filefield[id=excelfile]':{
- change: function(field){
- var filename = '';
- if(contains(field.value, "\\", true)){
- filename = field.value.substring(field.value.lastIndexOf('\\') + 1);
- } else {
- filename = field.value.substring(field.value.lastIndexOf('/') + 1);
- }
- field.ownerCt.getForm().submit({
- url: basePath + 'common/upload.action?em_code=' + em_code,
- waitMsg: "正在解析文件信息",
- success: function(fp,o){
- if(o.result.error){
- showError(o.result.error);
- } else {
- var filePath=o.result.filepath;
- var keyValue=Ext.getCmp('ap_id').getValue();
- Ext.Ajax.request({//拿到form的items
- url : basePath + 'scm/application/ImportExcel.action',
- params:{
- id:keyValue,
- fileId:filePath
- },
- method : 'post',
- callback : function(options,success,response){
- var result=Ext.decode(response.responseText);
- if(result.success){
- var grid=Ext.getCmp('grid');
- var param={
- caller:'Application',
- condition:'ad_apid='+keyValue
- };
- grid.GridUtil.loadNewStore(grid,param);
- }else{
- if(result.exceptionInfo != null){
- showError(res.exceptionInfo);return;
- }
- }
- }
- });
- }
- }
- });
- }
- },
- 'erpUpdateButton': {
- click: function(btn){
- var form = me.getForm(btn);
- if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
- me.BaseUtil.getRandomNumber();//自动添加编号
- }
- var bool = true;
- //数量不能为空或0
- //给从表赋值:vendcode、vendname
- var grid = Ext.getCmp('grid'), items = grid.store.data.items,
- c = Ext.getCmp('ap_code').value,
- recorddate = Ext.getCmp('ap_recorddate').value;
- Ext.each(items, function(item){
- item.set('ad_code',c);
- if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
- if(item.data['ad_qty'] == null || item.data['ad_qty'] == '' || item.data['ad_qty'] == '0'
- || item.data['pd_qty'] == 0){
- bool = false;
- showError('明细表第' + item.data['ad_detno'] + '行的数量为空');return;
- }
- if(Ext.isEmpty(item.data['ad_delivery'])){
- bool = false;
- showError('明细表第' + item.data['ad_detno'] + '行的需求日期不能为空');return;
- }
- if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(recorddate,'Y-m-d')){
- bool = false;
- showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据录入日期');return;
- }
- if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){
- bool = false;
- showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据当前日期');return;
- }
- }
- });
- if(bool){
- this.FormUtil.onUpdate(this);
- }
- }
- },
- 'erpAddButton': {
- click: function(){
- me.FormUtil.onAdd('addApplication', '新增请购单', 'jsps/scm/purchase/application.jsp');
- }
- },
- 'erpCloseButton': {
- click: function(btn){
- me.FormUtil.beforeClose(me);
- }
- },
- 'erpSubmitButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('ap_statuscode');
- if(status && status.value != 'ENTERING'){
- btn.hide();
- }
- },
- click: function(btn){
- var grid = Ext.getCmp('grid'), c = Ext.getCmp('ap_code').value,
- items = grid.store.data.items, recorddate = Ext.getCmp('ap_recorddate').value
- var bool = true;
- Ext.each(items, function(item){
- item.set('ad_code',c);
- if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
- if(item.data['ad_qty'] == null || item.data['ad_qty'] == '' || item.data['ad_qty'] == '0'
- || item.data['pd_qty'] == 0){
- bool = false;
- showError('明细表第' + item.data['ad_detno'] + '行的数量为空');return;
- }
- if(Ext.isEmpty(item.data['ad_delivery'])){
- bool = false;
- showError('明细表第' + item.data['ad_detno'] + '行的需求日期不能为空');return;
- }
- if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(recorddate,'Y-m-d')){
- bool = false;
- showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据录入日期');return;
- }
- if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){
- bool = false;
- showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据当前日期');return;
- }
- }
- });
- if(bool){
- me.FormUtil.onSubmit(Ext.getCmp('ap_id').value);
- }
- }
- },
- 'erpResSubmitButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('ap_statuscode');
- if(status && status.value != 'COMMITED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onResSubmit(Ext.getCmp('ap_id').value);
- }
- },
- 'erpAuditButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('ap_statuscode');
- if(status && status.value != 'COMMITED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onAudit(Ext.getCmp('ap_id').value);
- }
- },
- 'erpResAuditButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('ap_statuscode');
- if(status && status.value != 'AUDITED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onResAudit(Ext.getCmp('ap_id').value);
- }
- },
- 'erpPrintButton': {
- click:function(btn){
- var reportName="application";
- var condition='{Application.ap_id}='+Ext.getCmp('ap_id').value+'';
- var id=Ext.getCmp('ap_id').value;
- me.FormUtil.onwindowsPrint(id,reportName,condition);
- }
- },
- 'erpUpdateRemarkButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('ap_statuscode');
- if (status && status.value == 'ENTERING') {
- btn.hide();
- }
- },
- click : function(btn) {
- Ext.Ajax.request({
- url : basePath + 'common/updateByCondition.action',
- params : {
- caller : caller,
- table : 'Application',
- update : 'ap_remark=\'' + Ext.getCmp('ap_remark').value + '\'',
- condition : 'ap_id=' + Ext.getCmp('ap_id').value
- },
- callback : function(opt, s, res) {
- var r = Ext.decode(res.responseText);
- if (r.success) {
- alert('修改成功!');
- }
- }
- });
- }
- },
- /*'field[name=ad_qty]':{
- change: function(f){
- if(f.value == null || f.value == ''){
- f.value = 0;
- }
- var record = Ext.getCmp('grid').selModel.getLastSelected();
- var value=record.data['ad_qty'];
- if(!record.data['ad_minorder'] || record.data['ad_minorder']==null){
- showError('最小订购量为空,请先填写最小订购量');
- return;
- }
- if(!record.data['ad_minpack'] || record.data['ad_minpack']==null){
- showError('最小包装量为空,请先填写最小包装量');
- return;
- }
- if(value<record.data['ad_minorder']){
- showError('需求数量小于最小订购量,请重新填写!');
- record.set('ad_minorder',null);
- return;
- }
- if(value/record.data['ad_minpack'] !=0){
- showError('需求数量不是最小包装量的整数倍,请重新填写!');
- record.set('ad_minorder',null);
- return;
- }
- }
-
- },*/
- 'erp2PurcButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('ap_turnstatuscode');
- if(status && status.value != 'PARTPURC'){
- btn.hide();
- }
- },
- click: function(btn){
- warnMsg("确定要转入采购单吗?", function(btn){
- if(btn == 'yes'){
- me.FormUtil.getActiveTab().setLoading(true);//loading...
- Ext.Ajax.request({
- url : basePath + 'scm/purchase/turnPurchase.action',
- params: {
- id: Ext.getCmp('ap_id').value
- },
- method : 'post',
- callback : function(options,success,response){
- me.FormUtil.getActiveTab().setLoading(false);
- var localJson = new Ext.decode(response.responseText);
- if(localJson.exceptionInfo){
- showError(localJson.exceptionInfo);
- }
- if(localJson.success){
- turnSuccess(function(){
- window.location.reload();
- });
- }
- }
- });
- }
- });
- }
- }
- });
- },
- onGridItemClick: function(selModel, record){//grid行选择
- this.GridUtil.onGridItemClick(selModel, record);
- },
- getForm: function(btn){
- return btn.ownerCt.ownerCt;
- },
- 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;
- }
- });
|