Esempio n. 1
0
 public static System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.SLAStatistics> ItemLeadTimePercentage(string sku)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("SLALeadTime", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "ItemLeadTimePercentage")) {
         DSS1_RetailerDriverStockOptimisation.BO.Item item = new DSS1_RetailerDriverStockOptimisation.BO.Item();
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.SLAStatistics> stats = new System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.SLAStatistics>();
         if ((sku == null || sku == ""))
         {
             return(stats);
         }
         else
         {
             try {
                 item = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetById <DSS1_RetailerDriverStockOptimisation.BO.Item>(sku);
             }
             catch (System.Exception x) {
             }
         }
         foreach (var leadTime in item?.SLALeadTimes ?? Enumerable.Empty <DSS1_RetailerDriverStockOptimisation.BO.SLALeadTime>())
         {
             DSS1_RetailerDriverStockOptimisation.BO.SLAStatistics stat = new DSS1_RetailerDriverStockOptimisation.BO.SLAStatistics();
             stat.Item = item; stat.Percentage = (leadTime?.MonthlyPercentage ?? 0); stat.Month = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName((leadTime?.Month ?? 0)); stat.Threshold = 80; stats?.Add(stat);
         }
         return(stats);
     }
 }
 public static System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.InventoryDaysKPI> InventoryDaysKPI(string sku, int?warehouseId, DateTime?fromDate, DateTime?toDate)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("InventoryDaysKPI", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "InventoryDaysKPI")) {
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.InventoryDaysKPI> kpis = new System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.InventoryDaysKPI>();
         DSS1_RetailerDriverStockOptimisation.BO.Item item = new DSS1_RetailerDriverStockOptimisation.BO.Item();
         try {
             item = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetById <DSS1_RetailerDriverStockOptimisation.BO.Item>(sku);
         }
         catch (System.Exception x) {
         }
         if ((item == null))
         {
             return(kpis);
         }
         DSS1_RetailerDriverStockOptimisation.BO.Warehouse            warehouse = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetAsQueryable <DSS1_RetailerDriverStockOptimisation.BO.Warehouse>((a) => a.Id == warehouseId)?.FirstOrDefault();
         DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails sale      = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetAsQueryable <DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails>((s) => s.Item.SKU == item.SKU && s.Warehouse.Id == warehouse.Id)?.FirstOrDefault();
         decimal?inventoryDays = 0;
         var     _var4 = (fromDate?.Date ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); var _var5 = (toDate?.Date ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); foreach (var stock in item?.StocksOnHand?.Where((s) => s.StockOnHandDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date >= _var4 && s.StockOnHandDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date <= _var5 && s.Warehouse == warehouse).ToList() ?? Enumerable.Empty <DSS1_RetailerDriverStockOptimisation.BO.StockOnHand>())
         {
             DSS1_RetailerDriverStockOptimisation.BO.InventoryDaysKPI kpi = new DSS1_RetailerDriverStockOptimisation.BO.InventoryDaysKPI();
             kpi.SalesForecastDate = (stock?.StockOnHandDate ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); kpi.SalesForecastDateFormatted = (stock?.StockOnHandDate?.ToString("yyyy/MM/dd") ?? ""); if (sale == null)
             {
                 kpi.InventoryDays = 0;
             }
             else
             {
                 kpi.InventoryDays = (stock?.Units ?? 0) / (sale?.AvgDailyDemandForecast ?? 0);
             }
             kpi.ItemDescription = (item?.Description?.Substring(0, 15) ?? ""); kpis?.Add(kpi);
         }
         kpis = kpis?.OrderBy((a) => a.SalesForecastDate).ToList().ToList(); zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "InventoryDaysKPI", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, "stats length: " + (kpis?.Count() ?? 0));
         return(kpis);
     }
 }
 public static System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.Category> calcCompaniesOfBusinessUnit(int?businessUnit)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("Category", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "calcCompaniesOfBusinessUnit")) {
         DSS1_RetailerDriverStockOptimisation.BO.BusinessUnit unit = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetById <DSS1_RetailerDriverStockOptimisation.BO.BusinessUnit>(businessUnit);
         return(unit?.Categories);
     }
 }
 public static System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.Stats> ItemWaste(string sku)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("Stats", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "ItemWaste")) {
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.Stats> stats = new System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.Stats>();
         decimal?result = new decimal?();
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.Item> items = new System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.Item>();
         DSS1_RetailerDriverStockOptimisation.BO.Item foundItem = new DSS1_RetailerDriverStockOptimisation.BO.Item();
         if ((sku == null || sku == ""))
         {
         }
         else
         {
             try {
                 foundItem = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetById <DSS1_RetailerDriverStockOptimisation.BO.Item>(sku);
             }
             catch (System.Exception x) {
             }
             if (foundItem != null)
             {
             }
         }
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.WasteOld> wastes = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Get <DSS1_RetailerDriverStockOptimisation.BO.WasteOld>((a) => a.Item.SKU == foundItem.SKU);
         foreach (var waste in wastes ?? Enumerable.Empty <DSS1_RetailerDriverStockOptimisation.BO.WasteOld>())
         {
             DSS1_RetailerDriverStockOptimisation.BO.Stats stat = new DSS1_RetailerDriverStockOptimisation.BO.Stats();
             stat.Item = foundItem; stat.Percentage = (waste?.WastePercentage ?? 0); stat.DateFormatted = (waste?.DateFormatted ?? ""); stats?.Add(stat);
         }
         stats = stats?.OrderBy((a) => a.Date).ToList().ToList(); return(stats);
     }
 }
 public static System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.Stats> itemSLALeadTime(string sku)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("Stats", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "itemSLALeadTime")) {
         decimal?result = new decimal?();
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.Stats> stats = new System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.Stats>();
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.Item>  items = new System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.Item>();
         DSS1_RetailerDriverStockOptimisation.BO.Item foundItem = new DSS1_RetailerDriverStockOptimisation.BO.Item();
         if ((sku == null || sku == ""))
         {
         }
         else
         {
             try {
                 foundItem = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetById <DSS1_RetailerDriverStockOptimisation.BO.Item>(sku);
             }
             catch (System.Exception x) {
             }
             if (foundItem != null)
             {
             }
         }
         foreach (var slaLead in foundItem?.SLALeadTimes?.Take(10).ToList() ?? Enumerable.Empty <DSS1_RetailerDriverStockOptimisation.BO.SLALeadTime>())
         {
             DSS1_RetailerDriverStockOptimisation.BO.Stats stat = new DSS1_RetailerDriverStockOptimisation.BO.Stats();
             stat.Item = foundItem; stat.Percentage = (slaLead?.Percentage ?? 0); stat.DateFormatted = (slaLead?.SLALeadDate?.ToString("MMMM dd, yyyy") ?? ""); stat.Threshold = (slaLead?.Threshold ?? 0); stat.Date = (slaLead?.SLALeadDate ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); stats?.Add(stat);
         }
         stats = stats?.OrderBy((a) => a.Date).ToList().ToList(); return(stats);
     }
 }
 public static void CreateAppNotification(string itemSKU, int?delta, string recipientUsername, DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails ofDetail)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("AppNotification", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "CreateAppNotification")) {
         DSS1_RetailerDriverStockOptimisation.BO.Contact recipient = new DSS1_RetailerDriverStockOptimisation.BO.Contact();
         try {
             recipient = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetById <DSS1_RetailerDriverStockOptimisation.BO.Contact>(recipientUsername);
         }
         catch (System.Exception x) {
             zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Error, "AppNotification", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, x);
             return;
         }
         DSS1_RetailerDriverStockOptimisation.BO.AppNotification appNotification = new DSS1_RetailerDriverStockOptimisation.BO.AppNotification();
         appNotification.Recipient = recipient; appNotification.Item = itemSKU; appNotification.Delta = delta; appNotification.IsRead = false; appNotification.DateCreated = DateTime.UtcNow; DSS1_RetailerDriverStockOptimisation.BO.AppNotificationAction appNotificationAction = new DSS1_RetailerDriverStockOptimisation.BO.AppNotificationAction();
         appNotification?.AddAppNotificationActions(appNotificationAction);
         new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Save <DSS1_RetailerDriverStockOptimisation.BO.AppNotification>(appNotification);
         DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseAppNotificationCreated();
     }
 }
 public static System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.UnitsKPI> UnitsKPI(string sku, int?warehouseId, DateTime?fromDate, DateTime?toDate)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("UnitsKPI", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "UnitsKPI")) {
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.UnitsKPI> kpis = new System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.UnitsKPI>();
         DSS1_RetailerDriverStockOptimisation.BO.Item item = new DSS1_RetailerDriverStockOptimisation.BO.Item();
         try {
             item = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetById <DSS1_RetailerDriverStockOptimisation.BO.Item>(sku);
         }
         catch (System.Exception x) {
         }
         if ((item == null))
         {
             return(kpis);
         }
         DSS1_RetailerDriverStockOptimisation.BO.Warehouse warehouse = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetAsQueryable <DSS1_RetailerDriverStockOptimisation.BO.Warehouse>((a) => a.Id == warehouseId)?.FirstOrDefault();
         var _var2 = (fromDate?.Date ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); var _var3 = (toDate?.Date ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); foreach (var stock in item?.StocksOnHand?.Where((s) => s.Warehouse == warehouse && s.StockOnHandDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date >= _var2 && s.StockOnHandDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date <= _var3).ToList() ?? Enumerable.Empty <DSS1_RetailerDriverStockOptimisation.BO.StockOnHand>())
         {
             DSS1_RetailerDriverStockOptimisation.BO.UnitsKPI kpi = new DSS1_RetailerDriverStockOptimisation.BO.UnitsKPI();
             kpi.SalesForecastDate = (stock?.StockOnHandDate ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); kpi.SalesForecastDateFormatted = (stock?.StockOnHandDate?.ToString("yyyy/MM/dd") ?? ""); kpi.Units = (stock?.Units ?? 0); kpis?.Add(kpi);
         }
         kpis = kpis?.OrderBy((a) => a.SalesForecastDate).ToList().ToList(); return(kpis);
     }
 }
 public static int?GetUnitsOfStock(DSS1_RetailerDriverStockOptimisation.BO.StockOnHand stock)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("Item", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "GetUnitsOfStock")) {
         var _var1 = (stock?.StockOnHandDate?.Date ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); DSS1_RetailerDriverStockOptimisation.BO.StockOnHand lastStock = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetAsQueryable <DSS1_RetailerDriverStockOptimisation.BO.StockOnHand>((a) => a.StockOnHandDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date < _var1)?.OrderByDescending((b) => b.StockOnHandDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date).FirstOrDefault();
         if ((lastStock == null))
         {
             return(0);
         }
         int?LastPastStock = (lastStock?.Units ?? 0);
         var _var2 = stock?.StockOnHandDate?.Date; var _var3 = stock?.Warehouse?.Id; var _var4 = stock?.Item?.SKU; DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails salesforecast = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetAsQueryable <DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails>((s) => s.ForecastDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date == _var2 && _var3 == s.Warehouse.Id && s.Item.SKU == _var4)?.FirstOrDefault();
         if ((salesforecast == null))
         {
             return(0);
         }
         int?salesForecastUnits = (salesforecast?.Units ?? 0);
         return(LastPastStock.GetValueOrDefault(0) - salesForecastUnits.GetValueOrDefault(0));
     }
 }
 public static System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.UnitsKPI> UnitsKPIWithCriteria(System.Collections.Generic.List <int?> supplierIds, System.Collections.Generic.List <int?> warehouseIds, System.Collections.Generic.List <int?> businessUnitIds, System.Collections.Generic.List <int?> categoryIds, System.Collections.Generic.List <int?> subCategoryIds, System.Collections.Generic.List <int?> baseUnitIds, System.Collections.Generic.List <string> SKUs, DateTime?fromDate, DateTime?toDate)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("UnitsKPI", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "UnitsKPIWithCriteria")) {
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.UnitsKPI> kpis = new System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.UnitsKPI>();
         System.Collections.Generic.List <int?>   emptyIDs  = new System.Collections.Generic.List <int?>();
         System.Collections.Generic.List <string> emptySKUs = new System.Collections.Generic.List <string>();
         if ((warehouseIds == null))
         {
             warehouseIds = emptyIDs.ToList();
         }
         if ((SKUs == null))
         {
             SKUs = emptySKUs.ToList();
         }
         if ((businessUnitIds == null))
         {
             businessUnitIds = emptyIDs.ToList();
         }
         if ((categoryIds == null))
         {
             categoryIds = emptyIDs.ToList();
         }
         if ((subCategoryIds == null))
         {
             subCategoryIds = emptyIDs.ToList();
         }
         if ((baseUnitIds == null))
         {
             baseUnitIds = emptyIDs.ToList();
         }
         if ((supplierIds == null))
         {
             supplierIds = emptyIDs.ToList();
         }
         var _var0 = (fromDate?.Date ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); var _var1 = (toDate?.Date ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.StockOnHand> filteredStockOnHand = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Get <DSS1_RetailerDriverStockOptimisation.BO.StockOnHand>((a) => (SKUs.Count() == 0 || SKUs.Contains(a.Item.SKU)) && (businessUnitIds.Count() == 0 || businessUnitIds.Contains((a.Item.BusinessUnit.Id).GetValueOrDefault(0))) && (categoryIds.Count() == 0 || categoryIds.Contains((a.Item.Category.Id).GetValueOrDefault(0))) && (subCategoryIds.Count() == 0 || subCategoryIds.Contains((a.Item.SubCategory.Id).GetValueOrDefault(0))) && (baseUnitIds.Count() == 0 || baseUnitIds.Contains((a.Item.BaseUnit.Id).GetValueOrDefault(0))) && (supplierIds.Count() == 0 || supplierIds.Contains((a.Item.Supplier.Id).GetValueOrDefault(0))) && (warehouseIds.Count() == 0 || warehouseIds.Contains((a.Warehouse.Id).GetValueOrDefault(0))) && (fromDate == null || a.StockOnHandDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date >= _var0) && (toDate == null || a.StockOnHandDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date <= _var1));
         System.Collections.Generic.List <DateTime?> uniqueDates = filteredStockOnHand?.Select((a) => a.StockOnHandDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date).Select(_n => _n as DateTime?).ToList().Distinct().ToList().OrderBy((a) => a).ToList();
         foreach (var dt in uniqueDates ?? Enumerable.Empty <DateTime?>())
         {
             DSS1_RetailerDriverStockOptimisation.BO.UnitsKPI kpi = new DSS1_RetailerDriverStockOptimisation.BO.UnitsKPI();
             kpi.SalesForecastDate = dt; kpi.SalesForecastDateFormatted = (dt?.ToString("dd/MM") ?? ""); int?totalStockForDay = (filteredStockOnHand?.Where((a) => a.StockOnHandDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date == dt).Sum((a) => a.Units) ?? 0);
             kpi.Units             = totalStockForDay; kpis?.Add(kpi);
         }
         return(kpis);
     }
 }
