public async Task Should_Load_InvoiceClientCorrectly()
        {
            try
            {
                var facturas = new FACTURAS();

                using (var connection = _sqlExecutor.OpenNewDbConnection())
                {
                    var clientes = await connection.GetPagedAsync <FACTURAS>(10, 10);

                    var    singleClient = clientes.FirstOrDefault();
                    string query        = string.Format("SELECT * FROM FACTURAS WHERE CLIENTE_FAC='{0}'", singleClient.CLIENTE_FAC);
                    // 0000253
                    facturas = await connection.QueryFirstAsync <FACTURAS>(query);
                }

                var singleInvoiceData = await _invoiceDataService.GetDoAsync(facturas.NUMERO_FAC);

                Assert.NotNull(singleInvoiceData);
                Assert.IsNotInstanceOf <NullInvoice>(singleInvoiceData);
                Assert.AreEqual(facturas.NUMERO_FAC, singleInvoiceData.Value.NUMERO_FAC);
                Assert.Greater(singleInvoiceData.ClientSummary.Count(), 0);
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }
        }
Exemple #2
0
        public void Actualizar_Montos()
        {
            BD_JSYSEntities  db          = new BD_JSYSEntities();
            FACTURAS         obj_factura = new FACTURAS();
            DETALLES_CUOTAS  obj_detalle = new DETALLES_CUOTAS();
            RECIBOS_COBRADOS obj_recibo  = new RECIBOS_COBRADOS();

            //actualizar detalle cxc
            if (ch_pago_total.Checked == true)
            {
                obj_detalle.MONTO_PAGADO    = Convert.ToDecimal(txt_monto_cuota.Text);
                obj_detalle.MONTO_PENDIENTE = 0;
                obj_recibo.VALOR_PAGADO     = Convert.ToDecimal(txt_monto_cuota.Text);
                obj_factura.MONTO_PAGADO    = Convert.ToDecimal(txt_monto_cuota.Text);
                obj_recibo.VALOR_PENDIENTE  = 0;
            }
            else if (ch_pago_total.Checked == false && Convert.ToDecimal(txt_valor_a_pagar.Text) >= Convert.ToDecimal(txt_monto_cuota.Text))
            {
                obj_detalle.MONTO_PAGADO    = Convert.ToDecimal(txt_monto_cuota.Text);
                obj_detalle.MONTO_PENDIENTE = 0;
                obj_recibo.VALOR_PAGADO     = Convert.ToDecimal(txt_monto_cuota.Text);
                obj_factura.MONTO_PAGADO    = Convert.ToDecimal(txt_monto_cuota.Text);
                obj_recibo.VALOR_PENDIENTE  = 0;
            }
            else if (ch_pago_total.Checked == false && Convert.ToDecimal(txt_valor_a_pagar.Text) < Convert.ToDecimal(txt_monto_cuota.Text))
            {
                obj_detalle.MONTO_PAGADO    = Convert.ToDecimal(txt_valor_a_pagar.Text);
                obj_detalle.MONTO_PENDIENTE = Convert.ToDecimal(txt_monto_cuota.Text) - Convert.ToDecimal(txt_valor_a_pagar.Text);
                obj_recibo.VALOR_PAGADO     = Convert.ToDecimal(txt_valor_a_pagar.Text);
                obj_factura.MONTO_PAGADO    = Convert.ToDecimal(txt_valor_a_pagar.Text);
                obj_recibo.VALOR_PENDIENTE  = Convert.ToDecimal(txt_monto_cuota.Text) - Convert.ToDecimal(txt_valor_a_pagar.Text);
            }

            obj_detalle.NUMERO_CUOTA = Convert.ToInt32(txt_no_cuota.Text);
            obj_detalle.ID_FACTURA   = Convert.ToInt32(txt_no_factura.Text);
            S_Factura.Cobrar_Cuota(obj_detalle);

            //insertar recibo
            obj_recibo.ANULADO_POR = "";
            obj_recibo.CREADO_POR  = S_Utilidades.Datos_Usuario.USUARIO;
            int ID_FACTURA     = Convert.ToInt32(txt_no_factura.Text);
            var obj_encabezado = db.ENCABEZADO_CUOTAS.Where(a => a.ID_FACTURA == ID_FACTURA).Single();

            obj_recibo.CANTIDAD_CUOTAS = obj_encabezado.CANTIADA_CUOTA;
            obj_recibo.CUOTA_COBRADA   = Convert.ToInt32(txt_no_cuota.Text);
            obj_recibo.ESTADO          = "V";
            obj_recibo.FECHA_ANULADO   = "";
            obj_recibo.FECHA_CREADO    = DateTime.Now;
            obj_recibo.ID_FACTURA      = ID_FACTURA;
            var obj_fact = db.FACTURAS.Where(f => f.ID_FACTURA == ID_FACTURA).Single();

            obj_recibo.NOTA_ANULACION = "";
            obj_recibo.VALOR_CUOTA    = Convert.ToDecimal(txt_monto_cuota.Text);
            S_Factura.Insertar_Recibo_Cobros(obj_recibo);

            //actualizar monto factura
            obj_factura.ID_FACTURA = ID_FACTURA;
            S_Factura.Actualizar_Montos_Factura(obj_factura);
        }
