Exemplo n.º 1
0
        public ConsortiumConfiguration GetByTypeDescription(int consortiumId, string description)
        {
            var ConsortiumConfiguration = ConsortiumConfigurationRepository
                                          .GetAll().Where(x => x.Consortium.Id == consortiumId && x.Type.Description == description)
                                          .OrderByDescending(x => x.ConfigurationDate)
                                          .FirstOrDefault();

            return(ConsortiumConfiguration);

            ;
            if (ConsortiumConfiguration == null)
            {
                throw new BadRequestException(ErrorMessages.GastoNoEncontrado);
            }

            return(ConsortiumConfiguration);
        }
Exemplo n.º 2
0
        public IList <ConsortiumConfiguration> GetAll()
        {
            var ConsortiumConfigurations = ConsortiumConfigurationRepository.GetAll();

            if (ConsortiumConfigurations == null)
            {
                throw new BadRequestException(ErrorMessages.GastoNoEncontrado);
            }

            var result     = new List <ConsortiumConfiguration>();
            var enumerator = ConsortiumConfigurations.GetEnumerator();

            while (enumerator.MoveNext())
            {
                result.Add(enumerator.Current);
            }
            return(result);
        }
Exemplo n.º 3
0
        public AccountStatus CreateAccountStatus(AccountStatusRequest AccountStatus)
        {
            var entityToInsert = new AccountStatus()
            {
            };

            MergeAccountStatus(entityToInsert, AccountStatus);

            if (entityToInsert.IsPayment())
            {
                var unit       = UnitRepository.GetById(AccountStatus.UnitId);
                var consortium = ConsortiumRepository.GetAll().Where(x => x.Ownership.Id == unit.Ownership.Id).FirstOrDefault();

                var dateDay = AccountStatus.StatusDate.Day;
                var limitDateConfiguration = ConsortiumConfigurationRepository
                                             .GetAll().Where(x => x.Consortium.Id == consortium.Id && x.Type.Description == "Día límite pago adelantado")
                                             .OrderByDescending(x => x.ConfigurationDate)
                                             .FirstOrDefault();

                var limitDayValue = limitDateConfiguration != null?Convert.ToInt32(limitDateConfiguration.Value) : 0;

                if (dateDay <= limitDayValue)
                {
                    var advancedPaymentConfiguration = ConsortiumConfigurationRepository
                                                       .GetAll().Where(x => x.Consortium.Id == consortium.Id && x.Type.Description == "Descuento por pago adelantado")
                                                       .OrderByDescending(x => x.ConfigurationDate)
                                                       .FirstOrDefault();


                    var advandedPaymentValue = advancedPaymentConfiguration != null ? advancedPaymentConfiguration.Value : 0;

                    this.RecalculateAmount(entityToInsert, advandedPaymentValue);
                }
            }

            AccountStatusRepository.Insert(entityToInsert);

            if (entityToInsert.IsPayment())
            {
                var payment = new Payment()
                {
                    AccountStatus = entityToInsert,
                    PaymentType   = PaymentTypeRepository.GetById(AccountStatus.PaymentTypeId.Value)
                };

                PaymentRepository.Insert(payment);

                var unit       = UnitRepository.GetById(AccountStatus.UnitId);
                var consortium = ConsortiumRepository.GetAll().Where(x => x.Ownership.Id == unit.Ownership.Id).FirstOrDefault();

                var actualPatrimonyStatus = this.PatrimonyStatusRepository.GetByConsortiumId(consortium.Id)
                                            .OrderByDescending(x => x.StatusDate).FirstOrDefault();


                var patrimonyStatus = new PatrimonyStatus()
                {
                    Activo     = actualPatrimonyStatus != null ? actualPatrimonyStatus.Activo + entityToInsert.Haber : entityToInsert.Haber,
                    Debe       = 0,
                    Pasivo     = actualPatrimonyStatus != null ? actualPatrimonyStatus.Pasivo - entityToInsert.Haber : -entityToInsert.Haber,
                    Haber      = entityToInsert.Haber,
                    Consortium = consortium,
                    StatusDate = DateTime.Now
                };

                this.PatrimonyStatusRepository.Insert(patrimonyStatus);

                //modificar el ultimo estado de cuenta
                var unitAccount          = this.AccountStatusRepository.GetByUnitId(unit.Id).ToList();
                var lastSummarizedStatus = unitAccount.Where(x => !x.IsPayment() && !x.Interest).OrderByDescending(x => x.StatusDate).FirstOrDefault();
                lastSummarizedStatus.Haber += entityToInsert.Haber;
                lastSummarizedStatus.Debe  -= entityToInsert.Haber;

                this.AccountStatusRepository.Update(lastSummarizedStatus);
            }


            return(entityToInsert);
        }