// insertar nuevo precio para el articulo
        public bool insertPrecio(long articuloId, long precioEmpresaId, decimal?precLista)
        {
            bool result = false;
            int  rows   = 0;

            // define conexion con la cadena de conexion
            using (var conn = this._conexionFB.getConexionFB())
            {
                // abre la conexion
                conn.Open();

                using (var cmd = new FbCommand())
                {
                    cmd.Connection = conn;

                    string sql =
                        "insert into precios_articulos (precio_articulo_id, articulo_id, precio_empresa_id, precio, moneda_id, margen) " +
                        "values (-1, @artId, @precEmpId, @precio, 1, 0)";

                    cmd.Parameters.AddWithValue("@artId", articuloId);
                    cmd.Parameters.AddWithValue("@precEmpId", precioEmpresaId);
                    cmd.Parameters.AddWithValue("@precio", precLista);

                    ManejoSql_FB res = Utilerias.EjecutaSQL(sql, ref rows, cmd);

                    if (!res.ok)
                    {
                        throw new Exception(res.numErr + ": " + res.descErr);
                    }
                }
            }

            return(result);
        }
        // actualiza el precio segun el precio empresa
        public bool actPrecio(long precioArticuloId, decimal?precio)
        {
            bool result = false;
            int  rows   = 0;

            // define conexion con la cadena de conexion
            using (var conn = this._conexionFB.getConexionFB())
            {
                // abre la conexion
                conn.Open();

                using (var cmd = new FbCommand())
                {
                    cmd.Connection = conn;

                    string sql =
                        "update precios_articulos set precio = @precio, fecha_hora_ult_modif = current_timestamp " +
                        "where precio_articulo_id = @precArtId ";

                    cmd.Parameters.AddWithValue("@precio", precio ?? 0);
                    cmd.Parameters.AddWithValue("@precArtId", precioArticuloId);

                    ManejoSql_FB res = Utilerias.EjecutaSQL(sql, ref rows, cmd);

                    if (!res.ok)
                    {
                        throw new Exception(res.numErr + ": " + res.descErr);
                    }
                }
            }

            return(result);
        }
        public List <Almacen> getAlmacen()
        {
            List <Modelos.Almacen> result = new List <Modelos.Almacen>();

            Modelos.Almacen ent;

            string sql =
                "SELECT " +
                "ALMACENES.ALMACEN_ID, " +
                "ALMACENES.NOMBRE, " +
                "ALMACENES.NOMBRE_ABREV " +
                "FROM ALMACENES ";

            // define conexion con la cadena de conexion
            using (var conn = this._conexionFB.getConexionFB())
            {
                // abre la conexion
                conn.Open();

                using (var cmd = new FbCommand())
                {
                    cmd.Connection = conn;

                    ManejoSql_FB res = Utilerias.EjecutaSQL(sql, cmd);

                    if (res.ok)
                    {
                        if (res.reader.HasRows)
                        {
                            while (res.reader.Read())
                            {
                                ent = new Modelos.Almacen();

                                ent.almacenId = Convert.ToInt64(res.reader["ALMACEN_ID"]);
                                ent.nombre    = Convert.ToString(res.reader["NOMBRE"]);
                                ent.nombreAbr = Convert.ToString(res.reader["NOMBRE_ABREV"]);

                                result.Add(ent);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception(res.numErr + ": " + res.descErr);
                    }

                    // cerrar el reader
                    res.reader.Close();
                }
            }

            return(result);
        }
        // busca si el precio existe segun el articulo y el precio_empresa_id
        public Modelos.PrecioArticulo buscaPrecExistencia(string clave, long precioEmpresaId)
        {
            Modelos.PrecioArticulo result = null;

            string sql =
                "select pa.precio_articulo_id, pa.articulo_id, pa.precio_empresa_id, pa.precio, pa.moneda_id, pa.margen, pa.fecha_hora_ult_modif " +
                "from articulos a " +
                "left join precios_articulos pa on (a.articulo_id = pa.articulo_id) " +
                "left join claves_articulos ca on (a.articulo_id = ca.articulo_id) " +
                "where ca.clave_articulo = @cveArt and pa.precio_empresa_id = @precEmId";

            // define conexion con la cadena de conexion
            using (var conn = this._conexionFB.getConexionFB())
            {
                // abre la conexion
                conn.Open();

                using (var cmd = new FbCommand())
                {
                    cmd.Connection = conn;

                    // parametros
                    cmd.Parameters.AddWithValue("@cveArt", clave);
                    cmd.Parameters.AddWithValue("@precEmId", precioEmpresaId);

                    ManejoSql_FB res = Utilerias.EjecutaSQL(sql, cmd);

                    if (res.ok)
                    {
                        while (res.reader.Read())
                        {
                            result = new PrecioArticulo();
                            result.precioArticuloId  = Convert.ToInt64(res.reader["precio_articulo_id"]);
                            result.articuloId        = Convert.ToInt64(res.reader["articulo_id"]);
                            result.precioEmpresaId   = Convert.ToInt64(res.reader["precio_empresa_id"]);
                            result.precio            = Convert.ToDecimal(res.reader["precio"]);
                            result.monedaId          = Convert.ToInt16(res.reader["moneda_id"]);
                            result.margen            = Convert.ToDecimal(res.reader["margen"]);
                            result.fechaHoraUltModif = Convert.ToString(res.reader["fecha_hora_ult_modif"]);
                        }
                    }
                    else
                    {
                        throw new Exception(res.numErr + ": " + res.descErr);
                    }

                    // cerrar el reader
                    res.reader.Close();
                }
            }

            return(result);
        }
        // obtiene si el articulo tiene como estatus ACTIVO o no
        public Modelos.ArticulosFB buscaActivo(string clave)
        {
            Modelos.ArticulosFB result = new ArticulosFB();

            string sql =
                "select a.articulo_id, a.nombre, ca.clave_articulo, a.estatus " +
                "from articulos a " +
                "left join claves_articulos ca on (a.articulo_id = ca.articulo_id) " +
                "where ca.clave_articulo = @cveArt and ca.rol_clave_art_id = 17";

            // define conexion con la cadena de conexion
            using (var conn = this._conexionFB.getConexionFB())
            {
                // abre la conexion
                conn.Open();

                using (var cmd = new FbCommand())
                {
                    cmd.Connection = conn;

                    // parametros
                    cmd.Parameters.AddWithValue("@cveArt", clave);

                    ManejoSql_FB res = Utilerias.EjecutaSQL(sql, cmd);

                    if (res.ok)
                    {
                        if (res.reader.HasRows)
                        {
                            while (res.reader.Read())
                            {
                                result             = new ArticulosFB();
                                result.articulo    = Convert.ToString(res.reader["nombre"]);
                                result.articuloId  = Convert.ToInt64(res.reader["articulo_id"]);
                                result.cveArticulo = Convert.ToString(res.reader["clave_articulo"]);
                                result.estatus     = Convert.ToString(res.reader["estatus"]);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception(res.numErr + ": " + res.descErr);
                    }

                    // cerrar el reader
                    res.reader.Close();
                }
            }

            return(result);
        }
Exemple #6
0
        // obtiene precios empresas
        public Dictionary <string, long> getPreciosEmpresas()
        {
            Dictionary <string, long> result = new Dictionary <string, long>();

            string sql = "select precio_empresa_id, lower(nombre) as nombre from precios_empresa";

            // define conexion con la cadena de conexion
            using (var conn = this._conexionFB.getConexionFB())
            {
                // abre la conexion
                conn.Open();

                using (var cmd = new FbCommand())
                {
                    cmd.Connection = conn;

                    ManejoSql_FB res = Utilerias.EjecutaSQL(sql, cmd);

                    if (res.ok)
                    {
                        if (res.reader.HasRows)
                        {
                            while (res.reader.Read())
                            {
                                result.Add(
                                    Convert.ToString(res.reader["nombre"]).Trim(),
                                    Convert.ToInt64(res.reader["precio_empresa_id"])
                                    );
                            }
                        }
                    }
                    else
                    {
                        throw new Exception(res.numErr + ": " + res.descErr);
                    }

                    // cerrar el reader
                    res.reader.Close();
                }
            }

            return(result);
        }
Exemple #7
0
        // obtiene la fecha de firebird, es la hora exacta mas cercana posible
        // ya que se encuentra en un servidor en linea
        public string getFecha()
        {
            string result = Convert.ToString(DateTime.Now);

            string sql = "select current_timestamp from rdb$database";

            // define conexion con la cadena de conexion
            using (var conn = this._conexionFB.getConexionFB())
            {
                // abre la conexion
                conn.Open();

                using (var cmd = new FbCommand())
                {
                    cmd.Connection = conn;

                    ManejoSql_FB res = Utilerias.EjecutaSQL(sql, cmd);

                    if (res.ok)
                    {
                        while (res.reader.Read())
                        {
                            result = Convert.ToString(res.reader["current_timestamp"]).Trim();
                        }
                    }
                    else
                    {
                        throw new Exception(res.numErr + ": " + res.descErr);
                    }

                    // cerrar el reader
                    res.reader.Close();
                }
            }

            DateTime dt = DateTime.Parse(result);

            return(dt.ToString("yyyy-MM-dd HH:mm:ss"));
        }
        public List <Articulos> obtieneArticulos(long almacenId)
        {
            List <Modelos.Articulos> result = new List <Modelos.Articulos>();

            Modelos.Articulos ent;

            string sql =
                "SELECT ca.CLAVE_ARTICULO, a.articulo_id, a.NOMBRE, a.ESTATUS, a.COSTO_ULTIMA_COMPRA, " +
                "cc.almacen_id, cc.EXISTENCIA, cc.VALOR_TOTAL " +

                "from articulos a " +

                "left join CAPAS_COSTOS cc on (a.ARTICULO_ID = cc.ARTICULO_ID) " +

                "left join claves_articulos ca on (a.articulo_id = ca.ARTICULO_ID) " +

                "WHERE A.ESTATUS = 'A' AND CA.ROL_CLAVE_ART_ID = 17 and cc.almacen_Id = @almacenId " +

                "ORDER BY A.NOMBRE";

            // define conexion con la cadena de conexion
            using (var conn = this._conexionFB.getConexionFB())
            {
                // abre la conexion
                conn.Open();

                using (var cmd = new FbCommand())
                {
                    cmd.Connection = conn;

                    cmd.Parameters.AddWithValue("@almacenId", almacenId);

                    ManejoSql_FB res = Utilerias.EjecutaSQL(sql, cmd);

                    if (res.ok)
                    {
                        if (res.reader.HasRows)
                        {
                            while (res.reader.Read())
                            {
                                ent = new Modelos.Articulos();

                                ent.articuloId  = Convert.ToInt64(res.reader["ARTICULO_ID"]);
                                ent.cvearticulo = Convert.ToString(res.reader["CLAVE_ARTICULO"]);
                                ent.articulo    = Convert.ToString(res.reader["NOMBRE"]);
                                ent.estatus     = Convert.ToString(res.reader["ESTATUS"]);

                                // lista
                                if (res.reader["EXISTENCIA"] is DBNull)
                                {
                                    ent.costo = 0;
                                }
                                else
                                {
                                    if (res.reader["VALOR_TOTAL"] is DBNull)
                                    {
                                        ent.costo = 0;
                                    }
                                    else
                                    {
                                        decimal costo = 0;
                                        decimal exis  = Convert.ToDecimal(res.reader["EXISTENCIA"]);
                                        decimal valT  = Convert.ToDecimal(res.reader["VALOR_TOTAL"]);

                                        if (valT == 0)
                                        {
                                            ent.costo = costo;
                                        }
                                        else
                                        {
                                            costo = valT / exis;

                                            ent.costo = Math.Round(costo, 2);
                                        }
                                    }
                                }

                                result.Add(ent);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception(res.numErr + ": " + res.descErr);
                    }

                    // cerrar el reader
                    res.reader.Close();
                }
            }

            return(result);
        }
Exemple #9
0
        // obtiene todos los articulos de microsip (FIREBIRD)
        public List <Articulos> obtieneArticulos(Dictionary <string, long> precEmpr)
        {
            List <Modelos.Articulos> result = new List <Modelos.Articulos>();

            Modelos.Articulos ent;

            string sql =
                "SELECT CA.CLAVE_ARTICULO, A.ARTICULO_ID, A.NOMBRE,  " +
                "LISTA.PRECIO AS LISTA, " +
                "MINIMO.PRECIO AS MINIMO, " +
                "MAYOREO.PRECIO AS MAYOREO, " +
                "FILIAL.PRECIO AS FILIAL, " +
                "IMSS.PRECIO AS IMSS, " +
                "MEDIO_MAYO.PRECIO AS MEDIO_MAYO " +

                "FROM CLAVES_ARTICULOS CA " +

                "LEFT JOIN ARTICULOS A ON (CA.ARTICULO_ID = A.ARTICULO_ID) " +

                "LEFT JOIN " +
                "(SELECT ARTICULO_ID, PRECIO FROM PRECIOS_ARTICULOS WHERE PRECIO_EMPRESA_ID = @idLista) LISTA " +
                "ON (CA.ARTICULO_ID = LISTA.ARTICULO_ID) " +

                "LEFT JOIN " +
                "(SELECT ARTICULO_ID, PRECIO FROM PRECIOS_ARTICULOS WHERE PRECIO_EMPRESA_ID = @idMinimo) MINIMO " +
                "ON (CA.ARTICULO_ID = MINIMO.ARTICULO_ID) " +

                "LEFT JOIN " +
                "(SELECT ARTICULO_ID, PRECIO FROM PRECIOS_ARTICULOS WHERE PRECIO_EMPRESA_ID = @idMayoreo) MAYOREO " +
                "ON (CA.ARTICULO_ID = MAYOREO.ARTICULO_ID) " +

                "LEFT JOIN " +
                "(SELECT ARTICULO_ID, PRECIO FROM PRECIOS_ARTICULOS WHERE PRECIO_EMPRESA_ID = @idFilial) FILIAL " +
                "ON (CA.ARTICULO_ID = FILIAL.ARTICULO_ID) " +

                "LEFT JOIN " +
                "(SELECT ARTICULO_ID, PRECIO FROM PRECIOS_ARTICULOS WHERE PRECIO_EMPRESA_ID = @idImss) IMSS " +
                "ON (CA.ARTICULO_ID = IMSS.ARTICULO_ID) " +

                "LEFT JOIN " +
                "(SELECT ARTICULO_ID, PRECIO FROM PRECIOS_ARTICULOS WHERE PRECIO_EMPRESA_ID = @idMedioMayoreo) MEDIO_MAYO " +
                "ON (CA.ARTICULO_ID = MEDIO_MAYO.ARTICULO_ID) " +

                "WHERE A.ESTATUS = 'A' AND CA.ROL_CLAVE_ART_ID = 17 " +

                "ORDER BY A.NOMBRE";

            // define conexion con la cadena de conexion
            using (var conn = this._conexionFB.getConexionFB())
            {
                // abre la conexion
                conn.Open();

                using (var cmd = new FbCommand())
                {
                    cmd.Connection = conn;

                    // parametros
                    cmd.Parameters.AddWithValue("@idLista", precEmpr["precio de lista"]);
                    cmd.Parameters.AddWithValue("@idMinimo", precEmpr["precio mínimo"]);
                    cmd.Parameters.AddWithValue("@idMayoreo", precEmpr["prec.mayoreo"]);
                    cmd.Parameters.AddWithValue("@idFilial", precEmpr["prec.filial"]);
                    cmd.Parameters.AddWithValue("@idImss", precEmpr["prec.i.m.s.s."]);
                    cmd.Parameters.AddWithValue("@idMedioMayoreo", precEmpr["medio mayoreo"]);

                    ManejoSql_FB res = Utilerias.EjecutaSQL(sql, cmd);

                    if (res.ok)
                    {
                        if (res.reader.HasRows)
                        {
                            while (res.reader.Read())
                            {
                                ent = new Modelos.Articulos();

                                ent.idArticulo = Convert.ToInt64(res.reader["ARTICULO_ID"]);
                                ent.clave      = Convert.ToString(res.reader["CLAVE_ARTICULO"]);
                                ent.articulo   = Convert.ToString(res.reader["NOMBRE"]);

                                // lista
                                if (res.reader["LISTA"] is DBNull)
                                {
                                    ent.precLista = null;
                                }
                                else
                                {
                                    ent.precLista = Convert.ToDecimal(res.reader["LISTA"]);
                                }

                                // minimo
                                if (res.reader["MINIMO"] is DBNull)
                                {
                                    ent.precMinimo = null;
                                }
                                else
                                {
                                    ent.precMinimo = Convert.ToDecimal(res.reader["MINIMO"]);
                                }

                                // mayoreo
                                if (res.reader["MAYOREO"] is DBNull)
                                {
                                    ent.precMayoreo = null;
                                }
                                else
                                {
                                    ent.precMayoreo = Convert.ToDecimal(res.reader["MAYOREO"]);
                                }

                                // filial
                                if (res.reader["FILIAL"] is DBNull)
                                {
                                    ent.precFilial = null;
                                }
                                else
                                {
                                    ent.precFilial = Convert.ToDecimal(res.reader["FILIAL"]);
                                }

                                // imss
                                if (res.reader["IMSS"] is DBNull)
                                {
                                    ent.precIMSS = null;
                                }
                                else
                                {
                                    ent.precIMSS = Convert.ToDecimal(res.reader["IMSS"]);
                                }

                                // medio mayoreo
                                if (res.reader["MEDIO_MAYO"] is DBNull)
                                {
                                    ent.medioMayoreo = null;
                                }
                                else
                                {
                                    ent.medioMayoreo = Convert.ToDecimal(res.reader["MEDIO_MAYO"]);
                                }

                                result.Add(ent);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception(res.numErr + ": " + res.descErr);
                    }

                    // cerrar el reader
                    res.reader.Close();
                }
            }

            return(result);
        }