private AnnualPlanCostTypeModel GetAnnualPlanCostTypeModel(CostType costType, IList <CostPlanDto> previousMarketingYearCostPlans, IList <CostPlanDto> currentMarketingYearCostPlans) { var annualPlanCostTypeModel = new AnnualPlanCostTypeModel { CostType = costType, CostTypeName = TypeName.GetFodderTypeName((int)costType), PreviousPlan = previousMarketingYearCostPlans.FirstOrDefault(x => x.Type == (int)costType)?.Cost / 1000.0 ?? 0, CurrentState = 0, // TODO: How to determine it? FutureState = currentMarketingYearCostPlans.FirstOrDefault(x => x.Type == (int)costType)?.Cost / 1000.0 ?? 0 }; switch (costType) { case CostType.Cost: IList <ExpenseDto> previousMarketingYearExpenses = _expenseDao.GetByMarketingYear(PreviousMarketingYearId); annualPlanCostTypeModel.Execution = previousMarketingYearExpenses.Sum(x => x.Cost) / 1000.0; break; case CostType.Revenue: IList <CarcassRevenueDto> previousMarketingYearCarcassRevenues = _carcassRevenueDao.GetByMarketingYear(PreviousMarketingYearId); annualPlanCostTypeModel.Execution = previousMarketingYearCarcassRevenues.Sum(x => x.Revenue) / 1000.0; break; default: break; } return(annualPlanCostTypeModel); }
public FodderPlanBaseViewModel GetFodderPlanViewModel(int marketingYearId) { IList <FodderPlanDto> fodderPlanDtos = _fodderPlanDao.GetByMarketingYear(marketingYearId); List <FodderPlanViewModel> fodderPlanViewModels = ( from fodderPlan in fodderPlanDtos where fodderPlan.MarketingYearId == marketingYearId select new FodderPlanViewModel { Id = fodderPlan.Id, Type = fodderPlan.Type, TypeName = TypeName.GetFodderTypeName(fodderPlan.Type), Ton = fodderPlan.Ton } ).ToList(); MarketingYearModel marketingYearModel = _marketingYearService.GetMarketingYearModel(marketingYearId); AnnualPlanStatusModel annualPlanStatusModel = _annualPlanStatusService.GetByMarketingYearId(marketingYearId); var fodderPlanViewBaseModel = new FodderPlanBaseViewModel { FodderPlanViewModels = fodderPlanViewModels, MarketingYearModel = marketingYearModel, AnnualPlanStatusModel = annualPlanStatusModel }; return(fodderPlanViewBaseModel); }
public FodderBaseViewModel GetFodderViewModel(int marketingYearId) { IList <FodderDto> fodderDtos = _fodderDao.GetByMarketingYear(marketingYearId); List <FodderViewModel> fodderViewModels = fodderDtos.Select(x => new FodderViewModel { Id = x.Id, Type = x.Type, TypeName = TypeName.GetFodderTypeName(x.Type), Kilograms = x.Kilograms, Owner = x.Owner, Description = x.Description, Date = x.Date }).ToList(); MarketingYearModel marketingYearModel = _marketingYearService.GetMarketingYearModel(marketingYearId); AnnualPlanStatusModel annualPlanStatusModel = _annualPlanStatusService.GetByMarketingYearId(marketingYearId); var fodderPlanViewBaseModel = new FodderBaseViewModel { FodderViewModels = fodderViewModels, MarketingYearModel = marketingYearModel, AnnualPlanStatusModel = annualPlanStatusModel }; return(fodderPlanViewBaseModel); }
private MonthlyReportFodderTypeModel GetMonthlyReportFodderTypeModel(FodderType fodderType, IList <FodderDto> fodders) { var annualPlanFodderTypeModel = new MonthlyReportFodderTypeModel { FodderType = fodderType, FodderTypeName = TypeName.GetFodderTypeName((int)fodderType), PutOut = fodders.Where(x => x.Type == (int)fodderType).Sum(x => x.Kilograms) }; return(annualPlanFodderTypeModel); }
private AnnualPlanFodderTypeModel GetAnnualPlanFodderTypeModel(FodderType fodderType, IList <FodderPlanDto> previousMarketingYearFodderPlans, IList <FodderPlanDto> currentMarketingYearFodderPlans, IList <FodderDto> fodders) { var annualPlanFodderTypeModel = new AnnualPlanFodderTypeModel { FodderType = fodderType, FodderTypeName = TypeName.GetFodderTypeName((int)fodderType), PreviousPlan = previousMarketingYearFodderPlans.FirstOrDefault(x => x.Type == (int)fodderType)?.Ton ?? 0, Execution = fodders.Where(x => x.Type == (int)fodderType).Sum(x => x.Kilograms) / 1000.0, CurrentState = 0, FutureState = currentMarketingYearFodderPlans.FirstOrDefault(x => x.Type == (int)fodderType)?.Ton ?? 0 }; return(annualPlanFodderTypeModel); }
public void AddFodderPlan(FodderPlanViewModel model, int marketingYearId) { if (model.Type == 0) { throw new Exception("Nie można dodać planu gospodarczego karmy"); } IList <FodderPlanDto> existingEquipmentPlanDtos = _fodderPlanDao.GetByMarketingYear(marketingYearId); if (existingEquipmentPlanDtos.Any(x => x.Type == model.Type)) { throw new Exception($"Plan gospodarczy karmy {TypeName.GetFodderTypeName(model.Type)} już istnieje! Proszę użyć opcji edycji istniejącego już planu."); } var dto = new FodderPlanDto { Type = model.Type, Ton = model.Ton, MarketingYearId = marketingYearId }; _fodderPlanDao.Insert(dto); }