001// --------------------------------------------------------------------------------
002// Copyright 2002-2026 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.graphql.server.graphql.AmountObject;
020import com.echothree.model.control.graphql.server.graphql.BaseObject;
021import com.echothree.model.control.party.server.graphql.PartyObject;
022import com.echothree.model.control.party.server.graphql.PartySecurityUtils;
023import com.echothree.model.data.accounting.server.entity.TransactionGlEntry;
024import graphql.annotations.annotationTypes.GraphQLDescription;
025import graphql.annotations.annotationTypes.GraphQLField;
026import graphql.annotations.annotationTypes.GraphQLName;
027import graphql.annotations.annotationTypes.GraphQLNonNull;
028import graphql.schema.DataFetchingEnvironment;
029
030@GraphQLDescription("transaction GL entry object")
031@GraphQLName("TransactionGlEntry")
032public class TransactionGlEntryObject
033        extends BaseObject {
034
035    private final TransactionGlEntry transactionGlEntry; // Always Present
036
037    public TransactionGlEntryObject(TransactionGlEntry transactionGlEntry) {
038        this.transactionGlEntry = transactionGlEntry;
039    }
040
041    @GraphQLField
042    @GraphQLDescription("transaction")
043    public TransactionObject getTransaction(final DataFetchingEnvironment env) {
044        return AccountingSecurityUtils.getHasTransactionAccess(env) ?
045                new TransactionObject(transactionGlEntry.getTransaction()) :
046                null;
047    }
048
049    @GraphQLField
050    @GraphQLDescription("transaction GL entry sequence")
051    @GraphQLNonNull
052    public int getTransactionGlEntrySequence() {
053        return transactionGlEntry.getTransactionGlEntrySequence();
054    }
055
056    @GraphQLField
057    @GraphQLDescription("group party")
058    public PartyObject getGroupParty(final DataFetchingEnvironment env) {
059        var groupParty = transactionGlEntry.getGroupParty();
060
061        return PartySecurityUtils.getHasPartyAccess(env, groupParty) ?
062                new PartyObject(groupParty) :
063                null;
064    }
065
066    @GraphQLField
067    @GraphQLDescription("transaction GL account category")
068    public TransactionGlAccountCategoryObject getTransactionGlAccountCategory(final DataFetchingEnvironment env) {
069        var transactionGlAccountCategory = transactionGlEntry.getTransactionGlAccountCategory();
070
071        return transactionGlAccountCategory == null ? null :
072                AccountingSecurityUtils.getHasTransactionGlAccountCategoryAccess(env) ?
073                new TransactionGlAccountCategoryObject(transactionGlAccountCategory) :
074                null;
075    }
076
077    @GraphQLField
078    @GraphQLDescription("GL account")
079    public GlAccountObject getGlAccount(final DataFetchingEnvironment env) {
080        return AccountingSecurityUtils.getHasGlAccountAccess(env) ?
081                new GlAccountObject(transactionGlEntry.getGlAccount()) :
082                null;
083    }
084
085    @GraphQLField
086    @GraphQLDescription("original currency")
087    public CurrencyObject getOriginalCurrency(final DataFetchingEnvironment env) {
088        return AccountingSecurityUtils.getHasCurrencyAccess(env) ?
089                new CurrencyObject(transactionGlEntry.getOriginalCurrency()) :
090                null;
091    }
092
093    @GraphQLField
094    @GraphQLDescription("original debit")
095    public AmountObject getOriginalDebit() {
096        var originalDebit = transactionGlEntry.getOriginalDebit();
097
098        return originalDebit == null ? null :
099                new AmountObject(transactionGlEntry.getOriginalCurrency(), transactionGlEntry.getOriginalDebit());
100    }
101
102    @GraphQLField
103    @GraphQLDescription("original credit")
104    public AmountObject getOriginalCredit() {
105        var originalCredit = transactionGlEntry.getOriginalCredit();
106
107        return originalCredit == null ? null :
108                new AmountObject(transactionGlEntry.getOriginalCurrency(), transactionGlEntry.getOriginalCredit());
109    }
110
111    @GraphQLField
112    @GraphQLDescription("original debit")
113    public AmountObject getDebit() {
114        var debit = transactionGlEntry.getDebit();
115
116        return debit == null ? null :
117                new AmountObject(transactionGlEntry.getGlAccount().getLastDetail().getCurrency(), transactionGlEntry.getDebit());
118    }
119
120    @GraphQLField
121    @GraphQLDescription("original credit")
122    public AmountObject getCredit() {
123        var credit = transactionGlEntry.getCredit();
124
125        return credit == null ? null :
126                new AmountObject(transactionGlEntry.getGlAccount().getLastDetail().getCurrency(), transactionGlEntry.getCredit());
127    }
128
129}