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.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.TransactionGlAccountCategory; 024import com.echothree.model.data.accounting.server.entity.TransactionGlAccountCategoryDetail; 025import com.echothree.util.server.persistence.Session; 026import graphql.annotations.annotationTypes.GraphQLDescription; 027import graphql.annotations.annotationTypes.GraphQLField; 028import graphql.annotations.annotationTypes.GraphQLName; 029import graphql.annotations.annotationTypes.GraphQLNonNull; 030import graphql.schema.DataFetchingEnvironment; 031 032@GraphQLDescription("transaction GL account category object") 033@GraphQLName("TransactionGlAccountCategory") 034public class TransactionGlAccountCategoryObject 035 extends BaseEntityInstanceObject { 036 037 private final TransactionGlAccountCategory transactionGlAccountCategory; // Always Present 038 039 public TransactionGlAccountCategoryObject(TransactionGlAccountCategory transactionGlAccountCategory) { 040 super(transactionGlAccountCategory.getPrimaryKey()); 041 042 this.transactionGlAccountCategory = transactionGlAccountCategory; 043 } 044 045 private TransactionGlAccountCategoryDetail transactionGlAccountCategoryDetail; // Optional, use getTransactionGlAccountCategoryDetail() 046 047 private TransactionGlAccountCategoryDetail getTransactionGlAccountCategoryDetail() { 048 if(transactionGlAccountCategoryDetail == null) { 049 transactionGlAccountCategoryDetail = transactionGlAccountCategory.getLastDetail(); 050 } 051 052 return transactionGlAccountCategoryDetail; 053 } 054 055 @GraphQLField 056 @GraphQLDescription("transaction type") 057 public TransactionTypeObject getTransactionType(final DataFetchingEnvironment env) { 058 return AccountingSecurityUtils.getHasTransactionTypeAccess(env) ? 059 new TransactionTypeObject(getTransactionGlAccountCategoryDetail().getTransactionType()) : 060 null; 061 } 062 063 @GraphQLField 064 @GraphQLDescription("transaction GL account category name") 065 @GraphQLNonNull 066 public String getTransactionGlAccountCategoryName() { 067 return getTransactionGlAccountCategoryDetail().getTransactionGlAccountCategoryName(); 068 } 069 070 @GraphQLField 071 @GraphQLDescription("sort order") 072 @GraphQLNonNull 073 public int getSortOrder() { 074 return getTransactionGlAccountCategoryDetail().getSortOrder(); 075 } 076 077 @GraphQLField 078 @GraphQLDescription("GL account category") 079 public GlAccountCategoryObject getGlAccountCategory(final DataFetchingEnvironment env) { 080 var glaccountCategory = getTransactionGlAccountCategoryDetail().getGlAccountCategory(); 081 082 return glaccountCategory == null ? null : 083 AccountingSecurityUtils.getHasGlAccountCategoryAccess(env) ? 084 new GlAccountCategoryObject(glaccountCategory) : 085 null; 086 } 087 088 @GraphQLField 089 @GraphQLDescription("description") 090 @GraphQLNonNull 091 public String getDescription(final DataFetchingEnvironment env) { 092 var accountingControl = Session.getModelController(AccountingControl.class); 093 var userControl = Session.getModelController(UserControl.class); 094 095 return accountingControl.getBestTransactionGlAccountCategoryDescription(transactionGlAccountCategory, userControl.getPreferredLanguageFromUserVisit(BaseGraphQl.getUserVisit(env))); 096 } 097 098}