Exemple #1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            int  dia  = dtFechaInicial.Value.Day;
            int  mes  = dtFechaInicial.Value.Month;
            int  ano  = dtFechaInicial.Value.Year;
            int  tipo = ValidacionesCL.ValidarDiaPagoIndex(cmbDiaPago.SelectedItem.ToString());
            bool ValidacionQuincena = ValidacionesCL.validarQuincena(dia, mes, ano, tipo);

            // COMPRUEBA SI EL DIA DE PAGO NO ES QUINCENA
            if (ValidacionQuincena == false)
            {
                if (dtgCuotas.RowCount > 0)
                {
                    if (txtMonto.Text == "" || txtInteres.Text == "" || txtCuotas.Text == "")
                    {
                        MessageBox.Show("Rellene todos los campos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        PrestamosCL        oPrestamos        = new PrestamosCL();
                        Prestamos_CuotasCL oPrestamos_Cuotas = new Prestamos_CuotasCL();

                        double saldo = total;

                        oPrestamos.InsertarPrestamo(numeroPrestamo, dtFecha.Value, cliente, monto, interes, Convert.ToInt32(txtCuotas.Text), saldo, total, false, tipo);

                        foreach (DataRow item in cuotasGeneradas)
                        {
                            oPrestamos_Cuotas.InsertarPrestamo_Cuotas(

                                numeroPrestamo,
                                Convert.ToInt32(item.ItemArray[0]),
                                Convert.ToDateTime(item.ItemArray[1]),
                                Convert.ToInt32(item.ItemArray[2]),
                                Convert.ToInt32(item.ItemArray[3])

                                );
                        }

                        if (oPrestamos.IsError)
                        {
                            MessageBox.Show(oPrestamos.ErrorDescripcion, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            MessageBox.Show("Prestamo creado con exito", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            prestamos.CargarPrestamos();
                            this.Dispose();
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Genere primero las cuotas antes de crear un prestamo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #2
0
        // PROCESA LAS CUOTAS CON SU RESPECTIVA MODIFICACION DE FECHAS
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            // REVISA SI EL DATAGRID TIENE CUOTAS
            if (dtgCuotasPrevias.Rows.Count > 0)
            {
                Prestamos_CuotasCL oCuotas    = new Prestamos_CuotasCL();
                PrestamosCL        oPrestamos = new PrestamosCL();

                for (int i = 0; i < dtgCuotasPrevias.Rows.Count; i++)
                {
                    double monto = Convert.ToDouble(dtgCuotasPrevias["montoPre", i].Value);
                    double saldo = Convert.ToDouble(dtgCuotasPrevias["saldoPre", i].Value);



                    // ESTE IF COMPRUEBA LAS CUOTAS QUE SE DEBEN EDITAR
                    if (i < dtgCuotas.Rows.Count)
                    {
                        int id = Convert.ToInt32(dtgCuotasPrevias["idPre", i].Value);

                        oCuotas.EditarPrestamoCuotas_RecargoPrestamo(id, monto, saldo);
                    }
                    else
                    {
                        // AGREGA NUEVAS CUOTAS AL PRESTAMO COMO PARTE DE UN RECARGO
                        int      num_cuota     = Convert.ToInt32(dtgCuotasPrevias["num_cuotaPre", i].Value);
                        DateTime fecha_pactada = Convert.ToDateTime(dtgCuotasPrevias["fecha_pactadaPre", i].Value);

                        oCuotas.InsertarPrestamo_Cuotas(prestamo, num_cuota, fecha_pactada, monto, saldo);
                    }
                }

                if (oCuotas.IsError)
                {
                    MessageBox.Show(oCuotas.ErrorDescripcion, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    // CALCULA EL NUEVO SALDO DEL PRESTAMO
                    double oSaldoPrestamo = saldoPrestamo + Convert.ToDouble(txtMonto.Text);

                    // EDITA EL PRESTAMO AGREGANDOLE UN NUEVO SALDO Y ESTABLECIENDOLO COMO TIPO RECARGO
                    oPrestamos.EditarPrestamo_Recargo(prestamo, oSaldoPrestamo, totalPrestamo, true);

                    if (oPrestamos.IsError)
                    {
                        MessageBox.Show(oPrestamos.ErrorDescripcion, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show("Recargo creado con exito", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ofrmPrestamos.CargarPrestamos();
                        this.Dispose();
                    }
                }
            }
            else
            {
                MessageBox.Show("Debes generar primero la previsualización de cuotas", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            var dia  = dtFechaInicial.Value.Day;
            var mes  = dtFechaInicial.Value.Month;
            var ano  = dtFechaInicial.Value.Year;
            var tipo = ValidacionesCL.ValidarDiaPagoIndex(cmbDiaPago.SelectedItem.ToString());
            var validacionQuincena = ValidacionesCL.validarQuincena(dia, mes, ano, tipo);

            if (_dCuotasGeneradas == null || _dCuotasGeneradas.Rows.Count == 0)
            {
                MessageBox.Show("Debe hacer clic en Generar previsualización para poder procesar la edición", "Información", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }



            if (validacionQuincena == false)
            {
                var countErrors   = 0;
                var oCuotas       = new Prestamos_CuotasCL();
                var oPlanilla     = new PlanillaCL();
                var oAbonosCuotas = new Abonos_CuotasCL();


                foreach (DataRow item in _dCuotas.Rows)
                {
                    var id = item["id"].ToString();

                    // ELIMINAR ABONOS DE UNA CUOTA
                    oAbonosCuotas.EliminarAbono_Cuotas_Id_Cuota(id);

                    // ELIMINA DETALLE DE PLANILLA REFERENTE A UNA CUOTA
                    oPlanilla.EliminarPlanillaDetalle(id);

                    // ELIMINAR LA CUOTA
                    oCuotas.EliminarCuota(id);

                    if (oCuotas.IsError)
                    {
                        countErrors++;
                    }
                }

                foreach (DataRow item in _dCuotasGeneradas.Rows)
                {
                    // INSERTA NUEVAS CUOTAS
                    oCuotas.InsertarPrestamo_Cuotas(
                        _prestamoId,
                        Convert.ToInt32(item["Numero couta"].ToString()),
                        Convert.ToDateTime(item["Fecha de pago"].ToString()),
                        Convert.ToDouble(item["Monto"].ToString()),
                        Convert.ToDouble(item["Saldo"].ToString()));

                    if (oCuotas.IsError)
                    {
                        countErrors++;
                    }
                }

                if (countErrors > 0)
                {
                    MessageBox.Show("Se presentaron errores al editar las cuotas", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Préstamo modificado con éxito", "Información", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    this.Dispose();
                }
            }
        }