示例#1
0
        public QuoteDetailsDto Create(CreateQuoteDetailsDto model, decimal totalPrice)
        {
            var price = new decimal();

            if (model.Currency == "Soles")
            {
                price = totalPrice;
            }
            else
            {
                price = CurrencyConverter(totalPrice);
            }

            decimal tasa     = (_context.LOCs.Single(x => x.LOCId == model.LocId).Rate / 100);
            var     TypeRate = (_context.LOCs.Single(x => x.LOCId == model.LocId).TypeRate);
            decimal newTasa  = ConvertToTea(TypeRate, tasa);

            double  numerobase = 1 + Decimal.ToDouble(newTasa);
            decimal potencia   = Convert.ToDecimal(model.Frecuency) / 360m;

            decimal tasaConvertida = Convert.ToDecimal(Math.Pow(numerobase, Decimal.ToDouble(potencia)) - 1);

            decimal e     = Convert.ToDecimal(Math.Pow((1 + Decimal.ToDouble(tasaConvertida)), model.NumberQuotes));
            decimal quote = price * ((tasaConvertida * e) / (e - 1));

            List <Quote> cuotas          = new List <Quote>();
            decimal      Total           = 0m;
            var          primerDiaDePago = DateTime.Today;

            for (int i = 0; i < model.NumberQuotes; i++)
            {
                var ultimoDiaDePago = primerDiaDePago.AddDays(model.Frecuency);
                quote = Math.Round(quote, 1);
                cuotas.Add(new Quote {
                    Value = quote, FirstPaidDay = primerDiaDePago, LastPaidDay = ultimoDiaDePago
                });
                primerDiaDePago = ultimoDiaDePago.AddDays(model.Frecuency);
                Total          += quote;
            }



            var entry = new QuoteDetail
            {
                NumberQuotes = model.NumberQuotes,
                Frecuency    = model.Frecuency,
                InterestRate = tasa,
                Currency     = model.Currency,
                LocId        = model.LocId,
                Quotes       = cuotas,
                Debt         = cuotas[0].Value,
                LastTotal    = Total,
            };

            _context.QuoteDetails.Add(entry);
            _context.SaveChanges();

            return(_mapper.Map <QuoteDetailsDto>(entry));
        }
示例#2
0
        public ActionResult Create(CreateQuoteDetailsDto QuoteDetail, int orderId)
        {
            var result = _quoteDetailService.Create(QuoteDetail, orderId);

            return(CreatedAtAction(
                       "GetById",
                       new { id = result.QuoteDetailsId },
                       result
                       ));
        }
示例#3
0
        public void PrepareLoc(Order order, CreateQuoteDetailsDto entry)
        {
            var customer = _context.Customers.Single(x => x.CustomerId == order.CustomerId);
            var loc      = _context.LOCs.Single(x => x.CustomerId == customer.CustomerId);

            if (loc.AvalibleLineOfCredit > order.TotalPrice)
            {
                loc.AvalibleLineOfCredit -= order.TotalPrice;
                _quoteDetailService.Create(new CreateQuoteDetailsDto {
                    Frecuency = entry.Frecuency, LocId = loc.LOCId, NumberQuotes = entry.NumberQuotes, Currency = entry.Currency
                }, order.TotalPrice);
                DecreaseStock(order);
                _transactionService.Create(new TransactionCreateDto {
                    CustomerId = customer.CustomerId, Description = "La orden ha sido creada correctamente", Status = "Accepted"
                });
            }
            else
            {
                _transactionService.Create(new TransactionCreateDto {
                    CustomerId = customer.CustomerId, Description = "No hay suficiente dinero disponible en la linea de credito", Status = "Rejected"
                });
            }
        }