001// --------------------------------------------------------------------------------
002// Copyright 2002-2025 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.sales.server.logic;
018
019import com.echothree.model.control.order.common.transfer.OrderTimeTransfer;
020import com.echothree.model.control.order.server.logic.OrderTimeLogic;
021import com.echothree.model.data.order.server.entity.Order;
022import com.echothree.model.data.user.server.entity.UserVisit;
023import com.echothree.util.common.persistence.BasePK;
024import com.echothree.util.server.control.BaseLogic;
025import com.echothree.util.server.message.ExecutionErrorAccumulator;
026import java.util.List;
027import javax.enterprise.context.ApplicationScoped;
028import javax.enterprise.inject.spi.CDI;
029
030@ApplicationScoped
031public class SalesOrderTimeLogic
032        extends BaseLogic {
033
034    protected SalesOrderTimeLogic() {
035        super();
036    }
037
038    public static SalesOrderTimeLogic getInstance() {
039        return CDI.current().select(SalesOrderTimeLogic.class).get();
040    }
041    
042    public void createOrderTime(final ExecutionErrorAccumulator eea, final String orderName, final String orderTimeTypeName, final Long time, final BasePK createdBy) {
043        var order = SalesOrderLogic.getInstance().getOrderByName(eea, orderName);
044        
045        if(eea == null || !eea.hasExecutionErrors()) {
046            createOrderTime(eea, order, orderTimeTypeName, time, createdBy);
047        }
048    }
049
050    public void createOrderTime(final ExecutionErrorAccumulator eea, final Order order, final String orderTimeTypeName, final Long time, final BasePK createdBy) {
051        // TODO: Check Order's status.
052
053        OrderTimeLogic.getInstance().createOrderTime(eea, order, orderTimeTypeName, time, createdBy);
054    }
055
056    public void updateOrderTime(final ExecutionErrorAccumulator eea, final String orderName, final String orderTimeTypeName, final Long time, final BasePK updatedBy) {
057        var order = SalesOrderLogic.getInstance().getOrderByName(eea, orderName);
058        
059        if(eea == null || !eea.hasExecutionErrors()) {
060            updateOrderTime(eea, order, orderTimeTypeName, time, updatedBy);
061        }
062    }
063
064    public void updateOrderTime(final ExecutionErrorAccumulator eea, final Order order, final String orderTimeTypeName, final Long time, final BasePK updatedBy) {
065        // TODO: Check Order's status.
066
067        OrderTimeLogic.getInstance().updateOrderTime(eea, order, orderTimeTypeName, time, updatedBy);
068    }
069
070    public OrderTimeTransfer getOrderTimeTransfer(final ExecutionErrorAccumulator eea, final UserVisit userVisit, final String orderName, final String orderTimeTypeName) {
071        var order = SalesOrderLogic.getInstance().getOrderByName(eea, orderName);
072        OrderTimeTransfer result = null;
073        
074        if(eea == null || !eea.hasExecutionErrors()) {
075            result = getOrderTimeTransfer(eea, userVisit, order, orderTimeTypeName);
076        }
077        
078        return result;
079    }
080
081    public OrderTimeTransfer getOrderTimeTransfer(final ExecutionErrorAccumulator eea, final UserVisit userVisit, final Order order, final String orderTimeTypeName) {
082        return OrderTimeLogic.getInstance().getOrderTimeTransfer(eea, userVisit, order, orderTimeTypeName);
083    }
084
085    public List<OrderTimeTransfer> getOrderTimeTransfersByOrder(final ExecutionErrorAccumulator eea, final UserVisit userVisit, final String orderName) {
086        var order = SalesOrderLogic.getInstance().getOrderByName(eea, orderName);
087        
088        return OrderTimeLogic.getInstance().getOrderTimeTransfersByOrder(eea, userVisit, order);
089    }
090
091    public void deleteOrderTime(final ExecutionErrorAccumulator eea, final String orderName, final String orderTimeTypeName, final BasePK deletedBy) {
092        var order = SalesOrderLogic.getInstance().getOrderByName(eea, orderName);
093        
094        if(eea == null || !eea.hasExecutionErrors()) {
095            deleteOrderTime(eea, order, orderTimeTypeName, deletedBy);
096        }
097    }
098
099    public void deleteOrderTime(final ExecutionErrorAccumulator eea, final Order order, final String orderTimeTypeName, final BasePK deletedBy) {
100        // TODO: Check Order's status.
101
102        OrderTimeLogic.getInstance().deleteOrderTime(eea, order, orderTimeTypeName, deletedBy);
103    }
104
105}