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.inventory.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.control.inventory.common.transfer.InventoryConditionGlAccountTransfer;
023import com.echothree.model.control.inventory.common.transfer.InventoryConditionTransfer;
024import com.echothree.model.control.inventory.server.control.InventoryControl;
025import com.echothree.model.control.item.server.control.ItemControl;
026import com.echothree.model.data.accounting.server.entity.GlAccount;
027import com.echothree.model.data.inventory.server.entity.InventoryConditionGlAccount;
028import com.echothree.model.data.user.server.entity.UserVisit;
029import com.echothree.util.server.persistence.Session;
030
031public class InventoryConditionGlAccountTransferCache
032        extends BaseInventoryTransferCache<InventoryConditionGlAccount, InventoryConditionGlAccountTransfer> {
033    
034    AccountingControl accountingControl = Session.getModelController(AccountingControl.class);
035    ItemControl itemControl = Session.getModelController(ItemControl.class);
036    
037    /** Creates a new instance of InventoryConditionGlAccountTransferCache */
038    public InventoryConditionGlAccountTransferCache(UserVisit userVisit, InventoryControl inventoryControl) {
039        super(userVisit, inventoryControl);
040    }
041    
042    @Override
043    public InventoryConditionGlAccountTransfer getTransfer(InventoryConditionGlAccount inventoryConditionGlAccount) {
044        InventoryConditionGlAccountTransfer inventoryConditionGlAccountTransfer = get(inventoryConditionGlAccount);
045        
046        if(inventoryConditionGlAccountTransfer == null) {
047            InventoryConditionTransfer inventoryConditionTransfer = inventoryControl.getInventoryConditionTransfer(userVisit, inventoryConditionGlAccount.getInventoryCondition());
048            ItemAccountingCategoryTransfer itemAccountingCategoryTransfer = accountingControl.getItemAccountingCategoryTransfer(userVisit, inventoryConditionGlAccount.getItemAccountingCategory());
049            GlAccount inventoryGlAccount = inventoryConditionGlAccount.getInventoryGlAccount();
050            GlAccountTransfer inventoryGlAccountTransfer = inventoryGlAccount == null? null: accountingControl.getGlAccountTransfer(userVisit, inventoryGlAccount);
051            GlAccount salesGlAccount = inventoryConditionGlAccount.getSalesGlAccount();
052            GlAccountTransfer salesGlAccountTransfer = salesGlAccount == null? null: accountingControl.getGlAccountTransfer(userVisit, salesGlAccount);
053            GlAccount returnsGlAccount = inventoryConditionGlAccount.getReturnsGlAccount();
054            GlAccountTransfer returnsGlAccountTransfer = returnsGlAccount == null? null: accountingControl.getGlAccountTransfer(userVisit, returnsGlAccount);
055            GlAccount cogsGlAccount = inventoryConditionGlAccount.getCogsGlAccount();
056            GlAccountTransfer cogsGlAccountTransfer = cogsGlAccount == null? null: accountingControl.getGlAccountTransfer(userVisit, cogsGlAccount);
057            GlAccount returnsCogsGlAccount = inventoryConditionGlAccount.getReturnsCogsGlAccount();
058            GlAccountTransfer returnsCogsGlAccountTransfer = returnsCogsGlAccount == null? null: accountingControl.getGlAccountTransfer(userVisit, returnsCogsGlAccount);
059            
060            inventoryConditionGlAccountTransfer = new InventoryConditionGlAccountTransfer(inventoryConditionTransfer,
061                    itemAccountingCategoryTransfer, inventoryGlAccountTransfer, salesGlAccountTransfer, returnsGlAccountTransfer,
062                    cogsGlAccountTransfer, returnsCogsGlAccountTransfer);
063            put(inventoryConditionGlAccount, inventoryConditionGlAccountTransfer);
064        }
065        
066        return inventoryConditionGlAccountTransfer;
067    }
068    
069}