Ejemplo n.º 1
0
        public bool RemoveBudget(int iBudgetDimensionKey)
        {
            try
            {
                BudgetDimension budgetDimension = db.BudgetDimensions
                                                  .Include(i => i.BudgetDimensionRules)
                                                  .Include(i => i.Budgets)
                                                  .FirstOrDefault(f => f.iBudgetDimensionKey == iBudgetDimensionKey);

                db.Budgets.RemoveRange(budgetDimension.Budgets);
                db.SaveChanges();

                return(true);
            }
            catch (Exception e)
            {
                return(false);

                throw e;
            }
        }
Ejemplo n.º 2
0
        public bool CreateBudget(int iBudgetDimensionKey, int partnerid)
        {
            try
            {
                BudgetDimension budgetDimension = db.BudgetDimensions
                                                  .Include(i => i.BudgetBase)
                                                  .Include(i => i.Budgets)
                                                  .Include(i => i.BudgetDimensionRules)
                                                  .Include(i => i.BudgetDimensionRules.Select(s => s.ReportingStructure))
                                                  .Include(i => i.BudgetSetting)
                                                  .FirstOrDefault(f => f.iBudgetDimensionKey == iBudgetDimensionKey);

                if (budgetDimension.Budgets != null)
                {
                    if (!RemoveBudget(budgetDimension.iBudgetDimensionKey))
                    {
                        return(false);
                    }
                }

                foreach (BudgetDimensionRule item in budgetDimension.BudgetDimensionRules.Where(w => !w.bSpatie && !w.bSubtotaal))
                {
                    if (item.dJanuary != 0)
                    {
                        Budget budget = new Budget()
                        {
                            dcAmountBudget      = item.dJanuary,
                            iCustomerID         = budgetDimension.BudgetBase.iCustomerID,
                            iBudgetDimensionKey = budgetDimension.iBudgetDimensionKey,
                            sReportingCode      = item.ReportingStructure.RcStart,
                            iPartnerID          = partnerid,
                            iProjectKey         = budgetDimension.iProjectKey,
                            iYear    = budgetDimension.BudgetBase.iYear,
                            sPeriod  = "1",
                            sComment = item.sComment
                        };
                        db.Budgets.Add(budget);
                    }
                    if (item.dFebruary != 0)
                    {
                        Budget budget = new Budget()
                        {
                            dcAmountBudget      = item.dFebruary,
                            iCustomerID         = budgetDimension.BudgetBase.iCustomerID,
                            iBudgetDimensionKey = budgetDimension.iBudgetDimensionKey,
                            sReportingCode      = item.ReportingStructure.RcStart,
                            iPartnerID          = partnerid,
                            iProjectKey         = budgetDimension.iProjectKey,
                            iYear    = budgetDimension.BudgetBase.iYear,
                            sPeriod  = "2",
                            sComment = item.sComment
                        };
                        db.Budgets.Add(budget);
                    }
                    if (item.dMarch != 0)
                    {
                        Budget budget = new Budget()
                        {
                            dcAmountBudget      = item.dMarch,
                            iCustomerID         = budgetDimension.BudgetBase.iCustomerID,
                            iBudgetDimensionKey = budgetDimension.iBudgetDimensionKey,
                            sReportingCode      = item.ReportingStructure.RcStart,
                            iPartnerID          = partnerid,
                            iProjectKey         = budgetDimension.iProjectKey,
                            iYear    = budgetDimension.BudgetBase.iYear,
                            sPeriod  = "3",
                            sComment = item.sComment
                        };
                        db.Budgets.Add(budget);
                    }
                    if (item.dApril != 0)
                    {
                        Budget budget = new Budget()
                        {
                            dcAmountBudget      = item.dApril,
                            iCustomerID         = budgetDimension.BudgetBase.iCustomerID,
                            iBudgetDimensionKey = budgetDimension.iBudgetDimensionKey,
                            sReportingCode      = item.ReportingStructure.RcStart,
                            iPartnerID          = partnerid,
                            iProjectKey         = budgetDimension.iProjectKey,
                            iYear    = budgetDimension.BudgetBase.iYear,
                            sPeriod  = "4",
                            sComment = item.sComment
                        };
                        db.Budgets.Add(budget);
                    }
                    if (item.dMay != 0)
                    {
                        Budget budget = new Budget()
                        {
                            dcAmountBudget      = item.dMay,
                            iCustomerID         = budgetDimension.BudgetBase.iCustomerID,
                            iBudgetDimensionKey = budgetDimension.iBudgetDimensionKey,
                            sReportingCode      = item.ReportingStructure.RcStart,
                            iPartnerID          = partnerid,
                            iProjectKey         = budgetDimension.iProjectKey,
                            iYear    = budgetDimension.BudgetBase.iYear,
                            sPeriod  = "5",
                            sComment = item.sComment
                        };
                        db.Budgets.Add(budget);
                    }
                    if (item.dJune != 0)
                    {
                        Budget budget = new Budget()
                        {
                            dcAmountBudget      = item.dJune,
                            iCustomerID         = budgetDimension.BudgetBase.iCustomerID,
                            iBudgetDimensionKey = budgetDimension.iBudgetDimensionKey,
                            sReportingCode      = item.ReportingStructure.RcStart,
                            iPartnerID          = partnerid,
                            iProjectKey         = budgetDimension.iProjectKey,
                            iYear    = budgetDimension.BudgetBase.iYear,
                            sPeriod  = "6",
                            sComment = item.sComment
                        };
                        db.Budgets.Add(budget);
                    }
                    if (item.dJuly != 0)
                    {
                        Budget budget = new Budget()
                        {
                            dcAmountBudget      = item.dJuly,
                            iCustomerID         = budgetDimension.BudgetBase.iCustomerID,
                            iBudgetDimensionKey = budgetDimension.iBudgetDimensionKey,
                            sReportingCode      = item.ReportingStructure.RcStart,
                            iPartnerID          = partnerid,
                            iProjectKey         = budgetDimension.iProjectKey,
                            iYear    = budgetDimension.BudgetBase.iYear,
                            sPeriod  = "7",
                            sComment = item.sComment
                        };
                        db.Budgets.Add(budget);
                    }
                    if (item.dAugust != 0)
                    {
                        Budget budget = new Budget()
                        {
                            dcAmountBudget      = item.dAugust,
                            iCustomerID         = budgetDimension.BudgetBase.iCustomerID,
                            iBudgetDimensionKey = budgetDimension.iBudgetDimensionKey,
                            sReportingCode      = item.ReportingStructure.RcStart,
                            iPartnerID          = partnerid,
                            iProjectKey         = budgetDimension.iProjectKey,
                            iYear    = budgetDimension.BudgetBase.iYear,
                            sPeriod  = "8",
                            sComment = item.sComment
                        };
                        db.Budgets.Add(budget);
                    }
                    if (item.dSeptember != 0)
                    {
                        Budget budget = new Budget()
                        {
                            dcAmountBudget      = item.dSeptember,
                            iCustomerID         = budgetDimension.BudgetBase.iCustomerID,
                            iBudgetDimensionKey = budgetDimension.iBudgetDimensionKey,
                            sReportingCode      = item.ReportingStructure.RcStart,
                            iPartnerID          = partnerid,
                            iProjectKey         = budgetDimension.iProjectKey,
                            iYear    = budgetDimension.BudgetBase.iYear,
                            sPeriod  = "9",
                            sComment = item.sComment
                        };
                        db.Budgets.Add(budget);
                    }
                    if (item.dOctober != 0)
                    {
                        Budget budget = new Budget()
                        {
                            dcAmountBudget      = item.dOctober,
                            iCustomerID         = budgetDimension.BudgetBase.iCustomerID,
                            iBudgetDimensionKey = budgetDimension.iBudgetDimensionKey,
                            sReportingCode      = item.ReportingStructure.RcStart,
                            iPartnerID          = partnerid,
                            iProjectKey         = budgetDimension.iProjectKey,
                            iYear    = budgetDimension.BudgetBase.iYear,
                            sPeriod  = "10",
                            sComment = item.sComment
                        };
                        db.Budgets.Add(budget);
                    }
                    if (item.dNovember != 0)
                    {
                        Budget budget = new Budget()
                        {
                            dcAmountBudget      = item.dNovember,
                            iCustomerID         = budgetDimension.BudgetBase.iCustomerID,
                            iBudgetDimensionKey = budgetDimension.iBudgetDimensionKey,
                            sReportingCode      = item.ReportingStructure.RcStart,
                            iPartnerID          = partnerid,
                            iProjectKey         = budgetDimension.iProjectKey,
                            iYear    = budgetDimension.BudgetBase.iYear,
                            sPeriod  = "11",
                            sComment = item.sComment
                        };
                        db.Budgets.Add(budget);
                    }
                    if (item.dDecember != 0)
                    {
                        Budget budget = new Budget()
                        {
                            dcAmountBudget      = item.dDecember,
                            iCustomerID         = budgetDimension.BudgetBase.iCustomerID,
                            iBudgetDimensionKey = budgetDimension.iBudgetDimensionKey,
                            sReportingCode      = item.ReportingStructure.RcStart,
                            iPartnerID          = partnerid,
                            iProjectKey         = budgetDimension.iProjectKey,
                            iYear    = budgetDimension.BudgetBase.iYear,
                            sPeriod  = "12",
                            sComment = item.sComment
                        };
                        db.Budgets.Add(budget);
                    }

                    db.SaveChanges();
                }

                return(true);
            }
            catch (Exception e)
            {
                return(false);

                throw e;
            }
        }
