Ejemplo n.º 1
0
        public void AplicarMora(int condicion, int cuota)
        {
            Mora Mo = new Mora();

            string FechaInicio           = "";
            int    cuota2                = 0;
            float  auxCuota              = 0;
            int    cantidad              = 0;
            float  CantidadCuotaPrestamo = 0; //ESTA ES LA CANTIDAD DE $ CUOTA REGITRADA EN EL PRESTAMO



            DataTable dt  = new DataTable();
            DataTable dt2 = new DataTable();

            dt  = Utilitario.Lista(" FechaInicio,Cuota", " from Prestamo ", " where PrestamoId = " + tbxPrestamo.Text);
            dt2 = Utilitario.Lista(" Max(Fecha) as Fecha ", " from Abono ", " where PrestamoId  = " + tbxPrestamo.Text);


            FechaInicio = Utilitario.FormatoFecha(dt.Rows[0]["FechaInicio"].ToString());
            DateTime DateFechaInicio = Convert.ToDateTime(FechaInicio);

            cuota2 = Convert.ToInt32(dt.Rows[0]["Cuota"].ToString());

            string valortbla = dt2.Rows[0]["Fecha"].ToString();

            if (valortbla != string.Empty)      // ESTA CONDICIO ES SI HAY ABONO REGISTRADA PARA COMPARAR APARTIR DE AHI
            {
                DateTime FechaUltimaCuota = Convert.ToDateTime(dt2.Rows[0]["Fecha"].ToString());

                auxCuota = Utilitario.Cuota(cuota, DateTime.Now, DateFechaInicio);
            }
            else
            {
                auxCuota = Utilitario.Cuota(cuota, DateTime.Now, DateFechaInicio); //ES ES SI HAY RETRASO APARTIR DEL DIA DEL PRESTAMO
            }

            cantidad = CantidadCuota(auxCuota, cuota2);


            Mo.ClienteId  = Convert.ToInt32(tbxCliente.Text);
            Mo.PrestamoId = Convert.ToInt32(tbxPrestamo.Text);
            Mo.Fecha      = Utilitario.FormatoFecha(DateTime.Now.ToString());

            CantidadCuotaPrestamo = Convert.ToSingle(tbxCuota.Text);

            int UsuarioId = Utilitario.ObtenerIdUsuarioAdm(Convert.ToInt32(Session["UsuarioCoId"]));   //AQUI HAY QUE EXTRAER EL USUARIO

            if (cantidad == 0)
            {
                Mo.Cantidad    = CantidadCuotaPrestamo + Utilitario.PorcientoMora(CantidadCuotaPrestamo, UsuarioId); //AQUI SE MULTIPICA EL PORCIENTO DE LA MORA + LA CUOTA
                tbxAtraso.Text = Mo.Cantidad.ToString("N2");
            }
            else
            {
                Mo.Cantidad    = CantidadCuotaPrestamo + Utilitario.PorcientoMora(CantidadCuotaPrestamo, UsuarioId) * cantidad; //AQUI SE MULTIPICA EL PORCIENTO DE LA MORA + LA CUOTA X LA CANTIDAD DE TIEMPO DE CUOTA
                tbxAtraso.Text = Mo.Cantidad.ToString("N2");
            }


            if (condicion == 0)
            {
                Mo.Insertar("MoraAcumulada");
            }
            else
            {
                //ESTO ES PARA NO BORRAR LA FECHA DESDE CUANDO COMENZO A ACUMULAR MORA
                dt2 = Utilitario.Lista(" Fecha ", " from MoraAcumulada ", " where PrestamoId  = " + tbxPrestamo.Text);

                if (Utilitario.ValidarTabla(dt2))
                {
                    Mo.Fecha = Utilitario.FormatoFecha(dt2.Rows[0]["Fecha"].ToString());
                    Mo.Actualizar("MoraAcumulada");
                }
            }
        }