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