Example #1
0
        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);
        }
Example #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);
        }