Ejemplo n.º 3
0
        public int GenerateBudgetDimensionMonthPreview(BudgetDimensionYearPreviewViewModel model)
        {
            int budgetDimensionKey = 0;

            bool projectHasFixedPart = false;


            try
            {
                BudgetBase budgetBase = db.BudgetBases
                                        .FirstOrDefault(f => f.iBudgetBaseKey == model.iBudgetBaseKey);

                BudgetSetting budgetSettings = db.BudgetSettings
                                               .Include(i => i.BudgetSectionIndex)
                                               .Include(i => i.BudgetSectionIndex.Select(s => s.ReportingStructure))
                                               .Include(i => i.MonthDegreeDayIndex)
                                               .OrderByDescending(o => o.iBudgetSettingKey)
                                               .FirstOrDefault();

                // Create the BudgetDimension
                BudgetDimension budgetDimension = new BudgetDimension
                {
                    iBudgetBaseKey              = model.iBudgetBaseKey,
                    bDraft                      = true,
                    BudgetSetting               = budgetSettings,
                    iBudgetDimensionTypeKey     = model.iBudgetDimensionTypeKey,
                    iProjectKey                 = model.iProjectKey,
                    iYearBudget                 = model.iYearBudget,
                    iYearPreview                = model.iYearPreview,
                    iEndPeriodPreview           = model.iEndPeriodPreview,
                    sBudgetDimensionDescription = model.sDescription,
                    dtLastModified              = DateTime.UtcNow,
                    BudgetDimensionRules        = new Collection <BudgetDimensionRule>()
                };

                if (model.iProjectKey.HasValue)
                {
                    ProjectInfo projectInfo = db.ProjectInfo.FirstOrDefault(f => f.iFinProjectKey == model.iProjectKey);

                    if (projectInfo != null)
                    {
                        int[] gasKeys = db.TechnicalPrincipals.Where(w => w.bIsGas).Select(s => s.iTechnicalPrincipalKey).ToArray();
                        projectHasFixedPart = projectInfo.bHotWater || (projectInfo.iTechnicalPrincipalMainKey.HasValue && gasKeys.Contains(projectInfo.iTechnicalPrincipalMainKey.GetValueOrDefault()));
                        projectHasFixedPart = !projectHasFixedPart?projectInfo.iTechnicalPrincipalSub1Key.HasValue?gasKeys.Contains(projectInfo.iTechnicalPrincipalSub1Key.Value) : false : projectHasFixedPart;

                        projectHasFixedPart = !projectHasFixedPart?projectInfo.iTechnicalPrincipalSub2Key.HasValue?gasKeys.Contains(projectInfo.iTechnicalPrincipalSub2Key.Value) : false : projectHasFixedPart;
                    }
                }

                //Check of er gekozen is voor een DCF
                if (budgetBase.iBudgetBaseTypeKey == 1)
                {
                    //Hierbij is gekozen voor een DCF Hierbij hoeft geen verdeling over maanden plaats te vinden
                    foreach (BudgetSectionYearPreviewViewModel item in model.BudgetSections)
                    {
                        BudgetDimensionRule budgetDimensionRule = new BudgetDimensionRule
                        {
                            bSpatie                = item.bSpatie,
                            bSubtotaal             = item.bSubtotaal,
                            dJanuary               = item.dSuggestion.HasValue ? item.dSuggestion.Value : 0,
                            dFebruary              = 0,
                            dMarch                 = 0,
                            dApril                 = 0,
                            dMay                   = 0,
                            dJune                  = 0,
                            dJuly                  = 0,
                            dAugust                = 0,
                            dSeptember             = 0,
                            dOctober               = 0,
                            dNovember              = 0,
                            dDecember              = 0,
                            dTotal                 = !item.bSpatie && !item.bSubtotaal ? item.dSuggestion.HasValue ? item.dSuggestion.Value : 0 : 0,
                            iRecNo                 = item.iRecNo,
                            iReportingStructureKey = item.iReportingStructureKey,
                            sComment               = item.sComment
                        };

                        budgetDimension.BudgetDimensionRules.Add(budgetDimensionRule);
                    }
                }
                else
                {
                    // Hier wordt het bedrag over de maanden uitgesmeerd! Niet nodig voor begroting van DCF.
                    foreach (BudgetSectionYearPreviewViewModel item in model.BudgetSections)
                    {
                        BudgetDimensionRule budgetDimensionRule = new BudgetDimensionRule
                        {
                            bSpatie                = item.bSpatie,
                            bSubtotaal             = item.bSubtotaal,
                            dJanuary               = CalculateMonthSuggestion(item.dSuggestion.HasValue ? item.dSuggestion.Value : 0, budgetSettings.BudgetSectionIndex.FirstOrDefault(f => f.iBudgetSectionIndexKey == item.iBudgetSectionIndexKey), projectHasFixedPart, 1, budgetSettings.MonthDegreeDayIndex),
                            dFebruary              = CalculateMonthSuggestion(item.dSuggestion.HasValue ? item.dSuggestion.Value : 0, budgetSettings.BudgetSectionIndex.FirstOrDefault(f => f.iBudgetSectionIndexKey == item.iBudgetSectionIndexKey), projectHasFixedPart, 2, budgetSettings.MonthDegreeDayIndex),
                            dMarch                 = CalculateMonthSuggestion(item.dSuggestion.HasValue ? item.dSuggestion.Value : 0, budgetSettings.BudgetSectionIndex.FirstOrDefault(f => f.iBudgetSectionIndexKey == item.iBudgetSectionIndexKey), projectHasFixedPart, 3, budgetSettings.MonthDegreeDayIndex),
                            dApril                 = CalculateMonthSuggestion(item.dSuggestion.HasValue ? item.dSuggestion.Value : 0, budgetSettings.BudgetSectionIndex.FirstOrDefault(f => f.iBudgetSectionIndexKey == item.iBudgetSectionIndexKey), projectHasFixedPart, 4, budgetSettings.MonthDegreeDayIndex),
                            dMay                   = CalculateMonthSuggestion(item.dSuggestion.HasValue ? item.dSuggestion.Value : 0, budgetSettings.BudgetSectionIndex.FirstOrDefault(f => f.iBudgetSectionIndexKey == item.iBudgetSectionIndexKey), projectHasFixedPart, 5, budgetSettings.MonthDegreeDayIndex),
                            dJune                  = CalculateMonthSuggestion(item.dSuggestion.HasValue ? item.dSuggestion.Value : 0, budgetSettings.BudgetSectionIndex.FirstOrDefault(f => f.iBudgetSectionIndexKey == item.iBudgetSectionIndexKey), projectHasFixedPart, 6, budgetSettings.MonthDegreeDayIndex),
                            dJuly                  = CalculateMonthSuggestion(item.dSuggestion.HasValue ? item.dSuggestion.Value : 0, budgetSettings.BudgetSectionIndex.FirstOrDefault(f => f.iBudgetSectionIndexKey == item.iBudgetSectionIndexKey), projectHasFixedPart, 7, budgetSettings.MonthDegreeDayIndex),
                            dAugust                = CalculateMonthSuggestion(item.dSuggestion.HasValue ? item.dSuggestion.Value : 0, budgetSettings.BudgetSectionIndex.FirstOrDefault(f => f.iBudgetSectionIndexKey == item.iBudgetSectionIndexKey), projectHasFixedPart, 8, budgetSettings.MonthDegreeDayIndex),
                            dSeptember             = CalculateMonthSuggestion(item.dSuggestion.HasValue ? item.dSuggestion.Value : 0, budgetSettings.BudgetSectionIndex.FirstOrDefault(f => f.iBudgetSectionIndexKey == item.iBudgetSectionIndexKey), projectHasFixedPart, 9, budgetSettings.MonthDegreeDayIndex),
                            dOctober               = CalculateMonthSuggestion(item.dSuggestion.HasValue ? item.dSuggestion.Value : 0, budgetSettings.BudgetSectionIndex.FirstOrDefault(f => f.iBudgetSectionIndexKey == item.iBudgetSectionIndexKey), projectHasFixedPart, 10, budgetSettings.MonthDegreeDayIndex),
                            dNovember              = CalculateMonthSuggestion(item.dSuggestion.HasValue ? item.dSuggestion.Value : 0, budgetSettings.BudgetSectionIndex.FirstOrDefault(f => f.iBudgetSectionIndexKey == item.iBudgetSectionIndexKey), projectHasFixedPart, 11, budgetSettings.MonthDegreeDayIndex),
                            dDecember              = CalculateMonthSuggestion(item.dSuggestion.HasValue ? item.dSuggestion.Value : 0, budgetSettings.BudgetSectionIndex.FirstOrDefault(f => f.iBudgetSectionIndexKey == item.iBudgetSectionIndexKey), projectHasFixedPart, 12, budgetSettings.MonthDegreeDayIndex),
                            dTotal                 = !item.bSpatie && !item.bSubtotaal ? item.dSuggestion.HasValue ? item.dSuggestion.Value : 0 : 0,
                            iRecNo                 = item.iRecNo,
                            iReportingStructureKey = item.iReportingStructureKey,
                            sComment               = item.sComment
                        };

                        budgetDimensionRule.dDecember = item.dSuggestion.GetValueOrDefault() -
                                                        budgetDimensionRule.dJanuary -
                                                        budgetDimensionRule.dFebruary -
                                                        budgetDimensionRule.dMarch -
                                                        budgetDimensionRule.dApril -
                                                        budgetDimensionRule.dMay -
                                                        budgetDimensionRule.dJune -
                                                        budgetDimensionRule.dJuly -
                                                        budgetDimensionRule.dAugust -
                                                        budgetDimensionRule.dSeptember -
                                                        budgetDimensionRule.dOctober -
                                                        budgetDimensionRule.dNovember;

                        budgetDimension.BudgetDimensionRules.Add(budgetDimensionRule);
                    }
                }

                db.BudgetDimensions.Add(budgetDimension);
                db.SaveChanges();

                budgetDimensionKey = budgetDimension.iBudgetDimensionKey;
            }
            catch (Exception e)
            {
                throw e;
            }

            return(budgetDimensionKey);
        }