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