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