Esempio n. 10
0
 public static System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastStatistic> OrderForecastForSKU(DSS1_RetailerDriverStockOptimisation.BO.Item item)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("OrderForecastStatistic", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "OrderForecastForSKU")) {
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastStatistic> orderStats     = new System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastStatistic>();
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails>   orderProposals = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Get <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails>((a) => a.Item.SKU == item.SKU);
         if ((orderProposals?.Count() ?? 0) >= 10)
         {
         }
         foreach (var orderProposal in orderProposals ?? Enumerable.Empty <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails>())
         {
             DSS1_RetailerDriverStockOptimisation.BO.OrderForecastStatistic stat = new DSS1_RetailerDriverStockOptimisation.BO.OrderForecastStatistic();
             stat.Quantity = (orderProposal?.Quantity ?? 0); stat.RoundQuantity = (orderProposal?.RoundQuantity ?? 0); stat.OrderDate = (orderProposal?.RecommendedOrderDate ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); stat.OrderDateFormatted = (orderProposal?.RecommendedOrderDate?.ToString("MMMM dd, yyyy") ?? ""); stat.Item = item; stat.Warehouse = orderProposal?.Warehouse; orderStats?.Add(stat);
         }
         return(orderStats);
     }
 }
Esempio n. 11
0
 public static System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastStatistic> ShowOrderForecastStats()
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("OrderForecastStatistic", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "ShowOrderForecastStats")) {
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastStatistic> orderFStatistics = new System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastStatistic>();
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails>   orderProposals   = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetAsQueryable <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails>()?.Take(10).ToList();
         foreach (var orderProposal in orderProposals ?? Enumerable.Empty <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails>())
         {
             zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "OrderForecastStatistic", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, "------ " + (orderProposal?.Id?.ToString() ?? ""), true);
             DSS1_RetailerDriverStockOptimisation.BO.OrderForecastStatistic orderFStat = new DSS1_RetailerDriverStockOptimisation.BO.OrderForecastStatistic();
             orderFStat.Quantity = (orderProposal?.Quantity ?? 0); orderFStat.RoundQuantity = (orderProposal?.RoundQuantity ?? 0); orderFStat.OrderDate = (orderProposal?.RecommendedOrderDate?.Date ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); orderFStat.OrderDateFormatted = (orderProposal?.RecommendedOrderDate?.ToString("MMMM dd, yyyy") ?? ""); orderFStat.Item = orderProposal?.Item; orderFStat.Warehouse = orderProposal?.Warehouse; orderFStatistics?.Add(orderFStat);
         }
         return(orderFStatistics);
     }
 }
 public static void ComputeAllAvgDailyDemandForecastPerSKUPerWareHouse()
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("SalesForecastDetails", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "ComputeAllAvgDailyDemandForecastPerSKUPerWareHouse")) {
         foreach (var warehouse in new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetAll <DSS1_RetailerDriverStockOptimisation.BO.Warehouse>() ?? Enumerable.Empty <DSS1_RetailerDriverStockOptimisation.BO.Warehouse>())
         {
             foreach (var item in new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetAll <DSS1_RetailerDriverStockOptimisation.BO.Item>() ?? Enumerable.Empty <DSS1_RetailerDriverStockOptimisation.BO.Item>())
             {
                 System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails> salesfor = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Get <DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails>((a) => a.Item.SKU == item.SKU && a.Warehouse.Id == warehouse.Id);
                 if ((salesfor?.Count() == 0))
                 {
                     continue;
                 }
                 decimal?avgDemand = (salesfor?.Sum((a) => a.Units) ?? 0) / (salesfor?.Count() ?? 0);
                 foreach (var saleforecast in salesfor ?? Enumerable.Empty <DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails>())
                 {
                     saleforecast.AvgDailyDemandForecast = avgDemand; new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Save <DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails>(saleforecast);
                 }
             }
         }
     }
 }
 public static System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.InventoryDaysKPI> InventoryDaysKPIWithCriteria(System.Collections.Generic.List <int?> supplierIds, System.Collections.Generic.List <int?> warehouseIds, System.Collections.Generic.List <int?> businessUnitIds, System.Collections.Generic.List <int?> categoryIds, System.Collections.Generic.List <int?> subCategoryIds, System.Collections.Generic.List <int?> baseUnitIds, System.Collections.Generic.List <string> SKUs, DateTime?fromDate, DateTime?toDate)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("InventoryDaysKPI", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "InventoryDaysKPIWithCriteria")) {
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.InventoryDaysKPI> kpis = new System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.InventoryDaysKPI>();
         System.Collections.Generic.List <int?>   emptyIDs  = new System.Collections.Generic.List <int?>();
         System.Collections.Generic.List <string> emptySKUs = new System.Collections.Generic.List <string>();
         if ((warehouseIds == null))
         {
             warehouseIds = emptyIDs.ToList();
         }
         if ((SKUs == null))
         {
             SKUs = emptySKUs.ToList();
         }
         if ((businessUnitIds == null))
         {
             businessUnitIds = emptyIDs.ToList();
         }
         if ((categoryIds == null))
         {
             categoryIds = emptyIDs.ToList();
         }
         if ((subCategoryIds == null))
         {
             subCategoryIds = emptyIDs.ToList();
         }
         if ((baseUnitIds == null))
         {
             baseUnitIds = emptyIDs.ToList();
         }
         if ((supplierIds == null))
         {
             supplierIds = emptyIDs.ToList();
         }
         var _var0 = (fromDate?.Date ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); var _var1 = (toDate?.Date ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.StockOnHand> filteredStockOnHand = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Get <DSS1_RetailerDriverStockOptimisation.BO.StockOnHand>((a) => (SKUs.Count() == 0 || SKUs.Contains(a.Item.SKU)) && (businessUnitIds.Count() == 0 || businessUnitIds.Contains((a.Item.BusinessUnit.Id).GetValueOrDefault(0))) && (categoryIds.Count() == 0 || categoryIds.Contains((a.Item.Category.Id).GetValueOrDefault(0))) && (subCategoryIds.Count() == 0 || subCategoryIds.Contains((a.Item.SubCategory.Id).GetValueOrDefault(0))) && (baseUnitIds.Count() == 0 || baseUnitIds.Contains((a.Item.BaseUnit.Id).GetValueOrDefault(0))) && (supplierIds.Count() == 0 || supplierIds.Contains((a.Item.Supplier.Id).GetValueOrDefault(0))) && (warehouseIds.Count() == 0 || warehouseIds.Contains((a.Warehouse.Id).GetValueOrDefault(0))) && (fromDate == null || a.StockOnHandDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date >= _var0) && (toDate == null || a.StockOnHandDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date <= _var1));
         var _var2 = (fromDate?.Date ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); var _var3 = (toDate?.Date.AddDays(30) ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails> filteredSales = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Get <DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails>((a) => (SKUs.Count() == 0 || SKUs.Contains(a.Item.SKU)) && (businessUnitIds.Count() == 0 || businessUnitIds.Contains((a.Item.BusinessUnit.Id).GetValueOrDefault(0))) && (categoryIds.Count() == 0 || categoryIds.Contains((a.Item.Category.Id).GetValueOrDefault(0))) && (subCategoryIds.Count() == 0 || subCategoryIds.Contains((a.Item.SubCategory.Id).GetValueOrDefault(0))) && (baseUnitIds.Count() == 0 || baseUnitIds.Contains((a.Item.BaseUnit.Id).GetValueOrDefault(0))) && (supplierIds.Count() == 0 || supplierIds.Contains((a.Item.Supplier.Id).GetValueOrDefault(0))) && (warehouseIds.Count() == 0 || warehouseIds.Contains((a.Warehouse.Id).GetValueOrDefault(0))) && (fromDate == null || a.ForecastDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date >= _var2) && (toDate == null || a.ForecastDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date <= _var3));
         System.Collections.Generic.List <DateTime?> uniqueDates = filteredStockOnHand?.Select((a) => a.StockOnHandDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date).Select(_n => _n as DateTime?).ToList().Distinct().ToList().OrderBy((a) => a).ToList();
         System.Collections.Generic.List <string>    uniqueItemSKUs = filteredStockOnHand?.Select((a) => a.Item.SKU).ToList().Distinct().ToList();
         zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "InventoryDaysKPI", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, "uniqueItemSKUs: " + uniqueItemSKUs.Count());
         foreach (var dt in uniqueDates ?? Enumerable.Empty <DateTime?>())
         {
             DSS1_RetailerDriverStockOptimisation.BO.InventoryDaysKPI kpi = new DSS1_RetailerDriverStockOptimisation.BO.InventoryDaysKPI();
             kpi.SalesForecastDate = dt; kpi.SalesForecastDateFormatted = (dt?.ToString("dd/MM") ?? ""); int?totalStockForDay = (filteredStockOnHand?.Where((a) => a.StockOnHandDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date == dt).Sum((a) => a.Units) ?? 0);
             System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails>  salesAfterToday = filteredSales?.Where((a) => a.ForecastDate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date >= dt).ToList();
             int?runningTotalSales = 0;
             int?inventoryDays     = 0;
             foreach (var sale in salesAfterToday ?? Enumerable.Empty <DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails>())
             {
                 runningTotalSales = runningTotalSales.GetValueOrDefault(0) + (sale?.Units ?? 0); if ((runningTotalSales > totalStockForDay))
                 {
                     break;
                 }
                 inventoryDays = inventoryDays.GetValueOrDefault(0) + 1;
             }
             kpi.InventoryDays = inventoryDays; if ((uniqueItemSKUs.Count() > 1))
             {
                 int?calcInvDays = (int)((inventoryDays.GetValueOrDefault(0) / uniqueItemSKUs.Count()));
                 if ((calcInvDays == 0))
                 {
                     calcInvDays = 1;
                 }
                 kpi.InventoryDays = calcInvDays;
             }
             kpis?.Add(kpi);
         }
         return(kpis);
     }
 }