Exemple #3
0
        public void Recibir_Datos(FACTURAS obj)
        {
            using (var db = new BD_JSYSEntities())
            {
                //factura
                var obj_factura = db.FACTURAS.Find(obj.ID_FACTURA);
                txt_numero_factura.Text   = obj_factura.ID_FACTURA.ToString();
                txt_observacion.Text      = obj_factura.OBSERVACION;
                txt_total.Text            = obj_factura.MONTO_TOTAL.ToString("N2");
                cb_cliente.SelectedValue  = obj_factura.REFERENCIA;
                cb_cobrador.SelectedValue = obj_factura.ID_COBRADOR;
                cb_estado.SelectedValue   = obj_factura.ID_ESTADO;
                cb_numero_loteria.Text    = obj_factura.NUMERO_LOTERIA;
                txt_monto_pendiente.Text  = obj_factura.MONTO_PENDIENTE.ToString("N2");
                txt_garantia_1.Text       = obj_factura.GARANTIA1;
                txt_garantia_2.Text       = obj_factura.GARANTIA2;
                txt_garantia_3.Text       = obj_factura.GARANTIA3;
                txt_garantia_4.Text       = obj_factura.GARANTIA4;
                txt_garantia_5.Text       = obj_factura.GARANTIA5;
                txt_garantia_6.Text       = obj_factura.GARANTIA6;
                txt_garantia_7.Text       = obj_factura.GARANTIA7;
                txt_monto_pagado.Text     = obj_factura.MONTO_PAGADO.ToString("N2");
                txt_descuento.Text        = obj_factura.MONTO_DESCONTADO == null ? "0" : ((decimal)(obj_factura.MONTO_DESCONTADO)).ToString("N2");
                cb_ruta.Text = obj_factura.RUTA;

                if (cb_estado.Text != "Activo")
                {
                    cb_estado.Enabled       = false;
                    txt_observacion.Enabled = false;
                    btn_guardar.Enabled     = false;
                    groupBox1.Enabled       = false;
                    groupBox2.Enabled       = false;
                    groupBox3.Enabled       = false;
                    groupBox4.Enabled       = false;
                    groupBox6.Enabled       = false;
                    groupBox7.Enabled       = false;
                    cb_ruta.Enabled         = false;
                }

                groupBox6.Enabled = false;

                //encabezado cuotas
                var encabezado = db.ENCABEZADO_CUOTAS.Where(e => e.ID_FACTURA == obj_factura.ID_FACTURA).Single();
                cb_modo_calculo.Text        = encabezado.MODO_CALCULO;
                txt_cantidad_cuota.Text     = encabezado.CANTIADA_CUOTA.ToString();
                dt_fecha_primera_cuota.Text = encabezado.FECHA_PRIMERA_CUOTA.ToString();

                //detalle cuotas
                List <E_Detalles_Cuota> Lista_Cuotas = S_Factura.Listar_Detalles_Cuotas("A.ID_FACTURA=" + obj_factura.ID_FACTURA + " AND A.RE_CALCULADO='NO'");
                dg_detalle_cuotas.Rows.Clear();
                foreach (E_Detalles_Cuota p in Lista_Cuotas)
                {
                    dg_detalle_cuotas.Rows.Add(p.NUMERO_CUOTA, p.FECHA.ToString("dd/MM/yyyy"), p.MONTO_CUOTA);
                }
                dg_detalle_cuotas.DataSource = null;
            }
        }
