public void SalesForecastDetails_persistence_test()
        {
            DateTime now = DateTime.Now;

            // Get datetime without milliseconds
            now = new DateTime(now.Ticks - (now.Ticks % TimeSpan.TicksPerSecond), now.Kind);
            var _sale_salesforecast_salesforecastdetails = new DSS1_RetailerDriverStockOptimisation.BO.SalesForecast
            {
                ImportId   = 3530,
                ImportDate = now,
            };

            new PersistenceSpecification <DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails>(Session)
            .CheckProperty(p => p.AvgDailyDemandForecast, 222222.22M)
            .CheckProperty(p => p.ComputedStock, 5189)
            .CheckProperty(p => p.NewOrder, 3268)
            .CheckProperty(p => p.ForecastDate, now)
            .CheckProperty(p => p.Units, 3456)
            .CheckReference(p => p.SalesForecast, _sale_salesforecast_salesforecastdetails)
            .VerifyTheMappings();
        }
Пример #2
0
        public static DSS1_RetailerDriverStockOptimisation.BO.Response ImportImplementation(System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails> salesForecasts)
        {
            string message = "";

            DSS1_RetailerDriverStockOptimisation.BO.SalesForecast sForecast = new DSS1_RetailerDriverStockOptimisation.BO.SalesForecast();
            sForecast.ImportDate = DateTime.UtcNow;
            foreach (var salesForecast in salesForecasts ?? Enumerable.Empty <DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails>())
            {
                zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "API", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, "Warehouse: " + (salesForecast?.Warehouse?.Code ?? ""));
                if ((salesForecast?.Item == null || salesForecast?.Warehouse == null))
                {
                    zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "API", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, "NULL");
                    message = message + (salesForecast?.Id ?? 0) + " ,";
                    continue;
                }
                var _var0 = salesForecast?.Item?.SKU;
                DSS1_RetailerDriverStockOptimisation.BO.Item existingItem = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetAsQueryable <DSS1_RetailerDriverStockOptimisation.BO.Item>((s) => s.SKU == _var0)?.FirstOrDefault();
                var _var1 = salesForecast?.Warehouse?.Code;
                DSS1_RetailerDriverStockOptimisation.BO.Warehouse existingWarehouse = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetAsQueryable <DSS1_RetailerDriverStockOptimisation.BO.Warehouse>((a) => a.Code == _var1)?.FirstOrDefault();
                if ((existingItem == null || existingWarehouse == null))
                {
                    message = message + (salesForecast?.Id ?? 0) + " ,";
                    continue;
                }
                DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails newSalesForecast = new DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails();
                newSalesForecast.Warehouse     = existingWarehouse;
                newSalesForecast.Item          = existingItem;
                newSalesForecast.ForecastDate  = (salesForecast?.ForecastDate ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value);
                newSalesForecast.Units         = (salesForecast?.Units ?? 0);
                newSalesForecast.SalesForecast = sForecast;
                new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Save <DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails>(newSalesForecast);
            }
            new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Save <DSS1_RetailerDriverStockOptimisation.BO.SalesForecast>(sForecast);
            if (((((message == null || message == "")) == false)))
            {
                zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "API", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, "Error message: " + message);
                return(DSS1_RetailerDriverStockOptimisation.BO.ResponseExtensions.GenerateResponse("Failed", "Failed to import the entries with Ids " + message, "", "-1"));
            }
            return(DSS1_RetailerDriverStockOptimisation.BO.ResponseExtensions.GenerateResponse("Succeed", "All entries imported successfully.", "", "1"));
        }
        public void OrderForecast_persistence_test()
        {
            DateTime now = DateTime.Now;

            // Get datetime without milliseconds
            now = new DateTime(now.Ticks - (now.Ticks % TimeSpan.TicksPerSecond), now.Kind);
            var _orderproposal_orderforecastdetails_orderforecast = new DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails
            {
                ReplenishmentCycle        = 8070,
                AutomatedForecast         = 3282,
                Quantity                  = 2222222222.22222M,
                RoundQuantity             = 3538,
                OrderInventoryDays        = 2222222222.22222M,
                RecommendedOrderDate      = now,
                SalesForecastDate         = now,
                SupplierCanDeliver        = true,
                SupplierMaxQuantity       = 2222222222.22222M,
                SupplierCoverageDays      = 3462,
                ItemCoverageDays          = 8750,
                InitialStockLevel         = 1660,
                SupplierAvailableQuantity = 3781,
                SupplierSharesStock       = true,
                CreatedOn                 = now,
                Status = "OrderForecastDetails_Status",
            };
            var _orderproposal_orderforecastdetails_orderforecast2 = new DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails
            {
                ReplenishmentCycle        = 2590,
                AutomatedForecast         = 8073,
                Quantity                  = 2222222222.22222M,
                RoundQuantity             = 7556,
                OrderInventoryDays        = 2222222222.22222M,
                RecommendedOrderDate      = now,
                SalesForecastDate         = now,
                SupplierCanDeliver        = true,
                SupplierMaxQuantity       = 2222222222.22222M,
                SupplierCoverageDays      = 3548,
                ItemCoverageDays          = 9880,
                InitialStockLevel         = 5100,
                SupplierAvailableQuantity = 8731,
                SupplierSharesStock       = true,
                CreatedOn                 = now,
                Status = "OrderForecastDetails_Status",
            };
            var _orderproposal_salesforecast_orderforecasts = new DSS1_RetailerDriverStockOptimisation.BO.SalesForecast
            {
                ImportId   = 7819,
                ImportDate = now,
            };
            var _orderproposal_supplierparameters_orderforecast = new DSS1_RetailerDriverStockOptimisation.BO.SupplierParameter
            {
                CoverageDays = 4599,
                SupplierCanDeliverWholeForecast = true,
                SupplierComments  = "SupplierParameter_SupplierComments",
                HasReplied        = true,
                SharesExcessStock = true,
            };
            var _orderproposal_supplierparameters_orderforecast2 = new DSS1_RetailerDriverStockOptimisation.BO.SupplierParameter
            {
                CoverageDays = 9091,
                SupplierCanDeliverWholeForecast = true,
                SupplierComments  = "SupplierParameter_SupplierComments",
                HasReplied        = true,
                SharesExcessStock = true,
            };
            var _orderproposal_itemparameters_orderforecast = new DSS1_RetailerDriverStockOptimisation.BO.ItemParameter
            {
                CoverageDays       = 7970,
                SupplierCanDeliver = true,
                SupplierQuantity   = 8144,
                SupplierComments   = "ItemParameter_SupplierComments",
            };
            var _orderproposal_itemparameters_orderforecast2 = new DSS1_RetailerDriverStockOptimisation.BO.ItemParameter
            {
                CoverageDays       = 8048,
                SupplierCanDeliver = true,
                SupplierQuantity   = 4874,
                SupplierComments   = "ItemParameter_SupplierComments",
            };

            new PersistenceSpecification <DSS1_RetailerDriverStockOptimisation.BO.OrderForecast>(Session)
            .CheckProperty(p => p.ImportId, 2549)
            .CheckProperty(p => p.Status, "OrderForecast_Status")
            .CheckProperty(p => p.CreatedBy, "OrderForecast_CreatedBy")
            .CheckProperty(p => p.CreatedOn, now)
            .CheckProperty(p => p.StartDate, now)
            .CheckProperty(p => p.EndDate, now)
            .CheckProperty(p => p.State, "OrderForecast_State")
            .CheckBag(p => p.OrderForecastDetails, (new List <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails>
            {
                _orderproposal_orderforecastdetails_orderforecast,
                _orderproposal_orderforecastdetails_orderforecast2
            }))
            .CheckReference(p => p.SalesForecast, _orderproposal_salesforecast_orderforecasts)
            .CheckBag(p => p.SupplierParameters, (new List <DSS1_RetailerDriverStockOptimisation.BO.SupplierParameter>
            {
                _orderproposal_supplierparameters_orderforecast,
                _orderproposal_supplierparameters_orderforecast2
            }))
            .CheckBag(p => p.ItemParameters, (new List <DSS1_RetailerDriverStockOptimisation.BO.ItemParameter>
            {
                _orderproposal_itemparameters_orderforecast,
                _orderproposal_itemparameters_orderforecast2
            }))
            .VerifyTheMappings();
        }
