public void GetForecastsFromMonth(DateTime month, bool getAll) { List <IncomeProductCustomer> IPCs; if (getAll) { // Hämta inte från månad utan från alla IPCs = new List <IncomeProductCustomer>(GetAllIPCs()); // Lägg till produkter från vårat system var AllProducts = GetAllProducts(); // Lägg till alla produkter från systemet genom att fejka tomma ICPs // (Fulhack) IPCs.AddRange(AllProducts.Select(productObj => new IncomeProductCustomer { IeProductID = productObj.ProductID, IeCustomerID = "NULL", IeCustomerName = "NULL", IeIncomeDate = new DateTime(1973, 10, 24), IeProductName = productObj.ProductName })); // Order by product name IPCs = IPCs.OrderBy(p => p.IeProductName).ToList(); } else { IPCs = new List <IncomeProductCustomer>(GetIPCsByMonth(month)); } // Aj, inte så fin lista på redan tillagda produkter (då ska inte IPCn läggas in igen) List <string> tempProdukter = new List <string>(); foreach (var IPC in IPCs) { if (!tempProdukter.Contains(IPC.IeProductID)) { Forecasting fc = new Forecasting { IeProductID = IPC.IeProductID, IeProductName = IPC.IeProductName, OutcomeAcc = CalculateUtfallAcc(month, IPC.IeProductID), Trend = ((CalculateUtfallAcc(month, IPC.IeProductID) + GetReprocessedValue(month, IPC.IeProductID)) / month.Month) * 12, FormerPrognosis = GetFormerForecastValue(month, IPC.IeProductID), Forecast = GetForecastValue(month, IPC.IeProductID), OutcomeMonth = CalculateOutcomeMonth(month.Month, IPC.IeProductID), Budget = GetBudgetFromFinancialIncome(IPC.IeProductID), Reprocessed = GetReprocessedValue(month, IPC.IeProductID) }; // Add to the returning list Forecasts.Add(fc); // Vi ska inte använda den här igen tempProdukter.Add(IPC.IeProductID); } } }
/// <summary> /// Calculates the trend in a specific forecast object /// </summary> /// <param name="forecast"></param> /// <param name="passedMonths"></param> public void CalculateTrend(Forecasting forecast, int passedMonths) { forecast.Trend = ((forecast.OutcomeAcc + forecast.Reprocessed) / passedMonths) * 12; Forecasts.Single(f => f.Equals(forecast)).Trend = forecast.Trend; }