Exemple #4
0
        private void btn_anular_Click(object sender, EventArgs e)
        {
            if (DG.Rows.Count == 0)
            {
                return;
            }
            if (txt_observacion.Text == "")
            {
                S_Utilidades.Mensaje_Informacion("La Observación es Obligatoria");
                return;
            }
            DialogResult Resultado = MessageBox.Show("Deseas Anular Recibo(s)", "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (Resultado == DialogResult.Yes)
            {
                FACTURAS         obj_factura = new FACTURAS();
                DETALLES_CUOTAS  obj_detelle = new DETALLES_CUOTAS();
                RECIBOS_COBRADOS obj_recibo  = new RECIBOS_COBRADOS();

                foreach (DataGridViewRow row in DG.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[6].Value) == true)
                    {
                        int     id_factura   = Convert.ToInt32(row.Cells[2].Value);
                        decimal valor_pagado = Convert.ToDecimal(row.Cells[4].Value);

                        obj_factura.ID_FACTURA   = id_factura;
                        obj_factura.MONTO_PAGADO = valor_pagado;
                        S_Factura.Actualizar_Montos_Factura_Recibo_Anulado(obj_factura);

                        obj_detelle.ID_FACTURA   = id_factura;
                        obj_detelle.NUMERO_CUOTA = Convert.ToInt32(row.Cells[3].Value);
                        obj_detelle.MONTO_PAGADO = valor_pagado;
                        S_Factura.Anular_Detalle_Cuota(obj_detelle);

                        obj_recibo.ID_RECIBO      = Convert.ToInt32(row.Cells[0].Value);
                        obj_recibo.ESTADO         = "A";
                        obj_recibo.FECHA_ANULADO  = DateTime.Now.ToString();
                        obj_recibo.ANULADO_POR    = S_Utilidades.Datos_Usuario.USUARIO;
                        obj_recibo.NOTA_ANULACION = txt_observacion.Text.Trim();
                        S_Factura.Anular_Recibo(obj_recibo);
                    }
                }

                S_Utilidades.Mensaje_Informacion("Recibos Anulados Correctamente");
                Close();
            }
        }
Exemple #5
0
        /// <inheritdoc />
        /// <summary>
        ///  Generate a new identifier.
        /// </summary>
        /// <returns>Returns an unique identifier.</returns>
        public string NewId()
        {
            var uniqueId = string.Empty;

            using (var dbConnection = SqlExecutor.OpenNewDbConnection())
            {
                if (dbConnection == null)
                {
                    return(uniqueId);
                }
                var facturas = new FACTURAS();
                uniqueId = dbConnection.UniqueId <FACTURAS>(facturas);
            }

            return(uniqueId);
        }
Exemple #6
0
        public void Pasar_Datos()
        {
            if (DG.RowCount == 0)
            {
                return;
            }
            FACTURAS obj = new FACTURAS();

            obj.ID_FACTURA = Convert.ToInt32(DG.SelectedCells[0].Value);
            Frm_Factura frm = new Frm_Factura();

            frm.Recibir_Datos(obj);
            frm.Titulo("Editar Factura");
            frm.Closed += new EventHandler(frm_Closed);
            frm.ShowDialog();
        }