/// <summary>
///     Returns true if self and the provided entity have the same Id values
///     and the Ids are not of the default Id value
/// </summary>
        protected bool HasSameNonDefaultIdAs(SalesForecast compareTo)
        {
            return(!this.IsTransient() && !compareTo.IsTransient() && this.Id.Equals(compareTo.Id));
        }
/// <summary>
/// Copies the current object to a new instance
/// </summary>
/// <param name="deep">Copy members that refer to objects external to this class (not dependent)</param>
/// <param name="copiedObjects">Objects that should be reused</param>
/// <param name="asNew">Copy the current object as a new one, ready to be persisted, along all its members.</param>
/// <param name="reuseNestedObjects">If asNew is true, this flag if set, forces the reuse of all external objects.</param>
/// <param name="copy">Optional - An existing [SalesForecast] instance to use as the destination.</param>
/// <returns>A copy of the object</returns>
        public virtual SalesForecast Copy(bool deep = false, Hashtable copiedObjects = null, bool asNew = false, bool reuseNestedObjects = false, SalesForecast copy = null)
        {
            if (copiedObjects == null)
            {
                copiedObjects = new Hashtable();
            }
            if (copy == null && copiedObjects.Contains(this))
            {
                return((SalesForecast)copiedObjects[this]);
            }
            copy = copy ?? new SalesForecast();
            if (!asNew)
            {
                copy.TransientId = this.TransientId;
                copy.Id          = this.Id;
            }
            copy.ImportId   = this.ImportId;
            copy.ImportDate = this.ImportDate;
            if (!copiedObjects.Contains(this))
            {
                copiedObjects.Add(this, copy);
            }
            copy.orderForecasts = new List <OrderForecast>();
            if (deep && this.orderForecasts != null)
            {
                foreach (var __item in this.orderForecasts)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddOrderForecasts(__item);
                        }
                        else
                        {
                            copy.AddOrderForecasts(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddOrderForecasts((OrderForecast)copiedObjects[__item]);
                    }
                }
            }
            copy.salesForecastDetails = new List <SalesForecastDetails>();
            if (deep && this.salesForecastDetails != null)
            {
                foreach (var __item in this.salesForecastDetails)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddSalesForecastDetails(__item);
                        }
                        else
                        {
                            copy.AddSalesForecastDetails(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddSalesForecastDetails((SalesForecastDetails)copiedObjects[__item]);
                    }
                }
            }
            return(copy);
        }