Exemple #1
0
        public EncFactura GetFactura(double pNumeroFactura)
        {
            EncFactura      oFacturaEncabezado = new EncFactura();
            DataSet         ds               = null;
            IDALHuesped     _DALHuesped      = new DALHuesped();
            IDALTarjeta     _DALTarjeta      = new DALTarjeta();
            IDALReservacion _DALReservacion  = new DALReservacion();
            IDALEncFactura  _DALEncFactura   = new DALEncFactura();
            IBLLImpuesto    _BLLImpuestotest = new BLLImpuesto();
            SqlCommand      command          = new SqlCommand();

            string sql = @"";


            sql = @"usp_SELECT_EncFactura_ByID";

            try
            {
                command.Parameters.AddWithValue("@IDFactura", pNumeroFactura);
                command.CommandText = sql;
                command.CommandType = CommandType.StoredProcedure;


                using (IDataBase db = FactoryDataBase.CreateDataBase(FactoryConexion.CreateConnection(_Usuario.Login, _Usuario.Password)))
                {
                    ds = db.ExecuteReader(command, "query");
                }

                // Si devolvió filas
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = ds.Tables[0].Rows[0];
                    oFacturaEncabezado = new EncFactura()
                    {
                        IDFactura  = double.Parse(dr["IDFactura"].ToString()),
                        _Tarjeta   = _DALTarjeta.GetTarjetaById(int.Parse(dr["IDTarjeta"].ToString())),
                        Fecha      = DateTime.Parse(dr["Fecha"].ToString()),
                        EstadoFact = dr["EstadoFact"].ToString()
                    };

                    foreach (var item in ds.Tables[0].Rows)
                    {
                        DetFactura oFacturaDetalle = new DetFactura();
                        oFacturaDetalle._EncFactura = _DALEncFactura.GetFactura(pNumeroFactura);
                        oFacturaDetalle.Numero      = int.Parse(dr["Numero"].ToString());
                        oFacturaDetalle.Precio      = double.Parse(dr["Precio"].ToString());
                        oFacturaDetalle._Impuesto   = _BLLImpuestotest.GetImpuesto();
                        // Enumerar la secuencia
                        oFacturaDetalle._Reservacion = _DALReservacion.GetReserva(pNumeroFactura);
                        // Agregar
                        oFacturaEncabezado.AddDetalle(oFacturaDetalle);
                    }
                }


                return(oFacturaEncabezado);
            }
            catch (SqlException sqlError)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                msg.AppendFormat("SQL             {0}\n", command.CommandText);
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                throw;
            }
            catch (Exception er)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat(Utilitarios.CreateGenericErrorExceptionDetail(er));
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                throw;
            }
        }
        /// <summary>
        /// Método que obtiene la factura por número de factura
        /// </summary>
        /// <param name="numFact">Número de factura</param>
        /// <returns>Retorna la factura que coincida con el número</returns>
        public EncabezadoFactura ObtenerFactura(string numFact)
        {
            EncabezadoFactura oEncabezado     = new EncabezadoFactura();
            IConexion         conexion        = new Conexion();
            IDALCliente       _DALCliente     = new DALCliente();
            IDALMensajero     _DALMensajero   = new DALMensajero();
            IDALTarjeta       _DALTarjeta     = new DALTarjeta();
            IDALImpuesto      _DALImpuesto    = new DALImpuesto();
            IDALPrecioEnvio   _DALPrecioEnvio = new DALPrecioEnvio();
            DataSet           ds = new DataSet();

            using (SqlConnection conn = conexion.conexion())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("SELECT EncFactura.IDEncFactura, EncFactura.Fecha, EncFactura.IDCliente, EncFactura.IDMensajero, EncFactura.XML, EncFactura.IDTarjeta, DetFactura.NoFactura, DetFactura.Secuancial, DetFactura.Total, DetFactura.Cantidad, DetFactura.Kilometros, DetFactura.DescripcionRuta, DetFactura.Impuesto, DetFactura.DescripcionPaquete, DetFactura.TipoEnvio FROM EncFactura INNER JOIN DetFactura ON EncFactura.IDEncFactura = @IDEncabezado", conn);
                    cmd.Parameters.AddWithValue("@IDEncabezado", numFact);
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(ds);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        DataRow dr = ds.Tables[0].Rows[0];

                        oEncabezado.IDEncFactura = dr["IDEncFactura"].ToString();
                        oEncabezado.Fecha        = Convert.ToDateTime(dr["Fecha"].ToString());
                        oEncabezado.oCliente     = _DALCliente.BuscarClienteID(dr["IDCliente"].ToString());
                        oEncabezado.oMensajero   = _DALMensajero.BuscarMensajeroID(dr["IDMensajero"].ToString());
                        oEncabezado.XML          = dr["XML"].ToString();
                        oEncabezado.oTarjeta     = _DALTarjeta.GetTarjetID(dr["IDTarjeta"].ToString());

                        foreach (var item in ds.Tables[0].Rows)
                        {
                            DetFactura oFacturaDetalle = new DetFactura();
                            oFacturaDetalle.NoFactura          = dr["NoFactura"].ToString();
                            oFacturaDetalle.Secuencial         = int.Parse(dr["Secuancial"].ToString());
                            oFacturaDetalle.Total              = double.Parse(dr["Total"].ToString());
                            oFacturaDetalle.CantidadPaquetes   = Convert.ToInt32(dr["Cantidad"].ToString());
                            oFacturaDetalle.CantidadKilometros = Convert.ToInt32(dr["Kilometros"].ToString());
                            oFacturaDetalle.DescripcionRuta    = dr["DescripcionRuta"].ToString();
                            foreach (Impuesto impuesto in _DALImpuesto.ObtenerImpuesto())
                            {
                                oFacturaDetalle.Impuesto += impuesto.Valor;
                            }
                            oFacturaDetalle.DescripcionPaquete = dr["DescripcionPaquete"].ToString();
                            oFacturaDetalle.TipoEnvio          = _DALPrecioEnvio.MostrarXID(dr["TipoEnvio"].ToString());
                            oEncabezado.AgregrarDetalle(oFacturaDetalle);
                        }
                    }
                    else
                    {
                        oEncabezado = null;
                    }
                }
                catch (SqlException sqlError)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                    _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                    throw;
                }
                catch (Exception er)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.AppendFormat(Utilitarios.CreateGenericErrorExceptionDetail(er));
                    _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                    throw;
                }
                finally
                {
                    conn.Close();
                }
            }
            return(oEncabezado);
        }
