protected CostBatch addAssocCost(ICost cost)
        {
            CostBatch deltas       = new CostBatch();
            bool      containsItem = assocCostDictionary.ContainsKey(cost.Guid);

            if (containsItem)
            {
                CostSummaryItem item  = assocCostDictionary[cost.Guid];
                CostBatch       delta = item.AddQuantity(1);
                AssocTECCostTotal   += delta.GetCost(CostType.TEC);
                AssocTECLaborTotal  += delta.GetLabor(CostType.TEC);
                AssocElecCostTotal  += delta.GetCost(CostType.Electrical);
                AssocElecLaborTotal += delta.GetLabor(CostType.Electrical);
                deltas += delta;
            }
            else
            {
                CostSummaryItem item = new CostSummaryItem(cost);
                assocCostDictionary.Add(cost.Guid, item);
                if (cost.Type == CostType.TEC)
                {
                    _assocTECItems.Add(item);
                    AssocTECCostTotal  += item.TotalCost;
                    AssocTECLaborTotal += item.TotalLabor;
                }
                else if (cost.Type == CostType.Electrical)
                {
                    _assocElecItems.Add(item);
                    AssocElecCostTotal  += item.TotalCost;
                    AssocElecLaborTotal += item.TotalLabor;
                }
                deltas += new CostBatch(item.TotalCost, item.TotalLabor, cost.Type);
            }
            return(deltas);
        }
Ejemplo n.º 2
0
        public CostBatch ChangeQuantity(TECCost cost, int deltaQuantity)
        {
            bool containsItem = costDictionary.ContainsKey(cost.Guid);

            if (containsItem)
            {
                CostSummaryItem item = costDictionary[cost.Guid];
                if (item.Quantity + deltaQuantity < 0)
                {
                    logger.Error("Cannot remove more quantity than exists in CostSummaryItem. Removing all that exists." +
                                 "Cost: {0}", cost.Name);
                    deltaQuantity = item.Quantity;
                }
                CostBatch delta = item.AddQuantity(deltaQuantity);
                if (cost is TECMisc)
                {
                    if (cost.Type == CostType.TEC)
                    {
                        MiscTECCostTotal  += delta.GetCost(CostType.TEC);
                        MiscTECLaborTotal += delta.GetLabor(CostType.TEC);
                    }
                    else if (cost.Type == CostType.Electrical)
                    {
                        MiscElecCostTotal  += delta.GetCost(CostType.Electrical);
                        MiscElecLaborTotal += delta.GetLabor(CostType.Electrical);
                    }
                }
                else
                {
                    if (cost.Type == CostType.TEC)
                    {
                        AssocTECCostTotal  += delta.GetCost(CostType.TEC);
                        AssocTECLaborTotal += delta.GetLabor(CostType.TEC);
                    }
                    else if (cost.Type == CostType.Electrical)
                    {
                        AssocElecCostTotal  += delta.GetCost(CostType.Electrical);
                        AssocElecLaborTotal += delta.GetLabor(CostType.Electrical);
                    }
                }
                return(delta);
            }
            else
            {
                logger.Error("Cost not found. Cannot change quantity. Cost: {0}", cost.Name);
                return(new CostBatch());
            }
        }
Ejemplo n.º 3
0
        public CostBatch AddCost(ICost cost)
        {
            bool containsItem = costDictionary.ContainsKey(cost.Guid);

            if (containsItem)
            {
                CostSummaryItem item = costDictionary[cost.Guid];
                if (cost is TECMisc misc)
                {
                    CostBatch delta = item.AddQuantity(misc.Quantity);
                    if (cost.Type == CostType.TEC)
                    {
                        MiscTECCostTotal  += delta.GetCost(CostType.TEC);
                        MiscTECLaborTotal += delta.GetLabor(CostType.TEC);
                    }
                    else if (cost.Type == CostType.Electrical)
                    {
                        MiscElecCostTotal  += delta.GetCost(CostType.Electrical);
                        MiscElecLaborTotal += delta.GetLabor(CostType.Electrical);
                    }

                    foreach (TECAssociatedCost extraCost in misc.AssociatedCosts)
                    {
                        for (int i = 0; i < misc.Quantity; i++)
                        {
                            delta += AddCost(extraCost);
                        }
                    }
                    return(delta);
                }
                else
                {
                    CostBatch delta = item.AddQuantity(1);
                    if (cost.Type == CostType.TEC)
                    {
                        AssocTECCostTotal  += delta.GetCost(CostType.TEC);
                        AssocTECLaborTotal += delta.GetLabor(CostType.TEC);
                    }
                    else if (cost.Type == CostType.Electrical)
                    {
                        AssocElecCostTotal  += delta.GetCost(CostType.Electrical);
                        AssocElecLaborTotal += delta.GetLabor(CostType.Electrical);
                    }
                    return(delta);
                }
            }
            else
            {
                CostSummaryItem item  = new CostSummaryItem(cost);
                CostBatch       delta = new CostBatch(item.TotalCost, item.TotalLabor, cost.Type);
                costDictionary.Add(cost.Guid, item);
                if (cost is TECMisc misc)
                {
                    if (cost.Type == CostType.TEC)
                    {
                        _miscTECItems.Add(item);
                        MiscTECCostTotal  += item.TotalCost;
                        MiscTECLaborTotal += item.TotalLabor;
                    }
                    else if (cost.Type == CostType.Electrical)
                    {
                        _miscElecItems.Add(item);
                        MiscElecCostTotal  += item.TotalCost;
                        MiscElecLaborTotal += item.TotalLabor;
                    }
                    foreach (TECAssociatedCost assocCost in misc.AssociatedCosts)
                    {
                        for (int i = 0; i < misc.Quantity; i++)
                        {
                            delta += AddCost(assocCost);
                        }
                    }
                }
                else
                {
                    if (cost.Type == CostType.TEC)
                    {
                        _assocTECItems.Add(item);
                        AssocTECCostTotal  += item.TotalCost;
                        AssocTECLaborTotal += item.TotalLabor;
                    }
                    else if (cost.Type == CostType.Electrical)
                    {
                        _assocElecItems.Add(item);
                        AssocElecCostTotal  += item.TotalCost;
                        AssocElecLaborTotal += item.TotalLabor;
                    }
                }
                return(delta);
            }
        }