public bool MonthClosed(Consortium consortium, int month) { var accountsStatus = this.GetByUnitId(consortium.Ownership.FunctionalUnits.FirstOrDefault().Id) .Where(x => x.StatusDate.Month == month && x.StatusDate.Year == DateTime.Now.Year); return(accountsStatus.Any(x => !x.IsPayment())); }
public Consortium CreateConsortium(ConsortiumRequest consortium) { Consortium originalConsortium = new Consortium(); var entityToInsert = MergeConsortium(originalConsortium, consortium); ConsortiumRepository.Insert(entityToInsert); return(entityToInsert); }
private Consortium MergeConsortium(Consortium originalConsortium, ConsortiumRequest consortium) { originalConsortium.CUIT = consortium.CUIT; originalConsortium.FriendlyName = consortium.FriendlyName; originalConsortium.MailingList = consortium.MailingList; originalConsortium.Telephone = consortium.Telephone; originalConsortium.Administration = this.AdministrationRepository.GetById(consortium.AdministrationId); originalConsortium.Ownership = this.OwnershipRepository.GetById(consortium.OwnershipId); return(originalConsortium); }
public PaymentTicketsStruct GetTickets(Consortium consortium, IList <PaymentTicket> paymentTickets, int month) { Velocity.Init(); var toDate = month < 12 ? new DateTime(DateTime.Now.Year, month + 1, 18, 0, 0, 0).ToString("MMM dd", new CultureInfo("es-AR")).ToUpper() : new DateTime(DateTime.Now.Year + 1, 1, 18, 0, 0, 0).ToString("MMM dd", new CultureInfo("es-AR")).ToUpper(); foreach (var item in paymentTickets) { item.DiscountDay = item.DiscountDay ?? 0; } var model = new { FromDate = new DateTime(DateTime.Now.Year, month, 18, 0, 0, 0).ToString("MMM dd", new CultureInfo("es-AR")).ToUpper(), ToDate = toDate, ConsortiumAddress = consortium.Ownership.Address.Street + " " + consortium.Ownership.Address.Number, Items = paymentTickets, FontFamily = "Arial", FontSize = "12pt" }; var velocityContext = new VelocityContext(); velocityContext.Put("model", model); var templateFile = string.Format(@"{0}\Resources\PaymentTicketsTemplate.html", Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath)); var template = new StringBuilder(File.ReadAllText(templateFile)); var stylesFile = string.Format(@"{0}\Resources\PaymentTickets.css", Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath)); var styles = new StringBuilder(File.ReadAllText(stylesFile)); var finalTickets = new StringBuilder(); Velocity.Evaluate(velocityContext, new StringWriter(finalTickets), "Payment Tickets", new StringReader(template.ToString())); return(new PaymentTicketsStruct { HtmlTickets = finalTickets, HtmlTicketsStyles = styles }); }
public Consortium UpdateConsortium(Consortium originalConsortium, ConsortiumRequest consortium) { originalConsortium = this.MergeConsortium(originalConsortium, consortium); ConsortiumRepository.Update(originalConsortium); return(originalConsortium); }
public UnitAccountStatusSummary GetUnitSummary(FunctionalUnit unit, Consortium consortium, int month) { DateTime now = DateTime.Now; var configurationStartDate = DateTime.Now.AddYears(-1); // new DateTime(now.Year, month, 1); var configurationEndDate = now; // startDate.AddMonths(1).AddDays(-1); var startDate = new DateTime(now.Year, month, 1); var endDate = startDate.AddMonths(1).AddDays(-1); var previousMonth = new DateTime(now.Year, month, 1).AddMonths(-1); var consortiumConfig = this.ConsortiumConfigurationService.GetByConsortiumId(consortium.Id, configurationStartDate, configurationEndDate).ToList(); var unitConfig = this.UnitConfigurationService.GetByUnitId(unit.Id, configurationStartDate, configurationEndDate).ToList(); var auxConsortiumConfig = new List <ConsortiumConfigurationType>(); // = consortiumConfig.ForEach var auxUnitConfig = new List <UnitConfigurationType>(); // = consortiumConfig.ForEach foreach (var cc in consortiumConfig) { auxConsortiumConfig.Add(cc.Type); } foreach (var cc in unitConfig) { auxUnitConfig.Add(cc.Type); } var consortiumConfigList = this.MakeConsortiumConfigList(consortiumConfig); var unitConfigList = this.MakeUnitConfigList(unitConfig); decimal spendA = 0; decimal spendB = 0; decimal edesur = 0; decimal spendC = 0; decimal spendD = 0; decimal aysa = 0; decimal discount = 0; decimal expensas = 0; foreach (var uc in unitConfigList) { var consConfigAux = consortiumConfigList .Where(x => x.Type.Id == uc.Type.ConsortiumConfigurationType.Id) .OrderByDescending(x => x.ConfigurationDate) .FirstOrDefault(); if (consConfigAux != null) { var auxdebt = this.CalculateDebtFromConfigurations(uc, consConfigAux); switch (consConfigAux.Type.Description.ToLower()) { case "monto a recaudar gastos a": spendA = auxdebt; break; case "monto a recaudar gastos b": spendB = auxdebt; break; case "monto a recaudar gastos c": spendC = auxdebt; break; case "monto a recaudar gastos d": spendD = auxdebt; break; case "monto a recaudar edesur": edesur = auxdebt; break; case "monto a recaudar aysa": aysa = auxdebt; break; case "monto a recaudar expensas extraordinarias": expensas = auxdebt; break; } } } var alreadyClosed = this.MonthClosed(consortium, endDate.Month); var unitAccount = this.AccountStatusRepository.GetByUnitId(unit.Id).ToList(); var unitPayments = unitAccount.Where(x => x.StatusDate.Year == startDate.Year && x.StatusDate.Month == month && x.IsPayment()).Sum(x => x.Haber); var unitDebt = unitAccount.Where(x => x.StatusDate.Year == previousMonth.Year && x.StatusDate.Month == previousMonth.Month && !x.IsPayment() && !x.Interest).Sum(x => x.Debe); var unitInterest = unitDebt * 2 / 100;// unitAccount.Where(x => x.StatusDate.Year == previousMonth.Year && x.StatusDate.Month == previousMonth.Month && !x.IsPayment() && x.Interest).Sum(x => x.Debe); var currentMonth = spendA + spendB + spendC + spendD + edesur + aysa + expensas; var totalUnitDebt = unitDebt + unitInterest; var discountConfig = consortiumConfig.Where(x => x.Type.Description == "Descuento por pago adelantado").OrderByDescending(x => x.ConfigurationDate).FirstOrDefault(); var discountDateConfig = consortiumConfig.Where(x => x.Type.Description == "Día límite pago adelantado").OrderByDescending(x => x.ConfigurationDate).FirstOrDefault(); if (discountConfig != null && discountDateConfig != null && unitAccount.Any(x => x.IsPayment() && x.StatusDate.Year == startDate.Year && x.StatusDate.Month == month && x.StatusDate.Day < discountDateConfig.Value)) { discount = currentMonth * (discountConfig.Value / 100); } var result = new UnitAccountStatusSummary() { Uf = unit.Number.ToString(), Propietario = unit.Owner != null ? unit.Owner.User.Name + " " + unit.Owner.User.Surname : string.Empty, SaldoAnterior = unitDebt, MesActual = alreadyClosed ? currentMonth : 0, Pagos = unitPayments, Aysa = alreadyClosed ? aysa : 0, Edesur = alreadyClosed ? edesur : 0, Expensas = alreadyClosed ? expensas : 0, GastosA = alreadyClosed ? spendA : 0, GastosB = alreadyClosed ? spendB : 0, GastosC = alreadyClosed ? spendC : 0, GastosD = alreadyClosed ? spendD : 0, Dto = unit.Dto, Piso = unit.Floor.ToString(), SiPagaAntes = alreadyClosed ? discount : 0, Intereses = unitInterest, Total = alreadyClosed ? totalUnitDebt + currentMonth - discount - unitPayments: totalUnitDebt - discount - unitPayments, DiscountDay = discountConfig != null ? discountConfig.ConfigurationDate.Day : (int?)null, DiscountValue = alreadyClosed ? discountConfig != null ? discountConfig.Value : (decimal?)null : 0 }; return(result); }
public ConsortiumBalanceStruct GetBalance(Consortium consortium, IList <UnitAccountStatusSummary> balances, int month) { Velocity.Init(); List <ConsortiumBalanceItem> velocityBalances = new List <ConsortiumBalanceItem>(); foreach (var item in balances) { item.Expensas = item.GastosA + item.GastosB; item.GastosAPercent = GetExpensePencentage(balances.Sum(x => x.GastosA), item.GastosA); item.GastosBPercent = GetExpensePencentage(balances.Sum(x => x.GastosB), item.GastosB); velocityBalances.Add(new ConsortiumBalanceItem { Uf = item.Uf, Piso = item.Piso, Dto = item.Dto, Propietario = item.Propietario, SaldoAnterior = item.SaldoAnterior.ToString("$#,###,##0.00", new CultureInfo("es-AR")), Pagos = item.Pagos.ToString("$#,###,##0.00", new CultureInfo("es-AR")), Deuda = item.MesActual.ToString("$#,###,##0.00", new CultureInfo("es-AR")), Intereses = item.Intereses.ToString("$#,###,##0.00", new CultureInfo("es-AR")), GastosA = item.GastosA.ToString("$#,###,##0.00", new CultureInfo("es-AR")), GastosB = item.GastosB.ToString("$#,###,##0.00", new CultureInfo("es-AR")), Expensas = item.Expensas.ToString("$#,###,##0.00", new CultureInfo("es-AR")), Aysa = item.Aysa.ToString("$#,###,##0.00", new CultureInfo("es-AR")), Edesur = item.Edesur.ToString("$#,###,##0.00", new CultureInfo("es-AR")), SiPagaAntes = item.SiPagaAntes.ToString("$#,###,##0.00", new CultureInfo("es-AR")), Total = item.Total.ToString("$#,###,##0.00", new CultureInfo("es-AR")), DiscountValue = item.DiscountValue != null ? ((decimal)item.DiscountValue).ToString("$#,###,##0.00", new CultureInfo("es-AR")) : "", GastosAPercent = item.GastosAPercent.ToString("#,###,##0.00", new CultureInfo("es-AR")), GastosBPercent = item.GastosBPercent.ToString("#,###,##0.00", new CultureInfo("es-AR")), }); } var fromDate = new DateTime(DateTime.Now.Year, month, 1, 0, 0, 0); var toDate = new DateTime(fromDate.Year, month, fromDate.AddMonths(1).AddDays(-1).Day, 0, 0, 0); var model = new { FromDate = fromDate.ToString("MMM dd", new CultureInfo("es-AR")).ToUpper(), ToDate = toDate.ToString("MMM dd", new CultureInfo("es-AR")).ToUpper(), Month = fromDate.ToString("MMMM", new CultureInfo("es-AR")), Year = fromDate.Year, Consortium = consortium, Balances = velocityBalances, TotalSaldoAnterior = balances.Sum(x => x.SaldoAnterior).ToString("$#,###,##0.00", new CultureInfo("es-AR")), TotalPagos = balances.Sum(x => x.Pagos).ToString("$#,###,##0.00", new CultureInfo("es-AR")), TotalDeuda = balances.Sum(x => x.MesActual).ToString("$#,###,##0.00", new CultureInfo("es-AR")), TotalIntereses = balances.Sum(x => x.Intereses).ToString("$#,###,##0.00", new CultureInfo("es-AR")), TotalGastosA = balances.Sum(x => x.GastosA).ToString("$#,###,##0.00", new CultureInfo("es-AR")), TotalGastosB = balances.Sum(x => x.GastosB).ToString("$#,###,##0.00", new CultureInfo("es-AR")), TotalExpensas = balances.Sum(x => x.Expensas).ToString("$#,###,##0.00", new CultureInfo("es-AR")), TotalAysa = balances.Sum(x => x.Aysa).ToString("$#,###,##0.00", new CultureInfo("es-AR")), TotalEdesur = balances.Sum(x => x.Edesur).ToString("$#,###,##0.00", new CultureInfo("es-AR")), TotalSiPagaAntes = balances.Sum(x => x.SiPagaAntes).ToString("$#,###,##0.00", new CultureInfo("es-AR")), TotalTotal = balances.Sum(x => x.Total).ToString("$#,###,##0.00", new CultureInfo("es-AR")), DiscountDay = balances.First().DiscountDay ?? 0, TotalGastosAPercent = balances.Sum(x => x.GastosAPercent).ToString("#,###,##0.00", new CultureInfo("es-AR")), TotalGastosBPercent = balances.Sum(x => x.GastosBPercent).ToString("#,###,##0.00", new CultureInfo("es-AR")) }; var velocityContext = new VelocityContext(); velocityContext.Put("model", model); var templateFile = string.Format(@"{0}\Resources\ConsortiumBalanceTemplate.html", Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath)); var template = new StringBuilder(File.ReadAllText(templateFile)); var stylesFile = string.Format(@"{0}\Resources\ConsortiumBalance.css", Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath)); var styles = new StringBuilder(File.ReadAllText(stylesFile)); var finalTickets = new StringBuilder(); Velocity.Evaluate(velocityContext, new StringWriter(finalTickets), "Payment Tickets", new StringReader(template.ToString())); return(new ConsortiumBalanceStruct { HtmlBalance = finalTickets, HtmlBalanceStyles = styles }); }
public ExpensesBillStruct GetExpensesBill(Consortium consortium, IList <Spend> expenses, IList <UnitAccountStatusSummary> unitsReport, int month) { Velocity.Init(); foreach (var item in expenses) { item.Bill.FormatedAmount = item.Bill.Amount.ToString("$#,###,##0.00", new CultureInfo("es-AR")); } var salaryItems = expenses.Where(x => x.Type.Item.Description.ToLower().Equals("detalle de sueldo y cargas sociales")).ToList(); decimal salaryTotal = 0; var spendItemDetYSueldos = new List <Spend>(); foreach (var item in salaryItems) { if (item.Description != "Suterh" && item.Description != "Fateryh" && item.Description != "Seracarh") { if (item.Bill.Amount != 0) { salaryTotal += item.SpendClass.Id == 5 ? item.Bill.Amount * -1 : item.Bill.Amount; } spendItemDetYSueldos.Add(item); } } //var spendItemAportesYContr = expenses.Where(x => x.Type.Item.Description.ToLower().Equals("aportes y contribuciones")).ToList(); var spendItemAportesYContr = new List <Spend>(); salaryItems.ForEach(x => { if (x.Description == "Suterh" || x.Description == "Fateryh" || x.Description == "Seracarh") { spendItemAportesYContr.Add(x); } }); var contributionsTotal = spendItemAportesYContr.Sum(x => x.Bill.Amount); var salaryContributionsTotal = salaryTotal + spendItemAportesYContr.Sum(x => x.Bill.Amount); var spendItemServPub = expenses.Where(x => x.Type.Item.Description.ToLower().Equals("servicios públicos")).ToList(); foreach (var item in spendItemServPub) { item.Bill.SimpleExpirationDate = item.Bill.ExpirationDate.ToString("dd/mm/yyyy"); } var publicServicesTotal = spendItemServPub.Sum(x => x.Bill.Amount); var spendItemAbonoServ = expenses.Where(x => x.Type.Item.Description.ToLower().Equals("abono de servicios")).ToList(); var servicePaymentTotal = spendItemAbonoServ.Sum(x => x.Bill.Amount); var spendItemMantPartesComunes = expenses.Where(x => x.Type.Item.Description.ToLower().Equals("mantenimiento de partes comunes")).ToList(); var commonMaintenanceTotal = spendItemMantPartesComunes.Sum(x => x.Bill.Amount); var spendItemRepUnidades = expenses.Where(x => x.Type.Item.Description.ToLower().Equals("trabajo de reparaciones en unidades")).ToList(); var unitRepairsTotal = spendItemRepUnidades.Sum(x => x.Bill.Amount); var spendItemGastosBancarios = expenses.Where(x => x.Type.Item.Description.ToLower().Equals("gastos bancarios")).ToList(); var bankExpensesTotal = spendItemGastosBancarios.Sum(x => x.Bill.Amount); var spendItemGastosLimpieza = expenses.Where(x => x.Type.Item.Description.ToLower().Equals("gastos de limpieza")).ToList(); var cleaningExpensesTotal = spendItemGastosLimpieza.Sum(x => x.Bill.Amount); var spendItemGastosAdmin = expenses.Where(x => x.Type.Item.Description.ToLower().Equals("gastos de administracion")).ToList(); var adminExpensesTotal = spendItemGastosAdmin.Sum(x => x.Bill.Amount); var spendItemPagosSeguros = expenses.Where(x => x.Type.Item.Description.ToLower().Equals("pagos del período de seguros")).ToList(); var insuranceExpensesTotal = spendItemPagosSeguros.Sum(x => x.Bill.Amount); var spendItemOtros = expenses.Where(x => x.Type.Item.Description.ToLower().Equals("otros")).ToList(); var otherExpensesTotal = spendItemOtros.Sum(x => x.Bill.Amount); var total = salaryContributionsTotal + publicServicesTotal + servicePaymentTotal + commonMaintenanceTotal + unitRepairsTotal + bankExpensesTotal + cleaningExpensesTotal + adminExpensesTotal + insuranceExpensesTotal + otherExpensesTotal; var fromDate = new DateTime(DateTime.Now.Year, month, 1, 0, 0, 0); var toDate = new DateTime(fromDate.Year, month, fromDate.AddMonths(1).AddDays(-1).Day, 0, 0, 0); var juicios = consortium.Juicios; var model = new { FromDate = fromDate.ToString("MMM dd", new CultureInfo("es-AR")).ToUpper(), ToDate = toDate.ToString("MMM dd", new CultureInfo("es-AR")).ToUpper(), Month = fromDate.ToString("MMMM", new CultureInfo("es-AR")), Year = fromDate.Year, ConsortiumSuther = consortium.ClaveSuterh, ConsortiumCUIT = consortium.CUIT, ConsortiumName = consortium.FriendlyName, ConsortiumAddress = consortium.Ownership.Address.Street + " " + consortium.Ownership.Address.Number, AdministrationName = consortium.Administration.Name, ConsortiumMail = consortium.MailingList, ConsortiumPhone = consortium.Telephone, AdministrationCUIT = consortium.Administration.CUIT, AdministrationAddress = consortium.Administration.Address.Street + " " + consortium.Administration.Address.Number, ManagerName = consortium.Managers.FirstOrDefault() != null?consortium.Managers.FirstOrDefault().User.Name + " " + consortium.Managers.FirstOrDefault().User.Surname : "", ManagerCUIT = consortium.Managers.FirstOrDefault() != null?consortium.Managers.FirstOrDefault().User.CUIT : "", ManagerAlternate = consortium.Managers.FirstOrDefault()?.IsAlternate, BuildingCategory = consortium.Ownership.Category, ManagerCategory = "1° Categoría", Salary = spendItemDetYSueldos, SalaryTotal = salaryTotal.ToString("$#,###,##0.00", new CultureInfo("es-AR")), SalaryPercent = GetExpensepencentage(total, salaryTotal).ToString("#,###,##0.00", new CultureInfo("es-AR")), Contributions = spendItemAportesYContr, ContributionsTotal = contributionsTotal.ToString("$#,###,##0.00", new CultureInfo("es-AR")), ContributionsPercent = GetExpensepencentage(total, contributionsTotal).ToString("#,###,##0.00", new CultureInfo("es-AR")), SalaryContributionsTotal = salaryContributionsTotal.ToString("$#,###,##0.00", new CultureInfo("es-AR")), SalaryContributionsPercent = GetExpensepencentage(total, salaryContributionsTotal).ToString("#,###,##0.00", new CultureInfo("es-AR")), PublicServices = spendItemServPub, PublicServicesTotal = publicServicesTotal.ToString("$#,###,##0.00", new CultureInfo("es-AR")), PublicServicesPercent = GetExpensepencentage(total, publicServicesTotal).ToString("#,###,##0.00", new CultureInfo("es-AR")), ServicePayment = spendItemAbonoServ, ServicePaymentTotal = servicePaymentTotal.ToString("$#,###,##0.00", new CultureInfo("es-AR")), ServicePaymentPercent = GetExpensepencentage(total, servicePaymentTotal).ToString("#,###,##0.00", new CultureInfo("es-AR")), CommonMaintenance = spendItemMantPartesComunes, CommonMaintenanceTotal = commonMaintenanceTotal.ToString("$#,###,##0.00", new CultureInfo("es-AR")), CommonMaintenancePercent = GetExpensepencentage(total, commonMaintenanceTotal).ToString("#,###,##0.00", new CultureInfo("es-AR")), UnitRepairs = spendItemRepUnidades, UnitRepairsTotal = unitRepairsTotal.ToString("$#,###,##0.00", new CultureInfo("es-AR")), UnitRepairsPercent = GetExpensepencentage(total, unitRepairsTotal).ToString("#,###,##0.00", new CultureInfo("es-AR")), BankExpenses = spendItemGastosBancarios, BankExpensesTotal = bankExpensesTotal.ToString("$#,###,##0.00", new CultureInfo("es-AR")), BankExpensesPercent = GetExpensepencentage(total, bankExpensesTotal).ToString("#,###,##0.00", new CultureInfo("es-AR")), CleaningExpenses = spendItemGastosLimpieza, CleaningExpensesTotal = cleaningExpensesTotal.ToString("$#,###,##0.00", new CultureInfo("es-AR")), CleaningExpensesPercent = GetExpensepencentage(total, cleaningExpensesTotal).ToString("#,###,##0.00", new CultureInfo("es-AR")), AdminExpenses = spendItemGastosAdmin, AdminExpensesTotal = adminExpensesTotal.ToString("$#,###,##0.00", new CultureInfo("es-AR")), AdminExpensesPercent = GetExpensepencentage(total, adminExpensesTotal).ToString("#,###,##0.00", new CultureInfo("es-AR")), InsuranceExpenses = spendItemPagosSeguros, InsuranceExpensesTotal = insuranceExpensesTotal.ToString("$#,###,##0.00", new CultureInfo("es-AR")), InsuranceExpensesPercent = GetExpensepencentage(total, insuranceExpensesTotal).ToString("#,###,##0.00", new CultureInfo("es-AR")), OtherExpenses = spendItemOtros, OtherExpensesTotal = otherExpensesTotal.ToString("$#,###,##0.00", new CultureInfo("es-AR")), OtherExpensesPercent = GetExpensepencentage(total, otherExpensesTotal).ToString("#,###,##0.00", new CultureInfo("es-AR")), TotalDebt = (unitsReport.Sum(x => x.SaldoAnterior) * -1).ToString("$#,###,##0.00", new CultureInfo("es-AR")), TotalInTermsPayments = unitsReport.Sum(x => x.Pagos).ToString("$#,###,##0.00", new CultureInfo("es-AR")), TotalInterest = unitsReport.Sum(x => x.Intereses).ToString("$#,###,##0.00", new CultureInfo("es-AR")), ClosingTotal = (unitsReport.Sum(x => x.Pagos) - unitsReport.Sum(x => x.MesActual) + (unitsReport.Sum(x => x.SaldoAnterior))).ToString("$#,###,##0.00", new CultureInfo("es-AR")), ChargeTotal = (unitsReport.Sum(x => x.Total) * -1).ToString("$#,###,##0.00", new CultureInfo("es-AR")), Juicios = juicios, Total = total.ToString("$#,###,##0.00", new CultureInfo("es-AR")) }; var velocityContext = new VelocityContext(); velocityContext.Put("model", model); var templateFile = string.Format(@"{0}\Resources\ConsortiumExpensesTemplate.html", Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath)); var template = new StringBuilder(File.ReadAllText(templateFile)); var stylesFile = string.Format(@"{0}\Resources\ConsortiumExpenses.css", Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath)); var styles = new StringBuilder(File.ReadAllText(stylesFile)); var finalTickets = new StringBuilder(); Velocity.Evaluate(velocityContext, new StringWriter(finalTickets), "Payment Tickets", new StringReader(template.ToString())); return(new ExpensesBillStruct { HtmlExpenses = finalTickets, HtmlExpensesStyles = styles }); }