public ActionResult guardarPrestamo()
        {
            int prestamoID = 0;

            try {
                PrestamoEntidad prestamo = (PrestamoEntidad)Session["prestamoactual"];
                List <DetallePrestamoEntidad> listaDetallePrestamo = (List <DetallePrestamoEntidad>)Session["listadetalleprestamoactual"];
                Boolean verificacionprestamo = PrestamoServicio.Instancia.GuardarPrestamo(prestamo, ref prestamoID);
                if (verificacionprestamo)
                {
                    prestamo.prestamoID = prestamoID;

                    DetallePrestamoServicio.Instancia.ActualizarLista(ref listaDetallePrestamo, prestamo);
                    Boolean verificaciondetalles = DetallePrestamoServicio.Instancia.GuardarDetallePrestamo(listaDetallePrestamo);
                    if (verificaciondetalles)
                    {
                        ViewBag.verificacionguardar = "TRUE";
                    }
                    else
                    {
                        ViewBag.verificacionguardar = "FALSE";
                    }
                }
                else
                {
                    ViewBag.verificacionguardar = "FALSE";
                }
                return(View());
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public List <DetallePrestamoEntidad> GenerarCronograma(PrestamoEntidad pr)
        {
            List <DetallePrestamoEntidad> listadetalleprestamo    = new List <DetallePrestamoEntidad>();
            DetallePrestamoEntidad        detallePrestamoAnterior = null;


            for (int x = 0; x <= pr.prestamo_cuotas; x++)
            {
                DetallePrestamoEntidad detallePrestamoExistente = null;

                if (x == 0)
                {
                    detallePrestamoExistente = GenerarPrimeraCuota(pr.monto_prestado);
                }
                else
                {
                    detallePrestamoExistente = GenerarCuota(x, pr.tasa_efectiva_mensual, pr.cuota_fija_mensual, detallePrestamoAnterior);
                }
                detallePrestamoExistente.prestamoID = pr;
                detallePrestamoAnterior             = detallePrestamoExistente;

                listadetalleprestamo.Add(detallePrestamoExistente);
            }


            return(listadetalleprestamo);
        }
Esempio n. 3
0
        public Boolean TienePrestamoActivo(String dni)
        {
            SqlCommand      cmd      = null;
            PrestamoEntidad prestamo = new PrestamoEntidad();
            Boolean         esValidoPrestamo;

            try
            {
                SqlConnection cn = Conexion.Instancia.Conectar();
                cmd             = new SqlCommand("sp_tienePrestamoActivo", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("clienteDNI", dni);
                cn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    esValidoPrestamo = false;
                }
                else
                {
                    esValidoPrestamo = true;
                }
            }catch (Exception e)
            {
                throw e;
            }
            finally { cmd.Connection.Close(); }
            return(esValidoPrestamo);
        }
        public ActionResult pagarCuota(int id)
        {
            ClienteEntidad         cliente  = (ClienteEntidad)Session["clientebuscado"];
            PrestamoEntidad        prestamo = PrestamoServicio.Instancia.RetornarPrestamo(cliente.clienteID);
            DetallePrestamoEntidad cuota    = DetallePrestamoServicio.Instancia.RetornaDetallePrestamo(prestamo, id);

            try
            {
                Boolean pagado = DetallePrestamoServicio.Instancia.PagarCuota(cuota);
                if (pagado)
                {
                    if (!cuota.esUltimaCuota())
                    {
                        return(RedirectToAction("mostrarPrestamo", new { id = cliente.cliente_DNI }));
                    }
                    else
                    {
                        TempData["msj"] = "<script>alert('Todas las cuotas han sido pagadas');</script>";
                        return(RedirectToAction("buscarCliente"));
                    }
                }
                else
                {
                    return(View("Error"));
                }
            }catch (Exception e)
            {
                throw e;
            }
        }
        public void Agregar(Prestamo prestamo)
        {
            PrestamoEntidad prestamoEntidad = BuildPrestamoEntidad(prestamo);

            bibliotecaContexto.Prestamos.Add(prestamoEntidad);
            bibliotecaContexto.SaveChanges();
        }
Esempio n. 6
0
        public DetallePrestamoEntidad RetornaCuotaAPagar(PrestamoEntidad prestamo)
        {
            SqlCommand             cmd             = null;
            DetallePrestamoEntidad detalleprestamo = new DetallePrestamoEntidad();

            try
            {
                SqlConnection cn = Conexion.Instancia.Conectar();
                cmd             = new SqlCommand("sp_retornaCuotaAPagar", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@prestamoID", prestamo.prestamoID);
                cn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                dr.Read();



                detalleprestamo.detalleprestamoID        = Convert.ToInt16(dr["detalleprestamoID"]);
                detalleprestamo.detprestamo_nro_cuota    = Convert.ToInt16(dr["detprest_nro_cuota"]);
                detalleprestamo.detprestamo_monto_cuota  = Convert.ToDouble(dr["detprest_monto_cuota"]);
                detalleprestamo.detprestamo_interes      = Convert.ToDouble(dr["detprest_interes"]);
                detalleprestamo.detprestamo_amortizacion = Convert.ToDouble(dr["detprest_amortizacion"]);
                detalleprestamo.detprestamo_saldo        = Convert.ToDouble(dr["detprest_saldo"]);
                detalleprestamo.prestamoID = prestamo;
            }catch (Exception e)
            {
                throw e;
            }
            finally { cmd.Connection.Close(); }
            return(detalleprestamo);
        }
        public ActionResult generarCronogramaPost()
        {
            Session["prestamoactual"]             = null;
            Session["listadetalleprestamoactual"] = null;
            List <DetallePrestamoEntidad> cronograma = new List <DetallePrestamoEntidad>();
            ClienteEntidad  cliente  = (ClienteEntidad)Session["clientebuscado"];
            PrestamoEntidad prestamo = new PrestamoEntidad();

            prestamo.clienteID           = cliente;
            prestamo.monto_prestado      = Double.Parse(Request.Form["prestamo_monto"]);
            prestamo.prestamo_cuotas     = int.Parse(Request.Form["prestamo_nro_cuotas"]);
            prestamo.tasa_efectiva_anual = Double.Parse(Request.Form["prestamo_tea"]);
            prestamo.CalcularTasaEfectivaMensual();
            prestamo.CalcularCuotaFijaMensual();
            prestamo.prestamo_fecha = DateTime.Now;
            try
            {
                Boolean verificacion = prestamo.VerificarPrestamo();
                if (verificacion)
                {
                    cronograma = DetallePrestamoServicio.Instancia.GenerarCronograma(prestamo);
                    Session["prestamoactual"]             = prestamo;
                    Session["listadetalleprestamoactual"] = cronograma;
                    return(View("generarCronograma", cronograma));
                }
                else
                {
                    return(RedirectToAction("generarCronograma"));
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public void TestMontoCorrecto()
        {
            Double monto = 1000;

            PrestamoEntidad prestamo = new PrestamoEntidad();

            prestamo.monto_prestado = monto;
            Boolean expResult = true;
            Boolean result    = prestamo.MontoCorrecto();

            Assert.AreEqual(expResult, result);
        }
        private PrestamoEntidad BuildPrestamoEntidad(Prestamo prestamo)
        {
            LibroEntidad libroEntidad = libroRepositorio.ObtenerLibroEntidadPorIsbn(prestamo.Libro.Isbn);

            PrestamoEntidad prestamoEntidad = new PrestamoEntidad
            {
                LibroEntidad   = libroEntidad,
                FechaSolicitud = prestamo.FechaSolicitud,
            };

            return(prestamoEntidad);
        }
Esempio n. 10
0
        private PrestamoEntidad BuildPrestamoEntidad(Prestamo prestamo)
        {
            LibroEntidad libroEntidad = libroRepositorio.ObtenerLibroEntidadPorIsbn(prestamo.Libro.Isbn);

            PrestamoEntidad prestamoEntidad = new PrestamoEntidad
            {
                LibroEntidad       = libroEntidad,
                FechaSolicitud     = prestamo.FechaSolicitud,
                NombreUsuario      = prestamo.NombreUsuario,
                FechaEntregaMaxima = prestamo.FechaEntregaMaxima
            };

            return(prestamoEntidad);
        }
 public ActionResult mostrarPrestamo(String id)
 {
     try
     {
         ClienteEntidad  cliente  = ClienteServicio.Instancia.RetornarCliente(id);
         PrestamoEntidad prestamo = PrestamoServicio.Instancia.RetornarPrestamo(cliente.clienteID);
         List <DetallePrestamoEntidad> listadetalleprestamo = DetallePrestamoServicio.Instancia.RetornaListaDetallePrestamo(prestamo);
         DetallePrestamoEntidad        cuotapagar           = DetallePrestamoServicio.Instancia.RetornaCuotaAPagar(prestamo);
         return(View(Tuple.Create(listadetalleprestamo, cuotapagar)));
     }catch (Exception e)
     {
         throw e;
     }
 }
Esempio n. 12
0
 public void Agregar(Prestamo prestamo)
 {
     try
     {
         PrestamoEntidad prestamoEntidad = BuildPrestamoEntidad(prestamo);
         bibliotecaContexto.Prestamos.Add(prestamoEntidad);
         bibliotecaContexto.SaveChanges();
     }
     catch (ArgumentException e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Esempio n. 13
0
        public Prestamo Obtener(string isbn)
        {
            Prestamo        prestamo        = null;
            PrestamoEntidad prestamoEntidad = ObtenerPrestamoEntidadPorIsbn(isbn);

            if (prestamoEntidad != null)
            {
                prestamo = new Prestamo(
                    prestamoEntidad.FechaSolicitud,
                    LibroBuilder.ConvertirADominio(prestamoEntidad.LibroEntidad),
                    prestamoEntidad.FechaEntregaMaxima, prestamoEntidad.NombreUsuario
                    );
            }
            return(prestamo);
        }
Esempio n. 14
0
        private PrestamoEntidad BuildPrestamoEntidad(Prestamo prestamo)
        {
            if (EsPalindromo(prestamo.Libro.Isbn))
            {
                throw new ArgumentException("Los libros palíndromos solo se pueden utilizar en la biblioteca");
            }
            LibroEntidad libroEntidad = libroRepositorio.ObtenerLibroEntidadPorIsbn(prestamo.Libro.Isbn);

            PrestamoEntidad prestamoEntidad = new PrestamoEntidad
            {
                LibroEntidad   = libroEntidad,
                FechaSolicitud = prestamo.FechaSolicitud,
            };

            return(prestamoEntidad);
        }
Esempio n. 15
0
        public List <DetallePrestamoEntidad> RetornaListaDetallePrestamo(PrestamoEntidad prestamo)
        {
            SqlCommand cmd = null;
            List <DetallePrestamoEntidad> listadetalleentidad = new List <DetallePrestamoEntidad>();

            try
            {
                SqlConnection cn = Conexion.Instancia.Conectar();
                cmd             = new SqlCommand("sp_retornaListaDetallePrestamo", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@prestamoID", prestamo.prestamoID);
                cn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    DetallePrestamoEntidad detalleprestamo = new DetallePrestamoEntidad();
                    detalleprestamo.detalleprestamoID        = Convert.ToInt16(dr["detalleprestamoID"]);
                    detalleprestamo.detprestamo_nro_cuota    = Convert.ToInt16(dr["detprest_nro_cuota"]);
                    detalleprestamo.detprestamo_monto_cuota  = Convert.ToDouble(dr["detprest_monto_cuota"]);
                    detalleprestamo.detprestamo_interes      = Convert.ToDouble(dr["detprest_interes"]);
                    detalleprestamo.detprestamo_amortizacion = Convert.ToDouble(dr["detprest_amortizacion"]);
                    detalleprestamo.detprestamo_saldo        = Convert.ToDouble(dr["detprest_saldo"]);
                    detalleprestamo.prestamoID = prestamo;
                    if (dr["pagoID"] != DBNull.Value)
                    {
                        PagoEntidad pago = new PagoEntidad();
                        pago.pagoID            = Convert.ToInt16(dr["pagoID"]);
                        pago.pago_fechapago    = Convert.ToDateTime(dr["pago_fechapago"]);
                        pago.pago_nro_cuota    = Convert.ToInt16(dr["pago_nro_cuota"]);
                        pago.pago_activo       = Convert.ToBoolean(dr["pago_activo"]);
                        detalleprestamo.pagoID = pago;
                    }



                    listadetalleentidad.Add(detalleprestamo);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally { cmd.Connection.Close(); }
            return(listadetalleentidad);
        }
        /// <summary>
        /// Metodo para guardar toda la informacion relacionada al prestamo que se realiza.
        /// </summary>
        /// <param name="prestamo"></param>
        /// <returns></returns>
        private PrestamoEntidad BuildPrestamoEntidad(Prestamo prestamo)
        {
            LibroEntidad libroEntidad = libroRepositorio.ObtenerLibroEntidadPorIsbn(prestamo.Libro.Isbn);

            PrestamoEntidad prestamoEntidad = new PrestamoEntidad
            {
                LibroEntidad = new LibroEntidad {
                    Anio   = prestamo.Libro.Anio,
                    Isbn   = prestamo.Libro.Isbn,
                    Titulo = prestamo.Libro.Titulo,
                    Id     = (int)prestamo.FechaSolicitud.Ticks
                },
                FechaSolicitud     = prestamo.FechaSolicitud,
                FechaEntregaMaxima = prestamo.FechaEntregaMaxima,
                NombreUsuario      = prestamo.NombreUsuario
            };

            return(prestamoEntidad);
        }
Esempio n. 17
0
        public PrestamoEntidad RetornarPrestamo(int clienteID)
        {
            SqlCommand      cmd      = null;
            PrestamoEntidad prestamo = new PrestamoEntidad();

            try
            {
                SqlConnection cn = Conexion.Instancia.Conectar();
                cmd             = new SqlCommand("sp_retornaPrestamo", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("clienteID", clienteID);
                cn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                dr.Read();
                prestamo.prestamoID            = Convert.ToInt16(dr["prestamoID"]);
                prestamo.monto_prestado        = Convert.ToDouble(dr["monto_prestado"]);
                prestamo.tasa_efectiva_anual   = Convert.ToDouble(dr["tasaefec_anual"]);
                prestamo.tasa_efectiva_mensual = Convert.ToDouble(dr["tasaefec_mensual"]);
                prestamo.cuota_fija_mensual    = Convert.ToDouble(dr["cuotafija_mensual"]);
                prestamo.prestamo_cuotas       = Convert.ToInt16(dr["prestamo_cuotas"]);
                prestamo.prestamo_fecha        = Convert.ToDateTime(dr["prestamo_fecha"]);
                prestamo.prestamo_activo       = Convert.ToBoolean(dr["prestamo_activo"]);
                prestamo.prestamo_completo     = Convert.ToBoolean(dr["prestamo_completo"]);
                ClienteEntidad cliente = new ClienteEntidad();
                cliente.clienteID               = Convert.ToInt16(dr["clienteID"]);
                cliente.cliente_nombres         = dr["cliente_nombres"].ToString();
                cliente.cliente_apellidos       = dr["cliente_apellidos"].ToString();
                cliente.cliente_DNI             = dr["cliente_DNI"].ToString();
                cliente.cliente_direccion       = dr["cliente_direccion"].ToString();
                cliente.cliente_celular         = dr["cliente_celular"].ToString();
                cliente.cliente_fechanacimiento = Convert.ToDateTime(dr["cliente_fechanacimiento"]);
                cliente.cliente_activo          = Convert.ToBoolean(dr["cliente_activo"]);
                prestamo.clienteID              = cliente;
            }
            catch (Exception e)
            {
                throw e;
            }
            finally { cmd.Connection.Close(); }
            return(prestamo);
        }
Esempio n. 18
0
        public Boolean GuardarPrestamo(PrestamoEntidad prestamo, ref int prestamoID)
        {
            SqlCommand cmd            = null;
            Boolean    guardaprestamo = false;

            try
            {
                SqlConnection cn = Conexion.Instancia.Conectar();
                cmd = new SqlCommand("sp_guardarPrestamo", cn)
                {
                    CommandType = CommandType.StoredProcedure
                };
                cmd.Parameters.AddWithValue("@monto_prestado", prestamo.monto_prestado);
                cmd.Parameters.AddWithValue("@tasaefec_anual", prestamo.tasa_efectiva_anual);
                cmd.Parameters.AddWithValue("@tasaefec_mensual", prestamo.tasa_efectiva_mensual);
                cmd.Parameters.AddWithValue("@cuotafija_mensual", prestamo.cuota_fija_mensual);
                cmd.Parameters.AddWithValue("@prestamo_cuotas", prestamo.prestamo_cuotas);
                cmd.Parameters.AddWithValue("@prestamo_fecha", prestamo.prestamo_fecha.ToString("yyyy-MM-ddTHH:mm:ss.fff"));
                cmd.Parameters.AddWithValue("@clienteID", prestamo.clienteID.clienteID);
                //cmd.Parameters.AddWithValue("@usuarioID", prestamo.usuarioID.usuarioID);
                SqlParameter outParam = new SqlParameter();
                outParam.SqlDbType     = System.Data.SqlDbType.Int;
                outParam.ParameterName = "@prestamoID";
                outParam.Value         = 0;
                outParam.Direction     = System.Data.ParameterDirection.Output;
                cmd.Parameters.Add(outParam);
                cn.Open();
                int i = cmd.ExecuteNonQuery();
                prestamoID = (int)cmd.Parameters["@prestamoID"].Value;
                if (i > 0)
                {
                    guardaprestamo = true;
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally { cmd.Connection.Close(); }
            return(guardaprestamo);
        }
 public List <DetallePrestamoEntidad> RetornaListaDetallePrestamo(PrestamoEntidad prestamo)
 {
     return(DetallePrestamoDAO.Instancia.RetornaListaDetallePrestamo(prestamo));
 }
 public void ActualizarLista(ref List <DetallePrestamoEntidad> listadesactualizada, PrestamoEntidad prestamo)
 {
     foreach (DetallePrestamoEntidad p in listadesactualizada)//ACTUALIZA EL PRESTAMO EN LA LISTA CON EL VALOR COMPLETO DE PRESTAMO
     {
         p.prestamoID = prestamo;
     }
 }
 public DetallePrestamoEntidad RetornaCuotaAPagar(PrestamoEntidad prestamo)
 {
     return(DetallePrestamoDAO.Instancia.RetornaCuotaAPagar(prestamo));
 }
 public DetallePrestamoEntidad RetornaDetallePrestamo(PrestamoEntidad prestamo, int id)
 {
     return(DetallePrestamoDAO.Instancia.RetornaDetallePrestamo(prestamo, id));
 }
        public Libro ObtenerLibroPrestadoPorIsbn(string isbn)
        {
            PrestamoEntidad prestamoEntidad = ObtenerPrestamoEntidadPorIsbn(isbn);

            return(LibroBuilder.ConvertirADominio(prestamoEntidad != null ? prestamoEntidad.LibroEntidad : null));
        }
Esempio n. 24
0
        public Prestamo Obtener(string isbn)
        {
            PrestamoEntidad prestamoEntidad = ObtenerPrestamoEntidadPorIsbn(isbn);

            return(new Prestamo(prestamoEntidad.FechaSolicitud, LibroBuilder.ConvertirADominio(prestamoEntidad.LibroEntidad), prestamoEntidad.NombreUsuario));
        }
Esempio n. 25
0
 public Boolean GuardarPrestamo(PrestamoEntidad prestamo, ref int prestamoID)
 {
     return(PrestamoDAO.Instancia.GuardarPrestamo(prestamo, ref prestamoID));
 }