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.graphql;
018
019import com.echothree.model.control.accounting.server.control.AccountingControl;
020import com.echothree.model.control.graphql.server.graphql.BaseEntityInstanceObject;
021import com.echothree.model.control.graphql.server.util.BaseGraphQl;
022import com.echothree.model.control.user.server.control.UserControl;
023import com.echothree.model.data.accounting.server.entity.Currency;
024import com.echothree.util.server.persistence.Session;
025import graphql.annotations.annotationTypes.GraphQLDescription;
026import graphql.annotations.annotationTypes.GraphQLField;
027import graphql.annotations.annotationTypes.GraphQLName;
028import graphql.annotations.annotationTypes.GraphQLNonNull;
029import graphql.schema.DataFetchingEnvironment;
030
031@GraphQLDescription("currency object")
032@GraphQLName("Currency")
033public class CurrencyObject
034        extends BaseEntityInstanceObject {
035
036    private final Currency currency; // Always Present
037    
038    public CurrencyObject(Currency currency) {
039        super(currency.getPrimaryKey());
040        
041        this.currency = currency;
042    }
043    
044    @GraphQLField
045    @GraphQLDescription("currency iso name")
046    @GraphQLNonNull
047    public String getCurrencyIsoName() {
048        return currency.getCurrencyIsoName();
049    }
050
051    @GraphQLField
052    @GraphQLDescription("symbol")
053    public String getSymbol() {
054        return currency.getSymbol();
055    }
056
057    @GraphQLField
058    @GraphQLDescription("symbol position")
059    public SymbolPositionObject getSymbolPosition(final DataFetchingEnvironment env) {
060        return AccountingSecurityUtils.getHasSymbolPositionAccess(env) ? new SymbolPositionObject(currency.getSymbolPosition()) : null;
061    }
062    
063    @GraphQLField
064    @GraphQLDescription("symbol on list start")
065    public Boolean getSymbolOnListStart() {
066        return currency.getSymbolOnListStart();
067    }
068
069    @GraphQLField
070    @GraphQLDescription("symbol on list member")
071    public Boolean getSymbolOnListMember() {
072        return currency.getSymbolOnListMember();
073    }
074
075    @GraphQLField
076    @GraphQLDescription("symbol on subtotal")
077    public Boolean getSymbolOnSubtotal() {
078        return currency.getSymbolOnSubtotal();
079    }
080
081    @GraphQLField
082    @GraphQLDescription("symbol on total")
083    public Boolean getSymbolOnTotal() {
084        return currency.getSymbolOnTotal();
085    }
086
087    @GraphQLField
088    @GraphQLDescription("grouping separator")
089    @GraphQLNonNull
090    public String getGroupingSeparator() {
091        return currency.getGroupingSeparator();
092    }
093
094    @GraphQLField
095    @GraphQLDescription("grouping size")
096    @GraphQLNonNull
097    public Integer getGroupingSize() {
098        return currency.getGroupingSize();
099    }
100
101    @GraphQLField
102    @GraphQLDescription("fraction separator")
103    public String getFractionSeparator() {
104        return currency.getFractionSeparator();
105    }
106
107    @GraphQLField
108    @GraphQLDescription("default fraction digits")
109    public Integer getDefaultFractionDigits() {
110        return currency.getDefaultFractionDigits();
111    }
112
113    @GraphQLField
114    @GraphQLDescription("price unit fraction digits")
115    public Integer getPriceUnitFractionDigits() {
116        return currency.getPriceUnitFractionDigits();
117    }
118
119    @GraphQLField
120    @GraphQLDescription("price line fraction digits")
121    public Integer getPriceLineFractionDigits() {
122        return currency.getPriceLineFractionDigits();
123    }
124
125    @GraphQLField
126    @GraphQLDescription("cost unit fraction digits")
127    public Integer getCostUnitFractionDigits() {
128        return currency.getCostUnitFractionDigits();
129    }
130
131    @GraphQLField
132    @GraphQLDescription("cost line fraction digits")
133    public Integer getCostLineFractionDigits() {
134        return currency.getCostLineFractionDigits();
135    }
136
137    @GraphQLField
138    @GraphQLDescription("minus sign")
139    @GraphQLNonNull
140    public String getMinusSign() {
141        return currency.getMinusSign();
142    }
143
144    @GraphQLField
145    @GraphQLDescription("is default")
146    @GraphQLNonNull
147    public Boolean getIsDefault() {
148        return currency.getIsDefault();
149    }
150
151    @GraphQLField
152    @GraphQLDescription("sort order")
153    @GraphQLNonNull
154    public Integer getSortOrder() {
155        return currency.getSortOrder();
156    }
157
158    @GraphQLField
159    @GraphQLDescription("description")
160    @GraphQLNonNull
161    public String getDescription(final DataFetchingEnvironment env) {
162        var accountingControl = Session.getModelController(AccountingControl.class);
163        var userControl = Session.getModelController(UserControl.class);
164
165        return accountingControl.getBestCurrencyDescription(currency, userControl.getPreferredLanguageFromUserVisit(BaseGraphQl.getUserVisit(env)));
166    }
167
168}