private bool validar_factura(Factura factura)
        {
            int estado = FacturaDAO.estado_factura(factura.id);

            if (estado == 1)
            {
                MessageBox.Show("Esta factura no se encuentra pagada o ya fue devuelta!", "Error devolver Factura", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (factura.rendicion != null || estado == 3)
            {
                MessageBox.Show("Esta factura ya se encuentra rendida!", "Error devolver Factura", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (!factura.empresa.habilitada)
            {
                MessageBox.Show("Lo sentimos la Empresa de esta Factura se encuentra inactiva!", "Error devolver Factura", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (factura.fecha_venc < Utils.obtenerFecha())
            {
                MessageBox.Show("Lo sentimos esa factura está vencida!", "Error devolver Factura", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }
Exemple #2
0
        private bool validar_factura(Factura factura)
        {
            int estado = FacturaDAO.estado_factura(factura.id);

            if (estado != 1)
            {
                if (estado == 2 || estado == 3)
                {
                    MessageBox.Show("Esta factura ya se encuentra pagada!", "Error pagar Factura", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return(false);
            }
            if (!factura.empresa.habilitada)
            {
                MessageBox.Show("Lo sentimos la Empresa de esta Factura se encuentra inactiva!", "Error agregar Factura para pagar", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (facturas_a_pagar.Any(f => f.id == factura.id))
            {
                MessageBox.Show("Esa Factura ya se encuentra en las Facturas a pagar!", "Error agregar Factura para pagar", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (factura.fecha_venc < Utils.obtenerFecha())
            {
                MessageBox.Show("Lo sentimos esa factura está vencida!", "Error pagar Factura", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }
Exemple #3
0
        private void registrarFactura(object sender, EventArgs e)
        {
            FacturaDAO dao = new FacturaDAO();

            dao.isertarRegistro(Convert.ToInt32(vista.txtCodigoPaciente.Text), Convert.ToInt32(vista.txtCodigoPaciente.Text));
            MessageBox.Show("Dato Impreseo");
        }
 public FacturaDAO getFacturaDAO()
 {
     if (this.FacturaBean == null)
     {
         FacturaBean = new FacturaDAOImpl();
     }
     return(FacturaBean);
 }
Exemple #5
0
        private void RegistrarFactura_Load(object sender, EventArgs e)
        {
            cargarCombo();
            cargarCliente(idPedido);

            txt_nroFactura.Text = FacturaDAO.getUltimoNumeroFactura().ToString();

            dgv_detalle.ClearSelection();
        }
 private void cargarItemsFacturaSeleccionada()
 {
     loadFacturaSeleccionada();
     Utilidades.Utils.clearDataGrid(dataGridItems);
     if (facturaSelectedBM != null)
     {
         FacturaDAO.cargarGridItemsFactura(dataGridItems, facturaSelectedBM);
     }
 }
Exemple #7
0
        private int obtenerNumeroFacturacionAleatorio()
        {
            int numeroAleatorio = new Random().Next(150000, 160000);

            while (FacturaDAO.existeNumeroFactura(numeroAleatorio)) //mientras exista, genera otro
            {
                numeroAleatorio = new Random().Next(150000, 160000);
            }
            return(numeroAleatorio);
        }
        private void btn_guardar_Click(object sender, EventArgs e)
        {
            if (dgv_detalle.Rows.Count >= 1)
            {
                if (res == null && chk_Venta_Rapida.Checked == true || res != null && chk_Venta_Rapida.Checked == false)
                {
                    List <DetalleFactura> detalle = new List <DetalleFactura>();
                    Factura fact = new Factura();
                    Persona per  = new Persona();
                    Estado  est  = new Estado();
                    if (chk_Venta_Rapida.Checked == true)
                    {
                        per.idPersona = 17;
                    }
                    else
                    {
                        per.idPersona = res.idPersona;
                    }
                    fact.cliente       = per;
                    fact.fechaCreacion = DateTime.Now.Date;
                    est.idEstado       = 27;
                    fact.estado        = est;
                    fact.importeTotal  = int.Parse(txt_monto_total.Text);
                    fact.tipoFactura   = char.Parse(cmb_tipo_factura.Text);
                    fact.totalIVA      = double.Parse(txt_totalIva.Text);
                    for (int c = 0; c < dgv_detalle.RowCount; c++)
                    {
                        DetalleFactura de = new DetalleFactura();
                        Producto       p  = new Producto();

                        p.idProducto = (int)dgv_detalle.Rows[c].Cells["idProductodetalle"].Value;
                        de.subTotal  = (double)dgv_detalle.Rows[c].Cells["preciodetalle"].Value;
                        de.cantidad  = Convert.ToDouble(dgv_detalle.Rows[c].Cells["cantidad"].Value);
                        de.iva       = Convert.ToDouble(dgv_detalle.Rows[c].Cells["iva"].Value);
                        de.producto  = p;
                        detalle.Add(de);
                    }
                    fact.detalleFactura = detalle;

                    try
                    {
                        iniciador.idFactura = FacturaDAO.InsertFacturaDirecta(fact);
                        MessageBox.Show("Registrado con Exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                        btn_guardar.Enabled = false;
                    }
                    catch (ApplicationException ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    }
                    Emitir_Factura factura = new Emitir_Factura();
                    factura.ShowDialog();
                    btn_nuevo_Click(sender, e);
                }
            }
        }
        private Boolean pagaronLaFactura(int idPedido)
        {
            Boolean result = true;

            if (!FacturaDAO.GetFacturasPagadas(idPedido))
            {
                result = false;
            }

            return(result);
        }
        private void cargarGrilla()
        {
            String opcion = "Sin Opción";

            try
            {
                List <Factura> facturas = FacturaDAO.GetAll();


                dgv_factura.Rows.Clear();
                foreach (Factura factura in facturas)
                {
                    switch (factura.estado.idEstado)
                    {
                    case 27:
                        opcion = "Registrar Cobro";
                        break;

                    default:
                        opcion = "Sin Opción";
                        break;
                    }
                    DateTime aux = Convert.ToDateTime("01/01/1900");
                    DateTime?fec;

                    if (factura.fechaPago.Date == aux.Date)
                    {
                        fec = null;
                    }
                    else
                    {
                        fec = factura.fechaPago.Date;
                    }
                    int fila = dgv_factura.Rows.Add(factura.idFactura, factura.fechaCreacion, factura.cliente.RazonSocial, factura.cliente.Nombre, factura.cliente.Apellido, factura.estado.Nombre, factura.tipoFactura, factura.importeTotal, fec, opcion, factura.estado.idEstado);

                    dgv_factura.Rows[fila].DefaultCellStyle.BackColor = Color.Khaki;


                    if (factura.estado.idEstado == 28)
                    {
                        dgv_factura.Rows[fila].DefaultCellStyle.BackColor = Color.LightGreen;
                    }
                    if (factura.estado.idEstado == 30)
                    {
                        dgv_factura.Rows[fila].DefaultCellStyle.BackColor = Color.LightSalmon;
                    }
                }
            }

            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }
Exemple #11
0
 public bool RegistrarFactura(string idCliente, string Fecha, string Detalle)
 {
     try
     {
         return(FacturaDAO.getInstance().RegistrarFactura(idCliente, Fecha, Detalle));
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemple #12
0
        public void agregarFactura(String cliente)
        {
            this.Cliente = cliente;

            FacturaTO facturaTO = new FacturaTO();

            facturaTO.Cliente = this.Cliente;

            facturaDAO = new FacturaDAO();
            facturaDAO.insertarFactura(facturaTO);
            this.Consecutivo = facturaTO.Consecutivo;
        }
Exemple #13
0
        public void actualizarTotalFactura(double total)
        {
            this.Total = this.Total + total;

            FacturaTO facturaTO = new FacturaTO();

            facturaTO.Consecutivo = this.Consecutivo;
            facturaTO.Total       = this.Total;

            facturaDAO = new FacturaDAO();
            facturaDAO.actualizarTotalFactura(facturaTO);
        }
Exemple #14
0
        private void actualizar_items()
        {
            dgdItemsFactura.DataSource = null;
            Factura fact_pagar_selec = get_factura_a_pagar_seleccionada_grilla();

            if (fact_pagar_selec == null)
            {
                return;
            }
            List <Item_Factura> items = FacturaDAO.obtener_items_factura(fact_pagar_selec);

            dgdItemsFactura.DataSource = items;
            set_name_grilla_items();
        }
        private void Gestion_Venta_Directa_Load(object sender, EventArgs e)
        {
            txt_nroFactura.Text = (int.Parse(FacturaDAO.getUltimoNumeroFactura().ToString())).ToString();
            cargarCombo();
            cargarGrillaProductos();
            chk_Venta_Rapida.Checked = true;

            dgv_detalle.Enabled           = true;
            dgv_productos_finales.Enabled = true;
            txt_cantidad.Enabled          = true;
            btn_agregar.Enabled           = true;
            btn_quitar.Enabled            = true;
            btn_guardar.Enabled           = true;
            rdb_Contado.Checked           = true;

            dgv_productos_finales.ClearSelection();
        }
 private void btn_nuevo_Click(object sender, EventArgs e)
 {
     dgv_detalle.Rows.Clear();
     txt_monto_total.Text = "0";
     txt_totalIva.Text    = "0";
     txt_subTotal.Text    = "0";
     txt_nroFactura.Text  = (int.Parse(FacturaDAO.getUltimoNumeroFactura().ToString()) + 1).ToString();
     cargarCombo();
     cargarGrillaProductos();
     chk_Venta_Rapida.Checked = true;
     chk_Venta_Rapida_CheckedChanged(sender, e);
     dgv_detalle.Enabled           = true;
     dgv_productos_finales.Enabled = true;
     txt_cantidad.Enabled          = true;
     btn_agregar.Enabled           = true;
     btn_quitar.Enabled            = true;
     btn_guardar.Enabled           = true;
     rdb_Contado.Checked           = true;
 }
Exemple #17
0
 private void btnRendir_Click(object sender, EventArgs e)
 {
     if (dataGridFacturas.Rows.Count == 0)
     {
         exito(0);
     }
     else
     {
         Model.Rendicion rend = new Model.Rendicion(0, Utils.obtenerFecha(), totalRendido, porcentajeComision);
         int             idR  = RendicionDAO.nuevaRendicion(rend);
         if (idR == 0)
         {
             MessageBox.Show("Error al generar la rendicion", "Error en Rendicion de facturas", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else
         {
             foreach (DataGridViewRow fila in dataGridFacturas.Rows)
             {
                 string idFactura = fila.Cells[0].Value.ToString(); ///Para mostrar en el msgbox
                 try
                 {
                     rend.id = idR;
                     Factura f = new Factura(
                         int.Parse(fila.Cells[0].Value.ToString()),
                         DateTime.Parse(fila.Cells[1].Value.ToString()),
                         double.Parse(fila.Cells[2].Value.ToString()),
                         DateTime.Parse(fila.Cells[3].Value.ToString()),
                         seleccionada,
                         new Cliente(int.Parse(fila.Cells[4].Value.ToString()), "", "", 0, Utils.obtenerFecha(), "", "", "", "", true), //genero cualquier cliente, total solo importa el id en este update
                         rend,
                         true);                                                                                                         //Se supone que ya busca las habilitadas
                     FacturaDAO.modificarFactura(f);
                 }
                 catch (Exception)
                 {
                     MessageBox.Show("Error al actualizar la factura Nº " + idFactura, "Error en Rendicion de facturas", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                     return;
                 }
             }
             exito(idR);
         }
     }
 }
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (altaDateTimePicker.Value > vencimientoDateTimePicker.Value)
            {
                MessageBox.Show("La fecha de emisión no puede ser mayor a la de vencimiento!", "Error en las fechas", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Factura modificada = new Factura(factura.id, altaDateTimePicker.Value, factura.total, vencimientoDateTimePicker.Value, factura.empresa, clienteSelected, null, factura.habilitada);

            if (FacturaDAO.modificarFactura(modificada) != 0)
            {
                this.Close();
                MessageBox.Show("Factura Nº " + factura.id + " modificada");
                this.backForm.actualizarTabBM();
            }
            else
            {
                MessageBox.Show("Error al modificar Factura " + factura.id);
            }
        }
        //-------------------------------------------------------------------------------------------------------------------------------------------------------
        //-----------------------------------------MODIFICACION DE FACTURAS--------------------------------------------------------------------------------------
        //-------------------------------------------------------------------------------------------------------------------------------------------------------

        private void cargarListFacturasBM()
        {
            Utils.clearDataGrid(dataGridFacturasBM);
            Utils.clearDataGrid(dataGridItems);

            if (filtrando)
            {
                string query = string.Format(@"SELECT Factura_codigo Codigo, Factura_fecha Alta, Factura_total Total, Factura_fecha_venc Vencimiento, Factura_empresa Empresa, Factura_cliente Cliente, Factura_habilitada Habilitada
            FROM LORDS_OF_THE_STRINGS_V2.Factura F " + filtroJoin +
                                             " WHERE (SELECT COUNT(*) FROM LORDS_OF_THE_STRINGS_V2.Pago P2 WHERE P2.Pago_factura = F.Factura_codigo) <= (SELECT COUNT(*) FROM LORDS_OF_THE_STRINGS_V2.Devolucion D WHERE D.Devolucion_factura = F.Factura_codigo) " + filtroWhere);
                FacturaDAO.cargarFacturasFiltrada(dataGridFacturasBM, idFiltro, query, "@idFiltro");
                if (dataGridFacturasBM.Rows.Count < 1)
                {
                    MessageBox.Show("No se encontró ninguna factura habilitada no paga/rendida con esos datos", "PagoAgilFrba | ABM Factura", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    cargarItemsFacturaSeleccionada();
                }
            }
        }
Exemple #20
0
        public void buscarFactura(String consecutivo)
        {
            try
            {
                this.Consecutivo = int.Parse(consecutivo);

                FacturaTO facturaTO = new FacturaTO();
                facturaTO.Consecutivo = this.Consecutivo;

                facturaDAO = new FacturaDAO();
                facturaDAO.extraerFactura(facturaTO);

                this.Cliente   = facturaTO.Cliente;
                this.FechaHora = facturaTO.FechaHora;
                this.Total     = facturaTO.Total;
            }
            catch (Exception)
            {
                throw;
            }
        }
        private void dgv_factura_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgv_factura.CurrentCell is DataGridViewButtonCell)
            {
                if ((int)dgv_factura.CurrentRow.Cells["idestado"].Value != 28)
                {
                    int idFactura = (int)dgv_factura.CurrentRow.Cells["idFactura"].Value;

                    try
                    {
                        FacturaDAO.UpdateEstado(idFactura, 28, DateTime.Now.Date);
                        MessageBox.Show("Pago Registrado", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                    }
                    catch (ApplicationException ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    }
                    cargarGrilla();
                }
            }
        }
Exemple #22
0
 private void btnActualizar_Click(object sender, EventArgs e)
 {
     if (cambio)
     {
         if (factura.items.Count > 0)
         {
             if (FacturaDAO.modificarItems(factura.id, factura.items, borrados, total) != 0)
             {
                 backForm.actualizarTabBM();
                 this.Close();
                 MessageBox.Show("Factura Nº " + factura.id + " actualizada", "PagoAgilFrba | ABM Factura", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             else
             {
                 MessageBox.Show("Error al actualizar Factura Nº " + factura.id, "PagoAgilFrba | ABM Factura", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
         }
         else
         {
             MessageBox.Show("No se permite almacenar una factura vacia", "PagoAgilFrba | ABM Factura", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
 }
 private void btnHabilitar_Click(object sender, EventArgs e)
 {
     loadFacturaSeleccionada();
     if (facturaSelectedBM != null)
     {
         if (!facturaSelectedBM.habilitada)  //Si no esta habilitada modifico
         {
             facturaSelectedBM.habilitada = true;
             if (FacturaDAO.modificarFactura(facturaSelectedBM) != 0)
             {
                 MessageBox.Show("Factura Nº " + facturaSelectedBM.id + " habilitada", "PagoAgilFrba | ABM Factura", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 cargarListFacturasBM();
             }
             else
             {
                 MessageBox.Show("Error al habilitar factura Nº " + facturaSelectedBM.id, "PagoAgilFrba | ABM Factura", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
         }
         else
         {
             MessageBox.Show("La Factura seleccionada ya se encuentra habilitada!", "PagoAgilFrba | ABM Factura", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            if (Utilidades.Utils.cumple_campos_obligatorios(campos_obligatorios_ALTA, errorProvider) && dataGridEmpresas.SelectedRows.Count > 0 && dataGridCliente.SelectedRows.Count > 0)
            {
                lblMensaje.ForeColor = Color.Black;
                lblMensaje.Visible   = true;
                lblMensaje.Text      = "Espere por favor...";

                DateTime fecha = vencimientoDateTimePicker.Value;

                if (fecha <= Utils.obtenerFecha())
                {
                    lblMensaje.ForeColor = Color.DarkRed;
                    lblMensaje.Visible   = true;
                    lblMensaje.Text      = "Fecha ingresada es inválida";
                    MessageBox.Show("La fecha ingresada es inválida, no se pueden generar facturas vencidas", "PagoAgilFrba | ABM Factura", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (itemsIngresados < 1)
                {
                    lblMensaje.ForeColor = Color.DarkRed;
                    lblMensaje.Visible   = true;
                    lblMensaje.Text      = "Agregue al menos un item";
                    MessageBox.Show("No ha agregado ningun item, no se puede generar facturas vacias", "PagoAgilFrba | ABM Factura", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                loadEmpresaSeleccionada();

                if (empresaSelectedAlta == null)
                {
                    lblMensaje.ForeColor = Color.DarkRed;
                    lblMensaje.Visible   = true;
                    lblMensaje.Text      = "Empresa no seleccionada";
                    MessageBox.Show("Error al seleccionar empresa", "PagoAgilFrba | ABM Factura", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    loadClienteSeleccionado();
                    if (clienteSelectedAlta != null)
                    {
                        Factura nueva = new Factura(0, Utils.obtenerFecha(), totalSS, fecha, empresaSelectedAlta, clienteSelectedAlta, null);
                        generarListaItems();

                        int value = FacturaDAO.ingresar_factura_e_items(nueva, this.items);
                        if (value != 0)
                        {
                            exito(value);
                            return;
                        }
                        else
                        {
                            lblMensaje.ForeColor = Color.DarkRed;
                            lblMensaje.Visible   = true;
                            lblMensaje.Text      = "Error al cargar los datos";
                            return;
                        }
                    }
                    else
                    {
                        lblMensaje.ForeColor = Color.DarkRed;
                        lblMensaje.Visible   = true;
                        lblMensaje.Text      = "Cliente no seleccionado";
                        MessageBox.Show("Error al seleccionar cliente", "PagoAgilFrba | ABM Factura", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
            }
            else
            {
                lblMensaje.ForeColor = Color.DarkRed;
                lblMensaje.Visible   = true;
                lblMensaje.Text      = "Complete los Campos obligatorios";
            }
        }
 private void Emitir_Factura_Load(object sender, EventArgs e)
 {
     FacturaBindingSource.DataSource = FacturaDAO.GetAllEmitir(iniciador.idFactura);
     this.reportViewer1.RefreshReport();
 }
Exemple #26
0
        private void btn_guardar_Click(object sender, EventArgs e)
        {
            if (estadoFormulario == estados.nuevo)
            {
                Factura factura = new Factura();
                List <DetalleFactura> detalle = new List <DetalleFactura>();

                try
                {
                    if (Convert.ToInt32(cmb_iva.SelectedIndex) == 0)
                    {
                        for (int c = 0; c < dgv_detalle.RowCount; c++)
                        {
                            int            esSinpedido = (int)dgv_detalle.Rows[c].Cells["add"].Value;
                            DetalleFactura det         = new DetalleFactura();

                            det.cantidad = Convert.ToDouble(dgv_detalle.Rows[c].Cells["cantidad"].Value);
                            if (esSinpedido == 0)
                            {
                                det.detPedido = new DetallePedido()
                                {
                                    producto = new Producto()
                                    {
                                        idProducto = Convert.ToInt32(dgv_detalle.Rows[c].Cells["idProductodetalle"].Value)
                                    }, pedido = new Pedido()
                                    {
                                        idPedido = idPedido
                                    },
                                };
                                foreach (DetallePedido detp in ped.detallePedido)
                                {
                                    if (detp.producto.idProducto == Convert.ToInt32(dgv_detalle.Rows[c].Cells["idProductodetalle"].Value))
                                    {
                                        det.detPedido.cantidad = detp.cantidad;
                                    }
                                }
                            }
                            else
                            {
                                det.producto = new Producto()
                                {
                                    idProducto = Convert.ToInt32(dgv_detalle.Rows[c].Cells["idProductodetalle"].Value)
                                };
                            }
                            det.subTotal = Convert.ToDouble(dgv_detalle.Rows[c].Cells["preciodetalle"].Value);
                            det.iva      = Convert.ToDouble(dgv_detalle.Rows[c].Cells["sinIva"].Value);



                            detalle.Add(det);
                        }

                        factura.detalleFactura = detalle;
                        factura.cliente        = ped.cliente;
                        factura.pedido         = ped;
                        factura.fechaCreacion  = dtp_fecha_factura.Value.Date;
                        factura.importeTotal   = Convert.ToDouble(txt_monto_total.Text);
                        if (rbtn_contado.Checked)
                        {
                            factura.estado = new Estado()
                            {
                                idEstado = 28
                            };
                        }
                        else
                        {
                            factura.estado = new Estado()
                            {
                                idEstado = 27
                            };
                        }
                        factura.totalIVA    = Convert.ToDouble(txt_totalIva.Text);
                        factura.tipoFactura = Convert.ToChar(cmb_tipo_factura.Text);
                    }
                    else
                    {
                        for (int c = 0; c < dgv_detalle.RowCount; c++)
                        {
                            int            esSinpedido = (int)dgv_detalle.Rows[c].Cells["add"].Value;
                            DetalleFactura det         = new DetalleFactura();

                            det.cantidad = Convert.ToDouble(dgv_detalle.Rows[c].Cells["cantidad"].Value);
                            if (esSinpedido == 0)
                            {
                                det.detPedido = new DetallePedido()
                                {
                                    producto = new Producto()
                                    {
                                        idProducto = Convert.ToInt32(dgv_detalle.Rows[c].Cells["idProductodetalle"].Value)
                                    }, pedido = new Pedido()
                                    {
                                        idPedido = idPedido
                                    }
                                };
                                foreach (DetallePedido detp in ped.detallePedido)
                                {
                                    if (detp.producto.idProducto == Convert.ToInt32(dgv_detalle.Rows[c].Cells["idProductodetalle"].Value))
                                    {
                                        det.detPedido.cantidad = detp.cantidad;
                                    }
                                }
                            }
                            else
                            {
                                det.producto = new Producto()
                                {
                                    idProducto = Convert.ToInt32(dgv_detalle.Rows[c].Cells["idProductodetalle"].Value)
                                };
                            }
                            det.subTotal = Convert.ToDouble(dgv_detalle.Rows[c].Cells["preciodetalle"].Value);



                            detalle.Add(det);
                        }

                        factura.detalleFactura = detalle;
                        factura.cliente        = ped.cliente;
                        factura.fechaCreacion  = dtp_fecha_factura.Value.Date;
                        factura.importeTotal   = Convert.ToDouble(txt_monto_total.Text);
                        if (rbtn_contado.Checked)
                        {
                            factura.estado = new Estado()
                            {
                                idEstado = 28
                            };
                        }
                        else
                        {
                            factura.estado = new Estado()
                            {
                                idEstado = 27
                            };
                        }
                        factura.pedido      = ped;
                        factura.tipoFactura = Convert.ToChar(cmb_tipo_factura.Text);
                    }

                    iniciador.idFactura = FacturaDAO.Insert(factura, detalleAgregado);


                    //MessageBox.Show("Registrado con Exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                    _estado = estados.guardado;

                    btn_guardar.Enabled = false;
                    btn_salir_Click(sender, e);
                }
                catch (ApplicationException ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                }
            }
        }
        private void cargaGrillsFiltros()
        {
            //DateTime? fdesde = null;
            //DateTime? fhasta = null;
            double?mDesde = null;
            double?mHasta = null;
            int?   cuit   = null;
            int?   nroDoc = null;

            DateTime fdesde = dtp_desde.Value;
            DateTime fhasta = dtp_hasta.Value;

            String opcion = "Sin Opción";

            if (!string.IsNullOrEmpty(txt_monto_desde.Text))
            {
                mDesde = double.Parse(txt_monto_desde.Text);
            }

            if (!string.IsNullOrEmpty(txt_monto_hasta.Text))
            {
                mHasta = double.Parse(txt_monto_hasta.Text);
            }

            if (!string.IsNullOrEmpty(txt_cuit.Text))
            {
                cuit = int.Parse(txt_cuit.Text);
            }
            if (!string.IsNullOrEmpty(txt_nro_doc.Text))
            {
                nroDoc = int.Parse(txt_nro_doc.Text);
            }
            try
            {
                char tipo = 'j';
                if (cmb_tipo_factura.SelectedIndex != 3)
                {
                    tipo = Convert.ToChar(cmb_tipo_factura.Text);
                }

                List <Factura> facturas = FacturaDAO.GetByFiltros((int)cmb_estado_pedido.SelectedValue, (int)cmb_tipo_doc.SelectedValue, nroDoc, mDesde, mHasta, txt_nombre.Text, txt_apellido.Text, txt_razon_social.Text, cuit, fdesde, fhasta, tipo, cmb_tipo_factura.SelectedIndex);

                dgv_factura.Rows.Clear();
                foreach (Factura factura in facturas)
                {
                    switch (factura.estado.idEstado)
                    {
                    case 27:
                        opcion = "Registrar Cobro";
                        break;

                    default:
                        opcion = "Sin Opción";
                        break;
                    }
                    DateTime aux = Convert.ToDateTime("01/01/1900");
                    DateTime?fec;

                    if (factura.fechaPago.Date == aux.Date)
                    {
                        fec = null;
                    }
                    else
                    {
                        fec = factura.fechaPago.Date;
                    }
                    int fila = dgv_factura.Rows.Add(factura.idFactura, factura.fechaCreacion, factura.cliente.RazonSocial, factura.cliente.Nombre, factura.cliente.Apellido, factura.estado.Nombre, factura.tipoFactura, factura.importeTotal, fec, opcion, factura.estado.idEstado);

                    dgv_factura.Rows[fila].DefaultCellStyle.BackColor = Color.Khaki;


                    if (factura.estado.idEstado == 28)
                    {
                        dgv_factura.Rows[fila].DefaultCellStyle.BackColor = Color.LightGreen;
                    }
                    if (factura.estado.idEstado == 30)
                    {
                        dgv_factura.Rows[fila].DefaultCellStyle.BackColor = Color.LightSalmon;
                    }
                }
            }

            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }