| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153 |
- Ext.define('erp.controller.fa.gs.AccountRegister', {
- extend: 'Ext.app.Controller',
- FormUtil: Ext.create('erp.util.FormUtil'),
- BaseUtil: Ext.create('erp.util.BaseUtil'),
- GridUtil: Ext.create('erp.util.GridUtil'),
- views:[
- 'fa.gs.AccountRegister','core.form.Panel','core.grid.Panel2','core.toolbar.Toolbar',
- 'fa.gs.DetailAssGrid','core.form.MultiField','core.button.TurnPayBalance','core.button.TurnRecBalance',
- 'core.button.Add','core.button.Save','core.button.Close','core.button.Accounted','core.button.ResAccounted',
- 'core.button.Submit','core.button.ResSubmit','core.button.Audit','core.button.ResAudit','core.button.UpdateRemark',
- 'core.button.Update','core.button.Delete','core.form.YnField','core.button.DeleteDetail','core.button.AssMain','core.button.Print',
- 'core.button.CopyAll','core.button.confirmType','core.button.TurnRecBalanceIMRE','core.button.GetRefNum',
- 'core.trigger.DbfindTrigger','core.grid.YnColumn','core.trigger.TextAreaTrigger', 'core.form.SeparNumber','core.button.ExportExcelButton'
- ],
- init:function(){
- var me = this;
- this.control({
- 'textfield[name=ar_memo]':{
- beforerender: function(field){
- field.readOnly=false;
- }
- },
- 'textfield[name=ar_deposit]':{
- beforerender: function(field){
- if(Ext.getCmp('ar_type')&&Ext.getCmp('ar_type').value=="暂收款"){
- if(Ext.getCmp('ar_source')&&Ext.getCmp('ar_source').value!=""){
- field.readOnly=true;
- }
- }
- }
- },
- 'field[name=ar_vendcode]':{
- beforerender: function(field){
- if(Ext.getCmp('ar_sourcetype')&&Ext.getCmp('ar_sourcetype').value=="付款申请"){
- field.readOnly=true;
- }
- }
- },
- 'textfield[name=ar_payment]':{
- beforerender: function(field){
- var type = Ext.getCmp('ar_type');
- if(type &&type.value=="暂收款"){
- if(Ext.getCmp('ar_source')&&Ext.getCmp('ar_source').value!=""){
- field.readOnly=true;
- }
- }
- if(type&&(type.value=="应付款"||type.value=="预付款")){
- if(Ext.getCmp('ar_source')&&Ext.getCmp('ar_source').value!=""){
- if(Ext.getCmp('ar_sourcetype')&&Ext.getCmp('ar_sourcetype').value=="付款申请"){
- field.readOnly=false;
- } else {
- field.readOnly=true;
- }
- }
- }
- }
- },
- 'field[name=ar_precurrency]': {
- beforetrigger: function(field) {
- var t = field.up('form').down('field[name=ar_date]'),
- value = t.getValue();
- if(value) {
- field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym');
- }
- }
- },
- 'erpFormPanel' : {
- afterload : function(form) {
- form.getForm().getFields().each(function() {
- var val = getUrlParam(this.name);
- if(!Ext.isEmpty(val) && Ext.isEmpty(this.getValue())) {
- this.setValue(val);
- }
- });
- var t = form.down('#ar_type');
- /*if(t.value == '应收票据收款'||t.value == '应付票据付款'){
- form.getForm().getFields().each(function(field) {
- if(typeof field.setReadOnly == 'function' && field.name != 'ar_memo' && field.name != 'ar_accountcurrency' && field.name != 'ar_accountrate' && field.name != 'ar_deposit' && field.name != 'ar_payment')
- field.setReadOnly(true);
- });
- }*/
- this.hidecolumns(t);
- }
- },
- 'erpCopyButton': {
- click: function(btn) {
- this.copy();
- }
- },
- '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.getApamount();
- //保存之前的一些前台的逻辑判定
- this.beforeSave();
- }
- },
- 'erpCloseButton': {
- click: function(btn){
- this.FormUtil.beforeClose(this);
- }
- },
- 'erpUpdateButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('ar_statuscode');
- if(status && status.value != 'ENTERING' && status.value != 'COMMITED'){
- btn.hide();
- } else {
- btn.show();
- }
- },
- click: function(btn){
- this.getApamount();
- this.beforeUpdate();
- }
- },
- 'erpPrintButton': {
- click: function(btn) {
- var reportName = '';
- reportName = "AccountCount";
- var condition = '{AccountRegister.ar_id}=' + Ext.getCmp('ar_id').value + '';
- var id = Ext.getCmp('ar_id').value;
- me.FormUtil.onwindowsPrint(id, reportName, condition);
- }
- },
- 'erpExportExcelButton':{
- afterrender:function(btn){
- btn.exportCaller="AccountRegisterDetailAss!Export";
- var status = Ext.getCmp('ar_statuscode').value;
- if(status&&status!='ENTERING'){
- btn.hide();
- }
- }
- },
- 'erpDeleteButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('ar_statuscode');
- if(status && status.value != 'ENTERING'){
- btn.hide();
- }
- },
- click: function(btn){
- var source = Ext.getCmp('ar_sourcetype');
- if(!Ext.isEmpty(source.value)){
- if(source.value != '付款申请' && source.value != '应收发票' && source.value != '模具付款申请' && source.value != '费用报销单' && source.value != '总务申请单' && source.value != '还款申请单' && source.value != '借款申请单' && source.value != '差旅费报销单'){
- showError("请在来源:"+source.value+",单号:"+Ext.getCmp('ar_source').value+"中进行反记账操作!");
- return;
- }
- if(source.value == '应收发票'){
- showError("请在来源:"+source.value+",单号:"+Ext.getCmp('ar_source').value+"中进行取消收款操作!");
- return;
- }
- }
- me.FormUtil.onDelete(Ext.getCmp('ar_id').value);
- }
- },
- 'erpAddButton': {
- click: function(b){
- url = 'jsps/fa/gs/accountRegister.jsp?whoami=' + caller;
- var cacode = Ext.getCmp('ar_accountcode').value;
- if(cacode != null && cacode != ""){
- url += '&ar_cateid=' + Ext.getCmp('ar_cateid').value;
- url += '&ar_accountcode=' + cacode;
- url += '&ar_accountname=' + Ext.getCmp('ar_accountname').value;
- url += '&ar_accountcurrency=' + Ext.getCmp('ar_accountcurrency').value;
- url += '&ar_accountrate=' +Ext.getCmp('ar_accountrate').value;
- }
- var tab = me.FormUtil.getActiveTab();
- me.FormUtil.onAdd('addAccountRegister', '新增银行存款登记', url);
- setTimeout(function(){
- if(tab) {
- tab.close();
- }
- }, 200);
- }
- },
- 'filefield[id=excelfile]':{
- change: function(field){
- warnMsg('确认要重新导入吗?', function(btn){
- if(btn == 'yes'){
- var keyValue=Ext.getCmp('ar_id').getValue();
- 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;
- Ext.Ajax.request({//拿到form的items
- url : basePath + 'fa/gs/ImportRegisterExcel.action',
- params:{
- id:keyValue,
- fileId:filePath
- },
- method : 'post',
- callback : function(options,success,response){
- var result=Ext.decode(response.responseText);
- if(result.success){
- Ext.Msg.alert('提示','导入成功!');
- window.location.reload();
- }else{
- if(result.exceptionInfo != null){
- showError(res.exceptionInfo);return;
- }
- }
- }
- });
- }
- }
- });
- }
- });
- }
- },
- 'erpSubmitButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('ar_statuscode');
- if(status && status.value != 'ENTERING'){
- btn.hide();
- }
- },
- click: function(btn){
- me.beforeSubmit(btn);
- }
- },
- 'erpResSubmitButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('ar_statuscode');
- if(status && status.value != 'COMMITED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onResSubmit(Ext.getCmp('ar_id').value);
- }
- },
- 'erpAccountedButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('ar_statuscode');
- if(status && status.value != 'COMMITED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.beforeAccount(btn);
- }
- },
- /*'erpConfirmTypeButton':{
- afterrender: function(btn){
- if(!Ext.isEmpty(Ext.getCmp('ar_source').value)){
- btn.hide();
- }
- }
- },*/
- 'erpResAccountedButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('ar_statuscode');
- if(status && status.value != 'POSTED'){
- btn.hide();
- }
- },
- click: function(btn){
- me.FormUtil.onResAccounted(Ext.getCmp('ar_id').value);
- }
- },
- 'erpTurnPayBalanceButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('ar_statuscode');
- if(status && status.value != 'ACCOUNT'){
- btn.hide();
- }
- },
- click: function(b){
- warnMsg("确定要转入付款单吗?", function(btn){
- if(btn == 'yes'){
- me.turnPayBalance(b.ownerCt.ownerCt);
- }
- });
- }
- },
- 'erpTurnRecBalanceIMREButton':{
- afterrender: function(btn){
- var status = Ext.getCmp('ar_statuscode'), type = Ext.getCmp('ar_type');
- if(status && status.value != 'POSTED'){
- btn.hide();
- }
- if(type && type.value != '暂收款'){
- btn.hide();
- }
- },
- click: function(btn){
- var me = this, win = Ext.getCmp('Complaint-win');
- if(!win) {
- var amount = Ext.getCmp('ar_deposit'), yamount = Ext.getCmp('ar_recamount'),
- val1 = amount ? (amount.value-yamount.value) : 0;
- win = Ext.create('Ext.Window', {
- id: 'Complaint-win',
- title: '转冲应收款单',
- height: 200,
- width: 400,
- items: [{
- xtype: 'form',
- height: '100%',
- width: '100%',
- bodyStyle: 'background:#f1f2f5;',
- items: [{
- margin: '10 0 0 0',
- xtype: 'dbfindtrigger',
- fieldLabel: '客户编号',
- id: 'cu_code',
- name:'cu_code',
- allowBlank: false,
- listeners:{
- aftertrigger:function(t, d){
- t.ownerCt.down('textfield[name=cu_name]').setValue(d.get('cu_name'));
- }
- }
- },{
- margin: '3 0 0 0',
- xtype: 'textfield',
- fieldLabel: '客户名称',
- readOnly:true,
- id: 'cu_name',
- name:'cu_name',
- allowBlank: false
- },{
- margin: '3 0 0 0',
- xtype: 'textfield',
- fieldLabel: '本次转金额',
- id: 'ar_thisamount',
- readOnly:false,
- allowBlank: false,
- value: val1
- }],
- closeAction: 'hide',
- buttonAlign: 'center',
- layout: {
- type: 'vbox',
- align: 'center'
- },
- buttons: [{
- text: $I18N.common.button.erpConfirmButton,
- cls: 'x-btn-blue',
- handler: function(btn) {
- var thisform = btn.ownerCt.ownerCt;
- Ext.Ajax.request({
- url: basePath + '/fa/gs/arTurnRecBalanceIMRE.action',
- params: {
- id: Ext.getCmp('ar_id').value,
- custcode: thisform.down("#cu_code").value,
- thisamount: thisform.down("#ar_thisamount").value
- },
- callback : function(options,success,response){
- thisform.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/fa/ars/recBalance.jsp?formCondition=rb_id=" + id +"&whoami=RecBalance!IMRE";
- me.FormUtil.onAdd('RecBalance' + id, '冲应收款' + id, url);
- });
- }
- window.location.reload();
- }
- });
- }
- }, {
- text: $I18N.common.button.erpCloseButton,
- cls: 'x-btn-blue',
- handler: function(btn) {
- btn.up('window').hide();
- }
- }]
- }]
- });
- }
- win.show();
- }
- },
- 'erpTurnRecBalanceButton': {
- afterrender: function(btn){
- var status = Ext.getCmp('ar_statuscode');
- if(status && status.value != 'ACCOUNT'){
- btn.hide();
- }
- },
- click: function(b){
- warnMsg("确定要转入收款单吗?", function(btn){
- if(btn == 'yes'){
- me.turnRecBalance(b.ownerCt.ownerCt);
- }
- });
- }
- },
- 'erpUpdateRemarkButton':{
- click:function(){
- var remark=Ext.getCmp('ar_memo');
- me.updateRemark(remark.value,Ext.getCmp('ar_id').value);
-
- }
- },
- 'field[name=ar_errstring]': {
- afterrender: function(f){
- if(f.value != null && f.value != ''){
- f.inputEl.setStyle({color: 'OrangeRed'});
- } else {
- f.setValue('正常');
- f.inputEl.setStyle({color: '#B6E2FF'});
- f.originalValue = f.value;
- }
- },
- change: function(f){
- if(f.value != null && f.value != ''){
- f.inputEl.setStyle({color: 'OrangeRed'});
- } else {
- f.setValue('正常');
- f.inputEl.setStyle({color: '#B6E2FF'});
- f.originalValue = f.value;
- }
- }
- },
- 'field[name=ar_date]': {
- change: function(f){
- if(f.value == null){
- var d = new Date();
- f.setValue(d);
- }
- }
- },
- 'field[name=ard_explanation]': {
- change: function(f) {
- if(f.value == '=') {
- f.setValue(Ext.getCmp('ar_memo').value);
- }
- }
- },
- //计算转存汇率
- 'field[name = ar_payment]' : {
- change : function(f){
- var payment = f.ownerCt.down('#ar_payment').getValue(); //支出金额
- var preamount = f.ownerCt.down('#ar_preamount').getValue(); //转存金额
- var rate = f.ownerCt.down('#ar_prerate');
- var grid = Ext.getCmp('grid');
- var items = grid.store.data.items, form = Ext.getCmp('form');
- var apamount = 0;
- Ext.each(items,function(item,index){
- if(!Ext.isEmpty(item.data['ard_explanation']) || !Ext.isEmpty(item.data['ard_catecode'])){
- apamount= apamount + Number(item.data['ard_debit']);
- }
- });
- if(!Ext.isEmpty(payment) && payment != 0){
- var prerate = form.BaseUtil.numberFormat((preamount+apamount)/payment,8);
- if(rate.value !=prerate ){
- rate.setValue(prerate);
- }
- }
- }
- },
- 'field[name = ar_preamount]' : {
- change : function(f){
- var payment = f.ownerCt.down('#ar_payment').value; //支出金额
- var preamount = f.ownerCt.down('#ar_preamount').value; //转存金额
- var rate = f.ownerCt.down('#ar_prerate');
- var grid = Ext.getCmp('grid');
- var items = grid.store.data.items, form = Ext.getCmp('form');
- var apamount = 0;
- Ext.each(items,function(item,index){
- if((item.data['ard_explanation']!=null&&item.data['ard_explanation']!="")|| (item.data['ard_catecode']!=null&&item.data['ard_catecode']!="")){
- apamount= apamount + Number(item.data['ard_debit']);
- }
- });
- if(!Ext.isEmpty(payment) && payment != 0){
- var prerate = form.BaseUtil.numberFormat((preamount+apamount)/payment,12);
- if(rate.value !=prerate ){
- rate.setValue(prerate);
- }
- }
- }
- },
- 'checkbox[name=ar_currencytype]' : {
- beforerender : function(f) {
- f.readOnly = false;
- }
- },
- 'erpDeleteDetailButton': {
- afterrender: function(btn){
- //将当前行的 借方/贷方 以及外币借方/外币贷方 互换
- btn.ownerCt.add({
- text: '借贷调换',
- width: 85,
- disabled: true,
- cls: 'x-btn-gray',
- id: 'replace'
- });
- //当前行的借方 = 其它行的贷方总额-其它行的借方总额
- btn.ownerCt.add({
- text: '找平',
- width: 65,
- disabled: true,
- cls: 'x-btn-gray',
- id: 'level'
- });
- //复制一个相同的纪录,id不同, 但借方/贷方 互换
- btn.ownerCt.add({
- text: '冲红',
- width: 65,
- disabled: true,
- cls: 'x-btn-gray',
- id: 'bonus'
- });
- //辅助核算
- btn.ownerCt.add({
- text: '辅助核算',
- width: 85,
- disabled: true,
- cls: 'x-btn-gray',
- id: 'assdetail'
- });
- },
- afterdelete: function(d, r, btn){
- //更新状态
- Ext.Ajax.request({
- url: basePath + 'fa/gs/validAccountRegister.action',
- params: {
- id: d.ard_arid
- },
- callback: function(opt, s, r){
- var res = Ext.decode(r.responseText);
- if(res.success) {
- var f = Ext.getCmp('ar_errstring');
- f.setValue(res.errstring);
- f.dirty = false;
- f.originalValue = f.value;
- }
- }
- });
- }
- },
- 'erpGridPanel2': {
- afterrender: function(g) {
- g.plugins[0].on('beforeedit', function(args) {
- if(args.field == "ard_nowbalance") {
- if(Ext.getCmp('ar_type').value == '预付款'){
- return true;
- } else if (Ext.getCmp('ar_type').value == '转存' || Ext.getCmp('ar_type').value == '其它收款' || Ext.getCmp('ar_type').value == '其它付款'){
- return false;
- }
- }
- if (args.field == "ard_debit") {
- var bool = true;
- if (args.record.get('ard_credit') != null && args.record.get('ard_credit') > 0){
- bool = false;
- }
- if (args.record.get('ard_doublecredit') != null && args.record.get('ard_doublecredit') > 0){
- bool = false;
- }
- return bool;
- }
- if (args.field == "ard_credit") {
- var bool = true;
- if (args.record.get('ard_debit') != null && args.record.get('ard_debit') > 0){
- bool = false;
- }
- if (args.record.get('ard_doubledebit') != null && args.record.get('ard_doubledebit') > 0){
- bool = false;
- }
- return bool;
- }
- if (args.field == "ard_doubledebit") {
- var bool = true;
- if (args.record.get('ard_doublecredit') != null && args.record.get('ard_doublecredit') > 0){
- bool = false;
- }
- if (args.record.get('ard_credit') != null && args.record.get('ard_credit') > 0){
- bool = false;
- }
- return bool;
- }
- if (args.field == "ard_doublecredit") {
- var bool = true;
- if (args.record.get('ard_doubledebit') != null && args.record.get('ard_doubledebit') > 0){
- bool = false;
- }
- if (args.record.get('ard_debit') != null && args.record.get('ard_debit') > 0){
- bool = false;
- }
- return bool;
- }
- });
- },
- reconfigure: function(grid){
- var f = Ext.getCmp('ar_currencytype');
- if(f) {
- me.changeCurrencyType(f);
- }
- Ext.defer(function(){
- var form = grid.ownerCt.down('form'), status = form.down('#' + form.statuscodeField);
- source = Ext.getCmp('ar_source'), type = Ext.getCmp('ar_type');
- if(status && (status.value == 'ENTERING' || status.value == 'COMMITED')) {
- if(type && (type.value == '预付款' || type.value == '应付款')){
- if(source && source.value){
- grid.readOnly = false;
- } else {
- grid.readOnly = true;
- }
- } else {
- grid.readOnly = false;
- }
- }
- }, 500);
- },
- itemclick: function(selModel, record){
- this.GridUtil.onGridItemClick(selModel, record);
- var btn = Ext.getCmp('replace');
- btn.setDisabled(false);
- btn = Ext.getCmp('level');
- btn.setDisabled(false);
- btn = Ext.getCmp('bonus');
- btn.setDisabled(false);
- btn = Ext.getCmp('assdetail');
- var ass = record.data['ca_asstype'];
- if(!Ext.isEmpty(ass)){//辅助核算
- btn.setDisabled(false);
- } else {
- btn.setDisabled(true);
- }
- }
- },
- 'combo[name=ar_type]': {
- /*beforerender: function(field){
- if(Ext.getCmp('ar_code')&&Ext.getCmp('ar_code').value){
- field.readOnly=true;
- }
- },*/
- delay: 200,
- change: function(m){
- this.hidecolumns(m);
- var source = Ext.getCmp('ar_source'), grid = Ext.getCmp('grid');
- if(m.value == '应付款' || m.value == '预付款'){
- if(source && source.value){
- grid.readOnly = false;
- } else {
- grid.readOnly = true;
- }
- } else if(m.value == '应收款' || m.value == '预收款'|| m.value == '应付退款'|| m.value == '预付退款'||m.value == '应收退款'||m.value == '预收退款'){
- grid.readOnly = true;
- } else {
- grid.readOnly = false;
- }
- if(m.value == '应付票据付款' || m.value == '应收票据收款'){
- showError('应付票据付款/应收票据收款不能手工新增!');
- }
- }
- },
- 'field[name=ar_currencytype]': {
- change: function(c){
- me.changeCurrencyType(c);
- }
- },
- /**
- * 借调互换
- */
- 'button[id=replace]': {
- click: function(btn){
- var grid = btn.ownerCt.ownerCt;
- var record = grid.selModel.lastSelected;
- if(record){
- var v1 = record.data['ard_debit'];//借方
- var v2 = record.data['ard_credit'];//贷方
- var v3 = record.data['ard_doubledebit'];//原币借方
- var v4 = record.data['ard_doublecredit'];//原币贷方
- record.set('ard_debit', v2);
- record.set('ard_credit', v1);
- record.set('ard_doubledebit', v4);
- record.set('ard_doublecredit', v3);
- }
- }
- },
- /**
- * 找平
- */
- 'button[id=level]': {
- click: function(btn){
- var grid = btn.ownerCt.ownerCt;
- var record = grid.selModel.lastSelected;
- if(record){
- var items = grid.store.data.items;
- var f = Ext.getCmp('ar_currencytype'),
- debitF = 'ard_debit',creditF = 'ard_credit';
- if(f.checked) {
- debitF = 'ard_doubledebit';
- creditF = 'ard_doublecredit';
- }
- var debit = 0;
- var credit = 0;
- Ext.each(items, function(item, index){
- if(item.id != record.id){
- debit += item.data[debitF];
- credit += item.data[creditF];
- }
- });
- if(credit > debit) {
- record.set(debitF, credit - debit);
- } else {
- record.set(creditF, debit - credit);
- }
- }
- }
- },
- /**
- * 冲红
- */
- 'button[id=bonus]': {
- click: function(btn){
- var grid = btn.ownerCt.ownerCt;
- var record = grid.selModel.lastSelected;
- if(record){
- var keys = Ext.Object.getKeys(record.data);
- var values = Ext.Object.getValues(record.data);
- var o = new Object();
- var ard_debit = 0;
- var ard_credit = 0;
- Ext.each(keys, function(key, index){
- if(key != grid.detno && key != grid.keyField){//排序字段和主键字段的值均不复制
- var v = values[index];
- if(key == 'ard_debit'){
- ard_debit = v;
- }
- if(key == 'ard_credit'){
- ard_credit = v;
- }
- o[key] = v;
- }
- });
- o.ard_debit = ard_credit;//借方/贷方互换
- o.ard_credit = ard_debit;
- grid.copyData = o;//需要粘贴时,直接取grid.copyData即可
- }
- }
- },
- /**
- * 辅助核算
- */
- 'button[id=assdetail]': {
- click: function(btn){
- var grid = btn.ownerCt.ownerCt;
- var record = grid.selModel.lastSelected;
- if(record){
- var id = record.data[grid.keyField] || (-record.index), win = Ext.getCmp('dass-win');
- if(win){
- win.show();
- Ext.getCmp('win-form').removeAll(true);
- Ext.getCmp('win-form').add(me.createForm(grid));
- Ext.getCmp('assgrid').cacheAss[id] = record.data['ca_asstype'].toString();
- Ext.getCmp('assgrid').asstype = record.data['ca_asstype'].toString().split('#');
- Ext.getCmp('assgrid').getMyData(id);
- } else {
- win = Ext.create('Ext.window.Window', {
- id: 'dass-win',
- height: "100%",
- width: "80%",
- iconCls: 'x-button-icon-set',
- closeAction: 'hide',
- title: '银行登记明细辅助核算',
- maximizable : true,
- layout : 'anchor',
- items: [{
- anchor: '100% 30%',
- xtype: 'form',
- id: 'win-form',
- layout : 'column',
- autoScroll: true,
- labelSeparator : ':',
- bodyStyle: 'background:#f1f1f1;',
- fieldDefaults : {
- labelAlign : "left"
- },
- items: me.createForm(grid),
- buttonAlign: 'center',
- buttons: [{
- name: 'confirm',
- cls: 'x-btn-gray',
- text: $I18N.common.button.erpConfirmButton
- },{
- cls: 'x-btn-gray',
- text: $I18N.common.button.erpOffButton,
- handler: function(btn){
- btn.ownerCt.ownerCt.ownerCt.close();
- }
- },{
- cls: 'x-btn-gray',
- text: "上一条",
- handler: function(btn){
- me.prev(grid);
- }
- },{
- cls: 'x-btn-gray',
- text: "下一条",
- handler: function(btn){
- me.next(grid);
- }
- }]
- },{
- anchor: '100% 70%',
- xtype: 'detailassgrid',
- asstype: record.data['ca_asstype'].toString().split('#')
- }]
- }).show();
- Ext.getCmp('assgrid').getMyData(id, caller);
- }
- }
- }
- },
- 'button[name=confirm]': {
- click: function(btn){
- var record = Ext.getCmp('grid').selModel.lastSelected;
- var data = new Array();
- Ext.each(Ext.getCmp('assgrid').store.data.items, function(){
- data.push(this.data);
- });
- if(data.length > 0){
- Ext.getCmp('assgrid').cacheStore[record.data[Ext.getCmp('grid').keyField] || (-record.index)] = data;
- }
- btn.ownerCt.ownerCt.ownerCt.close();
- }
- },
- 'field[name=ard_doubledebit]': {//原币借方
- change: function(f){
- if(!f.ownerCt && f.value != null && f.value != 0 ){
- var grid = Ext.getCmp('grid');
- var record = grid.selModel.lastSelected,
- rate = record.data['ard_rate'];
- if(rate != null && rate > 0){
- var val = grid.BaseUtil.numberFormat(grid.BaseUtil.multiply(f.value, rate), 2);
- if(record.data['ard_debit'] != val) {
- record.set('ard_debit', val);//本币
- }
- }
- }
- }
- },
- 'field[name=ard_doublecredit]': {//原币贷方
- change: function(f){
- if(!f.ownerCt && f.value != null && f.value != 0 ){
- var grid = Ext.getCmp('grid'), record = grid.selModel.lastSelected,
- rate = record.data['ard_rate'];
- if(rate != null && rate > 0){
- var val = grid.BaseUtil.numberFormat(grid.BaseUtil.multiply(f.value, rate), 2);
- if(record.data['ard_credit'] != val) {
- record.set('ard_credit', val);//本币
- }
- }
- }
- }
- },
- 'field[name=ard_currency]': {
- aftertrigger: function(f){
- if(f.value != null && f.value != '' ){
- var grid = Ext.getCmp('grid');
- var record = grid.selModel.lastSelected;
- if(record.data['ard_rate'] != null && record.data['ard_rate'] > 0){
- if(record.data['ard_doubledebit'] != null){
- record.set('ard_debit',
- grid.BaseUtil.numberFormat(grid.BaseUtil.multiply(record.data['ard_doubledebit'], record.data['ard_rate']), 2));//原币计算本币
- }
- if(record.data['ard_doublecredit'] != null){
- record.set('ard_credit',
- grid.BaseUtil.numberFormat(grid.BaseUtil.multiply(record.data['ard_doublecredit'], record.data['ard_rate']), 2));//原币计算本币
- }
- }
- }
- }
- },
- 'dbfindtrigger[name=ard_catecode]': {
- aftertrigger: function(f, item){
- var record = Ext.getCmp('grid').selModel.lastSelected;
- var ass = record.data['ca_asstype'];
- var btn = Ext.getCmp('assdetail');
- if(!Ext.isEmpty(ass)){
- btn.setDisabled(false);
- } else {
- btn.setDisabled(true);
- }
- var idx = record.data[grid.keyField] || (-record.index);
- if(Ext.getCmp('assgrid') && Ext.getCmp('assgrid').cacheAss[idx] != ass){//科目改变,对应的辅助核算也置空
- Ext.getCmp('assgrid').cacheAss[idx] = ass;
- Ext.getCmp('assgrid').cacheStore[idx] = null;
- }
- }
- },
- 'field[name=ar_deposit]' : {
- afterrender : function(f) {
- f.setFieldStyle({
- 'color' : 'blue'
- });
- },
- change: me.changecmrate
- },
- 'field[name=ar_payment]' : {
- afterrender : function(f) {
- f.setFieldStyle({
- 'color' : 'red'
- });
- },
- change: me.changecmrate
- },
- 'field[name=ar_aramount]':{
- afterrender : function(f) {
- var sourcetype = Ext.getCmp('ar_sourcetype');
- if(sourcetype && sourcetype.value == '付款申请'){
- f.setReadOnly(true);
- }
- },
- change: me.changecmrate
- },
- 'field[name=ca_asstype]':{
- change: function(f){
- var btn = Ext.getCmp('assmainbutton');
- btn && btn.setDisabled(Ext.isEmpty(f.value));
- }
- },
- 'erpAssMainButton':{
- afterrender:function(btn){
- if(Ext.isEmpty(Ext.getCmp('ca_asstype').getValue())){
- btn.setDisabled(true);
- } else {
- btn.setDisabled(false);
- }
- }
- },
- 'erpGetRefNumButton':{
- afterrender:function(btn){
- var status=Ext.getCmp('ar_statuscode');
- if(status && status.value !='ENTERING'){
- btn.hide();
- }
- },
- click:function(btn){
- var payment=Ext.getCmp('ar_payment').value,posit=Ext.getCmp('ar_deposit').value,leadcode=null,refno=Ext.getCmp('ar_refno').value;
- if(refno!=null && refno!='' && Ext.String.trim(refno).length!=2) {
- showError('当前参考号已经存在不能重复获取!');
- return;
- }
- if(refno !=null && Ext.String.trim(refno).length==2) leadcode=Ext.String.trim(refno);
- else if(payment>0) leadcode='BP';
- else if(posit>0) leadcode='BR';
- else leadcode='TR';
- Ext.Ajax.request({
- url : basePath + 'fa/gs/getRefCode.action',
- params:{
- leadcode:leadcode,
- datemonth:Ext.Date.format(Ext.getCmp('ar_date').getValue(),'Ym')
- },
- async:false,
- method : 'get',
- callback : function(options,success,response){
- var result=Ext.decode(response.responseText);
- if(result.success){
- Ext.getCmp('ar_refno').setValue(result.code);
- }else{
- if(result.exceptionInfo != null){
- showError(res.exceptionInfo);return;
- }
- }
- }
- });
- }
- }
- });
- },
- getForm: function(btn){
- return btn.ownerCt.ownerCt;
- },
- //冲账汇率计算 = 冲账金额/预收金额
- changecmrate: function(){
- var form = Ext.getCmp('form');
- if(Ext.getCmp('ar_payment') && Ext.getCmp('ar_araprate') && Ext.getCmp('ar_deposit')) {
- var rbamount = Ext.Number.from(Ext.getCmp('ar_payment').getValue(), 0) + Ext.Number.from(Ext.getCmp('ar_deposit').getValue(), 0);
- var cmamount = Ext.Number.from(Ext.getCmp('ar_aramount').getValue(), 0);
- if(rbamount != 0){
- if(cmamount !=0){
- Ext.getCmp('ar_araprate').setValue(form.BaseUtil.numberFormat(cmamount/rbamount, 8));
- }
- }
- }
- },
- changeCurrencyType: function(c){
- var grid = Ext.getCmp('grid');
- if(c.checked){
- Ext.each(grid.columns, function(cn){
- if(cn.dataIndex == 'ard_doubledebit' || cn.dataIndex == 'ard_doublecredit'){
- cn.width = 110;
- cn.setVisible(true);
- }
- if(cn.dataIndex == 'ard_currency' || cn.dataIndex == 'ard_rate'){
- cn.width = 60;
- cn.setVisible(true);
- }
- if(cn.dataIndex == 'ard_debit'){
- cn.setText('本币借方');
- }
- if(cn.dataIndex == 'ard_credit'){
- cn.setText('本币贷方');
- }
- });
- } else {
- Ext.each(grid.columns, function(cn){
- if(cn.dataIndex == 'ard_currency' || cn.dataIndex == 'ard_rate'
- || cn.dataIndex == 'ard_doubledebit' || cn.dataIndex == 'ard_doublecredit'){
- cn.setVisible(false);
- }
- if(cn.dataIndex == 'ard_debit'){
- cn.setText('借方');
- }
- if(cn.dataIndex == 'ard_credit'){
- cn.setText('贷方');
- }
- });
- }
- },
- 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 ar_accountcurrency = Ext.getCmp('ar_accountcurrency').value,
- ar_arapcurrency = Ext.getCmp('ar_arapcurrency').value,
- deposit = Ext.getCmp('ar_deposit').value, //收入
- payment = Ext.getCmp('ar_payment').value, //支出
- type = Ext.getCmp('ar_type').value,
- sellercode = Ext.getCmp('ar_sellercode').value;
-
- var grid = Ext.getCmp('grid'), items = grid.store.data.items, bool = true,
- ar_accountrate = Ext.getCmp('ar_accountrate').value, //账户汇率
- ar_aramount = Ext.getCmp('ar_aramount').value, //冲账金额
- ar_preamount = Ext.getCmp('ar_preamount').value, //转存金额
- ar_prerate = Ext.getCmp('ar_prerate').value, //转存汇率
- ctype = Ext.getCmp('ar_currencytype');
- var debit = 0, credit = 0;
- Ext.each(items,function(item,index){
- if(!Ext.isEmpty(item.data['ard_explanation']) || !Ext.isEmpty(item.data['ard_catecode']) || !Ext.isEmpty(item.data['ard_ordercode']) || !Ext.isEmpty(item.data['ard_makecode'])){
- debit= debit + Number(item.data['ard_debit']);
- credit= credit + Number(item.data['ard_credit']);
- }
- });
- if(type != null && type != '' ){
- if(type == '应付款' || type == '预付款' || type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款' || type == '应收退款' || type == '预收退款'){
- if(ar_arapcurrency == null || ar_arapcurrency==''){
- Ext.getCmp('ar_arapcurrency').setValue(ar_accountcurrency);
- ar_arapcurrency = Ext.getCmp('ar_arapcurrency').value;
- }
- }
- if(type == '应付票据付款' || type == '应收票据收款'){
- showError('应付票据付款/应收票据收款不能手工新增!');
- return;
- }
- if(type == '应收款'){
- if(Ext.isEmpty(sellercode)){
- showError('业务员编号不能为空!');
- return;
- }
- }
- if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款'){
- if(deposit == 0 || deposit == null || deposit == '' ){
- showError('收入金额不能为空!');
- return;
- }
- }
- if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款') {
- if(ar_accountcurrency != ar_arapcurrency){
- if(Ext.getCmp('ar_araprate').value == '1'){
- showError('币别不一致,冲账汇率为1,请修改!');
- return;
- }
- }
- if(ar_accountcurrency == ar_arapcurrency){
- Ext.getCmp('ar_aramount').setValue(form.BaseUtil.multiply(Number(deposit), Number(Ext.getCmp('ar_araprate').value)));
- }
- }
- if (type == '预付款' || type == '应付款' || type == '应收退款' || type == '预收退款'){
- if(payment == 0 || payment == null || payment == '' ){
- showError('支出金额不能为空!');
- return;
- }
- }
- if(type == '预付款' || type == '应付款' || type == '应收退款' || type == '预收退款'){
- if(ar_accountcurrency != ar_arapcurrency){
- if(Ext.getCmp('ar_araprate').value == '1'){
- showError('币别不一致,冲账汇率为1,请修改!');
- return;
- }
- }
- if(ar_accountcurrency == ar_arapcurrency){
- Ext.getCmp('ar_aramount').setValue(form.BaseUtil.multiply(Number(payment), Number(Ext.getCmp('ar_araprate').value)));
- }
- }
- if(type == '应收票据收款' || type == '应付票据付款'){
- if(type == '应收票据收款') {
- if(deposit == 0 || deposit == null || deposit == '' ){
- showError('收入金额不能为空!');
- return;
- }
- if(Math.abs(form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2)-form.BaseUtil.numberFormat(credit-debit, 2)) > 0.01){
- showError('收入金额' + form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2) + '不一致!');
- return;
- }
- } else if(type == '应付票据付款'){
- if(payment == 0 || payment == null || payment == '' ){
- showError('支出金额不能为空!');
- return;
- }
- }
- }
- if(type == '转存'){
- if(!Ext.isEmpty(debit)){
- var prerate = form.BaseUtil.numberFormat((ar_preamount+(debit-credit))/(payment-deposit),8);
- if(ar_prerate != prerate ){
- Ext.getCmp('ar_prerate').setValue(prerate);
- }
- }
- }
- if(!Ext.isEmpty(Ext.getCmp('ar_source').value)){
- if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款'){
- if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(credit-debit, 2)) > 0.01){
- showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2) + '不一致!');
- return;
- }
- }
- if(type == '应付款' || type == '应收退款' || type == '预收退款'){
- if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2)) > 0.01){
- showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
- return;
- }
- }
- if(type == '预付款'){
- if(Ext.getCmp('ar_sourcetype')&&Ext.getCmp('ar_sourcetype').value!="付款申请"){
- if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2)) > 0.01){
- showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
- return;
- }
- }
- }
- }
- }
- var detail = Ext.getCmp('grid'), items = detail.store.data.items, bool = true;
- var ass = Ext.getCmp('assgrid');
- var param3 = ass == null ? '[]' : Ext.encode(ass.getEffectData());
- Ext.each(items, function(item){
- if(item.data.ard_id == null || item.data.ard_id == 0){
- item.data.ard_id = -item.index;
- }
- });
- Ext.Array.each(items, function(item){
- if(!Ext.isEmpty(item.data['ard_catecode'])){
- if(item.data['ca_currencytype'] != 0){
- if(ctype && ctype.value != '1'){
- ctype.setValue('1');
- }
- if(Ext.isEmpty(item.data['ard_currency'])){
- bool = false;
- showError('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,币别不能为空!');
- return;
- }
- if(Ext.isEmpty(item.data['ard_rate']) || item.data['ard_rate'] == 0){
- bool = false;
- showError('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,汇率不能为0!');
- return;
- }
- }
- if(item.data['ard_doubledebit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_debit'] != 0){
- if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doubledebit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_debit'],2)) {
- bool = false;
- showError('明细表第' + item.data['ard_detno'] + '行,原币借方*汇率不等于本币借方!');
- return;
- }
- }
- if(item.data['ard_doublecredit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_credit'] != 0){
- if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doublecredit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_credit'],2)) {
- bool = false;
- showError('明细表第' + item.data['ard_detno'] + '行,原币贷方*汇率不等于本币贷方!');
- return;
- }
- }
- }
- });
- var param1 = me.GridUtil.getGridStore(detail);
- if(detail.necessaryField.length > 0 && (param1.length == 0)){
- showError($I18N.common.grid.emptyDetail);
- return;
- }
- var ex = new Array(),d;
- Ext.each(param1, function(){//摘要未填写
- d = Ext.decode(this);
- if(Ext.isEmpty(d.ard_explanation)) {
- ex.push(d.ard_detno);
- }
- });
- if(ex.length > 0) {
- warnMsg("摘要未填写,序号:" + ex.join(',') + " 是否继续保存?", function(btn){
- if(btn == 'yes') {
- me.onSave(form, param1, param3);;
- }
- });
- } else {
- if(bool)
- me.onSave(form, param1, param3);
- }
- },
- onSave: function(form, param1, param3) {
- var me = this;
- param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
- param3 = param3 == null ? [] : param3.toString().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);
- }
- }
- });
- var r = form.getValues();
- form.getForm().getFields().each(function(){
- if(this.logic == 'ignore') {
- delete r[this.name];
- }
- });
- var ctype = Ext.getCmp('ar_currencytype');
- r.ar_currencytype = (typeof ctype.value == 'boolean' && ctype.value) ? -1 : 0;
- r.ar_errstring = r.ar_errstring == '正常' ? '' : r.ar_errstring;
- me.FormUtil.save(r, param1, param3);
- }else{
- me.FormUtil.checkForm();
- }
- },
- beforeUpdate: 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 ar_accountcurrency = Ext.getCmp('ar_accountcurrency').value,
- ar_arapcurrency = Ext.getCmp('ar_arapcurrency').value,
- deposit = Ext.getCmp('ar_deposit').value, //收入
- payment = Ext.getCmp('ar_payment').value, //支出
- type = Ext.getCmp('ar_type').value,
- sellercode = Ext.getCmp('ar_sellercode').value,
- ctype = Ext.getCmp('ar_currencytype');
- var grid = Ext.getCmp('grid'), items = grid.store.data.items, bool = true;
- ar_accountrate = Ext.getCmp('ar_accountrate').value; //账户汇率
- ar_aramount = Ext.getCmp('ar_aramount').value; //冲账金额
- var debit = 0, credit = 0;
- Ext.each(items,function(item,index){
- if(!Ext.isEmpty(item.data['ard_explanation']) || !Ext.isEmpty(item.data['ard_catecode']) || !Ext.isEmpty(item.data['ard_ordercode']) || !Ext.isEmpty(item.data['ard_makecode'])){
- debit= debit + Number(item.data['ard_debit']);
- credit= credit + Number(item.data['ard_credit']);
- }
- });
-
- if(type != null && type != '' ){
- if(type == '应付款' || type == '预付款' || type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款' || type == '应收退款' || type == '预收退款'){
- if(ar_arapcurrency == null || ar_arapcurrency==''){
- Ext.getCmp('ar_arapcurrency').setValue(ar_accountcurrency);
- ar_arapcurrency = Ext.getCmp('ar_arapcurrency').value;
- }
- }
- if(type == '应收款'){
- if(Ext.isEmpty(sellercode)){
- showError('业务员编号不能为空!');
- return;
- }
- }
- if(type == '应收款' || type == '预收款' || type == '应付退款'){
- if(deposit == 0 || deposit == null || deposit == '' ){
- showError('收入金额不能为空!');
- return;
- }
- }
- if(type == '应收款' || type == '预收款' || type == '应付退款'){
- if(ar_accountcurrency != ar_arapcurrency){
- if(Ext.getCmp('ar_araprate').value == '1'){
- showError('币别不一致,冲账汇率为1,请修改!');
- return;
- }
- }
- if(ar_accountcurrency == ar_arapcurrency){
- Ext.getCmp('ar_aramount').setValue(form.BaseUtil.multiply(Number(deposit),Number(Ext.getCmp('ar_araprate').value)));
- }
- }
- if (type == '预付款' || type == '应付款' || type == '应收退款'){
- if(payment == 0 || payment == null || payment == '' ){
- showError('支出金额不能为空!');
- return;
- }
- }
- if(type == '预付款' || type == '应付款' || type == '应收退款'){
- if(ar_accountcurrency != ar_arapcurrency){
- if(Ext.getCmp('ar_araprate').value == '1'){
- showError('币别不一致,冲账汇率为1,请修改!');
- return;
- }
- }
- if(ar_accountcurrency == ar_arapcurrency){
- Ext.getCmp('ar_aramount').setValue(form.BaseUtil.multiply(Number(payment), Number(Ext.getCmp('ar_araprate').value)));
- }
- }
- if(type == '应收票据收款' || type == '应付票据付款'){
- if(type == '应收票据收款') {
- if(deposit == 0 || deposit == null || deposit == '' ){
- showError('收入金额不能为空!');
- return;
- }
- if(form.BaseUtil.numberFormat(Math.abs(form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2)-form.BaseUtil.numberFormat(credit-debit, 2)),2) > 0.01){
- showError('收入金额' + form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2) + '不一致!');
- return;
- }
- } else if(type == '应付票据付款'){
- if(payment == 0 || payment == null || payment == '' ){
- showError('支出金额不能为空!');
- return;
- }
- }
- }
- if(!Ext.isEmpty(Ext.getCmp('ar_source').value)){
- if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款'){
- if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(credit-debit, 2))>0.011){
- showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2) + '不一致!');
- return;
- }
- }
- if(type == '应付款' || type == '应收退款' || type == '预收退款'){
- if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2))>0.011){
- showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
- return;
- }
- }
- if(type == '预付款'){
- if(Ext.getCmp('ar_sourcetype')&&Ext.getCmp('ar_sourcetype').value!="付款申请"){
- if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2))>0.011){
- showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
- return;
- }
- }
- }
- }
- }
-
- var detail = Ext.getCmp('grid'), ass = Ext.getCmp('assgrid'), bool = true,
- items = detail.store.data.items;
- Ext.each(items, function(item){
- if(item.data.ard_id == null || item.data.ard_id == 0){
- item.data.ard_id = -item.index;
- }
- });
- Ext.Array.each(items, function(item){
- if(!Ext.isEmpty(item.data['ard_catecode'])){
- if(item.data['ca_currencytype'] != 0){
- if(ctype && ctype.value != '1'){
- ctype.setValue('1');
- }
- if(Ext.isEmpty(item.data['ard_currency'])){
- bool = false;
- showError('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,币别不能为空!');
- return;
- }
- if(Ext.isEmpty(item.data['ard_rate']) || item.data['ard_rate'] == 0){
- bool = false;
- showError('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,汇率不能为0!');
- return;
- }
- }
- if(item.data['ard_doubledebit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_debit'] != 0){
- if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doubledebit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_debit'],2)) {
- bool = false;
- showError('明细表第' + item.data['ard_detno'] + '行,原币借方*汇率不等于本币借方!');
- return;
- }
- }
- if(item.data['ard_doublecredit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_credit'] != 0){
- if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doublecredit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_credit'],2)) {
- bool = false;
- showError('明细表第' + item.data['ard_detno'] + '行,原币贷方*汇率不等于本币贷方!');
- return;
- }
- }
- }
- });
- var param1 = me.GridUtil.getGridStore(detail);
- var param2 = ass == null ? '[]' : Ext.encode(ass.getEffectData());
- var param3 = new Array();
-
- 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) &&
- (param3.length <= 2)){
- showError($I18N.common.grid.emptyDetail);
- return;
- } else {
- param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
- param2 = param2 == null ? [] : param2.toString().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);
- }
- }
- });
- var r = form.getValues();
- form.getForm().getFields().each(function(){
- if(this.logic == 'ignore') {
- delete r[this.name];
- }
- });
- var ctype = Ext.getCmp('ar_currencytype');
- r.ar_currencytype = (typeof ctype.value == 'boolean' && ctype.value) ? -1 : 0;
- r.ar_errstring = r.ar_errstring == '正常' ? '' : r.ar_errstring;
- if(bool)
- me.FormUtil.update(r, param1, param2, param3);
- }else{
- me.FormUtil.checkForm();
- }
- }
- },
- createForm: function(grid){
- var record = grid.selModel.lastSelected;
- var data = new Object();
- if(record){
- data = record.data;
- }
- var items = new Array();
- var item;
- Ext.each(grid.columns, function(c){
- item = new Object();
- item.id = c.dataIndex;
- item.name = c.dataIndex;
- item.fieldLabel = c.text || c.header;
- item.value = data[c.dataIndex];
- item.columnWidth = .33;
- item.readOnly = true;
- item.xtype = 'textfield';
- item.fieldStyle = 'background:#f0f0f0;border: 1px solid #8B8970';
- item.cls = 'form-field-border';
- if(c.hidden){
- item.xtype = 'hidden';
- item.cls = "";
- }
- if(c.dataIndex == grid.detno){
- item.fieldStyle = 'background:#e0f0f0;font-weight:bold;border: 1px solid #8B8970';
- }
- items.push(item);
- });
- return items;
- },
- /**
- * 明细辅助核算的上一条
- */
- prev: function(grid, record){
- record = record || grid.selModel.lastSelected;
- if(record){
- //先保存当前数据
- var data = new Array();
- Ext.each(Ext.getCmp('assgrid').store.data.items, function(){
- data.push(this.data);
- });
- if(data.length > 0){
- Ext.getCmp('assgrid').cacheStore[record.data[grid.keyField] || (-record.index)] = data;
- }
- //递归查找上一条,并取到数据
- var d = grid.store.getAt(record.index - 1);
- if(d){
- Ext.getCmp('win-form').getForm().setValues(d.data);
- var idx = d.data[grid.keyField] || (-d.index);
- Ext.getCmp('assgrid').cacheAss[idx] = d.data['ca_asstype'];
- Ext.getCmp('assgrid').asstype = Ext.isEmpty(d.data['ca_asstype']) ?
- new Array() : d.data['ca_asstype'].toString().split('#');
- Ext.getCmp('assgrid').getMyData(idx, caller);
- grid.selModel.select(d);
- } else {
- if(record.index - 1 > 0){
- this.prev(grid, d);
- }
- }
- }
- },
- /**
- * 明细辅助核算的下一条
- */
- next: function(grid, record){
- record = record || grid.selModel.lastSelected;
- if(record){
- //先保存当前数据
- var data = new Array();
- Ext.each(Ext.getCmp('assgrid').store.data.items, function(){
- data.push(this.data);
- });
- if(data.length > 0){
- Ext.getCmp('assgrid').cacheStore[record.data[grid.keyField] || (-record.index)] = data;
- }
- //递归查找下一条,并取到数据
- var d = grid.store.getAt(record.index + 1);
- if(d){
- Ext.getCmp('win-form').getForm().setValues(d.data);
- var idx = d.data[grid.keyField] || (-d.index);
- Ext.getCmp('assgrid').cacheAss[idx] = d.data['ca_asstype'];
- Ext.getCmp('assgrid').asstype = Ext.isEmpty(d.data['ca_asstype']) ?
- new Array() : d.data['ca_asstype'].toString().split('#');
- Ext.getCmp('assgrid').getMyData(idx, caller);
- grid.selModel.select(d);
- } else {
- if(record.index + 1 < grid.store.data.items.length){
- this.next(grid, d);
- }
- }
- }
- },
- turnPayBalance: function(form) {
- var me = this;
- form.setLoading(true);//loading...
- Ext.Ajax.request({
- url : basePath + 'fa/gs/arTurnPayBalance.action',
- params: {
- id: Ext.getCmp('ar_id').value
- },
- method : 'post',
- callback : function(options,success,response){
- form.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/fa/arp/paybalance.jsp?formCondition=pb_id=" + id + "&whoami=PayBalance";
- me.FormUtil.onAdd('PayBalance' + id, '付款单' + id, url);
- });
- }
- }
- });
- },
- turnRecBalance: function(form) {
- var me = this;
- form.setLoading(true);//loading...
- Ext.Ajax.request({
- url : basePath + 'fa/gs/arTurnRecBalance.action',
- params: {
- id: Ext.getCmp('ar_id').value
- },
- method : 'post',
- callback : function(options,success,response){
- form.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/fa/ars/recBalance.jsp?formCondition=rb_id=" + id +"&whoami=RecBalance!PBIL";
- me.FormUtil.onAdd('RecBalance' + id, '收款单' + id, url);
- });
- }
- }
- });
- },
- updateRemark:function(remark,id){
- Ext.Ajax.request({
- url : basePath + 'fa/gs/updateRemark.action',
- params: {remark:remark,id:id},
- method : 'post',
- async:false,
- callback : function(options,success,response){
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo != null){
- showError(res.exceptionInfo);return;
- }
- showMessage("提示", '更新成功!');
- window.location.reload();
- }
- });
- },
- hidecolumns:function(m){
- if(!Ext.isEmpty(m.getValue())) {
- var form = m.ownerCt;
- if(m.value == '应付款' || m.value == '预付款' || m.value == '预付退款'|| m.value == '应付退款'){
- form.down('#ar_custcode').hide();
- form.down('#ar_custname').hide();
- form.down('#ar_sellercode').hide();
- form.down('#ar_sellername').hide();
- if(m.value == '应付款' || m.value == '预付款'){
- form.down('#ar_deposit').hide();
- form.down('#ar_payment').show();
- form.down('#ar_apamount') && form.down('#ar_apamount').show();
- } else if(m.value == '预付退款'|| m.value == '应付退款'){
- form.down('#ar_deposit').show();
- form.down('#ar_payment').hide();
- form.down('#ar_apamount') && form.down('#ar_apamount').hide();
- }
- form.down('#ar_arapcurrency').show();
- form.down('#ar_araprate').show();
- form.down('#ar_aramount').show();
- form.down('#ar_vendcode').show();
- form.down('#ar_vendname').show();
- form.down('#ar_category').hide();
- form.down('#ar_catedesc').hide();
- form.down('#ar_precurrency').hide();
- form.down('#ar_prerate').hide();
- form.down('#ar_preamount').hide();
- form.down('#ar_recamount') && form.down('#ar_recamount').hide();
- } else if(m.value == '应收款' || m.value == '预收款' || m.value == '预收退款' || m.value == '应收退款'){
- form.down('#ar_custcode').show();
- form.down('#ar_custname').show();
- form.down('#ar_sellercode').show();
- form.down('#ar_sellername').show();
- form.down('#ar_arapcurrency').show();
- form.down('#ar_araprate').show();
- form.down('#ar_aramount').show();
- form.down('#ar_vendcode').hide();
- form.down('#ar_vendname').hide();
- form.down('#ar_category').hide();
- form.down('#ar_catedesc').hide();
- form.down('#ar_precurrency').hide();
- form.down('#ar_prerate').hide();
- form.down('#ar_preamount').hide();
- form.down('#ar_apamount') && form.down('#ar_apamount').hide();
- if(m.value == '应收款' || m.value == '预收款'){
- form.down('#ar_payment').hide();
- form.down('#ar_deposit').show();
- } else if(m.value == '预收退款' || m.value == '应收退款'){
- form.down('#ar_payment').show();
- form.down('#ar_deposit').hide();
- }
- form.down('#ar_recamount') && form.down('#ar_recamount').hide();
- } else if(m.value == '应收票据收款' || m.value == '应付票据付款'){
- form.down('#ar_arapcurrency').show();
- form.down('#ar_araprate').show();
- form.down('#ar_aramount').show();
- form.down('#ar_category').hide();
- form.down('#ar_catedesc').hide();
- form.down('#ar_precurrency').hide();
- form.down('#ar_prerate').hide();
- form.down('#ar_preamount').hide();
- form.down('#ar_arapcurrency').hide();
- form.down('#ar_araprate').hide();
- form.down('#ar_aramount').hide();
- form.down('#ar_apamount') && form.down('#ar_apamount').hide();
- if(m.value == '应收票据收款'){
- form.down('#ar_payment').hide();
- form.down('#ar_deposit').show();
- form.down('#ar_vendcode').hide();
- form.down('#ar_vendname').hide();
- form.down('#ar_custcode').show();
- form.down('#ar_custname').show();
- form.down('#ar_sellercode').show();
- form.down('#ar_sellername').show();
- } else if (m.value == '应付票据付款'){
- form.down('#ar_payment').show();
- form.down('#ar_deposit').hide();
- form.down('#ar_vendcode').show();
- form.down('#ar_vendname').show();
- form.down('#ar_custcode').hide();
- form.down('#ar_custname').hide();
- form.down('#ar_sellercode').hide();
- form.down('#ar_sellername').hide();
- }
- form.down('#ar_checkno') && form.down('#ar_checkno').hide();
- form.down('#ar_recamount') && form.down('#ar_recamount').hide();
- } else if(m.value == '转存' || m.value == '自动转存'){
- form.down('#ar_custcode').hide();
- form.down('#ar_custname').hide();
- form.down('#ar_sellercode').hide();
- form.down('#ar_sellername').hide();
- form.down('#ar_arapcurrency').hide();
- form.down('#ar_araprate').hide();
- form.down('#ar_aramount').hide();
- form.down('#ar_vendcode').hide();
- form.down('#ar_vendname').hide();
- form.down('#ar_category').show();
- form.down('#ar_catedesc').show();
- form.down('#ar_precurrency').show();
- form.down('#ar_prerate').show();
- form.down('#ar_preamount').show();
- form.down('#ar_apamount') && form.down('#ar_apamount').hide();
- if(m.value == '转存'){
- form.down('#ar_payment').show();
- form.down('#ar_deposit').hide();
- }
- if(m.value == '自动转存'){
- form.down('#ar_payment').hide();
- form.down('#ar_deposit').show();
- }
- form.down('#ar_checkno') && form.down('#ar_checkno').hide();
- form.down('#ar_recamount') && form.down('#ar_recamount').hide();
- } else if(m.value == '暂收款'){
- form.down('#ar_custcode').hide();
- form.down('#ar_custname').hide();
- form.down('#ar_sellercode').hide();
- form.down('#ar_sellername').hide();
- form.down('#ar_arapcurrency').hide();
- form.down('#ar_araprate').hide();
- form.down('#ar_aramount').hide();
- form.down('#ar_vendcode').hide();
- form.down('#ar_vendname').hide();
- form.down('#ar_category').hide();
- form.down('#ar_catedesc').hide();
- form.down('#ar_precurrency').hide();
- form.down('#ar_prerate').hide();
- form.down('#ar_preamount').hide();
- form.down('#ar_recamount') && form.down('#ar_recamount').show();
- form.down('#ar_apamount') && form.down('#ar_apamount').hide();
- } else if(m.value == '其它付款' || m.value == '其它收款'){
- form.down('#ar_custcode').hide();
- form.down('#ar_custname').hide();
- form.down('#ar_sellercode').hide();
- form.down('#ar_sellername').hide();
- form.down('#ar_arapcurrency').hide();
- form.down('#ar_araprate').hide();
- form.down('#ar_aramount').hide();
- form.down('#ar_vendcode').hide();
- form.down('#ar_checkno').hide();
- form.down('#ar_vendname').hide();
- form.down('#ar_apamount') && form.down('#ar_apamount').hide();
- if(m.value == '其它付款'){
- form.down('#ar_deposit').hide();
- form.down('#ar_payment').show();
- }
- if(m.value == '其它收款'){
- form.down('#ar_deposit').show();
- form.down('#ar_payment').hide();
- }
- form.down('#ar_category').hide();
- form.down('#ar_catedesc').hide();
- form.down('#ar_precurrency').hide();
- form.down('#ar_prerate').hide();
- form.down('#ar_preamount').hide();
- form.down('#ar_recamount') && form.down('#ar_recamount').hide();
- form.down('#ar_pleaseman') && form.down('#ar_pleaseman').show();
- } else {
- form.down('#ar_custcode').hide();
- form.down('#ar_custname').hide();
- form.down('#ar_sellercode').hide();
- form.down('#ar_sellername').hide();
- form.down('#ar_arapcurrency').hide();
- form.down('#ar_araprate').hide();
- form.down('#ar_aramount').hide();
- form.down('#ar_vendcode').hide();
- form.down('#ar_vendname').hide();
- form.down('#ar_category').hide();
- form.down('#ar_catedesc').hide();
- form.down('#ar_precurrency').hide();
- form.down('#ar_prerate').hide();
- form.down('#ar_preamount').hide();
- form.down('#ar_payment').show();
- form.down('#ar_deposit').hide();
- form.down('#ar_checkno') && form.down('#ar_checkno').hide();
- form.down('#ar_recamount') && form.down('#ar_recamount').hide();
- form.down('#ar_apamount') && form.down('#ar_apamount').hide();
- }
- if(m.value == '费用'||m.value == '应付款'||m.value == '预付款'){
- form.down('#ar_pleaseman') && form.down('#ar_pleaseman').show();
- }else{
- form.down('#ar_pleaseman') && form.down('#ar_pleaseman').hide();
- }
- }
- },
- beforeAccount:function(){
- var ar_accountcurrency = Ext.getCmp('ar_accountcurrency').value,
- ar_arapcurrency = Ext.getCmp('ar_arapcurrency').value,
- ar_araprate = Ext.getCmp('ar_araprate').value, //冲账汇率
- ar_accountrate = Ext.getCmp('ar_accountrate').value, //账户汇率
- ar_aramount = Ext.getCmp('ar_aramount').value //冲账金额
- ar_category = Ext.getCmp('ar_category').value //转存科目
- ar_precurrency = Ext.getCmp('ar_precurrency').value //转存币别
- ar_preamount = Ext.getCmp('ar_preamount').value //转存金额
- ar_prerate = Ext.getCmp('ar_prerate').value //转存汇率
- f = Ext.getCmp('ar_aramount'),
- form = Ext.getCmp('form');
- var deposit = Ext.getCmp('ar_deposit').value,
- payment = Ext.getCmp('ar_payment').value,
- type = Ext.getCmp('ar_type').value;
- var grid = Ext.getCmp('grid'), items = grid.store.data.items;
- var debit = 0, credit = 0, me = this;
- Ext.each(items,function(item,index){
- if(!Ext.isEmpty(item.data['ard_explanation']) || !Ext.isEmpty(item.data['ard_catecode']) || !Ext.isEmpty(item.data['ard_ordercode']) || !Ext.isEmpty(item.data['ard_makecode'])){
- debit= debit + Number(item.data['ard_debit']);
- credit= credit + Number(item.data['ard_credit']);
- }
- });
- if(type == '转存'){
- if(!Ext.isEmpty(debit)){
- var prerate = form.BaseUtil.numberFormat((ar_preamount+(debit-credit))/(payment-deposit),12);
- if(ar_prerate != prerate ){
- Ext.getCmp('ar_prerate').setValue(prerate);
- }
- }
- }
- var errs = [];
- Ext.Array.each(items, function(item){
- if(!Ext.isEmpty(item.data['ard_catecode'])){
- if(item.data['ca_currencytype'] != 0){
- if(Ext.isEmpty(item.data['ard_currency'])){
- errs.push('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,币别不能为空!');
- return;
- }
- if(Ext.isEmpty(item.data['ard_rate']) || item.data['ard_rate'] == 0){
- errs.push('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,汇率不能为0!');
- return;
- }
- }
- if(item.data['ard_doubledebit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_debit'] != 0){
- if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doubledebit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_debit'],2)) {
- errs.push('明细表第' + item.data['ard_detno'] + '行,原币借方*汇率不等于本币借方!');
- return;
- }
- }
- if(item.data['ard_doublecredit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_credit'] != 0){
- if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doublecredit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_credit'],2)) {
- errs.push('明细表第' + item.data['ard_detno'] + '行,原币贷方*汇率不等于本币贷方!');
- return;
- }
- }
- } else {
- if(type == '其它收款' || type == '其它付款' || type == '费用'){
- errs.push('明细表第' + item.data['ard_detno'] + '行,科目未填写!');
- return;
- }
- }
- });
- if(errs.length > 0) {
- showError(errs.join('<br>'));
- return;
- }
- if(type != null && type != '' ){
- if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '应收票据收款'){
- if(deposit == 0 || deposit == null || deposit == '' ){
- showError('收入金额不能为空!');
- return;
- }
- if(type == '应收款' || type == '预收款' || type == '应付退款'){
- if(form.BaseUtil.numberFormat(ar_araprate,8) != form.BaseUtil.numberFormat(ar_aramount/deposit,8)){
- showError('冲账汇率不正确!');
- return;
- }
- }
- } else if (type == '预付款' || type == '应付款' || type == '应收退款' || type == '应付票据付款'){
- if(payment == 0 || payment == null || payment == '' ){
- showError('支出金额不能为空!');
- return;
- }
- if(type == '预付款' || type == '应付款' || type == '应收退款'){
- if(form.BaseUtil.numberFormat(ar_araprate,8) != form.BaseUtil.numberFormat(ar_aramount/payment,8)){
- showError('冲账汇率不正确!');
- return;
- }
- }
- } else if(type == '转存') {
- if(payment == 0 || payment == null || payment == '' ){
- showError('支出金额不能为空!');
- return;
- }
- if(Ext.isEmpty(ar_category)){
- showError('转存科目不能为空!');
- return;
- }
- if(Ext.isEmpty(ar_precurrency)){
- showError('转存币别不能为空!');
- return;
- }
- if(ar_preamount == 0 || ar_preamount == null || ar_preamount == '' ){
- showError('转存金额不能为空!');
- return;
- }
- if(ar_accountcurrency != ar_precurrency){
- if(ar_prerate == 1){
- showError('币别不一致,转存汇率为1,不能记账!');
- return;
- }
- }
- }
- if(type != '应收票据收款' && type != '应付票据付款' && type != '费用' && type != '转存' && type != '其它收款' && type != '其它付款'){
- if(ar_accountcurrency != ar_arapcurrency){
- if(Ext.getCmp('ar_araprate').value == '1'){
- showError('币别不一致,冲账汇率为1,不能记账!');
- return;
- }
- }
- }
- if(type == '应收票据收款' || type == '其它收款'){
- if(form.BaseUtil.numberFormat(Math.abs(form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2)-form.BaseUtil.numberFormat(credit-debit, 2)),2) > 0.01){
- showError('收入金额' + form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2) + '不一致,不能记账!');
- return;
- }
- }
- if(type == '应付票据付款' || type == '其它付款' || type == '费用'){
- if(Math.abs(form.BaseUtil.numberFormat(form.BaseUtil.numberFormat(form.BaseUtil.multiply(payment, ar_accountrate), 2)- form.BaseUtil.numberFormat(debit-credit, 2),2)) > 0.01){
- showError('支出金额' + form.BaseUtil.numberFormat(form.BaseUtil.multiply(payment, ar_accountrate), 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致,不能记账!');
- return;
- }
- }
- if(!Ext.isEmpty(Ext.getCmp('ar_source').value)){
- if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款'){
- if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(credit-debit, 2)) > 0.01){
- showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2)+ '不一致!');
- return;
- }
- }
- if(type == '应付款' || type == '应收退款' || type == '预收退款'){
- if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2))>0.011){
- showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
- return;
- }
- }
- if(type == '预付款'){
- if(Ext.getCmp('ar_sourcetype')&&Ext.getCmp('ar_sourcetype').value!="付款申请"){
- if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2))>0.011){
- showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
- return;
- }
- }
- }
- }
- }
- this.FormUtil.onAccounted(Ext.getCmp('ar_id').value);
- },
- beforeSubmit:function(){
- var ar_accountcurrency = Ext.getCmp('ar_accountcurrency').value,
- ar_arapcurrency = Ext.getCmp('ar_arapcurrency').value,
- ar_araprate = Ext.getCmp('ar_araprate').value, //冲账汇率
- ar_accountrate = Ext.getCmp('ar_accountrate').value, //账户汇率
- ar_aramount = Ext.getCmp('ar_aramount').value //冲账金额
- ar_category = Ext.getCmp('ar_category').value //转存科目
- ar_precurrency = Ext.getCmp('ar_precurrency').value //转存币别
- ar_preamount = Ext.getCmp('ar_preamount').value //转存金额
- ar_prerate = Ext.getCmp('ar_prerate').value //转存汇率
- f = Ext.getCmp('ar_aramount'),
- form = Ext.getCmp('form');
- var deposit = Ext.getCmp('ar_deposit').value,
- payment = Ext.getCmp('ar_payment').value,
- type = Ext.getCmp('ar_type').value;
- var grid = Ext.getCmp('grid'), items = grid.store.data.items;
- var debit = 0, credit = 0, me = this;
- if(type != null && type != '' ){
- if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '应收票据收款'){
- if(deposit == 0 || deposit == null || deposit == '' ){
- showError('收入金额不能为空!');
- return;
- }
- if(type == '应收款' || type == '预收款' || type == '应付退款'){
- if(form.BaseUtil.numberFormat(ar_araprate,8) != form.BaseUtil.numberFormat(ar_aramount/deposit,8)){
- showError('冲账汇率不正确!');
- return;
- }
- }
- } else if (type == '预付款' || type == '应付款' || type == '应收退款' || type == '应付票据付款'){
- if(payment == 0 || payment == null || payment == '' ){
- showError('支出金额不能为空!');
- return;
- }
- if(type == '预付款' || type == '应付款' || type == '应收退款'){
- if(form.BaseUtil.numberFormat(ar_araprate,8) != form.BaseUtil.numberFormat(ar_aramount/payment,8)){
- showError('冲账汇率不正确!');
- return;
- }
- }
- } else if(type == '转存') {
- if(payment == 0 || payment == null || payment == '' ){
- showError('支出金额不能为空!');
- return;
- }
- if(Ext.isEmpty(ar_category)){
- showError('转存科目不能为空!');
- return;
- }
- if(Ext.isEmpty(ar_precurrency)){
- showError('转存币别不能为空!');
- return;
- }
- if(ar_preamount == 0 || ar_preamount == null || ar_preamount == '' ){
- showError('转存金额不能为空!');
- return;
- }
- if(ar_accountcurrency != ar_precurrency){
- if(ar_prerate == 1){
- showError('币别不一致,转存汇率为1,不能提交!');
- return;
- }
- }
- }
- if(type != '应收票据收款' && type != '应付票据付款' && type != '费用' && type != '转存' && type != '其它收款' && type != '其它付款'){
- if(ar_accountcurrency != ar_arapcurrency){
- if(ar_araprate == '1'){
- showError('币别不一致,冲账汇率为1,不能提交!');
- return;
- }
- }
- }
- }
- Ext.each(items,function(item,index){
- if(!Ext.isEmpty(item.data['ard_explanation']) || !Ext.isEmpty(item.data['ard_catecode']) || !Ext.isEmpty(item.data['ard_ordercode']) || !Ext.isEmpty(item.data['ard_makecode'])){
- debit= debit + Number(item.data['ard_debit']);
- credit= credit + Number(item.data['ard_credit']);
- }
- });
- if(!Ext.isEmpty(Ext.getCmp('ar_source').value)){
- if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款'){
- if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(credit-debit, 2))>0.011){
- showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2) + '不一致!');
- return;
- }
- }
- if(type == '应付款' || type == '应收退款' || type == '预收退款'){
- if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2))>0.011){
- showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
- return;
- }
- }
- if(type == '预付款'){
- if(Ext.getCmp('ar_sourcetype')&&Ext.getCmp('ar_sourcetype').value!="付款申请"){
- if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2))>0.011){
- showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
- return;
- }
- }
- }
- if(type == '应收票据收款'){
- console.log(Math.abs(form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2)-form.BaseUtil.numberFormat(credit-debit, 2)));
- if(Math.abs(form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2)-form.BaseUtil.numberFormat(credit-debit, 2))>0.011){
- showError('收入金额' + form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2) + '不一致!');
- return;
- }
- }
- if(type == '应付票据付款'){
- if(Math.abs(form.BaseUtil.numberFormat(form.BaseUtil.multiply(payment, ar_accountrate), 2)-form.BaseUtil.numberFormat(debit-credit, 2))>0.011){
- showError('支出金额' + form.BaseUtil.numberFormat(form.BaseUtil.multiply(payment, ar_accountrate), 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
- return;
- }
- }
- }
- var errs = [];
- Ext.Array.each(items, function(item){
- if(!Ext.isEmpty(item.data['ard_catecode'])){
- if(item.data['ca_currencytype'] != 0){
- if(Ext.isEmpty(item.data['ard_currency'])){
- errs.push('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,币别不能为空!');
- return;
- }
- if(Ext.isEmpty(item.data['ard_rate']) || item.data['ard_rate'] == 0){
- errs.push('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,汇率不能为0!');
- return;
- }
- }
- if(item.data['ard_doubledebit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_debit'] != 0){
- if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doubledebit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_debit'],2)) {
- errs.push('明细表第' + item.data['ard_detno'] + '行,原币借方*汇率不等于本币借方!');
- return;
- }
- }
- if(item.data['ard_doublecredit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_credit'] != 0){
- if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doublecredit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_credit'],2)) {
- errs.push('明细表第' + item.data['ard_detno'] + '行,原币贷方*汇率不等于本币贷方!');
- return;
- }
- }
- }
- });
- if(errs.length > 0) {
- showError(errs.join('<br>'));
- return;
- }
- this.FormUtil.onSubmit(Ext.getCmp('ar_id').value, false, this.beforeUpdate, this);
- },
- copy: function(){
- var me = this;
- var form = Ext.getCmp('form');
- var v = form.down('#ar_id').value;
- if(v > 0) {
- form.setLoading(true);
- Ext.Ajax.request({
- url: basePath + 'fa/gs/copyAccountRegister.action',
- params: {
- id: v
- },
- callback: function(opt, s, r){
- form.setLoading(false);
- var res = Ext.decode(r.responseText);
- if(res.ar) {
- turnSuccess(function(){
- var id = res.ar.ar_id;
- var url = "jsps/fa/gs/accountRegister.jsp?formCondition=ar_idIS" +
- + id + "&gridCondition=ard_aridIS" + id + "&whoami=AccountRegister!Bank";
- me.FormUtil.onAdd('accountRegister' + id, '银行登记' + id, url);
- });
- } else {
- showError(res.exceptionInfo);
- }
- }
- });
- }
- },
- getApamount: function(){
- var grid = Ext.getCmp('grid');
- var items = grid.store.data.items;
- var apamount = 0, type = Ext.getCmp('ar_type').value;
- if(type != null && type != '' ){
- if(type == '应付款'){
- Ext.each(items,function(item,index){
- if(!Ext.isEmpty(item.data['ard_ordercode'])){
- apamount= apamount + Number(item.data['ard_nowbalance']);
- }
- });
- Ext.getCmp('ar_apamount').setValue(Ext.util.Format.number(apamount,'0.00'));
- }
- if(type == '预付款'){
- var cmamount = Ext.Number.from(Ext.getCmp('ar_aramount').getValue(), 0);
- Ext.each(items,function(item,index){
- if(Ext.isEmpty(item.data['ard_ordercode']) && Ext.isEmpty(item.data['ard_makecode'])){
- apamount= apamount + Number(item.data['ard_nowbalance']);
- }
- });
- Ext.getCmp('ar_apamount').setValue(Ext.util.Format.number(cmamount-apamount,'0.00'));
- }
- }
- }
- });
|