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.tax.server.transfer; 018 019import com.echothree.model.control.accounting.common.transfer.GlAccountTransfer; 020import com.echothree.model.control.accounting.server.control.AccountingControl; 021import com.echothree.model.control.contact.common.transfer.ContactMechanismPurposeTransfer; 022import com.echothree.model.control.contact.server.control.ContactControl; 023import com.echothree.model.control.tax.common.transfer.TaxTransfer; 024import com.echothree.model.control.tax.server.control.TaxControl; 025import com.echothree.model.data.tax.server.entity.Tax; 026import com.echothree.model.data.tax.server.entity.TaxDetail; 027import com.echothree.model.data.user.server.entity.UserVisit; 028import com.echothree.util.server.persistence.Session; 029 030public class TaxTransferCache 031 extends BaseTaxTransferCache<Tax, TaxTransfer> { 032 033 AccountingControl accountingControl = Session.getModelController(AccountingControl.class); 034 ContactControl contactControl = Session.getModelController(ContactControl.class); 035 036 /** Creates a new instance of TaxTransferCache */ 037 public TaxTransferCache(UserVisit userVisit, TaxControl taxControl) { 038 super(userVisit, taxControl); 039 040 setIncludeEntityInstance(true); 041 } 042 043 @Override 044 public TaxTransfer getTransfer(Tax tax) { 045 TaxTransfer taxTransfer = get(tax); 046 047 if(taxTransfer == null) { 048 TaxDetail taxDetail = tax.getLastDetail(); 049 String taxName = taxDetail.getTaxName(); 050 ContactMechanismPurposeTransfer contactMechanismPurpose = contactControl.getContactMechanismPurposeTransfer(userVisit, taxDetail.getContactMechanismPurpose()); 051 GlAccountTransfer glAccount = accountingControl.getGlAccountTransfer(userVisit, taxDetail.getGlAccount()); 052 String percent = formatFractionalPercent(taxDetail.getPercent()); 053 Boolean isDefault = taxDetail.getIsDefault(); 054 Integer sortOrder = taxDetail.getSortOrder(); 055 String description = taxControl.getBestTaxDescription(tax, getLanguage()); 056 057 taxTransfer = new TaxTransfer(taxName, contactMechanismPurpose, glAccount, percent, isDefault, sortOrder, description); 058 put(tax, taxTransfer); 059 } 060 061 return taxTransfer; 062 } 063 064}