Ejemplo n.º 1
0
        public fa_cliente_Info get_info(int IdEmpresa, decimal IdCliente)
        {
            try
            {
                fa_cliente_Info      info      = new fa_cliente_Info();
                Entities_facturacion Context_f = new Entities_facturacion();
                Entities_general     Context_g = new Entities_general();

                fa_cliente Entity = Context_f.fa_cliente.FirstOrDefault(q => q.IdEmpresa == IdEmpresa && q.IdCliente == IdCliente);
                if (Entity == null)
                {
                    return(null);
                }

                info = new fa_cliente_Info
                {
                    IdEmpresa = Entity.IdEmpresa,
                    cl_Cupo   = Entity.cl_Cupo,
                    cl_plazo  = Entity.cl_plazo,
                    Codigo    = Entity.Codigo,
                    Estado    = Entity.Estado,
                    es_empresa_relacionada = Entity.es_empresa_relacionada == null ? false : Convert.ToBoolean(Entity.es_empresa_relacionada),
                    IdCliente             = Entity.IdCliente,
                    FormaPago             = Entity.FormaPago,
                    IdCtaCble_Anti        = Entity.IdCtaCble_Anti,
                    IdCtaCble_cxc         = Entity.IdCtaCble_cxc,
                    IdCtaCble_cxc_Credito = Entity.IdCtaCble_cxc_Credito,
                    IdPersona             = Entity.IdPersona,
                    IdTipoCredito         = Entity.IdTipoCredito,
                    Idtipo_cliente        = Entity.Idtipo_cliente,
                    NivelPrecio           = Entity.NivelPrecio,
                    EsClienteExportador   = Entity.EsClienteExportador
                };
                tb_persona Entity_p = Context_g.tb_persona.Where(q => q.IdPersona == info.IdPersona).FirstOrDefault();
                info.info_persona = new Info.General.tb_persona_Info
                {
                    IdPersona         = Entity_p.IdPersona,
                    pe_apellido       = Entity_p.pe_apellido,
                    pe_nombre         = Entity_p.pe_nombre,
                    pe_cedulaRuc      = Entity_p.pe_cedulaRuc,
                    pe_nombreCompleto = Entity_p.pe_nombreCompleto,
                    pe_razonSocial    = Entity_p.pe_razonSocial,
                    pe_Naturaleza     = Entity_p.pe_Naturaleza,
                    IdTipoDocumento   = Entity_p.IdTipoDocumento
                };

                Context_f.Dispose();
                Context_g.Dispose();
                return(info);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public fa_cliente_Info get_info(int IdEmpresa, decimal IdCliente)
        {
            try
            {
                fa_cliente_Info      info      = new fa_cliente_Info();
                Entities_facturacion Context_f = new Entities_facturacion();
                Entities_general     Context_g = new Entities_general();

                fa_cliente Entity = Context_f.fa_cliente.FirstOrDefault(q => q.IdEmpresa == IdEmpresa && q.IdCliente == IdCliente);
                if (Entity == null)
                {
                    return(null);
                }

                info = new fa_cliente_Info
                {
                    IdEmpresa = Entity.IdEmpresa,
                    cl_Cupo   = Entity.cl_Cupo,
                    cl_plazo  = Entity.cl_plazo,
                    Codigo    = Entity.Codigo,
                    Estado    = Entity.Estado,
                    es_empresa_relacionada = Entity.es_empresa_relacionada,
                    IdCliente             = Entity.IdCliente,
                    FormaPago             = Entity.FormaPago,
                    IdCtaCble_cxc_Credito = Entity.IdCtaCble_cxc_Credito,
                    IdCtaCble_Anticipo    = Entity.IdCtaCble_Anticipo,
                    IdPersona             = Entity.IdPersona,
                    IdTipoCredito         = Entity.IdTipoCredito,
                    Idtipo_cliente        = Entity.Idtipo_cliente,
                    IdNivel             = Entity.IdNivel,
                    EsClienteExportador = Entity.EsClienteExportador
                };

                fa_cliente_contactos Entity_contacto = Context_f.fa_cliente_contactos.Where(q => q.IdEmpresa == info.IdEmpresa && q.IdCliente == info.IdCliente).FirstOrDefault();
                info.IdContacto  = Entity_contacto.IdContacto;
                info.Correo      = Entity_contacto.Correo;
                info.Direccion   = Entity_contacto.Direccion;
                info.Telefono    = Entity_contacto.Telefono;
                info.Celular     = Entity_contacto.Celular;
                info.IdCiudad    = Entity_contacto.IdCiudad;
                info.IdParroquia = Entity_contacto.IdParroquia;

                tb_ciudad Entity_ciudad = Context_g.tb_ciudad.Where(q => q.IdCiudad == info.IdCiudad).FirstOrDefault();
                info.Descripcion_Ciudad = Entity_ciudad.Descripcion_Ciudad;

                tb_persona Entity_p = Context_g.tb_persona.Where(q => q.IdPersona == info.IdPersona).FirstOrDefault();
                info.info_persona = new Info.General.tb_persona_Info
                {
                    IdPersona         = Entity_p.IdPersona,
                    pe_apellido       = Entity_p.pe_apellido,
                    pe_nombre         = Entity_p.pe_nombre,
                    pe_cedulaRuc      = Entity_p.pe_cedulaRuc,
                    pe_nombreCompleto = Entity_p.pe_nombreCompleto,
                    pe_razonSocial    = Entity_p.pe_razonSocial,
                    pe_Naturaleza     = Entity_p.pe_Naturaleza,
                    IdTipoDocumento   = Entity_p.IdTipoDocumento
                };

                Context_f.Dispose();
                Context_g.Dispose();
                return(info);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        public bool ValidarCupoCreditoCliente(int IdEmpresa, int IdSucursal, int IdBodega, decimal IdCbteVta, string vt_tipoDoc, decimal IdCliente, double Total, ref string mensaje)
        {
            Entities_cuentas_por_cobrar db_cxc = new Entities_cuentas_por_cobrar();
            Entities_facturacion        db_fac = new Entities_facturacion();

            try
            {
                #region variables
                double ValorDocumento = 0;
                double SaldoPorCobrar = 0;
                #endregion

                var cliente = db_fac.fa_cliente.Where(q => q.IdEmpresa == IdEmpresa && q.IdCliente == IdCliente).FirstOrDefault();
                if (cliente == null)
                {
                    db_cxc.Dispose();
                    db_fac.Dispose();
                    mensaje = "Seleccione el cliente";
                    return(false);
                }

                if (cliente.cl_Cupo == 0)
                {
                    db_cxc.Dispose();
                    db_fac.Dispose();
                    return(true);
                }

                if (IdCbteVta != 0)
                {
                    if (vt_tipoDoc == "FACT")
                    {
                        var fac = db_fac.vwfa_factura.Where(q => q.IdEmpresa == IdEmpresa && q.IdSucursal == IdSucursal && q.IdBodega == IdBodega && q.IdCbteVta == IdCbteVta).FirstOrDefault();
                        if (fac != null)
                        {
                            ValorDocumento = fac.vt_total == null ? 0 : Convert.ToDouble(fac.vt_total);
                        }
                    }
                    else
                    {
                        var fac = db_fac.vwfa_notaCreDeb.Where(q => q.IdEmpresa == IdEmpresa && q.IdSucursal == IdSucursal && q.IdBodega == IdBodega && q.IdNota == IdCbteVta).FirstOrDefault();
                        if (fac != null)
                        {
                            ValorDocumento = fac.sc_total == null ? 0 : Convert.ToDouble(fac.sc_total);
                        }
                    }
                }

                var cartera = db_cxc.vwcxc_cartera_x_cobrar.Where(q => q.IdEmpresa == IdEmpresa && q.IdCliente == IdCliente && q.Estado == "A");
                if (cartera.Count() > 0)
                {
                    SaldoPorCobrar = Convert.ToDouble(cartera.Sum(q => q.Saldo));
                }

                if (Math.Round(Total + SaldoPorCobrar - ValorDocumento, 2, MidpointRounding.AwayFromZero) > cliente.cl_Cupo)
                {
                    mensaje = "El cliente ha sobrepasado su cupo de crédito de: $" + Math.Round(cliente.cl_Cupo, 2, MidpointRounding.AwayFromZero) + ", Actualmente tiene un crédito en documentos de : $" + Math.Round(SaldoPorCobrar, 2, MidpointRounding.AwayFromZero) + " El total del documento actual es de $" + Math.Round(Total, 2, MidpointRounding.AwayFromZero);
                    db_cxc.Dispose();
                    db_fac.Dispose();
                    return(false);
                }

                db_cxc.Dispose();
                db_fac.Dispose();

                return(true);
            }
            catch (Exception)
            {
                db_cxc.Dispose();
                db_fac.Dispose();
                throw;
            }
        }
Ejemplo n.º 4
0
        public fa_cliente_Info get_info_x_num_cedula(int IdEmpresa, string pe_cedulaRuc)
        {
            try
            {
                fa_cliente_Info info = new fa_cliente_Info
                {
                    info_persona = new Info.General.tb_persona_Info()
                };

                Entities_general Context_general = new Entities_general();
                tb_persona       Entity_p        = Context_general.tb_persona.Where(q => q.pe_cedulaRuc == pe_cedulaRuc).FirstOrDefault();
                if (Entity_p == null)
                {
                    Context_general.Dispose();
                    return(info);
                }

                Entities_facturacion Context_facturacion = new Entities_facturacion();
                fa_cliente           Entity_c            = Context_facturacion.fa_cliente.Where(q => q.IdEmpresa == IdEmpresa && q.IdPersona == Entity_p.IdPersona).FirstOrDefault();
                if (Entity_c == null)
                {
                    info.IdPersona    = Entity_p.IdPersona;
                    info.info_persona = new Info.General.tb_persona_Info
                    {
                        IdPersona           = Entity_p.IdPersona,
                        pe_apellido         = Entity_p.pe_apellido,
                        pe_nombre           = Entity_p.pe_nombre,
                        pe_cedulaRuc        = Entity_p.pe_cedulaRuc,
                        pe_nombreCompleto   = Entity_p.pe_nombreCompleto,
                        pe_razonSocial      = Entity_p.pe_razonSocial,
                        pe_celular          = Entity_p.pe_celular,
                        pe_telfono_Contacto = Entity_p.pe_telfono_Contacto,
                        pe_correo           = Entity_p.pe_correo,
                        pe_direccion        = Entity_p.pe_direccion
                    };
                    Context_general.Dispose();
                    Context_facturacion.Dispose();
                    return(info);
                }

                info = new fa_cliente_Info
                {
                    IdEmpresa    = Entity_c.IdEmpresa,
                    IdCliente    = Entity_c.IdCliente,
                    IdPersona    = Entity_p.IdPersona,
                    info_persona = new Info.General.tb_persona_Info
                    {
                        IdPersona           = Entity_p.IdPersona,
                        pe_apellido         = Entity_p.pe_apellido,
                        pe_nombre           = Entity_p.pe_nombre,
                        pe_cedulaRuc        = Entity_p.pe_cedulaRuc,
                        pe_nombreCompleto   = Entity_p.pe_nombreCompleto,
                        pe_razonSocial      = Entity_p.pe_razonSocial,
                        pe_celular          = Entity_p.pe_celular,
                        pe_telfono_Contacto = Entity_p.pe_telfono_Contacto,
                        pe_correo           = Entity_p.pe_correo,
                        pe_direccion        = Entity_p.pe_direccion
                    }
                };

                return(info);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 5
0
        public tb_persona_Info get_info(int IdEmpresa, string IdTipoPersona, decimal IdEntidad)
        {
            tb_persona_Info info = new tb_persona_Info();

            Entities_general context_g = new Entities_general();

            switch (IdTipoPersona)
            {
            case "PERSONA":
                info = (from q in context_g.tb_persona
                        where q.pe_estado == "A" &&
                        q.IdPersona == IdEntidad
                        select new tb_persona_Info
                {
                    IdPersona = q.IdPersona,
                    pe_nombreCompleto = q.pe_nombreCompleto,
                    pe_cedulaRuc = q.pe_cedulaRuc,
                    IdEntidad = q.IdPersona
                }).FirstOrDefault();
                break;

            case "CLIENTE":
                Entities_facturacion context_f = new Entities_facturacion();
                info = (from q in context_f.vwfa_cliente_consulta
                        where q.Estado == "A" &&
                        q.IdEmpresa == IdEmpresa &&
                        q.IdCliente == IdEntidad
                        select new tb_persona_Info
                {
                    IdPersona = q.IdPersona,
                    pe_nombreCompleto = q.pe_nombreCompleto,
                    pe_cedulaRuc = q.pe_cedulaRuc,
                    IdEntidad = q.IdCliente
                }).FirstOrDefault();
                context_f.Dispose();
                break;

            case "EMPLEA":
                Entities_rrhh context_e = new Entities_rrhh();
                info = (from q in context_e.vwro_empleados_consulta
                        where q.em_estado == "A" &&
                        q.IdEmpresa == IdEmpresa &&
                        q.IdEmpleado == IdEntidad
                        select new tb_persona_Info
                {
                    IdPersona = q.IdPersona,
                    pe_nombreCompleto = q.Empleado,
                    pe_cedulaRuc = q.pe_cedulaRuc,
                    IdEntidad = q.IdEmpleado
                }).FirstOrDefault();
                context_e.Dispose();
                break;

            case "PROVEE":
                Entities_cuentas_por_pagar context_p = new Entities_cuentas_por_pagar();
                info = (from q in context_p.vwcp_proveedor_consulta
                        where q.pr_estado == "A" &&
                        q.IdEmpresa == IdEmpresa &&
                        q.IdProveedor == IdEntidad
                        select new tb_persona_Info
                {
                    IdPersona = q.IdPersona,
                    pe_nombreCompleto = q.pe_nombreCompleto,
                    pe_cedulaRuc = q.pe_cedulaRuc,
                    IdEntidad = q.IdProveedor
                }).FirstOrDefault();
                context_p.Dispose();
                break;
            }

            context_g.Dispose();

            return(info);
        }
Ejemplo n.º 6
0
        public List <tb_persona_Info> get_list(int IdEmpresa, string IdTipo_persona, int skip, int take, string filter)
        {
            try
            {
                List <tb_persona_Info> Lista = new List <tb_persona_Info>();

                Entities_general context_g = new Entities_general();
                switch (IdTipo_persona)
                {
                case "PERSONA":
                    var lstg = context_g.tb_persona.Where(q => q.pe_estado == "A" && (q.IdPersona.ToString() + " " + q.pe_cedulaRuc + " " + q.pe_nombreCompleto).Contains(filter)).OrderBy(q => q.IdPersona).Skip(skip).Take(take);
                    foreach (var q in lstg)
                    {
                        Lista.Add(new tb_persona_Info
                        {
                            IdPersona         = q.IdPersona,
                            pe_nombreCompleto = q.pe_nombreCompleto,
                            pe_cedulaRuc      = q.pe_cedulaRuc,
                            IdEntidad         = q.IdPersona
                        });
                    }
                    break;

                case "CLIENTE":
                    Entities_facturacion context_f = new Entities_facturacion();
                    var lstf = context_f.vwfa_cliente_consulta.Where(q => q.IdEmpresa == IdEmpresa && q.Estado == "A" && (q.IdCliente.ToString() + " " + q.pe_cedulaRuc + " " + q.pe_nombreCompleto).Contains(filter)).OrderBy(q => q.IdCliente).Skip(skip).Take(take);
                    foreach (var q in lstf)
                    {
                        Lista.Add(new tb_persona_Info
                        {
                            IdPersona         = q.IdPersona,
                            pe_nombreCompleto = q.pe_nombreCompleto,
                            pe_cedulaRuc      = q.pe_cedulaRuc,
                            IdEntidad         = q.IdCliente,
                            CodPersona        = q.Descripcion_tip_cliente
                        });
                    }
                    context_f.Dispose();
                    break;

                case "EMPLEA":
                    Entities_rrhh context_e = new Entities_rrhh();
                    var           lstr      = context_e.vwro_empleados_consulta.Where(q => q.IdEmpresa == IdEmpresa && q.em_estado == "A" && (q.IdEmpleado.ToString() + " " + q.pe_cedulaRuc + " " + q.Empleado).Contains(filter)).OrderBy(q => q.IdEmpleado).Skip(skip).Take(take);
                    foreach (var q in lstr)
                    {
                        Lista.Add(new tb_persona_Info
                        {
                            IdPersona         = q.IdPersona,
                            pe_nombreCompleto = q.Empleado,
                            pe_cedulaRuc      = q.pe_cedulaRuc,
                            IdEntidad         = q.IdEmpleado
                        });
                    }
                    context_e.Dispose();
                    break;

                case "PROVEE":
                    Entities_cuentas_por_pagar context_p = new Entities_cuentas_por_pagar();
                    var lstp = context_p.vwcp_proveedor_consulta.Where(q => q.IdEmpresa == IdEmpresa && q.pr_estado == "A" && (q.IdProveedor.ToString() + " " + q.pe_cedulaRuc + " " + q.pe_nombreCompleto).Contains(filter)).OrderBy(q => q.IdProveedor).Skip(skip).Take(take);
                    foreach (var q in lstp)
                    {
                        Lista.Add(new tb_persona_Info
                        {
                            IdPersona         = q.IdPersona,
                            pe_nombreCompleto = q.pe_nombreCompleto,
                            pe_cedulaRuc      = q.pe_cedulaRuc,
                            IdEntidad         = q.IdProveedor
                        });
                    }
                    context_p.Dispose();
                    break;
                }

                context_g.Dispose();
                return(Lista);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 7
0
        public bool GuardarDB(fa_CambioProducto_Info info)
        {
            try
            {
                Entities_facturacion db = new Entities_facturacion();
                #region Cambio producto
                db.fa_CambioProducto.Add(new fa_CambioProducto
                {
                    IdEmpresa   = info.IdEmpresa,
                    IdSucursal  = info.IdSucursal,
                    IdBodega    = info.IdBodega,
                    IdCambio    = info.IdCambio = GetId(info.IdEmpresa, info.IdSucursal, info.IdBodega),
                    Fecha       = info.Fecha.Date,
                    Observacion = info.Observacion,
                    Estado      = true,

                    IdUsuario    = info.IdUsuario,
                    FechaTransac = DateTime.Now
                });
                int secuencia = 1;
                foreach (var item in info.LstDet)
                {
                    db.fa_CambioProductoDet.Add(new fa_CambioProductoDet
                    {
                        IdEmpresa  = info.IdEmpresa,
                        IdSucursal = info.IdSucursal,
                        IdBodega   = info.IdBodega,
                        IdCambio   = info.IdCambio,
                        Secuencia  = secuencia++,

                        IdCbteVta        = item.IdCbteVta,
                        SecuenciaFact    = item.SecuenciaFact,
                        IdProductoFact   = item.IdProductoFact,
                        IdProductoCambio = item.IdProductoCambio,
                        CantidadCambio   = item.CantidadCambio,
                        CantidadFact     = item.CantidadFact
                    });
                }
                db.SaveChanges();

                #endregion



                #region Egreso y devoluciones
                if (info.GenerarDevolucion)
                {
                    Entities_inventario   dbi     = new Entities_inventario();
                    in_Ing_Egr_Inven_Data odata_i = new in_Ing_Egr_Inven_Data();

                    var parametro = dbi.in_parametro.Where(q => q.IdEmpresa == info.IdEmpresa).FirstOrDefault();
                    if (parametro == null)
                    {
                        return(true);
                    }

                    info.IdMovi_inven_tipo = parametro.IdMovi_inven_tipo_Cambio;
                    var movi = GenerarMoviInven(info);
                    if (movi == null)
                    {
                        return(true);
                    }

                    if (info.IdNumMovi == null && odata_i.guardarDB(movi, "-"))
                    {
                        info.IdNumMovi = movi.IdNumMovi;

                        var Entity = db.fa_CambioProducto.Where(q => q.IdEmpresa == info.IdEmpresa && q.IdSucursal == info.IdSucursal && q.IdBodega == info.IdBodega && q.IdCambio == info.IdCambio).FirstOrDefault();
                        if (Entity == null)
                        {
                            return(true);
                        }
                        Entity.IdMovi_inven_tipo = info.IdMovi_inven_tipo;
                        Entity.IdNumMovi         = info.IdNumMovi;
                        db.SaveChanges();

                        GenerarDevoluciones(info);
                    }
                    else
                    {
                        GenerarDevoluciones(info);
                    }
                }
                db.Dispose();
                #endregion

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 8
0
        private void GenerarDevoluciones(fa_CambioProducto_Info info)
        {
            Entities_facturacion dbf = new Entities_facturacion();

            try
            {
                var ListaDetalleCambio = dbf.vwfa_CambioProductoDet_FacturasConMovimiento.Where(q => q.IdEmpresa == info.IdEmpresa && q.IdSucursal == info.IdSucursal && q.IdBodega == info.IdBodega && q.IdCambio == info.IdCambio).ToList();
                if (ListaDetalleCambio.Where(q => q.IdNumMovi_eg == null).Count() > 0)
                {
                    return;
                }

                in_devolucion_inven_Data odata_d = new in_devolucion_inven_Data();

                var DevolucionesAgrupadas = ListaDetalleCambio.GroupBy(q => new { q.IdEmpresa_eg, q.IdSucursal_eg, q.IdMovi_inven_tipo_eg, q.IdNumMovi_eg }).ToList();
                foreach (var item in DevolucionesAgrupadas)
                {
                    var ListaPorMovimiento = ListaDetalleCambio.Where(q => q.IdEmpresa_eg == item.Key.IdEmpresa_eg && q.IdSucursal_eg == item.Key.IdSucursal_eg && q.IdMovi_inven_tipo_eg == item.Key.IdMovi_inven_tipo_eg && q.IdNumMovi_eg == item.Key.IdNumMovi_eg).ToList();
                    in_devolucion_inven_Info devolucion = new in_devolucion_inven_Info
                    {
                        IdEmpresa             = info.IdEmpresa,
                        IdEmpresa_inv         = (int)item.Key.IdEmpresa_eg,
                        IdSucursal_inv        = (int)item.Key.IdSucursal_eg,
                        IdMovi_inven_tipo_inv = (int)item.Key.IdMovi_inven_tipo_eg,
                        IdNumMovi_inv         = (decimal)item.Key.IdNumMovi_eg,
                        cod_Dev_Inven         = "CAMB#" + info.IdCambio,
                        Estado      = true,
                        dev_signo   = "+",
                        Fecha       = info.Fecha.Date,
                        IdUsuario   = info.IdUsuario,
                        observacion = "CAMB#" + info.IdCambio + " " + info.Observacion,

                        lst_det = new List <in_devolucion_inven_det_Info>()
                    };
                    foreach (var Det in ListaPorMovimiento)
                    {
                        devolucion.lst_det.Add(new in_devolucion_inven_det_Info
                        {
                            IdEmpresa             = info.IdEmpresa,
                            inv_IdEmpresa         = (int)Det.IdEmpresa_eg,
                            inv_IdSucursal        = (int)Det.IdSucursal_eg,
                            inv_IdMovi_inven_tipo = (int)Det.IdMovi_inven_tipo_eg,
                            inv_IdNumMovi         = (int)Det.IdNumMovi_eg,
                            inv_Secuencia         = (int)Det.Secuencia_eg,

                            IdProducto     = (decimal)Det.IdProducto,
                            IdBodega       = (int)Det.IdBodega_eg,
                            cant_devuelta  = Det.CantidadCambio,
                            IdUnidadMedida = Det.IdUnidadMedida_sinConversion,
                            mv_costo       = Det.Costo
                        });
                    }

                    if (odata_d.guardarDB(devolucion))
                    {
                        ListaDetalleCambio.ForEach(q => dbf.fa_CambioProductoDet_x_in_devolucion_inven.Add(new fa_CambioProductoDet_x_in_devolucion_inven
                        {
                            IdEmpresa_ca  = info.IdEmpresa,
                            IdSucursal_ca = info.IdSucursal,
                            IdBodega_ca   = info.IdBodega,
                            IdCambio      = info.IdCambio,
                            Secuencia_ca  = q.Secuencia_ca,

                            IdEmpresa_de = devolucion.IdEmpresa,
                            IdDev_Inven  = devolucion.IdDev_Inven
                        }));
                        dbf.SaveChanges();
                    }
                }

                dbf.Dispose();
            }
            catch (Exception)
            {
                dbf.Dispose();
                throw;
            }
        }