示例#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);
        }
示例#2
0
        private static decimal?GetSumOfInvoiceForStairCaseCounter(AssociationExpenses associationExpense, int?stairCase)
        {
            decimal?sumOfInvoices = null;
            var     invoice       = associationExpense.Invoices.FirstOrDefault();

            if (invoice == null)
            {
                return(null);
            }

            var invoiceIndexes = InvoiceIndexesManager.Get(invoice, stairCase);

            foreach (var invoiceIndex in invoiceIndexes)
            {
                var pricePerUnit = UnitPricesManager.GetPrice(invoice.AssociationExpenses.Id, stairCase);

                if (invoiceIndex != null && invoiceIndex.IndexNew.HasValue && invoiceIndex.IndexOld.HasValue && invoiceIndex.Invoices.Value.HasValue &&
                    pricePerUnit.HasValue)
                {
                    if (!sumOfInvoices.HasValue)
                    {
                        sumOfInvoices = 0m;
                    }
                    decimal?valueToAdd = (invoiceIndex.IndexNew - invoiceIndex.IndexOld) * pricePerUnit.Value;

                    sumOfInvoices = sumOfInvoices + valueToAdd;
                }
            }

            return(sumOfInvoices);
        }
示例#3
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);
        }
示例#4
0
 public static void UpdatePricePerUnit(int idAssociationExpense, decimal?newPricePerUnit, int?stairCase)
 {
     UnitPricesManager.AddOrUpdate(stairCase, idAssociationExpense, newPricePerUnit);
     ApartmentExpensesManager.UpdateValueForPriceUpdate(idAssociationExpense, newPricePerUnit);
 }