Exemple #7
0
        public void Cambiar_Estado()
        {
            FACTURAS obj_factura = new FACTURAS();

            if (cb_estado.Text == "Activo")
            {
                return;
            }
            obj_factura.ID_FACTURA          = Convert.ToInt32(txt_numero_factura.Text);
            obj_factura.ID_ESTADO           = Convert.ToInt32(cb_estado.SelectedValue);
            obj_factura.CAMBIO_ESTADO_POR   = S_Utilidades.Datos_Usuario.USUARIO;
            obj_factura.FECHA_CAMBIO_ESTADO = DateTime.Now.ToString("dd/MM/yyyy");
            obj_factura.NOTA_CAMBIO_ESTADO  = txt_observacion.Text.Trim();
            S_Factura.Cambiar_Estado_Factura(obj_factura);


            S_Utilidades.Mensaje_Informacion("Datos Actualizados con Exito");
            Close();
        }
Exemple #8
0
        public static bool agregarFactura(FACTURAS factura)
        {
            try
            {
                SQLSentencia peticion = new SQLSentencia();
                peticion.Peticion = @"EXEC SP_AGREGAR_FACTURA @idCliente,@idCaja,@numeroFactura,@fecha, @descripcion,@total,@tipoPago,@estado";
                SqlParameter paramIdCliente = new SqlParameter();
                paramIdCliente.Value         = factura.ID_Cliente;
                paramIdCliente.ParameterName = "@idCliente";
                paramIdCliente.SqlDbType     = System.Data.SqlDbType.Int;

                SqlParameter paramIdCaja = new SqlParameter();
                paramIdCaja.Value         = factura.ID_Caja;
                paramIdCaja.ParameterName = "@idCaja";
                paramIdCaja.SqlDbType     = System.Data.SqlDbType.Int;

                SqlParameter paramnumeroFactura = new SqlParameter();
                paramnumeroFactura.Value         = factura.Numero_Factura;
                paramnumeroFactura.ParameterName = "@numeroFactura";
                paramnumeroFactura.SqlDbType     = System.Data.SqlDbType.Int;


                SqlParameter paramFecha = new SqlParameter();
                paramFecha.Value         = factura.Fecha;
                paramFecha.ParameterName = "@fecha";
                paramFecha.SqlDbType     = System.Data.SqlDbType.Date;

                SqlParameter paramdescripcion = new SqlParameter();
                paramdescripcion.Value         = factura.Descripcion;
                paramdescripcion.ParameterName = "@descripcion";
                paramdescripcion.SqlDbType     = System.Data.SqlDbType.VarChar;

                SqlParameter paramtotal = new SqlParameter();
                paramtotal.Value         = factura.Total;
                paramtotal.ParameterName = "@total";
                paramtotal.SqlDbType     = System.Data.SqlDbType.Decimal;

                SqlParameter paramtipoPago = new SqlParameter();
                paramtipoPago.Value         = factura.Tipo_Pago;
                paramtipoPago.ParameterName = "@tipoPago";
                paramtipoPago.SqlDbType     = System.Data.SqlDbType.TinyInt;

                SqlParameter paramestado = new SqlParameter();
                paramestado.Value         = factura.Estado;
                paramestado.ParameterName = "@estado";
                paramestado.SqlDbType     = System.Data.SqlDbType.Int;



                peticion.lstParametros.Add(paramIdCliente);
                peticion.lstParametros.Add(paramIdCaja);
                peticion.lstParametros.Add(paramnumeroFactura);
                peticion.lstParametros.Add(paramFecha);
                peticion.lstParametros.Add(paramdescripcion);
                peticion.lstParametros.Add(paramtotal);
                peticion.lstParametros.Add(paramtipoPago);
                peticion.lstParametros.Add(paramestado);

                DA acceso = new DA();
                return(acceso.ejecutarSentecia(peticion));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #9
0
        public static void Cambiar_Estado_Factura(FACTURAS obj)
        {
            D_Factura Metodo = new D_Factura();

            Metodo.Cambiar_Estado_Factura(obj);
        }
Exemple #10
0
        public static void Actualizar_Factura(FACTURAS obj)
        {
            D_Factura Metodo = new D_Factura();

            Metodo.Actualizar(obj);
        }
Exemple #11
0
        public static void Insertar_Factura(FACTURAS obj)
        {
            D_Factura Metodo = new D_Factura();

            Metodo.Insertar_Factura(obj);
        }
Exemple #12
0
        public static void Actualizar_Montos_Factura_Recibo_Anulado(FACTURAS obj)
        {
            D_Factura Metodo = new D_Factura();

            Metodo.Actualizar_Montos_Factura_Recibo_Anulado(obj);
        }
Exemple #13
0
        public void Actualizar()
        {
            try
            {
                BD_JSYSEntities db = new BD_JSYSEntities();
                //insertar_factura
                FACTURAS obj_factura = new FACTURAS();
                obj_factura.ID_FACTURA       = Convert.ToInt32(txt_numero_factura.Text);
                obj_factura.ID_COBRADOR      = Convert.ToInt32(cb_cobrador.SelectedValue);
                obj_factura.ID_ESTADO        = Convert.ToInt32(cb_estado.SelectedValue);
                obj_factura.MONTO_TOTAL      = Convert.ToDecimal(txt_total.Text);
                obj_factura.NUMERO_LOTERIA   = cb_numero_loteria.Text;
                obj_factura.OBSERVACION      = txt_observacion.Text.Trim();
                obj_factura.GARANTIA1        = txt_garantia_1.Text.Trim();
                obj_factura.GARANTIA2        = txt_garantia_2.Text.Trim();
                obj_factura.GARANTIA3        = txt_garantia_3.Text.Trim();
                obj_factura.GARANTIA4        = txt_garantia_4.Text.Trim();
                obj_factura.GARANTIA5        = txt_garantia_5.Text.Trim();
                obj_factura.GARANTIA6        = txt_garantia_6.Text.Trim();
                obj_factura.GARANTIA7        = txt_garantia_7.Text.Trim();
                obj_factura.RUTA             = cb_ruta.Text;
                obj_factura.MONTO_DESCONTADO = Convert.ToDecimal(txt_descuento.Text);

                var factura = db.FACTURAS.Where(f => f.ID_FACTURA == obj_factura.ID_FACTURA).SingleOrDefault();
                if ((factura.FECHA_DESCUENTO == null || factura.FECHA_DESCUENTO.ToString() == "") && obj_factura.MONTO_DESCONTADO > 0)
                {
                    obj_factura.FECHA_DESCUENTO = DateTime.Now;
                }
                else
                {
                    obj_factura.FECHA_DESCUENTO = factura.FECHA_DESCUENTO;
                }
                S_Factura.Actualizar_Factura(obj_factura);

                if (cb_recalcular.Text == "Si")
                {
                    //insertar encabezado cuota
                    ENCABEZADO_CUOTAS obj_encabezado_cuota = new ENCABEZADO_CUOTAS();
                    obj_encabezado_cuota.CANTIADA_CUOTA      = Convert.ToInt32(txt_cantidad_cuota.Text);
                    obj_encabezado_cuota.ID_FACTURA          = Convert.ToInt32(txt_numero_factura.Text);
                    obj_encabezado_cuota.MODO_CALCULO        = cb_modo_calculo.Text;
                    obj_encabezado_cuota.FECHA_PRIMERA_CUOTA = dt_fecha_primera_cuota.Value;
                    S_Factura.Actualizar_Encabezado_Cuota(obj_encabezado_cuota);

                    //insertar detalles cuotas
                    S_Factura.Eliminar_Cuotas(Convert.ToInt32(txt_numero_factura.Text));



                    DETALLES_CUOTAS obj_detalle = new DETALLES_CUOTAS();

                    obj_detalle.ID_FACTURA   = Convert.ToInt32(txt_numero_factura.Text);
                    obj_detalle.RE_CALCULADO = "SI";

                    S_Factura.Actualizar_Cuotas(obj_detalle);

                    foreach (DataGridViewRow row in dg_detalle_cuotas.Rows)
                    {
                        DETALLES_CUOTAS obj_detalle_cuotas = new DETALLES_CUOTAS();

                        obj_detalle_cuotas.ID_FACTURA      = Convert.ToInt32(txt_numero_factura.Text);
                        obj_detalle_cuotas.NUMERO_CUOTA    = Convert.ToInt32(row.Cells[0].Value);
                        obj_detalle_cuotas.FECHA           = Convert.ToDateTime(row.Cells[1].Value);
                        obj_detalle_cuotas.MONTO_CUOTA     = Convert.ToDecimal(row.Cells[2].Value);
                        obj_detalle_cuotas.MONTO_PAGADO    = 0;
                        obj_detalle_cuotas.MONTO_PENDIENTE = Convert.ToDecimal(row.Cells[2].Value);
                        obj_detalle_cuotas.RE_CALCULADO    = "NO";
                        S_Factura.Insertar_Detalle_Cuota(obj_detalle_cuotas);
                    }
                }

                Close();
            }
            catch (Exception ex)
            {
                S_Utilidades.Mensaje_Error(ex.Message);
            }
        }
Exemple #14
0
        public void Insertar()
        {
            try
            {
                //insertar_factura
                FACTURAS obj_factura = new FACTURAS();
                obj_factura.CREADO_POR          = S_Utilidades.Datos_Usuario.USUARIO;
                obj_factura.CAMBIO_ESTADO_POR   = "";
                obj_factura.FECHA               = dt_fecha_factura.Value;
                obj_factura.FECHA_CAMBIO_ESTADO = "";
                obj_factura.FECHA_CREADO        = DateTime.Now;
                obj_factura.REFERENCIA          = cb_cliente.SelectedValue.ToString();
                obj_factura.ID_COBRADOR         = Convert.ToInt32(cb_cobrador.SelectedValue);
                obj_factura.ID_ESTADO           = Convert.ToInt32(cb_estado.SelectedValue);
                obj_factura.MONTO_PAGADO        = 0;
                obj_factura.MONTO_PENDIENTE     = Convert.ToDecimal(txt_total.Text);
                obj_factura.MONTO_TOTAL         = Convert.ToDecimal(txt_total.Text);
                obj_factura.NOTA_CAMBIO_ESTADO  = "";
                obj_factura.NUMERO_LOTERIA      = cb_numero_loteria.Text;
                obj_factura.OBSERVACION         = txt_observacion.Text.Trim();
                obj_factura.GARANTIA1           = txt_garantia_1.Text.Trim();
                obj_factura.GARANTIA2           = txt_garantia_2.Text.Trim();
                obj_factura.GARANTIA3           = txt_garantia_3.Text.Trim();
                obj_factura.GARANTIA4           = txt_garantia_4.Text.Trim();
                obj_factura.GARANTIA5           = txt_garantia_5.Text.Trim();
                obj_factura.GARANTIA6           = txt_garantia_6.Text.Trim();
                obj_factura.GARANTIA7           = txt_garantia_7.Text.Trim();
                obj_factura.MONTO_DESCONTADO    = 0;
                obj_factura.RUTA = cb_ruta.Text;
                S_Factura.Insertar_Factura(obj_factura);

                BD_JSYSEntities db = new BD_JSYSEntities();

                //obtener ultimo numero de factura
                int id_factura = db.FACTURAS.Max(m => m.ID_FACTURA);


                //insertar encabezado cuota
                ENCABEZADO_CUOTAS obj_encabezado_cuota = new ENCABEZADO_CUOTAS();
                obj_encabezado_cuota.CANTIADA_CUOTA      = Convert.ToInt32(txt_cantidad_cuota.Text);
                obj_encabezado_cuota.ID_FACTURA          = id_factura;
                obj_encabezado_cuota.MODO_CALCULO        = cb_modo_calculo.Text;
                obj_encabezado_cuota.FECHA_PRIMERA_CUOTA = dt_fecha_primera_cuota.Value;
                S_Factura.Insertar_Encabezado_Cuota(obj_encabezado_cuota);

                //insertar detalles cuotas
                foreach (DataGridViewRow row in dg_detalle_cuotas.Rows)
                {
                    DETALLES_CUOTAS obj_detalle_cuotas = new DETALLES_CUOTAS();

                    obj_detalle_cuotas.ID_FACTURA      = id_factura;
                    obj_detalle_cuotas.NUMERO_CUOTA    = Convert.ToInt32(row.Cells[0].Value);
                    obj_detalle_cuotas.FECHA           = Convert.ToDateTime(row.Cells[1].Value);
                    obj_detalle_cuotas.MONTO_CUOTA     = Convert.ToDecimal(row.Cells[2].Value);
                    obj_detalle_cuotas.MONTO_PAGADO    = 0;
                    obj_detalle_cuotas.MONTO_PENDIENTE = Convert.ToDecimal(row.Cells[2].Value);
                    obj_detalle_cuotas.RE_CALCULADO    = "NO";
                    S_Factura.Insertar_Detalle_Cuota(obj_detalle_cuotas);
                }
                Close();
            }
            catch (Exception ex)
            {
                S_Utilidades.Mensaje_Error(ex.Message);
            }
        }
Exemple #15
0
        private void btn_guardar_Click(object sender, EventArgs e)
        {
            if (txt_total.TextLength == 0)
            {
                S_Utilidades.Mensaje_Informacion("No hay Cuota(s) Seleccionada(s)");
                return;
            }

            DETALLES_CUOTAS  obj_detalle = new DETALLES_CUOTAS();
            RECIBOS_COBRADOS obj_recibo  = new RECIBOS_COBRADOS();
            FACTURAS         obj_factura = new FACTURAS();

            try
            {
                foreach (DataGridViewRow row in dg_detalle_cuotas.Rows)
                {
                    obj_detalle.ID_FACTURA = Convert.ToInt32(Txt_ID.Text);
                    if (Convert.ToBoolean(row.Cells[3].Value) == true && Convert.ToDecimal(row.Cells[4].Value) > 0)
                    {
                        if (Convert.ToDecimal(row.Cells[4].Value) > Convert.ToDecimal(row.Cells[2].Value))
                        {
                            //actualizar totales de cuotas
                            obj_detalle.MONTO_PAGADO    = Convert.ToDecimal(row.Cells[2].Value);
                            obj_detalle.MONTO_PENDIENTE = 0;
                            obj_detalle.NUMERO_CUOTA    = Convert.ToInt32(row.Cells[0].Value);
                            S_Factura.Cobrar_Cuota(obj_detalle);

                            //actualizar totales de factura
                            obj_factura.ID_FACTURA   = Convert.ToInt32(Txt_ID.Text);
                            obj_factura.MONTO_PAGADO = obj_detalle.MONTO_PAGADO;
                            S_Factura.Actualizar_Montos_Factura(obj_factura);

                            //asignar montos de recibos
                            obj_recibo.VALOR_PAGADO    = Convert.ToDecimal(row.Cells[2].Value);
                            obj_recibo.VALOR_PENDIENTE = 0;
                        }
                        else
                        {
                            //actualizar totales de cuotas
                            obj_detalle.MONTO_PAGADO    = Convert.ToDecimal(row.Cells[4].Value);
                            obj_detalle.MONTO_PENDIENTE = Convert.ToDecimal(row.Cells[2].Value) - Convert.ToDecimal(row.Cells[4].Value);
                            obj_detalle.NUMERO_CUOTA    = Convert.ToInt32(row.Cells[0].Value);
                            S_Factura.Cobrar_Cuota(obj_detalle);

                            //actualizar totales de factura
                            obj_factura.ID_FACTURA   = Convert.ToInt32(Txt_ID.Text);
                            obj_factura.MONTO_PAGADO = obj_detalle.MONTO_PAGADO;
                            S_Factura.Actualizar_Montos_Factura(obj_factura);

                            //asignar montos de recibos
                            obj_recibo.VALOR_PAGADO    = Convert.ToDecimal(row.Cells[4].Value);
                            obj_recibo.VALOR_PENDIENTE = obj_detalle.MONTO_PENDIENTE;
                        }
                    }
                    else if (Convert.ToBoolean(row.Cells[3].Value) == true)
                    {
                        //actualizar totales de cuotas
                        obj_detalle.MONTO_PAGADO    = Convert.ToDecimal(row.Cells[2].Value);
                        obj_detalle.MONTO_PENDIENTE = 0;
                        obj_detalle.NUMERO_CUOTA    = Convert.ToInt32(row.Cells[0].Value);
                        S_Factura.Cobrar_Cuota(obj_detalle);

                        //actualizar totales de factura
                        obj_factura.ID_FACTURA   = Convert.ToInt32(Txt_ID.Text);
                        obj_factura.MONTO_PAGADO = obj_detalle.MONTO_PAGADO;
                        S_Factura.Actualizar_Montos_Factura(obj_factura);

                        //asignar montos de recibos
                        obj_recibo.VALOR_PAGADO    = Convert.ToDecimal(row.Cells[2].Value);
                        obj_recibo.VALOR_PENDIENTE = 0;
                    }

                    if (Convert.ToBoolean(row.Cells[3].Value) == true)
                    {
                        //insertar recibos de cobros
                        obj_recibo.ANULADO_POR = "";
                        obj_recibo.CREADO_POR  = S_Utilidades.Datos_Usuario.USUARIO;
                        int ID_FACTURA     = Convert.ToInt32(Txt_ID.Text);
                        var obj_encabezado = db.ENCABEZADO_CUOTAS.Where(a => a.ID_FACTURA == ID_FACTURA).Single();
                        obj_recibo.CANTIDAD_CUOTAS = obj_encabezado.CANTIADA_CUOTA;
                        obj_recibo.CUOTA_COBRADA   = Convert.ToInt32(row.Cells[0].Value);
                        obj_recibo.ESTADO          = "V";
                        obj_recibo.FECHA_ANULADO   = "";
                        obj_recibo.FECHA_CREADO    = DateTime.Now;
                        obj_recibo.ID_FACTURA      = Convert.ToInt32(Txt_ID.Text);
                        var obj_fact = db.FACTURAS.Where(f => f.ID_FACTURA == ID_FACTURA).Single();
                        obj_recibo.NOTA_ANULACION = "";
                        obj_recibo.VALOR_CUOTA    = Convert.ToDecimal(row.Cells[2].Value);
                        S_Factura.Insertar_Recibo_Cobros(obj_recibo);
                    }
                }

                String arry       = "";
                int    id_factura = Convert.ToInt32(Txt_ID.Text);

                foreach (DataGridViewRow row in dg_detalle_cuotas.Rows)
                {
                    int cuota = Convert.ToInt32(row.Cells[0].Value);
                    if (Convert.ToBoolean(row.Cells[3].Value) == true)
                    {
                        var id_recibo = db.RECIBOS_COBRADOS.Where(s => s.ID_FACTURA == id_factura && s.CUOTA_COBRADA == cuota).Max(s => s.ID_RECIBO);

                        arry += id_recibo.ToString() + ",";
                    }
                }
                String recibos = arry.TrimEnd(',');



                S_Utilidades.Mensaje_Informacion("Cobros Realizados con Correctamente por un Monto Total de: " + txt_total.Text);

                Reportes.Rep_Recibo_Pago report = new Reportes.Rep_Recibo_Pago();
                report.FilterString = "([ID_FACTURA] = " + Txt_ID.Text + " AND [ID_RECIBO] IN (" + recibos + "))";
                ReportPrintTool tool = new ReportPrintTool(report);
                tool.ShowPreview();

                Close();
            }
            catch (Exception ex)
            {
                S_Utilidades.Mensaje_Informacion(ex.Message);
            }
        }