| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612 |
- Ext.QuickTips.init();
- Ext.define('erp.controller.fa.ars.APBill', {
- 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','fa.ars.APBill','core.grid.Panel2','core.toolbar.Toolbar',
- '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.ResSubmit',
- 'core.button.Post','core.button.ResPost','core.button.AutoInvoice', 'core.button.Confirm', 'core.button.Cancel',
- 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.form.MonthDateField',
- 'core.trigger.CateTreeDbfindTrigger','core.button.AssDetail','core.button.BillDateUpdate','core.form.SeparNumber',
- 'core.button.PrintVoucherCode', 'core.button.TicketTaxes'
- ],
- init:function(){
- var me = this;
- me.gridLastSelected = null;
- this.control({
- 'erpGridPanel2': {
- itemclick:function(selModel, record){
- me.onGridItemClick(selModel, record);
- if(caller =='APBill!OTDW'){
- var btn = Ext.getCmp('assdetail');
- var ass = record.data['ca_asstype'];
- if(!Ext.isEmpty(ass)){
- btn.setDisabled(false);
- } else {
- btn.setDisabled(true);
- }
- }
- },
- afterrender:function(grid){
- grid.plugins[0].on('afteredit',function(e){
- setTimeout(function(){
- var amount = grid.store.getSum(grid.store.data.items, 'abd_apamount');
- Ext.getCmp('ab_apamount').setValue(amount);
- },200);
-
- });
- }
- },
- 'erpDeleteDetailButton': {
- afterrender: function(btn){
- if(caller =='APBill!OTDW'){
- //辅助核算
- btn.ownerCt.add({
- xtype:'erpAssDetailButton',
- disabled:true
- });
- }
- }
- },
- 'field[name=ab_currency]': {
- beforetrigger: function(field) {
- var t = field.up('form').down('field[name=ab_date]'),
- value = t.getValue();
- if(value) {
- field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym');
- }
- }
- },
- 'erpSaveButton': {
- click: function(btn){
- var form = me.getForm(btn);
- if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
- me.BaseUtil.getRandomNumber();
- }
- //保存之前的一些前台的逻辑判定
- this.beforeSaveAPBill();
- }
- },
- 'erpDeleteButton' : {
- afterrender: function(btn){
- var poststatus = Ext.getCmp('ab_statuscode');
- if(poststatus && poststatus.value == 'POSTED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onDelete(Ext.getCmp('ab_id').value);
- }
- },
- 'erpUpdateButton': {
- afterrender: function(btn){
- var poststatus = Ext.getCmp('ab_statuscode');
- if(poststatus && poststatus.value == 'POSTED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.beforeUpdateAPBill();
- }
- },
- 'erpAddButton': {
- click: function(){
- var form = Ext.getCmp('form');
- var title = '新增';
- if(form){
- if(form.title){
- title = title+form.title;
- }
- }
- me.FormUtil.onAdd('addAPBill', title, 'jsps/fa/ars/apbill.jsp?whoami='+caller);
- }
- },
- 'erpCloseButton': {
- click: function(btn){
- me.FormUtil.beforeClose(me);
- }
- },
- 'erpSubmitButton': {
- afterrender: function(btn){
- var auditStatus = Ext.getCmp(me.getForm(btn).auditStatusCode);
- if(auditStatus && auditStatus.value != 'ENTERING'){
- btn.hide();
- }
- var poststatus = Ext.getCmp('ab_statuscode');
- if(poststatus && poststatus.value == 'POSTED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onSubmit(Ext.getCmp('ab_id').value, false, me.beforeUpdateAPBill, me);
- }
- },
- 'erpResSubmitButton': {
- afterrender: function(btn){
- var auditStatus = Ext.getCmp(me.getForm(btn).auditStatusCode);
- if(auditStatus && auditStatus.value != 'COMMITED'){
- btn.hide();
- }
- var poststatus = Ext.getCmp('ab_statuscode');
- if(poststatus && poststatus.value == 'POSTED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onResSubmit(Ext.getCmp('ab_id').value);
- }
- },
- 'erpAuditButton': {
- afterrender: function(btn){
- var auditStatus = Ext.getCmp(me.getForm(btn).auditStatusCode);
- if(auditStatus && auditStatus.value != 'COMMITED'){
- btn.hide();
- }
- var poststatus = Ext.getCmp('ab_statuscode');
- if(poststatus && poststatus.value == 'POSTED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onAudit(Ext.getCmp('ab_id').value);
- }
- },
- 'erpResAuditButton': {
- afterrender: function(btn){
- var auditStatus = Ext.getCmp(me.getForm(btn).auditStatusCode);
- if(auditStatus && auditStatus.value != 'AUDITED'){
- btn.hide();
- }
- var poststatus = Ext.getCmp('ab_statuscode');
- if(poststatus && poststatus.value == 'POSTED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onResAudit(Ext.getCmp('ab_id').value);
- }
- },
- 'erpPrintButton': {
- click: function(btn){
- var reportName="PurcInvoice";
- var id=Ext.getCmp('ab_id').value;
- var condition = '{APBill.ab_id}=' + Ext.getCmp('ab_id').value;
- me.FormUtil.onwindowsPrint(id, reportName, condition);
- }
- },
- 'erpPrintVoucherCodeButton': {
- click: function(btn){
- if(Ext.getCmp('ab_vouchercode').value ==null || Ext.getCmp('ab_vouchercode').value ==''){
- showError('当前发票还没有制作凭证,不能打印');
- }else{
- var reportName = '';
- reportName = "PurcVCInvoice";
- var condition = '{APBill.ab_vouchercode}=\'' + Ext.getCmp('ab_vouchercode').value +'\'';
- var id=Ext.getCmp('ab_id').value;
- me.FormUtil.onwindowsPrint(id, reportName, condition);
- }
-
- }
- },
- 'erpPostButton': {
- afterrender: function(btn){
- var status = Ext.getCmp(me.getForm(btn).statusCode);
- if(status && status.value == 'UNPOST'){
- btn.show();
- }else{
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onPost(Ext.getCmp('ab_id').value);
- }
- },
- 'erpResPostButton': {
- afterrender: function(btn){
- var status = Ext.getCmp(me.getForm(btn).statusCode);
- if(status && status.value == 'POSTED'){
- btn.show();
- }else{
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onResPost(Ext.getCmp('ab_id').value);
- }
- },
- 'erpConfirmButton': {
- afterrender: function(btn){
- btn.setText( $I18N.common.button.erpConfirmCheckButton );
- btn.setWidth( 100 );
- var status = Ext.getCmp('ab_statuscode');
- if(status && status.value != 'POSTED'){
- btn.hide();
- }
- confirmstatus = Ext.getCmp('ab_confirmstatus');
- if(confirmstatus && confirmstatus.value == '已对账'){
- btn.hide();
- }
- },
- click: function(btn){
- warnMsg("确定对账吗?", function(btn){
- if(btn == 'yes'){
- me.FormUtil.getActiveTab().setLoading(true);//loading...
- Ext.Ajax.request({
- url : basePath + 'fa/arp/confirmAPBill.action',
- params: {
- id: Ext.getCmp('ab_id').value,
- caller : caller
- },
- 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){
- window.location.reload();
- }
- }
- });
- }
- });
- }
- },
- 'erpCancelButton': {
- afterrender: function(btn){
- btn.setText( $I18N.common.button.erpCancelCheckButton );
- btn.setWidth( 100 );
- var status = Ext.getCmp('ab_confirmstatus');
- if(status && status.value != '已对账'){
- btn.hide();
- }
- },
- click: function(btn){
- warnMsg("取消对账吗?", function(btn){
- if(btn == 'yes'){
- me.FormUtil.getActiveTab().setLoading(true);//loading...
- Ext.Ajax.request({
- url : basePath + 'fa/arp/cancelAPBill.action',
- params: {
- id: Ext.getCmp('ab_id').value,
- caller : caller
- },
- 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){
- window.location.reload();
- }
- }
- });
- }
- });
- }
- },
- 'erpAutoInvoiceButton': {
- click: function(btn){
- var abcode=Ext.getCmp('ab_code').value;
- var abdate=Ext.getCmp('ab_date').value;
- Ext.Ajax.request({
- url : basePath + 'fa/ars/createVoucherAPO.action',
- params: {
- abcode: abcode,
- abdate: abdate
- },
- 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(){
- //var id = localJson.id;
- //var url = "jsps/scm/purchase/purchasePrice.jsp?formCondition=pp_id=" + id +
- //"&gridCondition=ppd_ppid=" + id;
- //me.FormUtil.onAdd('PurchasePrice' + id, '物料核价单' + id, url);
- });
- }
- }
- });
- }
- },
- 'numberfield[name=ab_apamount]':{
- beforerender:function(num){
- num.minValue = Number.NEGATIVE_INFINITY;
- num.setMinValue(num.minValue);
- b = num.baseChars+"";
- b += num.decimalSeparator;
- b += "-";
- b = Ext.String.escapeRegex(b);
- num.maskRe = new RegExp("[" + b + "]");
- }
- },
- 'erpTicketTaxesButton': {
- click: function(btn){
- var me = this, win = Ext.getCmp('ticketTaxes-win');
- if(!win){
- var ab_refno = Ext.getCmp('ab_refno').value, ab_remark = Ext.getCmp('ab_remark').value,
- win = Ext.create('Ext.Window', {
- id: 'ticketTaxes-win',
- title: '更新税票信息',
- height: 200,
- width: 400,
- items: [{
- xtype: 'form',
- height: '100%',
- width: '100%',
- bodyStyle: 'background:#f1f2f5;',
- items: [{
- margin: '10 0 0 0',
- xtype: 'textfield',
- fieldLabel: '税票编号',
- name:'ab_refno',
- value: ab_refno
- },{
- margin: '10 0 0 0',
- xtype: 'textfield',
- fieldLabel: '备注',
- name:'ab_remark',
- value: ab_remark
- }],
- closeAction: 'hide',
- buttonAlign: 'center',
- layout: {
- type: 'vbox',
- align: 'center'
- },
- buttons: [{
- text: $I18N.common.button.erpConfirmButton,
- cls: 'x-btn-blue',
- handler: function(btn) {
- var form = btn.ownerCt.ownerCt,
- a = form.down('textfield[name=ab_refno]'),
- b = form.down('textfield[name=ab_remark]');
- if(form.getForm().isDirty()) {
- me.updateTaxcode(Ext.getCmp('ab_id').value, a.value, b.value);
- }
- }
- }, {
- text: $I18N.common.button.erpCloseButton,
- cls: 'x-btn-blue',
- handler: function(btn) {
- btn.up('window').hide();
- }
- }]
- }]
- });
- }
- win.show();
- }
- },
- 'field[name=ab_differ]':{/*
- change:function(field){
- if(Ext.getCmp('ab_differ')){
- var sum = 0;
- var v_differ = Ext.isNumber(Ext.getCmp('ab_differ').getValue())?Ext.getCmp('ab_differ').getValue():'0';
- var grid = Ext.getCmp('grid');
- Ext.each(grid.store.data.items,function(item,index){
- if(item.dirty && !me.GridUtil.isBlank(grid, item.data)){
- sum += Number(item.data['abd_taxamount']);
- }
- });
- sum += Number(v_differ);
- Ext.getCmp('ab_taxsum').setValue(sum);
- }
- }
-
- */}
- });
- },
-
- //此CALLER为 应收发票维护界面 删除单据需要把明细行中开票数据还原
- //在此做还原操作
-
- //此CALLER为 应收发票维护界面 修改单据需要把明细行中开票数据还原
- // //在此做还原操作
- onGridItemClick: function(selModel, record){//grid行选择
- this.gridLastSelected = record;
- var grid = Ext.getCmp('grid');
- if(record.data[grid.necessaryField] == null || record.data[grid.necessaryField] == ''){
- this.gridLastSelected.findable = true;//空数据可以在输入完code,并移开光标后,自动调出该条数据
- } else {
- this.gridLastSelected.findable = false;
- }
- this.GridUtil.onGridItemClick(selModel, record);
- },
- getForm: function(btn){
- return btn.ownerCt.ownerCt;
- },
- beforeSaveAPBill: function(){
- if(caller =='APBill!CWIM'){
- var date_s = Ext.getCmp('ab_date').rawValue;
- var date_str = date_s.replace("-","");
- if(date_str.length>=6){
- date_str = date_str.substring(0,6);
- }else{
- var myDate = new Date();
- var dateString = Ext.Date.format(myDate,'Ymd');
- date_str = dateString.substring(0,6);
- }
-
- Ext.getCmp('ab_yearmonth').setValue(date_str);
- }
- this.BaseUtil.getPaydate('ab_paymentsmethodid','ab_date','ab_paydate');
-
- //保存ARBill
- /*if(bool)*/
- this.beforeSave(this);
- },
- beforeSave: function(){
- var me = this;
- var form = Ext.getCmp('form');
- if(! me.FormUtil.checkForm()){
- return;
- }
- if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
- me.FormUtil.getSeqId(form);
- }
- var detail = Ext.getCmp('grid');
- var param2 = new Array();
- var param3 = new Array();
-
- if(Ext.getCmp('assdetail')){
- Ext.each(Ext.Object.getKeys(Ext.getCmp('assdetail').cacheStoreGrid), function(key){
- Ext.each(Ext.getCmp('assdetail').cacheStoreGrid[key], function(d){
- d['dass_condid'] = key;
- param2.push(d);
- });
- });
- }
- if(Ext.getCmp('assmainbutton')){
- // Ext.each(Ext.Object.getKeys(Ext.getCmp('assmainbutton').cacheStoreForm), function(key){
- // Ext.each(Ext.getCmp('assmainbutton').cacheStoreForm[key], function(d){
- // d['ass_conid'] = key;
- // param3.push(d);
- // });
- // }
- }
- Ext.each(detail.store.data.items, function(item){
- if(item.data.prd_id == null || item.data.prd_id == 0){
- item.data.prd_id = -item.index;
- }
- });
- var param1 = me.GridUtil.getGridStore(detail);
- me.onSave(form, param1, param2,param3);
- },
- onSave: function(form, param1, param2,param3){
- var me = this;
- param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
- param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
- param3 = param3 == null ? [] : Ext.encode(param3).replace(/\\/g,"%");
- if(form.getForm().isValid()){
- Ext.each(form.items.items, function(item){
- if(item.xtype == 'numberfield'){
- if(item.value == null || item.value == ''){
- item.setValue(0);
- }
- }
- });
- me.FormUtil.save(form.getValues(), param1, param2,param3);
- }else{
- me.FormUtil.checkForm();
- }
- },
- beforeUpdateAPBill: function(){
- var grid = Ext.getCmp('grid');
- if(caller =='APBill!CWIM'){
- var date_s = Ext.getCmp('ab_date').rawValue;
- var date_str = date_s.replace("-","");
- if(date_str.length>=6){
- date_str = date_str.substring(0,6);
- }else{
- var myDate = new Date();
- var dateString = Ext.Date.format(myDate,'Ymd');
- date_str = dateString.substring(0,6);
- }
-
- Ext.getCmp('ab_yearmonth').setValue(date_str);
- }
- this.BaseUtil.getPaydate('ab_paymentsmethodid','ab_date','ab_paydate');
- Ext.Array.each(grid.store.data.items, function(item){
- item.set('abd_abid',Ext.getCmp('ab_id').value);
- });
- var bool = true;
-
- //保存
- if(bool)
- this.beforeUpdate(this);
- },
- beforeUpdate: function(){
- var me = this;
- var form = Ext.getCmp('form');
- if(! me.FormUtil.checkForm()){
- return;
- }
- var detail = Ext.getCmp('grid');
- Ext.each(detail.store.data.items, function(item){
- if(item.data.prd_id == null || item.data.prd_id == 0){
- item.data.prd_id = -item.index;
- }
- });
- var param1 = me.GridUtil.getGridStore(detail);
- var param2 = new Array();
- var param3 = new Array();
- if(Ext.getCmp('assdetail')){
- Ext.each(Ext.Object.getKeys(Ext.getCmp('assdetail').cacheStoreGrid), function(key){
- Ext.each(Ext.getCmp('assdetail').cacheStoreGrid[key], function(d){
- d['dass_condid'] = key;
- param2.push(d);
- });
- });
- }
- if(Ext.getCmp('assmainbutton')){
- // Ext.each(Ext.Object.getKeys(Ext.getCmp('assmainbutton').cacheStoreForm), function(key){
- // Ext.each(Ext.getCmp('assmainbutton').cacheStoreForm[key], function(d){
- // d['ass_conid'] = key;
- // param3.push(d);
- // });
- // }
- }
- if(me.FormUtil.checkFormDirty(form) == '' && detail.necessaryField.length > 0 && (param1.length == 0)
- && param2.length == 0&& param3.length == 0){
- showError($I18N.common.grid.emptyDetail);
- return;
- } else {
- param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
- param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
- param3 = param3 == null ? [] : Ext.encode(param3).replace(/\\/g,"%");
- if(form.getForm().isValid()){
- Ext.each(form.items.items, function(item){
- if(item.xtype == 'numberfield'){
- if(item.value == null || item.value == ''){
- item.setValue(0);
- }
- }
- });
- me.FormUtil.update(form.getValues(), param1, param2,param3);
- }else{
- me.FormUtil.checkForm();
- }
- }
-
- },
- beforePostAPBill:function(){
-
- },
- updateTaxcode: function(abid, val1, val2) {
- var me = this;
- Ext.Ajax.request({
- url: basePath + 'fa/arp/updateAPBillTaxcode.action',
- params: {
- caller: caller,
- ab_id: abid,
- ab_refno: val1,
- ab_remark: val2
- },
- callback: function(opt, s, r) {
- var rs = Ext.decode(r.responseText);
- if(rs.exceptionInfo) {
- showError(rs.exceptionInfo);
- } else {
- alert('更新成功!');
- window.location.reload();
- }
- }
- });
- }
- });
|