Exemple #1
0
        public static decimal?CalculateRedistributeValueForStairCase(int associationExpenseId, Apartments apartment, IEnumerable <ApartmentExpenses> apartmentExpenses)
        {
            decimal?result = null;

            AssociationExpenses associationExpense = AssociationExpensesManager.GetById(associationExpenseId);

            if (!associationExpense.RedistributeType.HasValue)
            {
                return(null);
            }

            switch (associationExpense.RedistributeType.Value)
            {
            case (int)RedistributionType.PerApartament:
                result = RedistributeValuePerApartment(associationExpense, apartment);
                break;

            case (int)RedistributionType.PerDependents:
                result = RedistributeValuePerApartmentDependents(associationExpense, apartment);
                break;

            case (int)RedistributionType.PerConsumption:
                result = RedistributeValuePerConsumption(associationExpense, apartment, apartmentExpenses);
                break;
            }

            return(result);
        }
Exemple #2
0
        public static Invoices GetPreviousMonthById(int invoiceId)
        {
            Invoices result = null;

            var invoice = GetById(invoiceId);

            if (invoice != null && invoice.Id_EstateExpense.HasValue)
            {
                var ee    = AssociationExpensesManager.GetById(invoice.Id_EstateExpense.Value);
                var month = ee.Month;
                var year  = ee.Year;

                if (month == 1)
                {
                    month = 12;
                    year  = year - 1;
                }
                else
                {
                    month = month - 1;
                }

                var associationExpense = AssociationExpensesManager.GetAssociationExpense(ee.Id_Estate, ee.Id_Expense, year, month);
                if (associationExpense != null)
                {
                    result = associationExpense.Invoices.FirstOrDefault();
                }
            }

            return(result);
        }
Exemple #3
0
        public static void Update(Invoices invoice, decimal?value, int?stairCaseId, string description, int?redistributionId,
                                  string issueNumber, DateTime?issueDate)
        {
            Invoices result;

            result = GetContext(true).Invoices.FirstOrDefault(c => c.Id == invoice.Id);

            if (result != null)
            {
                result.Value                 = value;
                result.Description           = description;
                result.Id_StairCase          = stairCaseId;
                result.id_Redistributiontype = redistributionId;
                result.issueDate             = issueDate;
                result.issueNumber           = issueNumber;

                GetContext().Entry(result).CurrentValues.SetValues(result);

                if (invoice.Id_EstateExpense.HasValue)
                {
                    var ee = AssociationExpensesManager.GetById(invoice.Id_EstateExpense.Value);
                    if (ee != null && ee.Id_Expense != (int)Expense.Diverse)
                    {
                        ApartmentExpensesManager.UpdateApartmentExpenses(ee, value, stairCaseId, result.id_assCounter);
                    }
                }

                GetContext().SaveChanges();
            }
        }
Exemple #4
0
        public static List <Apartments> GetAllThatAreRegisteredWithSpecificCounters(int associationId, int assExpenseId, int?stairCase = null)
        {
            var result = new List <Apartments>();

            AssociationExpenses associationExpense = AssociationExpensesManager.GetById(assExpenseId);

            if (associationExpense != null)
            {
                List <Apartments> allApartments;
                if (stairCase.HasValue)
                {
                    allApartments = Get(associationId, stairCase.Value);
                }
                else
                {
                    allApartments = Get(associationId);
                }

                foreach (var apartment in allApartments)
                {
                    IEnumerable <AssociationCounters> counters = AssociationCountersManager.GetByApartment(apartment.Id);

                    if (counters.Any(c => c.Id_Expense == associationExpense.Expenses.Id))
                    {
                        result.Add(apartment);
                    }
                }
            }

            return(result);
        }
        public static void RecalculateMonthlyExpenses(int associationId, int year, int month)
        {
            var associationExpenses = AssociationExpensesManager.GetByMonthAndYearWithoutDiverse(associationId, year, month);

            foreach (var associationExpense in associationExpenses)
            {
                RelalculateExpense(associationExpense);
            }
        }
Exemple #6
0
        public static decimal?CalculateRedistributeValue(int associationExpenseId)
        {
            decimal?result = null;

            AssociationExpenses associationExpense = AssociationExpensesManager.GetById(associationExpenseId);

            if (associationExpense.Id_ExpenseType == (int)ExpenseType.PerIndex)
            {
                result = GetRedistributeValuePerIndex(associationExpense);
            }

            return(result);
        }
Exemple #7
0
        public static AssociationExpensesUnitPrices Get(int associationExpenseId, int?stairCase)
        {
            AssociationExpensesUnitPrices result = null;

            var associationExpense = AssociationExpensesManager.GetById(associationExpenseId);

            if (associationExpense != null)
            {
                var assCounter = AssociationCountersManager.GetByExpenseAndStairCase(associationExpense.Id_Estate, associationExpense.Id_Expense, stairCase);
                if (assCounter != null)
                {
                    result = Get(associationExpenseId, assCounter.Id);
                }
            }

            return(result);
        }
Exemple #8
0
        public static IEnumerable <Apartments> GetForIndividual(int associationId, int associationExpenseId)
        {
            var result             = Enumerable.Empty <Apartments>();
            var associationExpense = AssociationExpensesManager.GetById(associationExpenseId);

            if (associationExpense != null)
            {
                if (associationExpense.Id_Expense == (int)Expense.AjutorÎncălzire)
                {
                    result = GetAllEnabledForHeatHelp(associationId);
                }
                else
                {
                    result = GetAllThatAreRegisteredWithSpecificCounters(associationId, associationExpenseId);
                }
            }

            return(result);
        }