Exemple #3
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            //IBLLImpuesto _BLLImpuesto = new BLLImpuesto();
            DetFactura oFacturaDetalle = new DetFactura();

            IBLLEncFactura _BLLFactura = new BLLEncFactura();

            IBLLReservacion _BLLReservacion = new BLLReservacion();

            IBLLTarjeta _BLLTarjeta = new BLLTarjeta();

            _FacturaEncabezado = new EncFactura();



            try
            {
                erpError.Clear();

                _FacturaEncabezado = new EncFactura()
                {
                    IDFactura  = _BLLFactura.GetCurrentNumeroFactura(),
                    _Tarjeta   = _BLLTarjeta.GetTarjetaById(Double.Parse(this.txtNumeroTarjeta.Text)),
                    Fecha      = DateTime.Now.Date,
                    EstadoFact = this.cmbEstado.SelectedIndex.ToString()
                };

                if (_FacturaEncabezado == null)
                {
                    MessageBox.Show("Debe agregar los datos del encabezado de la factura para continuar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // Validar que el Producto ya no se haya agregado
                if (_FacturaEncabezado._ListaFacturaDetalle.Count > 0)
                {
                    // Si ya se agrego no permitir agregarlo nuevamente
                    if (_FacturaEncabezado._ListaFacturaDetalle.FindAll(p => p._Reservacion.ID == double.Parse(this.mskIDReserva.Text)).Count > 0)
                    {
                        MessageBox.Show("La Reservacion ya fue agregado previamente.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                oFacturaDetalle._EncFactura  = _BLLFactura.GetFactura(Double.Parse(this.txtNumeroFactura.Text));
                oFacturaDetalle._Reservacion = _BLLReservacion.GetReserva(Double.Parse(this.mskIDReserva.Text.ToString()));



                oFacturaDetalle.Precio = Double.Parse(this.txtPrecio.Text.ToString());

                // Calcular el Impuesto
                IBLLImpuesto _BLLImpuestotest = new BLLImpuesto();
                oFacturaDetalle._Impuesto = _BLLImpuestotest.GetImpuesto();//((double)_BLLImpuesto.GetImpuesto().Porcentaje / 100D) * oFacturaDetalle.Precio * 1;
                // Enumerar la secuencia
                oFacturaDetalle.Numero = _FacturaEncabezado._ListaFacturaDetalle.Count == 0 ?
                                         1 : _FacturaEncabezado._ListaFacturaDetalle.Max(p => p.Numero) + 1;


                // Agregar
                _FacturaEncabezado.AddDetalle(oFacturaDetalle);

                if (oFacturaDetalle._Reservacion.CheckOUT.Day < this.dtpOut.Value.Day)
                {
                    MessageBox.Show(

                        "  Ha sobrepasado la fecha para realizar su Check Out , por lo que se realizara un cobro equivalente a $50 adicional. Disculpe. "

                        , "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                this.txtNUMDetalle.Text = (cont++ + 1).ToString();

                string[] lineaFactura = { _BLLFactura.GetCurrentNumeroFactura().ToString(),
                                          (cont).ToString(),
                                          oFacturaDetalle.Precio.ToString(),
                                          oFacturaDetalle._Reservacion.ID.ToString(),
                                          this.txtNumeroTarjeta.Text,
                                          DateTime.Now.Date.ToString(),
                                          this.cmbEstado.SelectedItem.ToString() };

                this.dgvDetalleFactura.Rows.Add(lineaFactura);
            }
            catch (Exception er)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat("Message        {0}\n", er.Message);
                msg.AppendFormat("Source         {0}\n", er.Source);
                msg.AppendFormat("InnerException {0}\n", er.InnerException);
                msg.AppendFormat("StackTrace     {0}\n", er.StackTrace);
                msg.AppendFormat("TargetSite     {0}\n", er.TargetSite);
                // Log error
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                // Mensaje de Error
                MessageBox.Show("Se ha producido el siguiente error " + er.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #4
0
        /// <summary>
        /// Método que guarda el detalle de factura en el encabezado
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            IBLLImpuesto    _BLLImpuesto       = new BLLImpuesto();
            IBLLPrecioEnvio _BLLPrecioEnvio    = new BLLPrecioEnvio();
            IBLLFactura     _BLLFactura        = new BLLFactura();
            DetFactura      oDetFactura        = new DetFactura();
            string          descripcionPaquete = "";
            string          descripcionruta    = "";

            try
            {
                erpErrores.Clear();
                if (_EncabezadoFactura == null)
                {
                    MessageBox.Show("Debe agregar los datos del encabezado de la factura para continuar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    if (string.IsNullOrEmpty(txtIDMensajero.Text))
                    {
                        erpErrores.SetError(txtIDMensajero, "Debe ingresar la identificación del mensajero");
                        return;
                    }
                    if (string.IsNullOrEmpty(txtNombreMensajero.Text))
                    {
                        erpErrores.SetError(txtNombreMensajero, "Debe ingresar el nombre del mensajero");
                        return;
                    }
                    if (string.IsNullOrEmpty(mskNoTarjeta.Text))
                    {
                        erpErrores.SetError(mskNoTarjeta, "Debe ingresar el número de tarjeta");
                        return;
                    }
                    int cantidad = 0;
                    foreach (var item in mskNoTarjeta.Text)
                    {
                        cantidad++;
                    }
                    if (cantidad < 16)
                    {
                        erpErrores.SetError(mskNoTarjeta, "Debe ingresar un número válido");
                        return;
                    }
                    if (Convert.ToInt32(txtCantidadPaquetes.Text) == 0 || string.IsNullOrEmpty(txtCantidadPaquetes.Text))
                    {
                        erpErrores.SetError(txtCantidadPaquetes, "Debe ingresar un paquete");
                        return;
                    }
                    if ((Convert.ToDouble(txtKilometros.Text) == 0 || string.IsNullOrEmpty(txtKilometros.Text)))
                    {
                        erpErrores.SetError(txtKilometros, "Debe ingresar una ruta válida");
                        return;
                    }
                    if (lstUbicaciones.Items.Count <= 1)
                    {
                        erpErrores.SetError(lstUbicaciones, "Debe ingresar una ruta válida");
                        return;
                    }
                    oDetFactura.CantidadKilometros = (int)Math.Round(Convert.ToDouble(txtKilometros.Text));
                    for (int i = 0; i < lstPaquetes.Items.Count; i++)
                    {
                        descripcionPaquete += lstPaquetes.Items[i].ToString() + "\n";
                    }
                    oDetFactura.DescripcionPaquete = descripcionPaquete;
                    for (int i = 0; i < lstUbicaciones.Items.Count; i++)
                    {
                        descripcionruta += lstUbicaciones.Items[i].ToString() + "\n";
                    }
                    oDetFactura.DescripcionRuta  = descripcionruta;
                    oDetFactura.Impuesto         = Convert.ToDouble(txtImpuesto.Text);
                    oDetFactura.NoFactura        = _EncabezadoFactura.IDEncFactura;
                    oDetFactura.PrecioKilometro  = _BLLPrecioEnvio.MostrarXID(cboTipoEnvio.SelectedItem.ToString()).PrecioRango;
                    oDetFactura.Secuencial       = _BLLFactura.GetNextNumeroFactura();
                    oDetFactura.CantidadPaquetes = Convert.ToInt32(txtCantidadPaquetes.Text);
                    oDetFactura.TipoEnvio        = _BLLPrecioEnvio.MostrarXID(cboTipoEnvio.SelectedItem.ToString());
                    _EncabezadoFactura.AgregrarDetalle(oDetFactura);
                    txtSubTotal.Text       = _EncabezadoFactura.SubTotal() + "";
                    txtTotal.Text          = _EncabezadoFactura.SubTotal() + ((_EncabezadoFactura.SubTotal() * _EncabezadoFactura.Impuesto())) + "";
                    oDetFactura.Total      = _EncabezadoFactura.SubTotal() + ((_EncabezadoFactura.SubTotal() * _EncabezadoFactura.Impuesto()));
                    _EncabezadoFactura.XML = _EncabezadoFactura.GenerarXML();
                    File.WriteAllText(@"c:\temp\proyecto.xml", _EncabezadoFactura.GenerarXML());
                }
            }
            catch (Exception er)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat("Message        {0}\n", er.Message);
                msg.AppendFormat("Source         {0}\n", er.Source);
                msg.AppendFormat("InnerException {0}\n", er.InnerException);
                msg.AppendFormat("StackTrace     {0}\n", er.StackTrace);
                msg.AppendFormat("TargetSite     {0}\n", er.TargetSite);
                // Log error
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                // Mensaje de Error
                MessageBox.Show("Se ha producido el siguiente error " + er.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #5
0
        private void toolStripBtnFacturar_Click(object sender, EventArgs e)
        {
            IBLLEncFactura _BLLFactura    = new BLLEncFactura();
            IBLLTarjeta    _BLLTarjeta    = new BLLTarjeta();
            IBLLHuesped    _BLLHuesped    = new BLLHuesped();
            IBLLHabitacion _BLLHabitacion = new BLLHabitacion();

            IBLLImpuesto _BLLImpuesto = new BLLImpuesto();

            DetFactura oFacturaDetalle = new DetFactura();

            this.cmbEstado.SelectedIndex = 1;

            IBLLReservacion _BLLReservacion = new BLLReservacion();


            Tarjeta oTarjeta      = new Tarjeta();
            string  rutaImagen    = @"c:\temp\qr.png";
            double  numeroFactura = 0d;

            try
            {
                _FacturaEncabezado = new EncFactura()
                {
                    IDFactura  = Double.Parse(this.txtNumeroFactura.Text),
                    _Tarjeta   = cmbTarjeta.SelectedItem as Tarjeta,//_BLLTarjeta.GetTarjetaById(Double.Parse(this.txtNumeroTarjeta.Text)),
                    Fecha      = DateTime.Now.Date,
                    EstadoFact = this.cmbEstado.SelectedIndex.ToString(),
                };

                oFacturaDetalle._EncFactura  = _BLLFactura.GetFactura(Double.Parse(this.txtNumeroFactura.Text));
                oFacturaDetalle._Reservacion = _BLLReservacion.GetReserva(Double.Parse(this.mskIDReserva.Text.ToString()));



                oFacturaDetalle.Precio = Double.Parse(this.txtPrecio.Text.ToString());

                // Calcular el Impuesto
                IBLLImpuesto _BLLImpuestotest = new BLLImpuesto();
                oFacturaDetalle._Impuesto = _BLLImpuestotest.GetImpuesto();
                // Enumerar la secuencia
                oFacturaDetalle.Numero = _FacturaEncabezado._ListaFacturaDetalle.Count == 0 ?
                                         1 : _FacturaEncabezado._ListaFacturaDetalle.Max(p => p.Numero) + 1;

                ;
                // Agregar
                _FacturaEncabezado.AddDetalle(oFacturaDetalle);


                if (_FacturaEncabezado == null)
                {
                    MessageBox.Show("No hay datos por facturar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (_FacturaEncabezado._ListaFacturaDetalle.Count == 0)
                {
                    MessageBox.Show("No hay items en la factura ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }



                this.txtSubtotal.Text = _FacturaEncabezado.GetSubTotal().ToString();
                this.txtImpuesto.Text = _FacturaEncabezado.GetImpuesto().ToString();
                this.txtTotal.Text    = (_FacturaEncabezado.GetSubTotal() + (_FacturaEncabezado.GetImpuesto())).ToString();

                _FacturaEncabezado = _BLLFactura.SaveFactura(_FacturaEncabezado);

                numeroFactura = _BLLFactura.GetCurrentNumeroFactura();

                EstadoHabitaciones();

                if (_FacturaEncabezado == null)
                {
                    MessageBox.Show("Error al crear factura!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                //toolStripBtnNuevo_Click(null, null);


                // Si existe borrelo
                if (File.Exists(rutaImagen))
                {
                    File.Delete(rutaImagen);
                }


                // Crear imagen quickresponse
                Image quickResponseImage = QuickResponse.QuickResponseGenerador(numeroFactura.ToString(), 53);



                // Salvarla en c:\temp para luego ser leida
                quickResponseImage.Save(rutaImagen, ImageFormat.Png);

                frmFacturaImpresion ofrmFacturaImpresion = new frmFacturaImpresion((int)numeroFactura, _BLLHuesped.GetHuespedById(Double.Parse(this.txtIdHuesped.Text)).Nombre);


                ofrmFacturaImpresion.ShowDialog();


                this.txtNumeroTarjeta.Text    = "";
                this.txtNumHabitacion.Text    = "";
                this.txtNUMDetalle.Text       = "1";
                this.txtImpuesto.Text         = "";
                this.txtIdHuesped.Text        = "";
                this.txtCantDias.Text         = "";
                this.txtPrecio.Text           = "";
                this.txtSubtotal.Text         = "";
                this.txtTotal.Text            = "";
                this.cmbEstado.SelectedIndex  = 0;
                this.cmbTarjeta.SelectedIndex = 0;
                this.Subtotal.Text            = "";
                this.mskIDReserva.Text        = "";
                this.dgvDetalleFactura.Rows.Clear();
                this.dgvDetalleFactura.Refresh();
            }
            catch (Exception er)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat("Message        {0}\n", er.Message);
                msg.AppendFormat("Source         {0}\n", er.Source);
                msg.AppendFormat("InnerException {0}\n", er.InnerException);
                msg.AppendFormat("StackTrace     {0}\n", er.StackTrace);
                msg.AppendFormat("TargetSite     {0}\n", er.TargetSite);
                // Log error
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                // Mensaje de Error
                MessageBox.Show("Se ha producido el siguiente error " + er.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }