Example #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);
        }
Example #2
0
        private Panel AddBodyPanelCol4(AssociationExpenses associationExpense, TextBox tb1)
        {
            // column 4
            var col4 = new Panel
            {
                CssClass = "col-md-2 col-sm-2 col-xs-6"
            };
            Button btn4 = new Button();

            if (tb1.Text == string.Empty)
            {
                btn4.Text     = "Adaugă factura";
                btn4.CssClass = "btn btn-warning";
            }
            else
            {
                btn4.Text     = "Modifică factura";
                btn4.CssClass = "btn btn-success";
            }

            btn4.Click          += ClickablePanel1_Click;
            btn4.CommandArgument = associationExpense.Id.ToString();
            btn4.Visible         = associationExpense.Id_Expense != (int)Expense.AjutorÎncălzire;
            col4.Controls.Add(btn4);

            return(col4);
        }
Example #3
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);
        }
Example #4
0
        private static string ExpensePercentageFilledInAsString(AssociationExpenses associationExpense, int apartmentsWithCounters)
        {
            var addedExpenses = associationExpense.ApartmentExpenses.Count(te => te.Value.HasValue);
            var percentage    = ((addedExpenses / apartmentsWithCounters) * 100).ToString("0.##");

            return(percentage);
        }
Example #5
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 #6
0
        private void InitializeGridViewExpensesPerIndex(DataTable dt, int esexId)
        {
            var apartments = ApartmentsManager.GetForIndividual(Association.Id, esexId);

            AssociationExpenses ee = AssociationExpensesManager.GetById(esexId);

            foreach (var apartment in apartments)
            {
                ApartmentExpensesManager.ConfigureIndividual(ee, apartment);

                string query = @"
                    Select 
                    TE.Id as Id,
                    A.Number as Apartament,
                    TE.Value as 'Valoare'
                    from ApartmentExpenses TE
                    Inner join Apartments A
                    ON TE.Id_Tenant = A.Id
                    where Id_EstateExpense = " + esexId + " and Id_Tenant = " + apartment.Id +
                               " and A.Id_Estate = " + Association.Id;

                SqlConnection  cnn = new SqlConnection("data source=HOME\\SQLEXPRESS;initial catalog=Administratoro;integrated security=True;MultipleActiveResultSets=True;");
                SqlCommand     cmd = new SqlCommand(query, cnn);
                SqlDataAdapter adp = new SqlDataAdapter(cmd);
                adp.Fill(dt);
            }

            ViewState["dtIndividual"]     = dt;
            gvExpensesPerIndex.DataSource = dt;
            gvExpensesPerIndex.DataBind();
        }
Example #7
0
        private static decimal ExpensePercentageFilledIn(AssociationExpenses associationExpense, int apartmentsWithCounters)
        {
            var addedExpenses = associationExpense.ApartmentExpenses.Count(te => te.Value.HasValue);
            var percentage    = ((addedExpenses / apartmentsWithCounters) * 100);

            return(percentage);
        }
Example #8
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);
        }
Example #9
0
        public static AssociationExpenses Add(int associationId, int expenseId, int month, int year, string expenseType, bool?isStairCaseSplit)
        {
            AssociationExpenses ee = null;

            ExpenseType expenseTypeEnum;

            if (Enum.TryParse <ExpenseType>(expenseType, out expenseTypeEnum))
            {
                ee = new AssociationExpenses
                {
                    Id_Expense        = expenseId,
                    Id_ExpenseType    = (int)expenseTypeEnum,
                    Id_Estate         = associationId,
                    Month             = month,
                    Year              = year,
                    isDefault         = false,
                    WasDisabled       = false,
                    SplitPerStairCase = isStairCaseSplit
                };

                GetContext().AssociationExpenses.Add(ee);
                GetContext().SaveChanges();
            }

            return(ee);
        }
Example #10
0
        public static string ExpensePercentageFilledInMessage(AssociationExpenses associationExpense)
        {
            var addedExpenses = associationExpense.ApartmentExpenses.Count(te => te.Value.HasValue);

            int apartmentsWithCountersOfThatExpense = associationExpense.ApartmentExpenses.Count();

            return("<b>" + addedExpenses + "</b> citiri adăugate din <b>" + apartmentsWithCountersOfThatExpense + "</b> ");
        }
Example #11
0
        public static AssociationCounters GetByExpenseAndStairCase(AssociationExpenses associationExpenses, int?stairCase)
        {
            if (associationExpenses == null)
            {
                return(null);
            }

            return(GetByExpenseAndStairCase(associationExpenses.Id_Estate, associationExpenses.Id_Expense, stairCase));
        }
Example #12
0
        public static void UpdateAssociationExpenseType(AssociationExpenses ee, ExpenseType selectedExpenseType)
        {
            var et = GetContext().ExpenseTypes.FirstOrDefault(ext => ext.Id == (int)selectedExpenseType);

            if (ee != null && et != null)
            {
                ee.ExpenseTypes = et;
                GetContext().SaveChanges();
            }
        }
Example #13
0
 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);
     }
 }
Example #14
0
        private static bool IsDplExpenseTypesSelected(AssociationExpenses expense, ExpenseType expenseType)
        {
            bool result = false;

            if (expense != null)
            {
                result = expense.Id_ExpenseType == (int)expenseType;
            }

            return(result);
        }
Example #15
0
        public static void MarkAssociationExpensesDisableProperty(AssociationExpenses ee, bool isDisabled, bool?isStairCaseSplit)
        {
            if (ee == null)
            {
                return;
            }

            ee.WasDisabled       = isDisabled;
            ee.SplitPerStairCase = isStairCaseSplit;
            GetContext().SaveChanges();
        }
Example #16
0
        public static AssociationExpenses GetForSameMonthByExpense(int id, Expense expense)
        {
            AssociationExpenses result = null;
            var ae = GetById(id);

            if (ae != null)
            {
                result = GetContext(true).AssociationExpenses.FirstOrDefault(x => x.Year == ae.Year && x.Month == ae.Month && x.Id_Estate == ae.Id_Estate && x.Id_Expense == (int)expense);
            }

            return(result);
        }
Example #17
0
        public static void UpdateRedistributeMethod(int associationExpenseId, int?type)
        {
            AssociationExpenses result = new AssociationExpenses();

            result = GetContext(true).AssociationExpenses.FirstOrDefault(ee => ee.Id == associationExpenseId && !ee.Expenses.specialType.HasValue);
            if (result != null)
            {
                result.RedistributeType = type;
                GetContext().Entry(result).CurrentValues.SetValues(result);
                GetContext().SaveChanges();
            }
        }
Example #18
0
 public static void UpdatePricePerUnitDefaultPreviousMonth(AssociationExpenses newEe, IEnumerable <AssociationExpenses> oldEEs)
 {
     if (newEe != null)
     {
         AssociationExpenses oldEe = oldEEs.FirstOrDefault(ee => ee.Id_Expense == newEe.Id_Expense && !ee.Expenses.specialType.HasValue);
         if (oldEe != null && oldEe.Id_ExpenseType == (int)ExpenseType.PerIndex)
         {
             //UpdatePricePerUnit(newEE.Id, oldEE.PricePerExpenseUnit);
             UpdateRedistributeMethod(newEe.Id, oldEe.RedistributeType);
         }
     }
 }
Example #19
0
        protected void btnOpening_Click(object sender, EventArgs e)
        {
            lblMessage.Attributes.Add("style", "");
            var year  = drpOpeningYear.SelectedValue.ToNullableInt().Value;
            var month = drpOpeningMonth.SelectedValue.ToNullableInt().Value;

            var ee = AssociationExpensesManager.GetAllAssociationExpensesByMonthAndYearIncludingDisabled(Association.Id, year, month);

            if (ee.Count() != 0)
            {
                lblMessage.Text = "Luna deschisa deja, selecteaza alta luna-an";
                lblMessage.Attributes.Add("style", "color: red");
                return;
            }
            IEnumerable <AssociationExpenses> oldEe = AssociationExpensesManager.GetFromLastestOpenedMonth(Association.Id);

            foreach (TableRow row in tblMonthlyExpenses.Rows)
            {
                if (row.Cells.Count > 2)
                {
                    TableCell cellIsSelected  = row.Cells[0];
                    TableCell cellExpenseType = row.Cells[2];

                    if (cellIsSelected.Controls.Count == 1 && cellIsSelected.Controls[0] is CheckBox &&
                        cellExpenseType.Controls.Count == 1 && cellExpenseType.Controls[0] is DropDownList)
                    {
                        CheckBox     cbIsSelected               = (CheckBox)cellIsSelected.Controls[0];
                        DropDownList drpExpenseType             = (DropDownList)cellExpenseType.Controls[0];
                        bool         cbIsStairCaseSplitSelected = false;

                        if (row.Cells.Count > 3)
                        {
                            TableCell cellIsStairCaseSplit = row.Cells[3];
                            cbIsStairCaseSplitSelected = ((CheckBox)cellIsStairCaseSplit.Controls[0]).Checked;
                        }

                        if (cbIsSelected.Checked)
                        {
                            string cbId = cbIsSelected.ID.Replace("expense", "");
                            int    expenseId;
                            if (int.TryParse(cbId, out expenseId))
                            {
                                AssociationExpenses newEe = AssociationExpensesManager.Add(Association.Id, expenseId,
                                                                                           month, year, drpExpenseType.SelectedValue, cbIsStairCaseSplitSelected);
                                AssociationExpensesManager.UpdatePricePerUnitDefaultPreviousMonth(newEe, oldEe);
                            }
                        }
                    }
                }
            }

            Response.Redirect("~/Expenses/Invoices.aspx?year=" + year + "&month=" + month);
        }
Example #20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            InitializeStairCases();
            var idExes = Request.QueryString["id_exes"];
            int idExpenseEstate;

            if (int.TryParse(idExes, out idExpenseEstate))
            {
                AssociationExpenses ee = AssociationExpensesManager.GetById(idExpenseEstate);
                if (ee != null)
                {
                    btnRedirect.PostBackUrl = "Invoices.aspx?year=" + ee.Year + "&month=" + ee.Month;
                    btnRedirect.Visible     = true;

                    lblExpenseMeessage.Text = "Modifică <b>" + ee.Expenses.Name + "</b> pe luna <b>"
                                              + CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(ee.Month) + "</b> (cheltuială " + ee.ExpenseTypes.Name + ")";

                    if (ee.ExpenseTypes.Id == (int)ExpenseType.PerIndex)
                    {
                        DataTable dt = new DataTable();
                        if (!Page.IsPostBack)
                        {
                            //todo1 - work around counters and staircase
                            //txtExpensesPerIndexValue.Text = ee.AssociationExpensesUnitPrices.FirstOrDefault().PricePerExpenseUnit.ToString();
                        }

                        if (ViewState["dtPerIndex"] == null)
                        {
                            InitializeGridViewExpensesPerIndex(dt, ee.Id);
                        }
                        else
                        {
                            dt = (DataTable)ViewState["dtPerIndex"];
                            ViewState["dtPerIndex"]       = dt;
                            gvExpensesPerIndex.DataSource = dt;
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Expense type not per index");
                    }
                }
                else
                {
                    throw new ArgumentException("AddEditExpenseRequest parameter does not exist");
                }
            }
            else
            {
                throw new ArgumentException("AddEditExpenseRequest parameter not correct");
            }
        }
Example #21
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);
        }
Example #22
0
        private static Panel AddBodyPanelCol0(AssociationExpenses associationExpense, bool isExpensePerIndex)
        {
            // column 0
            var     col0     = new Panel();
            Literal literal0 = new Literal
            {
                Text = AssociationExpensesManager.StatusOfInvoices(associationExpense, isExpensePerIndex)
            };

            col0.Controls.Add(literal0);
            col0.CssClass = "col-md-1 col-sm-2 col-xs-6";
            return(col0);
        }
Example #23
0
        public static AssociationExpenses GetPreviousMonth(AssociationExpenses ae)
        {
            if (ae == null)
            {
                return(null);
            }

            //todo -1 does not work for month 1(january)
            var lastMonthEE = GetContext(true).AssociationExpenses.FirstOrDefault(e => e.Month == ae.Month - 1 &&
                                                                                  e.Id_Estate == ae.Id_Estate && e.Id_Expense == ae.Id_Expense && e.Id_ExpenseType == ae.Id_ExpenseType &&
                                                                                  e.isDefault == ae.isDefault && e.Year == ae.Year && e.WasDisabled == ae.WasDisabled);

            return(lastMonthEE);
        }
Example #24
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);
        }
Example #25
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);
        }
Example #26
0
        private static bool StatusHasRedistributedTheValue(AssociationExpenses associationExpense, string redistributeValue)
        {
            bool result = false;

            if (associationExpense.RedistributeType.HasValue)
            {
                result = true;
            }
            else if (string.IsNullOrEmpty(redistributeValue) || redistributeValue == "0,0000000")
            {
                result = true;
            }

            return(result);
        }
Example #27
0
        private static Panel AddBodyPanelCol1(Expenses expense, AssociationExpenses associationExpense)
        {
            // column 1
            var col1 = new Panel
            {
                CssClass = "col-md-1 col-sm-2 col-xs-6",
            };
            Literal literal1 = new Literal
            {
                Text = "<b>" + expense.Name + "</b> (" + associationExpense.ExpenseTypes.Name + ")"
            };

            col1.Controls.Add(literal1);
            return(col1);
        }
Example #28
0
        private static decimal?GetRedistributeValueForIndexExpenseForStairCase(AssociationExpenses associationExpense, Apartments apartment)
        {
            decimal?result = null;
            decimal?sumOfInvoiceForCounter = GetSumOfInvoiceForStairCaseCounter(associationExpense, apartment.Id_StairCase);

            if (sumOfInvoiceForCounter.HasValue)
            {
                var sumOfExpensesForCounter = ApartmentExpensesManager.GetConsumption(associationExpense, apartment.Id_StairCase);
                if (sumOfExpensesForCounter.HasValue)
                {
                    result = sumOfInvoiceForCounter - sumOfExpensesForCounter;
                }
            }

            return(result);
        }
Example #29
0
        public static decimal GetPercentage(AssociationExpenses associationExpense)
        {
            decimal percentage;

            int allApartmentExpenses = associationExpense.ApartmentExpenses.Count();

            if (allApartmentExpenses > 0)
            {
                percentage = ExpensePercentageFilledIn(associationExpense, allApartmentExpenses);
            }
            else
            {
                percentage = 100m;
            }

            return(percentage);
        }
Example #30
0
        public static string GetPercentageAsString(AssociationExpenses associationExpense)
        {
            string percentage;

            int allApartmentExpenses = associationExpense.ApartmentExpenses.Count();

            if (allApartmentExpenses > 0)
            {
                percentage = ExpensePercentageFilledInAsString(associationExpense, allApartmentExpenses);
            }
            else
            {
                percentage = "100";
            }

            return(percentage);
        }