Ejemplo n.º 1
0
 private void btnProcesar_Click(object sender, EventArgs e)
 {
     if (this.dtgPrestamosCuotas.Rows.Count != 0)
     {
         PrestamosCL        prestamosCL        = new PrestamosCL();
         Prestamos_CuotasCL prestamos_CuotasCL = new Prestamos_CuotasCL();
         Abonos_CuotasCL    abonos_CuotasCL    = new Abonos_CuotasCL();
         PlanillaCL         planillaCL         = new PlanillaCL();
         if (this.ValidarPago())
         {
             if (this.ObtenerFechaPago())
             {
                 foreach (DataGridViewRow dataGridViewRow in dtgPrestamosCuotas.Rows)
                 {
                     int       num        = Convert.ToInt32(dataGridViewRow.Cells["Prestamos_cuotas_id"].Value.ToString());
                     int       id         = Convert.ToInt32(dataGridViewRow.Cells["Prestamo"].Value.ToString());
                     DataSet   dataSet    = prestamosCL.TraerPrestamoSaldo(id.ToString());
                     DataTable dataTable  = dataSet.Tables[0];
                     DataRow   dataRow    = dataTable.Rows[0];
                     double    num2       = (double)Convert.ToInt32(dataRow.ItemArray.GetValue(0).ToString());
                     DataSet   dataSet2   = abonos_CuotasCL.TraerSuma_Abonos(dataGridViewRow.Cells["Prestamos_cuotas_id"].Value.ToString());
                     DataTable dataTable2 = dataSet2.Tables[0];
                     DataRow   dataRow2   = dataTable2.Rows[0];
                     if (!string.IsNullOrEmpty(dataRow2.ItemArray.GetValue(0).ToString()))
                     {
                         double num3  = Convert.ToDouble(dataRow2.ItemArray.GetValue(0).ToString());
                         double monto = (double)Convert.ToInt32(dataGridViewRow.Cells["Monto"].Value.ToString()) - num3;
                         abonos_CuotasCL.InsertarAbono_Cuotas(num, monto, this.fechaPago);
                         num2 -= (double)Convert.ToInt32(dataGridViewRow.Cells["Monto"].Value.ToString()) - num3;
                     }
                     else
                     {
                         num2 -= (double)Convert.ToInt32(dataGridViewRow.Cells["Monto"].Value.ToString());
                     }
                     prestamosCL.EditarPrestamo(id, num2);
                     prestamos_CuotasCL.EditarPrestamoCuotas(num, this.fechaPago, true, "");
                 }
                 planillaCL.EditarPlanilla(Convert.ToInt32(this.numPlanilla), true);
                 if (planillaCL.IsError)
                 {
                     MessageBox.Show(planillaCL.ErrorDescripcion, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                 }
                 else
                 {
                     MessageBox.Show("Planilla procesada con exito", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                     this.iPlanilla.CargarPlanilla("");
                     base.Dispose();
                 }
             }
         }
         else
         {
             MessageBox.Show(this.errores, "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
     }
     else
     {
         MessageBox.Show("No hay cuotas que procesar", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
Ejemplo n.º 2
0
        private void eliminarAbonoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listAbonosCuotas.CheckedItems.Count == 0)
            {
                MessageBox.Show("Debes marcar en la casila los abonos que deseas eliminar", "Informacion", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            }
            else
            {
                DialogResult opcion = MessageBox.Show("Desea eliminar los siguientes abonos marcados", "Informacion", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);


                double saldo = 0;

                // ELIMINA LOS ABONOS MARCADS CON EL CHECK
                if (opcion == DialogResult.OK)
                {
                    Abonos_CuotasCL oAbonos = new Abonos_CuotasCL();

                    Prestamos_CuotasCL oCuotas = new Prestamos_CuotasCL();

                    oCuotas.EditarPrestamoCuotas(cuota, Convert.ToDateTime(null), false, "eliminar");



                    foreach (ListViewItem item in listAbonosCuotas.Items)
                    {
                        if (item.Checked)
                        {
                            oAbonos.EliminarAbono_Cuotas_Id(lAbonos.Rows[item.Index].ItemArray[0].ToString());

                            saldo += Convert.ToDouble(lAbonos.Rows[item.Index].ItemArray[2]);
                        }
                    }
                }

                EditarSaldoPrestamo(saldo);

                LimpiarValores();

                CargarAbonos(cuota);

                abonos.CargarPrestamos();
            }
        }
Ejemplo n.º 3
0
        private void btnEliminarAbono_Click(object sender, EventArgs e)
        {
            // COMPRUEBA SI LA CUOTA TIENE UN PAGO REGISTRADO
            if (Convert.ToBoolean(dtgCuotas["pago", dtgCuotas.CurrentCell.RowIndex].Value.ToString()) == true)
            {
                DialogResult opcion = MessageBox.Show("Esta seguro de eliminar este abono", "Advertencia", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                // SI EL USUARIO DIGITA SI EN EL DIALOGO ENTONCES PROCEDE A ELIMINAR EL ABONO
                if (opcion == DialogResult.Yes)
                {
                    // INSTANCIAS
                    Prestamos_CuotasCL oCuotas    = new Prestamos_CuotasCL();
                    Abonos_CuotasCL    oAbonos    = new Abonos_CuotasCL();
                    PrestamosCL        oPrestamos = new PrestamosCL();

                    StringBuilder errores    = new StringBuilder();
                    int           idPrestamo = Convert.ToInt32(dtgPrestamos["idPrestamo", dtgPrestamos.CurrentCell.RowIndex].Value.ToString());
                    double        saldo      = Convert.ToInt32(dtgPrestamos["saldoPrestamo", dtgPrestamos.CurrentCell.RowIndex].Value.ToString());

                    foreach (DataGridViewRow dtg in dtgCuotas.SelectedRows)
                    {
                        // ELIMINA SOLO LOS ABONOS QUE HAN SIDO PAGADOS
                        if (Convert.ToBoolean(dtg.Cells["pago"].Value) == true)
                        {
                            // EDITAMOS PRESTAMO CUOTAS
                            oCuotas.EditarPrestamoCuotas(
                                Convert.ToInt32(dtg.Cells["id"].Value.ToString()),
                                Convert.ToDateTime(null),
                                false,
                                "eliminar"
                                );

                            // ELIMINA LOS ABONOS DE LA CUOTA
                            oAbonos.EliminarAbono_Cuotas_Id_Cuota(dtg.Cells["id"].Value.ToString());

                            // CALCULA EL NUEVO SALDO
                            saldo += Convert.ToInt32(dtg.Cells["monto_cuota"].Value.ToString());

                            // SI ENCUENTRA ERRORES
                            if (oCuotas.IsError)
                            {
                                errores.AppendLine(oCuotas.ErrorDescripcion);
                            }
                        }
                    }


                    // EDITA EL PRESTAMO
                    oPrestamos.EditarPrestamo(idPrestamo, saldo);

                    // GUARDA LA POSICION DEL PRESTAMO EN EL DATAGRID
                    int prestamoSelecion = dtgPrestamos.CurrentCell.RowIndex;

                    // LLAMA AL METODO CARGAR PRESTAMO
                    CargarPrestamos();

                    //ESTABLECE LA SELECION DEL PRESTAMO EN EL DATAGRID
                    dtgPrestamos.CurrentCell = dtgPrestamos.Rows[prestamoSelecion].Cells[0];

                    if (errores.Length == 0)
                    {
                        MessageBox.Show("Abono eliminado con exito", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            else
            {
                // EN CASO DE QUE LA CUOTA NO TUVIERA PAGOS REGISTRADOS
                MessageBox.Show("Esta cuota no tiene registros de pagos que eliminar", "Información", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 4
0
        public void PagoCuotas()
        {
            // INSTANCIAS
            oPrestamosCuotas = new Prestamos_CuotasCL();

            oPrestamos = new PrestamosCL();

            oAbonosCuotas = new Abonos_CuotasCL();

            // VARIABLE CONTIENE SALDO DEL PRESTAMO
            saldo = Convert.ToDouble(oPrestamos.TraerPrestamoSaldo(Convert.ToString(Prestamo)).Tables[0].Rows[0].ItemArray[0]);

            double saldoActual = saldo;

            double MontoAbono = Convert.ToDouble(txtMonto.Text);

            if (Abonos.dtgCuotas["num_cuota", 0].Value.ToString() != "0")
            {
                NumCuota -= 1;
            }


            for (int i = NumCuota; i < Abonos.dtgCuotas.Rows.Count; i++)
            {
                Monto = Convert.ToDouble(Abonos.dtgCuotas["monto_cuota", i].Value.ToString());

                DataSet oAbonosSuma = oAbonosCuotas.TraerSuma_Abonos(Abonos.dtgCuotas["id", i].Value.ToString());

                saldo = Convert.ToDouble(Abonos.dtgCuotas["saldo", i].Value.ToString());

                NumCuota     = Convert.ToInt32(Abonos.dtgCuotas["num_cuota", i].Value.ToString());
                fechaPactada = Convert.ToDateTime(Abonos.dtgCuotas["fecha_pactada", i].Value.ToString());


                DataSet oAbonosCantidad = oAbonosCuotas.TraerCantidad_Abonos(Abonos.dtgCuotas["id", i].Value.ToString());

                // TERMINA EL PAGO DE CUOTAS
                if (MontoAbono <= 0 || saldoActual <= 0)
                {
                    break;
                }

                if (oAbonosCantidad.Tables[0].Rows.Count > 0)
                {
                    double totalAbonos = Convert.ToDouble(oAbonosSuma.Tables[0].Rows[0].ItemArray.GetValue(0));

                    double totalFaltante = Monto - totalAbonos;

                    if (MontoAbono >= totalFaltante)
                    {
                        saldoActual -= totalFaltante;

                        oPrestamos.EditarPrestamo(Prestamo, saldoActual);

                        oAbonosCuotas.InsertarAbono_Cuotas(
                            Convert.ToInt32(Abonos.dtgCuotas["id", i].Value.ToString()),
                            totalFaltante,
                            dtFechaPago.Value);

                        oPrestamosCuotas.EditarPrestamoCuotas(
                            Convert.ToInt32(Abonos.dtgCuotas["id", i].Value.ToString()),
                            dtFechaPago.Value,
                            true,
                            null);

                        MontoAbono -= totalFaltante;

                        mensajeImpresion();
                    }
                    else
                    {
                        saldoActual -= MontoAbono;

                        oAbonosCuotas.InsertarAbono_Cuotas(
                            Convert.ToInt32(Abonos.dtgCuotas["id", i].Value.ToString()),
                            MontoAbono,
                            dtFechaPago.Value);

                        oPrestamos.EditarPrestamo(Prestamo, saldoActual);

                        MontoAbono -= MontoAbono;
                    }
                }
                else
                {
                    // PAGA LA CUOTA O CUOTAS
                    if (MontoAbono >= Monto)
                    {
                        saldoActual -= Monto;

                        oPrestamos.EditarPrestamo(Prestamo, saldoActual);

                        oPrestamosCuotas.EditarPrestamoCuotas(
                            Convert.ToInt32(Abonos.dtgCuotas["id", i].Value.ToString()),
                            dtFechaPago.Value,
                            true,
                            null);

                        MontoAbono -= Monto;

                        mensajeImpresion();
                    }
                    else
                    {
                        saldoActual -= MontoAbono;

                        oAbonosCuotas.InsertarAbono_Cuotas(
                            Convert.ToInt32(Abonos.dtgCuotas["id", i].Value.ToString()),
                            MontoAbono,
                            dtFechaPago.Value);

                        oPrestamos.EditarPrestamo(Prestamo, saldoActual);

                        MontoAbono -= MontoAbono;
                    }
                }
            }



            //  DialogResult opcion = MessageBox.Show("El monto es mayor al pactado \nDesea pagar esta cuota y abonar el resto a las demas cuotas?", "Informacion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        }