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.transfer; 018 019import javax.inject.Inject; 020import com.echothree.model.control.accounting.common.transfer.ItemAccountingCategoryTransfer; 021import com.echothree.model.control.accounting.server.control.AccountingControl; 022import com.echothree.model.data.accounting.server.entity.ItemAccountingCategory; 023import com.echothree.model.data.user.server.entity.UserVisit; 024import javax.enterprise.context.RequestScoped; 025 026@RequestScoped 027public class ItemAccountingCategoryTransferCache 028 extends BaseAccountingTransferCache<ItemAccountingCategory, ItemAccountingCategoryTransfer> { 029 030 @Inject 031 AccountingControl accountingControl; 032 033 /** Creates a new instance of ItemAccountingCategoryTransferCache */ 034 protected ItemAccountingCategoryTransferCache() { 035 super(); 036 037 setIncludeEntityInstance(true); 038 } 039 040 @Override 041 public ItemAccountingCategoryTransfer getTransfer(UserVisit userVisit, ItemAccountingCategory itemAccountingCategory) { 042 var itemAccountingCategoryTransfer = get(itemAccountingCategory); 043 044 if(itemAccountingCategoryTransfer == null) { 045 var itemAccountingCategoryDetail = itemAccountingCategory.getLastDetail(); 046 var itemAccountingCategoryName = itemAccountingCategoryDetail.getItemAccountingCategoryName(); 047 var parentItemAccountingCategory = itemAccountingCategoryDetail.getParentItemAccountingCategory(); 048 var parentItemAccountingCategoryTransfer = parentItemAccountingCategory == null ? null : getTransfer(userVisit, parentItemAccountingCategory); 049 var inventoryGlAccount = itemAccountingCategoryDetail.getInventoryGlAccount(); 050 var inventoryGlAccountTransfer = inventoryGlAccount == null? null: accountingControl.getGlAccountTransfer(userVisit, inventoryGlAccount); 051 var salesGlAccount = itemAccountingCategoryDetail.getSalesGlAccount(); 052 var salesGlAccountTransfer = salesGlAccount == null? null: accountingControl.getGlAccountTransfer(userVisit, salesGlAccount); 053 var returnsGlAccount = itemAccountingCategoryDetail.getReturnsGlAccount(); 054 var returnsGlAccountTransfer = returnsGlAccount == null? null: accountingControl.getGlAccountTransfer(userVisit, returnsGlAccount); 055 var cogsGlAccount = itemAccountingCategoryDetail.getCogsGlAccount(); 056 var cogsGlAccountTransfer = cogsGlAccount == null? null: accountingControl.getGlAccountTransfer(userVisit, cogsGlAccount); 057 var returnsCogsGlAccount = itemAccountingCategoryDetail.getReturnsCogsGlAccount(); 058 var returnsCogsGlAccountTransfer = returnsCogsGlAccount == null? null: accountingControl.getGlAccountTransfer(userVisit, returnsCogsGlAccount); 059 var isDefault = itemAccountingCategoryDetail.getIsDefault(); 060 var sortOrder = itemAccountingCategoryDetail.getSortOrder(); 061 var description = accountingControl.getBestItemAccountingCategoryDescription(itemAccountingCategory, getLanguage(userVisit)); 062 063 itemAccountingCategoryTransfer = new ItemAccountingCategoryTransfer(itemAccountingCategoryName, 064 parentItemAccountingCategoryTransfer, inventoryGlAccountTransfer, salesGlAccountTransfer, 065 returnsGlAccountTransfer, cogsGlAccountTransfer, returnsCogsGlAccountTransfer, isDefault, sortOrder, 066 description); 067 put(userVisit, itemAccountingCategory, itemAccountingCategoryTransfer); 068 } 069 070 return itemAccountingCategoryTransfer; 071 } 072 073}