001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016 017package com.echothree.model.control.accounting.server.transfer; 018 019import com.echothree.model.control.accounting.common.transfer.CurrencyTransfer; 020import com.echothree.model.control.accounting.common.transfer.GlAccountCategoryTransfer; 021import com.echothree.model.control.accounting.common.transfer.GlAccountClassTransfer; 022import com.echothree.model.control.accounting.common.transfer.GlAccountTransfer; 023import com.echothree.model.control.accounting.common.transfer.GlAccountTypeTransfer; 024import com.echothree.model.control.accounting.common.transfer.GlResourceTypeTransfer; 025import com.echothree.model.control.accounting.server.control.AccountingControl; 026import com.echothree.model.data.accounting.server.entity.GlAccount; 027import com.echothree.model.data.accounting.server.entity.GlAccountCategory; 028import com.echothree.model.data.accounting.server.entity.GlAccountDetail; 029import com.echothree.model.data.user.server.entity.UserVisit; 030 031public class GlAccountTransferCache 032 extends BaseAccountingTransferCache<GlAccount, GlAccountTransfer> { 033 034 /** Creates a new instance of GlAccountTransferCache */ 035 public GlAccountTransferCache(UserVisit userVisit, AccountingControl accountingControl) { 036 super(userVisit, accountingControl); 037 038 setIncludeEntityInstance(true); 039 } 040 041 @Override 042 public GlAccountTransfer getTransfer(GlAccount glAccount) { 043 GlAccountTransfer glAccountTransfer = get(glAccount); 044 045 if(glAccountTransfer == null) { 046 GlAccountDetail glAccountDetail = glAccount.getLastDetail(); 047 String glAccountName = glAccountDetail.getGlAccountName(); 048 GlAccount parentGlAccount = glAccountDetail.getParentGlAccount(); 049 GlAccountTransfer parentGlAccountTransfer = parentGlAccount == null? null: getTransfer(parentGlAccount); 050 GlAccountTypeTransfer glAccountTypeTransfer = accountingControl.getGlAccountTypeTransfer(userVisit, glAccountDetail.getGlAccountType()); 051 GlAccountClassTransfer glAccountClassTransfer = accountingControl.getGlAccountClassTransfer(userVisit, glAccountDetail.getGlAccountClass()); 052 GlAccountCategory glAccountCategory = glAccountDetail.getGlAccountCategory(); 053 GlAccountCategoryTransfer glAccountCategoryTransfer = glAccountCategory == null? null: accountingControl.getGlAccountCategoryTransfer(userVisit, glAccountCategory); 054 GlResourceTypeTransfer glResourceTypeTransfer = accountingControl.getGlResourceTypeTransfer(userVisit, glAccountDetail.getGlResourceType()); 055 CurrencyTransfer currencyTransfer = accountingControl.getCurrencyTransfer(userVisit, glAccountDetail.getCurrency()); 056 Boolean isDefault = glAccountDetail.getIsDefault(); 057 String description = accountingControl.getBestGlAccountDescription(glAccount, getLanguage()); 058 059 glAccountTransfer = new GlAccountTransfer(glAccountName, parentGlAccountTransfer, glAccountTypeTransfer, 060 glAccountClassTransfer, glAccountCategoryTransfer, glResourceTypeTransfer, currencyTransfer, isDefault, 061 description); 062 put(glAccount, glAccountTransfer); 063 } 064 065 return glAccountTransfer; 066 } 067 068}