Esempio n. 14
0
 public static System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.SLAStatistics> CalculateOrderForecastAccuracy(System.Collections.Generic.List <int?> supplierIds, System.Collections.Generic.List <int?> warehouseIds, System.Collections.Generic.List <int?> businessUnitIds, System.Collections.Generic.List <int?> categoryIds, System.Collections.Generic.List <int?> subCategoryIds, System.Collections.Generic.List <int?> baseUnitIds, System.Collections.Generic.List <string> SKUs, DateTime?fromDate, DateTime?toDate)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("Platform", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "CalculateOrderForecastAccuracy")) {
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.SLAStatistics> stats = new System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.SLAStatistics>();
         System.Collections.Generic.List <int?>   emptyIDs  = new System.Collections.Generic.List <int?>();
         System.Collections.Generic.List <string> emptySKUs = new System.Collections.Generic.List <string>();
         if ((warehouseIds == null))
         {
             warehouseIds = emptyIDs.ToList();
         }
         if ((SKUs == null))
         {
             SKUs = emptySKUs.ToList();
         }
         if ((businessUnitIds == null))
         {
             businessUnitIds = emptyIDs.ToList();
         }
         if ((categoryIds == null))
         {
             categoryIds = emptyIDs.ToList();
         }
         if ((subCategoryIds == null))
         {
             subCategoryIds = emptyIDs.ToList();
         }
         if ((baseUnitIds == null))
         {
             baseUnitIds = emptyIDs.ToList();
         }
         if ((supplierIds == null))
         {
             supplierIds = emptyIDs.ToList();
         }
         var _var0 = (fromDate?.Month ?? 0); var _var1 = (toDate?.Month ?? 0); System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.Platform> filteredPlatforms = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Get <DSS1_RetailerDriverStockOptimisation.BO.Platform>((a) => (SKUs.Count() == 0 || SKUs.Contains(a.Item.SKU)) && (businessUnitIds.Count() == 0 || businessUnitIds.Contains((a.Item.BusinessUnit.Id).GetValueOrDefault(0))) && (categoryIds.Count() == 0 || categoryIds.Contains((a.Item.Category.Id).GetValueOrDefault(0))) && (subCategoryIds.Count() == 0 || subCategoryIds.Contains((a.Item.SubCategory.Id).GetValueOrDefault(0))) && (baseUnitIds.Count() == 0 || baseUnitIds.Contains((a.Item.BaseUnit.Id).GetValueOrDefault(0))) && (supplierIds.Count() == 0 || supplierIds.Contains((a.Item.Supplier.Id).GetValueOrDefault(0))) && (warehouseIds.Count() == 0 || warehouseIds.Contains((a.Warehouse.Id).GetValueOrDefault(0))) && (fromDate == null || int.Parse(a.Month) >= _var0) && (toDate == null || int.Parse(a.Month) <= _var1));
         System.Collections.Generic.List <int?> uniqueMonths = filteredPlatforms?.Select((a) => int.Parse(a.Month)).Select(_n => _n as int?).ToList().Distinct().ToList().OrderBy((a) => a).ToList();
         foreach (var i in uniqueMonths ?? Enumerable.Empty <int?>())
         {
             System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.Platform> thisMonthsPlatforms = filteredPlatforms?.Where((a) => int.Parse(a.Month) == i).ToList();
             if ((thisMonthsPlatforms?.Count() == 0))
             {
                 continue;
             }
             DSS1_RetailerDriverStockOptimisation.BO.SLAStatistics stat = new DSS1_RetailerDriverStockOptimisation.BO.SLAStatistics();
             stat.Percentage = (thisMonthsPlatforms?.Sum((a) => a.percentage) ?? 0) / (thisMonthsPlatforms?.Count() ?? 0); stat.Percentage = Math.Round((stat?.Percentage ?? 0), 2) / 100; stat.Month = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName((i).GetValueOrDefault(0)); stat.Threshold = 80; stats?.Add(stat);
         }
         return(stats);
     }
 }
 public static void CalculateCurrentInventoryDays()
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("StockOnHand", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "CalculateCurrentInventoryDays")) {
         foreach (var stock in new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetAll <DSS1_RetailerDriverStockOptimisation.BO.StockOnHand>() ?? Enumerable.Empty <DSS1_RetailerDriverStockOptimisation.BO.StockOnHand>())
         {
             var _var0 = stock?.Item?.SKU; var _var1 = stock?.Warehouse?.Id; DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails salesfor = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetAsQueryable <DSS1_RetailerDriverStockOptimisation.BO.SalesForecastDetails>((a) => a.Item.SKU == _var0 && a.Warehouse.Id == _var1)?.FirstOrDefault();
             if ((salesfor == null || salesfor?.AvgDailyDemandForecast == 0))
             {
                 stock.CurrentInventoryDays = 0; new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Save <DSS1_RetailerDriverStockOptimisation.BO.StockOnHand>(stock);
                 continue;
             }
             zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "StockOnHand", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, "salesfor.AvgDailyDemandForecast : " + (salesfor?.AvgDailyDemandForecast ?? 0) + " ::: " + (stock?.Units ?? 0));
             zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "StockOnHand", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, "(stock.Units / salesfor.AvgDailyDemandForecast) : " + ((stock?.Units ?? 0) / (salesfor?.AvgDailyDemandForecast ?? 0)));
             stock.CurrentInventoryDays = zAppDev.DotNet.Framework.Utilities.Common.SafeCast <decimal?>(((stock?.Units ?? 0) / (salesfor?.AvgDailyDemandForecast ?? 0))); new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Save <DSS1_RetailerDriverStockOptimisation.BO.StockOnHand>(stock);
         }
     }
 }
 public static System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.SLAStatistics> ItemDeliveryPercentageWithCriteria(System.Collections.Generic.List <int?> supplierIds, System.Collections.Generic.List <int?> warehouseIds, System.Collections.Generic.List <int?> businessUnitIds, System.Collections.Generic.List <int?> categoryIds, System.Collections.Generic.List <int?> subCategoryIds, System.Collections.Generic.List <int?> baseUnitIds, System.Collections.Generic.List <string> SKUs, DateTime?fromDate, DateTime?toDate)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("SLADelivery", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "ItemDeliveryPercentageWithCriteria")) {
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.SLAStatistics> stats = new System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.SLAStatistics>();
         System.Collections.Generic.List <int?>   emptyIDs  = new System.Collections.Generic.List <int?>();
         System.Collections.Generic.List <string> emptySKUs = new System.Collections.Generic.List <string>();
         if ((warehouseIds == null))
         {
             warehouseIds = emptyIDs.ToList();
         }
         if ((SKUs == null))
         {
             SKUs = emptySKUs.ToList();
         }
         if ((businessUnitIds == null))
         {
             businessUnitIds = emptyIDs.ToList();
         }
         if ((categoryIds == null))
         {
             categoryIds = emptyIDs.ToList();
         }
         if ((subCategoryIds == null))
         {
             subCategoryIds = emptyIDs.ToList();
         }
         if ((baseUnitIds == null))
         {
             baseUnitIds = emptyIDs.ToList();
         }
         if ((supplierIds == null))
         {
             supplierIds = emptyIDs.ToList();
         }
         var _var0 = (fromDate?.Month ?? 0); var _var1 = (toDate?.Month ?? 0); System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.SLADelivery> filteredDeliveries = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Get <DSS1_RetailerDriverStockOptimisation.BO.SLADelivery>((a) => (SKUs.Count() == 0 || SKUs.Contains(a.Item.SKU)) && (businessUnitIds.Count() == 0 || businessUnitIds.Contains((a.Item.BusinessUnit.Id).GetValueOrDefault(0))) && (categoryIds.Count() == 0 || categoryIds.Contains((a.Item.Category.Id).GetValueOrDefault(0))) && (subCategoryIds.Count() == 0 || subCategoryIds.Contains((a.Item.SubCategory.Id).GetValueOrDefault(0))) && (baseUnitIds.Count() == 0 || baseUnitIds.Contains((a.Item.BaseUnit.Id).GetValueOrDefault(0))) && (supplierIds.Count() == 0 || supplierIds.Contains((a.Item.Supplier.Id).GetValueOrDefault(0))) && (warehouseIds.Count() == 0 || warehouseIds.Contains((a.Warehouse.Id).GetValueOrDefault(0))) && (fromDate == null || a.Month >= _var0) && (toDate == null || a.Month <= _var1));
         System.Collections.Generic.List <int?> uniqueMonths = filteredDeliveries?.Select((a) => a.Month).ToList().Distinct().ToList().OrderBy((a) => a).ToList();
         if (SKUs.Contains("4047706") && SKUs.Count() == 1)
         {
             zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "SLADelivery", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, "Months: " + uniqueMonths.Count());
         }
         foreach (var i in uniqueMonths ?? Enumerable.Empty <int?>())
         {
             System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.SLADelivery> thisMonthsDeliveries = filteredDeliveries?.Where((a) => a.Month == i).ToList();
             if ((thisMonthsDeliveries?.Count() == 0))
             {
                 continue;
             }
             if (SKUs.Contains("4047706") && SKUs.Count() == 1)
             {
                 zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "SLADelivery", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, "thisMonthsDeliveries: " + (thisMonthsDeliveries?.Count() ?? 0));
             }
             DSS1_RetailerDriverStockOptimisation.BO.SLAStatistics stat = new DSS1_RetailerDriverStockOptimisation.BO.SLAStatistics();
             stat.Percentage = (thisMonthsDeliveries?.Sum((a) => a.Percentage) ?? 0) / (thisMonthsDeliveries?.Count() ?? 0); stat.Percentage = Math.Round((stat?.Percentage ?? 0), 2); stat.Month = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName((i).GetValueOrDefault(0)); stat.Threshold = 80; stats?.Add(stat);
         }
         return(stats);
     }
 }
 public static void CreateNotifications(DSS1_RetailerDriverStockOptimisation.BO.OrderForecast orderForecast)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("Notification", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "CreateNotifications")) {
         zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "Notification", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, "Creating Alerts for Order Forecast: " + (orderForecast?.Id ?? 0));
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails> forecastOrderDetails = orderForecast?.OrderForecastDetails;
         foreach (var order in forecastOrderDetails ?? Enumerable.Empty <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails>())
         {
             if ((order?.Notification != null))
             {
                 zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "Notification", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, "---- Deleting " + (order?.Notification?.Id ?? 0) + "----");
                 new DSS1_RetailerDriverStockOptimisation.DAL.Repository().DeleteNotification(order?.Notification);
             }
             DSS1_RetailerDriverStockOptimisation.BO.Item currItem = order?.Item;
             var _var0 = currItem?.SKU; var _var1 = order?.RecommendedOrderDate?.Date; DSS1_RetailerDriverStockOptimisation.BO.SupplierCapacity supplierCapacity = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetAsQueryable <DSS1_RetailerDriverStockOptimisation.BO.SupplierCapacity>((a) => a.Item.SKU == _var0 && a.DateOfStockUpdate.GetValueOrDefault(System.Data.SqlTypes.SqlDateTime.MinValue.Value).Date == _var1)?.FirstOrDefault();
             if ((supplierCapacity == null || supplierCapacity?.Stock == 0))
             {
                 zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "Notification", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, "Don't have supplier capacity for item : " + (currItem?.SKU ?? ""));
                 continue;
             }
             int?totalStock    = (supplierCapacity?.Stock ?? 0);
             int?orderQuantity = (int)((order?.Quantity ?? 0));
             zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "Notification", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, "totalStock " + (totalStock?.ToString() ?? "") + " : orderQuantity" + (orderQuantity?.ToString() ?? ""));
             if ((totalStock < orderQuantity))
             {
                 DSS1_RetailerDriverStockOptimisation.BO.Notification notification = new DSS1_RetailerDriverStockOptimisation.BO.Notification();
                 notification.Message = "Low Stock"; notification.Item = currItem; notification.Warehouse = order?.Warehouse; notification.TotalSupplierStock = totalStock; notification.SalesForecastDate = (order?.RecommendedOrderDate ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); notification.OrderForecastQuantity = orderQuantity; notification.Diff = orderQuantity.GetValueOrDefault(0) - totalStock.GetValueOrDefault(0); notification.OrderForecastDetails = order; notification.CreatedBy = "System"; new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Save <DSS1_RetailerDriverStockOptimisation.BO.Notification>(notification);
                 zAppDev.DotNet.Framework.Utilities.EMailMessage em = new zAppDev.DotNet.Framework.Utilities.EMailMessage();
                 em.To = new List <string> {
                     "*****@*****.**"
                 }.ToList(); em.Subject = "New Alert"; em.IsBodyHtml = true; em.Body = "A new alert is created due to low stock " + "for the Item: " + (notification?.Item?.SKU ?? ""); zAppDev.DotNet.Framework.Utilities.Email.SendMail(em, true);
             }
             string recommendationThresholdPercentString = zAppDev.DotNet.Framework.Identity.Model.ApplicationSetting.GetValue("RecommendationThresholdPercent");
             if (((recommendationThresholdPercentString == null || recommendationThresholdPercentString.Trim() == "")))
             {
                 continue;
             }
             int?recommendationThresholdPercent = int.Parse(recommendationThresholdPercentString);
             if ((100 * (totalStock.GetValueOrDefault(0) - orderQuantity.GetValueOrDefault(0)) / totalStock.GetValueOrDefault(0) >= recommendationThresholdPercent))
             {
                 DSS1_RetailerDriverStockOptimisation.BO.Notification notification = new DSS1_RetailerDriverStockOptimisation.BO.Notification();
                 notification.Message = "Excess of Stock"; notification.Item = currItem; notification.Warehouse = order?.Warehouse; notification.TotalSupplierStock = totalStock; notification.SalesForecastDate = (order?.RecommendedOrderDate ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value); notification.OrderForecastQuantity = orderQuantity; notification.Diff = totalStock.GetValueOrDefault(0) - orderQuantity.GetValueOrDefault(0); notification.OrderForecastDetails = order; notification.CreatedBy = "System"; new DSS1_RetailerDriverStockOptimisation.DAL.Repository().Save <DSS1_RetailerDriverStockOptimisation.BO.Notification>(notification);
             }
         }
     }
 }
 public static void CreateNotificationsForAll()
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("Notification", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "CreateNotificationsForAll")) {
         System.Collections.Generic.List <DSS1_RetailerDriverStockOptimisation.BO.OrderForecast> orderForecasts = new DSS1_RetailerDriverStockOptimisation.DAL.Repository().GetAll <DSS1_RetailerDriverStockOptimisation.BO.OrderForecast>();
         foreach (var forecast in orderForecasts ?? Enumerable.Empty <DSS1_RetailerDriverStockOptimisation.BO.OrderForecast>())
         {
             DSS1_RetailerDriverStockOptimisation.BO.NotificationExtensions.CreateNotifications(forecast);
         }
     }
 }