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.accounting.server.transfer; 018 019import com.echothree.model.control.accounting.common.AccountingProperties; 020import com.echothree.model.control.accounting.common.transfer.CurrencyTransfer; 021import com.echothree.model.control.accounting.server.control.AccountingControl; 022import com.echothree.model.data.accounting.server.entity.Currency; 023import com.echothree.model.data.user.server.entity.UserVisit; 024import com.echothree.util.common.form.TransferProperties; 025import com.echothree.util.server.persistence.Session; 026import javax.enterprise.context.RequestScoped; 027 028@RequestScoped 029public class CurrencyTransferCache 030 extends BaseAccountingTransferCache<Currency, CurrencyTransfer> { 031 032 AccountingControl accountingControl = Session.getModelController(AccountingControl.class); 033 034 TransferProperties transferProperties; 035 boolean filterCurrencyIsoName; 036 boolean filterSymbol; 037 boolean filterSymbolPosition; 038 boolean filterSymbolOnListStart; 039 boolean filterSymbolOnListMember; 040 boolean filterSymbolOnSubtotal; 041 boolean filterSymbolOnTotal; 042 boolean filterGroupingSeparator; 043 boolean filterGroupingSize; 044 boolean filterFractionSeparator; 045 boolean filterDefaultFractionDigits; 046 boolean filterPriceUnitFractionDigits; 047 boolean filterPriceLineFractionDigits; 048 boolean filterCostUnitFractionDigits; 049 boolean filterCostLineFractionDigits; 050 boolean filterMinusSign; 051 boolean filterisDefault; 052 boolean filterSortOrder; 053 boolean filterDescription; 054 055 /** Creates a new instance of CurrencyTransferCache */ 056 protected CurrencyTransferCache() { 057 super(); 058 059 transferProperties = session.getTransferProperties(); 060 if(transferProperties != null) { 061 var properties = transferProperties.getProperties(CurrencyTransfer.class); 062 063 if(properties != null) { 064 filterCurrencyIsoName = !properties.contains(AccountingProperties.CURRENCY_ISO_NAME); 065 filterSymbol = !properties.contains(AccountingProperties.SYMBOL); 066 filterSymbolPosition = !properties.contains(AccountingProperties.SYMBOL_POSITION); 067 filterSymbolOnListStart = !properties.contains(AccountingProperties.SYMBOL_ON_LIST_START); 068 filterSymbolOnListMember = !properties.contains(AccountingProperties.SYMBOL_ON_LIST_MEMBER); 069 filterSymbolOnSubtotal = !properties.contains(AccountingProperties.SYMBOL_ON_SUBTOTAL); 070 filterSymbolOnTotal = !properties.contains(AccountingProperties.SYMBOL_ON_TOTAL); 071 filterGroupingSeparator = !properties.contains(AccountingProperties.GROUPING_SEPARATOR); 072 filterGroupingSize = !properties.contains(AccountingProperties.GROUPING_SIZE); 073 filterFractionSeparator = !properties.contains(AccountingProperties.FRACTION_SEPARATOR); 074 filterDefaultFractionDigits = !properties.contains(AccountingProperties.DEFAULT_FRACTION_DIGITS); 075 filterPriceUnitFractionDigits = !properties.contains(AccountingProperties.PRICE_UNIT_FRACTION_DIGITS); 076 filterPriceLineFractionDigits = !properties.contains(AccountingProperties.PRICE_LINE_FRACTION_DIGITS); 077 filterCostUnitFractionDigits = !properties.contains(AccountingProperties.COST_UNIT_FRACTION_DIGITS); 078 filterCostLineFractionDigits = !properties.contains(AccountingProperties.COST_LINE_FRACTION_DIGITS); 079 filterMinusSign = !properties.contains(AccountingProperties.MINUS_SIGN); 080 filterisDefault = !properties.contains(AccountingProperties.IS_DEFAULT); 081 filterSortOrder = !properties.contains(AccountingProperties.SORT_ORDER); 082 filterDescription = !properties.contains(AccountingProperties.DESCRIPTION); 083 } 084 } 085 } 086 087 @Override 088 public CurrencyTransfer getTransfer(UserVisit userVisit, Currency currency) { 089 var currencyTransfer = get(currency); 090 091 if(currencyTransfer == null) { 092 var currencyIsoName = filterCurrencyIsoName ? null : currency.getCurrencyIsoName(); 093 var symbol = filterSymbol ? null : currency.getSymbol(); 094 var symbolPosition = filterSymbolPosition ? null : accountingControl.getSymbolPositionTransfer(userVisit, currency.getSymbolPosition()); 095 var symbolOnListStart = filterSymbolOnListStart ? null : currency.getSymbolOnListStart(); 096 var symbolOnListMember = filterSymbolOnListMember ? null : currency.getSymbolOnListMember(); 097 var symbolOnSubtotal = filterSymbolOnSubtotal ? null : currency.getSymbolOnSubtotal(); 098 var symbolOnTotal = filterSymbolOnTotal ? null : currency.getSymbolOnTotal(); 099 var groupingSeparator = filterGroupingSeparator ? null : currency.getGroupingSeparator(); 100 var groupingSize = filterGroupingSize ? null : currency.getGroupingSize(); 101 var fractionSeparator = filterFractionSeparator ? null : currency.getFractionSeparator(); 102 var defaultFractionDigits = filterDefaultFractionDigits ? null : currency.getDefaultFractionDigits(); 103 var priceUnitFractionDigits = filterPriceUnitFractionDigits ? null : currency.getPriceUnitFractionDigits(); 104 var priceLineFractionDigits = filterPriceLineFractionDigits ? null : currency.getPriceLineFractionDigits(); 105 var costUnitFractionDigits = filterCostUnitFractionDigits ? null : currency.getCostUnitFractionDigits(); 106 var costLineFractionDigits = filterCostLineFractionDigits ? null : currency.getCostLineFractionDigits(); 107 var minusSign = filterMinusSign ? null : currency.getMinusSign(); 108 var isDefault = filterisDefault ? null : currency.getIsDefault(); 109 var sortOrder = filterSortOrder ? null : currency.getSortOrder(); 110 var description = filterDescription ? null : accountingControl.getBestCurrencyDescription(currency, getLanguage(userVisit)); 111 112 currencyTransfer = new CurrencyTransfer(currencyIsoName, symbol, symbolPosition, symbolOnListStart, symbolOnListMember, 113 symbolOnSubtotal, symbolOnTotal, groupingSeparator, groupingSize, fractionSeparator, defaultFractionDigits, 114 priceUnitFractionDigits, priceLineFractionDigits, costUnitFractionDigits, costLineFractionDigits, minusSign, 115 isDefault, sortOrder, description); 116 put(userVisit, currency, currencyTransfer); 117 } 118 return currencyTransfer; 119 } 120 121}