Ejemplo n.º 1
0
        private static decimal?RedistributeValuePerConsumption(AssociationExpenses associationExpense, Apartments apartment, IEnumerable <ApartmentExpenses> apartmentExpenses)
        {
            decimal?result = null;
            decimal apartmentConsumption = GetApartmentConsumprionAsDecimal(apartmentExpenses);

            var     redistributeValue = GetRedistributeValuePerIndex(associationExpense, apartment.Id_StairCase);
            decimal?sumOfIndexes      = ApartmentExpensesManager.GetSumOfIndexesOnSameCounter(associationExpense.Id, apartment.Id_StairCase);

            if (redistributeValue.HasValue && sumOfIndexes.HasValue && sumOfIndexes.Value != 0)
            {
                result = (apartmentConsumption / sumOfIndexes.Value) * redistributeValue;
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static decimal?GetRedistributeValuePerIndex(AssociationExpenses associationExpense, int?stairCase)
        {
            decimal?result = null;

            var invoice = associationExpense.Invoices.FirstOrDefault(i => i.Id_StairCase == null && i.Id_EstateExpense == associationExpense.Id);
            var assCountersForThisExpense = AssociationCountersManager.GetByExpenseAndStairCase(associationExpense, stairCase);

            if (assCountersForThisExpense != null)
            {
                var     pricePerUnit = UnitPricesManager.GetPrice(associationExpense.Id, assCountersForThisExpense.AssociationCountersStairCase.FirstOrDefault().Id_StairCase);
                decimal?sumOfIndexes = ApartmentExpensesManager.GetSumOfIndexesOnSameCounter(associationExpense.Id, assCountersForThisExpense.AssociationCountersStairCase.FirstOrDefault().Id_StairCase);
                if (sumOfIndexes.HasValue & invoice != null && pricePerUnit.HasValue)
                {
                    var consummedIndices = InvoiceIndexesManager.GetByInvoiceAndCounterFirst(invoice, assCountersForThisExpense);

                    if (consummedIndices != null && consummedIndices.IndexOld.HasValue && consummedIndices.IndexNew.HasValue)
                    {
                        result = ((consummedIndices.IndexNew.Value - consummedIndices.IndexOld.Value) - sumOfIndexes.Value) * pricePerUnit.Value;
                    }
                }
            }

            return(result);
        }