private static decimal?GetPriceForHotWather(AssociationExpenses associationExpense, List <InvoiceSubcategories> invoiceSubcategories) { decimal? result = null; Invoices invoice = InvoicesManager.GetByAssociationExpenseForExpense(associationExpense, Expense.ApaRece); var coldWAtherExpense = GetAssociationExpense(associationExpense.Id_Estate, (int)Expense.ApaRece, associationExpense.Year, associationExpense.Month); if (invoice != null) { foreach (var invoiceSubcategory in invoiceSubcategories.Where(i => i.Id_subCategType == (int)InvoiceSubcategoryType.PreparatApaCalda)) { var assCounter = AssociationCountersManager.GetById(invoiceSubcategory.id_assCounter.Value); foreach (var assCounterStairCase in assCounter.AssociationCountersStairCase) { if (invoiceSubcategory.Value.HasValue && invoiceSubcategory.VAT.HasValue) { var coldWatherUnitPrice = UnitPricesManager.GetPrice(coldWAtherExpense.Id, assCounterStairCase.Id_StairCase); var invoiceSubcategoryForApaCT = InvoiceIndexesManager.GetByInvoiceAndCounterFirst(invoice, assCounter); if (coldWatherUnitPrice.HasValue && invoiceSubcategoryForApaCT != null && invoiceSubcategoryForApaCT.IndexNew.HasValue && invoiceSubcategoryForApaCT.IndexOld.HasValue) { var difference = invoiceSubcategoryForApaCT.IndexNew.Value - invoiceSubcategoryForApaCT.IndexOld.Value; if (difference != 0) { var newPricePerUnit = coldWatherUnitPrice + (invoiceSubcategory.Value.Value + invoiceSubcategory.VAT.Value) / difference; UpdatePricePerUnit(associationExpense.Id, newPricePerUnit, assCounterStairCase.Id_StairCase); result = newPricePerUnit; } } } } } } return(result); }
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); }
internal static int GetInvoicesNr(AssociationExpenses associationExpense) { if (associationExpense.SplitPerStairCase.HasValue && associationExpense.SplitPerStairCase.Value) { return(AssociationCountersManager.GetAllByExpenseType(associationExpense.Id_Estate, associationExpense.Id_Expense).Count()); } else { return(1); } }
public static IEnumerable <InvoiceIndexes> Get(Invoices invoice, int?stairCase) { var result = new List <InvoiceIndexes>(); // find which counter has on that stairCase var assocCounter = AssociationCountersManager.GetByExpenseAndStairCase(invoice, stairCase); if (assocCounter != null) { // get Invoice inces result = GetByInvoiceAndCounter(invoice, assocCounter); } return(result); }
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); }
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); } } } }
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); }
public static void AddDefault(AssociationExpenses associationExpense) { if (associationExpense == null) { return; } if (associationExpense.SplitPerStairCase.HasValue && associationExpense.SplitPerStairCase.Value) { var assCounters = AssociationCountersManager.GetAllByExpenseType(associationExpense.Id_Estate, associationExpense.Id_Expense); foreach (var assCounter in assCounters) { var result = new Invoices { Id_EstateExpense = associationExpense.Id, Value = null, Id_StairCase = null, id_assCounter = assCounter.Id }; GetContext().Invoices.Add(result); } } else { var result = new Invoices { Id_EstateExpense = associationExpense.Id, Value = null, Id_StairCase = null }; GetContext().Invoices.Add(result); } GetContext().SaveChanges(); }
public static bool HasCounterOfExpense(int apartmentId, int expenseId) { var counters = AssociationCountersManager.GetByApartment(apartmentId); return(counters.Any(c => c.Id_Expense == expenseId)); }