Exemple #9
0
        public static void AddOrUpdate(int?stairCase, int assExpenseId, decimal?newPrice)
        {
            var associationExpense = AssociationExpensesManager.GetById(assExpenseId);

            if (associationExpense != null)
            {
                var assCounter = AssociationCountersManager.GetByExpenseAndStairCase(associationExpense.Id_Estate, associationExpense.Id_Expense, stairCase);
                if (assCounter != null)
                {
                    var assExUnitPrice = Get(assExpenseId, assCounter.Id);
                    if (assExUnitPrice == null)
                    {
                        Add(assExpenseId, assCounter.Id, newPrice);
                    }
                    else
                    {
                        Update(assExUnitPrice.Id, newPrice);
                    }
                }
            }
        }
Exemple #10
0
        private static decimal?RedistributeValuePerApartment(AssociationExpenses associationExpense, Apartments apartment)
        {
            decimal?result = null;
            // todo change this to be for index expense or add new if branch
            //if (associationExpense.SplitPerStairCase.HasValue && associationExpense.SplitPerStairCase.Value)
            //{
            var redistributeSum = GetRedistributeValueForIndexExpenseForStairCase(associationExpense, apartment);

            var allApartmentsOnSamecounter = ApartmentExpensesManager.GetApartmentsOnSameCounter(associationExpense.Id, apartment.Id_StairCase).Count();

            if (redistributeSum.HasValue && allApartmentsOnSamecounter != 0)
            {
                if (associationExpense.Id_ExpenseType == (int)ExpenseType.PerIndex && !AssociationExpensesManager.HasCounterOfExpense(apartment.Id, associationExpense.Id_Expense))
                {
                }
                else
                {
                    result = redistributeSum / allApartmentsOnSamecounter;
                }
            }
            //}
            //else
            //{
            //    var redistributeVal = CalculateRedistributeValue(associationExpense.Id);
            //    int allApartmentsNr;
            //    if (associationExpense.Id_ExpenseType == (int)ExpenseType.PerIndex)
            //    {
            //        IEnumerable<Apartments> apartments = AssociationExpensesManager.GetApartmentsNrThatShouldRedistributeTo(associationExpense.Id);
            //        allApartmentsNr = apartments.Count();
            //    }
            //    else
            //    {
            //        allApartmentsNr = associationExpense.Associations.Apartments.Count();
            //    }

            //    if (redistributeVal != null && redistributeVal.HasValue && allApartmentsNr != 0)
            //    {
            //        if (associationExpense.Id_ExpenseType == (int)ExpenseType.PerIndex && !AssociationExpensesManager.HasCounterOfExpense(apartment.Id, associationExpense.Id_Expense))
            //        {
            //        }
            //        else
            //        {
            //            result = redistributeVal.Value / allApartmentsNr;
            //        }
            //    }
            //}

            return(result);
        }
Exemple #11
0
        private static decimal?RedistributeValuePerApartmentDependents(AssociationExpenses associationExpense, Apartments apartment)
        {
            decimal?result = null;

            //if (associationExpense.SplitPerStairCase.HasValue && associationExpense.SplitPerStairCase.Value)
            //{
            var redistributeSum         = GetRedistributeValueForIndexExpenseForStairCase(associationExpense, apartment);
            var allApartmentsDependents = ApartmentExpensesManager.GetApartmentsOnSameCounter(associationExpense.Id, apartment.Id_StairCase).Sum(t => t.Dependents);

            if (redistributeSum.HasValue && allApartmentsDependents != 0)
            {
                if (associationExpense.Id_ExpenseType == (int)ExpenseType.PerIndex && !AssociationExpensesManager.HasCounterOfExpense(apartment.Id, associationExpense.Id_Expense))
                {
                }
                else
                {
                    result = redistributeSum * apartment.Dependents / allApartmentsDependents;
                }
            }
            //}
            //else
            //{
            // var allApartmentsDependentsu = AssociationExpensesManager.GetApartmentsNrThatShouldRedistributeTo(associationExpense.Id).Sum(e => e.Dependents);

            //if (allApartmentsDependents != 0)
            //{
            //    var redistributeVal = CalculateRedistributeValue(associationExpense.Id);
            //    if (redistributeVal != null && redistributeVal.HasValue && allApartmentsDependents != 0)
            //    {
            //        if (associationExpense.Id_ExpenseType == (int)ExpenseType.PerIndex && !AssociationExpensesManager.HasCounterOfExpense(apartment.Id, associationExpense.Id_Expense))
            //        {
            //        }
            //        else
            //        {
            //            result = redistributeVal.Value * apartment.Dependents / allApartmentsDependents;
            //        }
            //    }
            //}
            //}

            return(result);
        }
Exemple #12
0
        public static void AddDefault(int associationId, int expenseId, int year, int month)
        {
            var associationExpense = AssociationExpensesManager.GetMonthYearAssoiationExpense(associationId, expenseId, year, month);

            AddDefault(associationExpense);
        }
Exemple #13
0
        public static Invoices GetByAssociationExpenseForExpense(AssociationExpenses associationExpense, Expense expense)
        {
            var ae = AssociationExpensesManager.GetForSameMonthByExpense(associationExpense.Id, expense);

            return(ae.Invoices.FirstOrDefault());
        }