Esempio n. 1
0
        public void Delete(int Id)
        {
            Init();
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioTIPO_FACTURA repositorio   = new RepositorioTIPO_FACTURA(context);
                    TIPO_FACTURA            _TIPO_FACTURA = repositorio.GetById(Id);

                    if (Equals(_TIPO_FACTURA, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado TIPO_FACTURA con Id =", Id.ToString()));
                    }

                    _TIPO_FACTURA.ACTIVO = false;

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
Esempio n. 2
0
        public int Add(string RUT_FACTURA, string NOMBRE_FACTURA, bool AFECTO_IVA, string NOMBRE_REPORTE_FACTURA, string NOMBRE_REPORTE_FACTURA_INDIVIDUAL = "")
        {
            Init();
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    TIPO_FACTURA _TIPO_FACTURA = new TIPO_FACTURA();

                    //properties

                    _TIPO_FACTURA.RUT_FACTURA                       = RUT_FACTURA;
                    _TIPO_FACTURA.NOMBRE_FACTURA                    = NOMBRE_FACTURA;
                    _TIPO_FACTURA.AFECTO_IVA                        = AFECTO_IVA;
                    _TIPO_FACTURA.NOMBRE_REPORTE_FACTURA            = NOMBRE_REPORTE_FACTURA;
                    _TIPO_FACTURA.NOMBRE_REPORTE_FACTURA_INDIVIDUAL = NOMBRE_REPORTE_FACTURA_INDIVIDUAL;
                    _TIPO_FACTURA.ACTIVO = true;

                    //parents


                    context.AddObject("TIPO_FACTURA", _TIPO_FACTURA);
                    context.SaveChanges();

                    return(_TIPO_FACTURA.ID);
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
Esempio n. 3
0
        public void Update(int Id, string RUT_FACTURA, string NOMBRE_FACTURA, bool AFECTO_IVA, string NOMBRE_REPORTE_FACTURA, string NOMBRE_REPORTE_FACTURA_INDIVIDUAL = "")
        {
            Init();
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioTIPO_FACTURA repositorio   = new RepositorioTIPO_FACTURA(context);
                    TIPO_FACTURA            _TIPO_FACTURA = repositorio.GetById(Id);
                    if (Equals(_TIPO_FACTURA, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado TIPO_FACTURA con Id =", Id.ToString()));
                    }

                    //properties

                    if (!string.IsNullOrEmpty(RUT_FACTURA))
                    {
                        _TIPO_FACTURA.RUT_FACTURA = RUT_FACTURA;
                    }
                    if (!string.IsNullOrEmpty(NOMBRE_FACTURA))
                    {
                        _TIPO_FACTURA.NOMBRE_FACTURA = NOMBRE_FACTURA;
                    }
                    _TIPO_FACTURA.AFECTO_IVA = AFECTO_IVA;
                    if (!string.IsNullOrEmpty(NOMBRE_REPORTE_FACTURA))
                    {
                        _TIPO_FACTURA.NOMBRE_REPORTE_FACTURA = NOMBRE_REPORTE_FACTURA;
                    }
                    if (!string.IsNullOrEmpty(NOMBRE_REPORTE_FACTURA_INDIVIDUAL))
                    {
                        _TIPO_FACTURA.NOMBRE_REPORTE_FACTURA_INDIVIDUAL = NOMBRE_REPORTE_FACTURA_INDIVIDUAL;
                    }

                    //parents


                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
Esempio n. 4
0
        public void Update(int Id, int CLIENTEId, int FACTURACIONId, int TIPO_FACTURAId, int CORRELATIVO, string RUT_LABORATORIO, int NETO, int IVA, int TOTAL, string NOMBRE_CLIENTE = "", string RUT_CLIENTE = "", string DIRECCION = "", string NOMBRE_COMUNA = "", int?NUMERO_FACTURA = null, int?DESCUENTO = null, string FONO = "", string GIRO = "", string DETALLE = "", bool?PAGADA = null)
        {
            Init();
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioFACTURA repositorio = new RepositorioFACTURA(context);
                    FACTURA            _FACTURA    = repositorio.GetById(Id);
                    if (Equals(_FACTURA, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado FACTURA con Id =", Id.ToString()));
                    }

                    RepositorioCLIENTE _repositorioCLIENTE = new RepositorioCLIENTE(context);
                    CLIENTE            _objCLIENTE         = _repositorioCLIENTE.GetById(CLIENTEId);
                    if (Equals(_objCLIENTE, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado CLIENTE con Id =", CLIENTEId.ToString()));
                    }

                    RepositorioFACTURACION _repositorioFACTURACION = new RepositorioFACTURACION(context);
                    FACTURACION            _objFACTURACION         = _repositorioFACTURACION.GetById(FACTURACIONId);
                    if (Equals(_objFACTURACION, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado FACTURACION con Id =", FACTURACIONId.ToString()));
                    }

                    RepositorioTIPO_FACTURA _repositorioTIPO_FACTURA = new RepositorioTIPO_FACTURA(context);
                    TIPO_FACTURA            _objTIPO_FACTURA         = _repositorioTIPO_FACTURA.GetById(TIPO_FACTURAId);
                    if (Equals(_objTIPO_FACTURA, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado TIPO_FACTURA con Id =", TIPO_FACTURAId.ToString()));
                    }

                    //properties

                    _FACTURA.CORRELATIVO = CORRELATIVO;
                    if (!string.IsNullOrEmpty(NOMBRE_CLIENTE))
                    {
                        _FACTURA.NOMBRE_CLIENTE = NOMBRE_CLIENTE;
                    }
                    if (!string.IsNullOrEmpty(RUT_CLIENTE))
                    {
                        _FACTURA.RUT_CLIENTE = RUT_CLIENTE;
                    }
                    if (!string.IsNullOrEmpty(DIRECCION))
                    {
                        _FACTURA.DIRECCION = DIRECCION;
                    }
                    if (!string.IsNullOrEmpty(NOMBRE_COMUNA))
                    {
                        _FACTURA.NOMBRE_COMUNA = NOMBRE_COMUNA;
                    }
                    if (NUMERO_FACTURA.HasValue)
                    {
                        _FACTURA.NUMERO_FACTURA = NUMERO_FACTURA.Value;
                    }
                    if (!string.IsNullOrEmpty(RUT_LABORATORIO))
                    {
                        _FACTURA.RUT_LABORATORIO = RUT_LABORATORIO;
                    }
                    if (DESCUENTO.HasValue)
                    {
                        _FACTURA.DESCUENTO = DESCUENTO.Value;
                    }
                    if (!string.IsNullOrEmpty(FONO))
                    {
                        _FACTURA.FONO = FONO;
                    }
                    if (!string.IsNullOrEmpty(GIRO))
                    {
                        _FACTURA.GIRO = GIRO;
                    }
                    if (!string.IsNullOrEmpty(DETALLE))
                    {
                        _FACTURA.DETALLE = DETALLE;
                    }
                    _FACTURA.NETO  = NETO;
                    _FACTURA.IVA   = IVA;
                    _FACTURA.TOTAL = TOTAL;
                    if (PAGADA.HasValue)
                    {
                        _FACTURA.PAGADA = PAGADA.Value;
                    }

                    //parents

                    _FACTURA.CLIENTE      = _objCLIENTE;
                    _FACTURA.FACTURACION  = _objFACTURACION;
                    _FACTURA.TIPO_FACTURA = _objTIPO_FACTURA;

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
Esempio n. 5
0
        public int Add(int CLIENTEId, int FACTURACIONId, int TIPO_FACTURAId, int CORRELATIVO, string RUT_LABORATORIO, int NETO, int IVA, int TOTAL, string NOMBRE_CLIENTE = "", string RUT_CLIENTE = "", string DIRECCION = "", string NOMBRE_COMUNA = "", int?NUMERO_FACTURA = null, int?DESCUENTO = null, string FONO = "", string GIRO = "", string DETALLE = "", bool?PAGADA = null)
        {
            Init();
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioCLIENTE _repositorioCLIENTE = new RepositorioCLIENTE(context);
                    CLIENTE            _objCLIENTE         = _repositorioCLIENTE.GetById(CLIENTEId);
                    if (Equals(_objCLIENTE, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado CLIENTE con Id =", CLIENTEId.ToString()));
                    }

                    RepositorioFACTURACION _repositorioFACTURACION = new RepositorioFACTURACION(context);
                    FACTURACION            _objFACTURACION         = _repositorioFACTURACION.GetById(FACTURACIONId);
                    if (Equals(_objFACTURACION, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado FACTURACION con Id =", FACTURACIONId.ToString()));
                    }

                    RepositorioTIPO_FACTURA _repositorioTIPO_FACTURA = new RepositorioTIPO_FACTURA(context);
                    TIPO_FACTURA            _objTIPO_FACTURA         = _repositorioTIPO_FACTURA.GetById(TIPO_FACTURAId);
                    if (Equals(_objTIPO_FACTURA, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado TIPO_FACTURA con Id =", TIPO_FACTURAId.ToString()));
                    }

                    FACTURA _FACTURA = new FACTURA();

                    //properties

                    _FACTURA.CORRELATIVO     = CORRELATIVO;
                    _FACTURA.NOMBRE_CLIENTE  = NOMBRE_CLIENTE;
                    _FACTURA.RUT_CLIENTE     = RUT_CLIENTE;
                    _FACTURA.DIRECCION       = DIRECCION;
                    _FACTURA.NOMBRE_COMUNA   = NOMBRE_COMUNA;
                    _FACTURA.NUMERO_FACTURA  = NUMERO_FACTURA;
                    _FACTURA.RUT_LABORATORIO = RUT_LABORATORIO;
                    _FACTURA.DESCUENTO       = DESCUENTO;
                    _FACTURA.FONO            = FONO;
                    _FACTURA.GIRO            = GIRO;
                    _FACTURA.DETALLE         = DETALLE;
                    _FACTURA.NETO            = NETO;
                    _FACTURA.IVA             = IVA;
                    _FACTURA.TOTAL           = TOTAL;
                    _FACTURA.PAGADA          = PAGADA;
                    _FACTURA.ACTIVO          = true;

                    //parents

                    _FACTURA.CLIENTE      = _objCLIENTE;
                    _FACTURA.FACTURACION  = _objFACTURACION;
                    _FACTURA.TIPO_FACTURA = _objTIPO_FACTURA;

                    context.AddObject("FACTURA", _FACTURA);
                    context.SaveChanges();

                    return(_FACTURA.ID);
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
Esempio n. 6
0
        public static Clases.CFDS CargarXMLFactura(string RutaArchivo, TIPO_FACTURA tipo)
        {
            Clases.CFDS CFDS     = null;
            Provedor    provedor = null;
            bool        found    = false;

            try
            {
                string     xml  = File.ReadAllText(RutaArchivo);
                XDocument  doc  = XDocument.Parse(xml);
                XNamespace cfdi = doc.Root.Name.Namespace;
                CFDS = new Clases.CFDS();

                XElement comprobante = doc.Element(cfdi + "Comprobante");
                if (comprobante != null)
                {
                    XAttribute atributo = comprobante.Attribute("certificado");
                    CFDS.Certificado = (atributo != null) ? atributo.Value.ToString() : "";

                    atributo   = comprobante.Attribute("serie");
                    CFDS.Serie = (atributo != null) ? atributo.Value.ToString() : "";

                    atributo   = comprobante.Attribute("folio");
                    CFDS.Folio = (atributo != null) ? atributo.Value.ToString() : "";

                    atributo = comprobante.Attribute("noAprobacion");
                    CFDS.Numero_Aprobacion = (atributo != null) ? atributo.Value.ToString() : "";

                    atributo = comprobante.Attribute("fecha");
                    if (atributo == null)
                    {
                        CFDS.Fecha = CFDS.Fecha;
                    }
                    else
                    {
                        CFDS.Fecha = Convert.ToDateTime(atributo.Value);
                    }

                    atributo        = comprobante.Attribute("TipoCambio");
                    CFDS.TipoCambio = (atributo != null) ? Convert.ToDouble(atributo.Value) : 1.00;

                    atributo    = comprobante.Attribute("Moneda");
                    CFDS.Moneda = (atributo != null) ? atributo.Value.ToString() : "";

                    atributo      = comprobante.Attribute("subTotal");
                    CFDS.SubTotal = CFDS.TipoCambio * ((atributo != null) ? Convert.ToDouble(atributo.Value) : 0.00);

                    atributo       = comprobante.Attribute("descuento");
                    CFDS.Descuento = CFDS.TipoCambio * ((atributo != null) ? Convert.ToDouble(atributo.Value) : 0.00);

                    atributo   = comprobante.Attribute("total");
                    CFDS.Total = CFDS.TipoCambio * ((atributo != null) ? Convert.ToDouble(atributo.Value) : 0.00);

                    atributo   = comprobante.Attribute("sello");
                    CFDS.Sello = (atributo != null) ? atributo.Value.ToString() : "";

                    atributo = comprobante.Attribute("tipoDeComprobante");
                    CFDS.Tipo_Comprobante = (atributo != null) ? atributo.Value.ToString() : "";

                    provedor = new Provedor();
                    XElement emisor = comprobante.Element(cfdi + "Emisor");
                    if (emisor != null)
                    {
                        XAttribute att = emisor.Attribute("rfc");
                        CFDS.RFC_Emisor = (att != null) ? att.Value.ToString() : "";

                        att = emisor.Attribute("nombre");
                        CFDS.Nombre_Emisor = (att != null) ? att.Value.ToString() : "";
                    }
                    if (tipo == TIPO_FACTURA.ENTRADA || tipo == TIPO_FACTURA.GASTOS)
                    {
                        provedor.Nombre       = CFDS.Nombre_Emisor;
                        provedor.Razon_Social = CFDS.Nombre_Emisor;
                        provedor.RFC          = CFDS.RFC_Emisor;
                        found = provedor.Cargar().Result;
                        if (!found)
                        {
                            XElement domicilioFiscal = emisor.Element(cfdi + "DomicilioFiscal");
                            if (domicilioFiscal != null)
                            {
                                XAttribute att = domicilioFiscal.Attribute("calle");
                                provedor.Calle = (att != null) ? att.Value.ToString() : "";

                                att = domicilioFiscal.Attribute("codigoPostal");
                                provedor.Codigo_Postal = (att != null) ? att.Value.ToString() : "";

                                att = domicilioFiscal.Attribute("colonia");
                                provedor.Colonia = (att != null) ? att.Value.ToString() : "";

                                att             = domicilioFiscal.Attribute("estado");
                                provedor.Estado = (att != null) ? att.Value.ToString() : "";

                                att = domicilioFiscal.Attribute("localidad");
                                provedor.Localidad = (att != null) ? att.Value.ToString() : "";

                                att             = domicilioFiscal.Attribute("municipio");
                                provedor.Ciudad = (att != null) ? att.Value.ToString() : "";

                                att             = domicilioFiscal.Attribute("noExterior");
                                provedor.NumExt = (att != null) ? att.Value.ToString() : "";

                                att             = domicilioFiscal.Attribute("noInterior");
                                provedor.NumInt = (att != null) ? att.Value.ToString() : "";

                                att           = domicilioFiscal.Attribute("pais");
                                provedor.Pais = (att != null) ? att.Value.ToString() : "";
                            }
                            provedor.Activo = true;
                            provedor.Grabar();
                        }
                    }
                    XElement receptor = comprobante.Element(cfdi + "Receptor");
                    if (receptor != null)
                    {
                        XAttribute att = receptor.Attribute("rfc");
                        CFDS.RFC_Receptor = (att != null) ? att.Value.ToString() : "";

                        att = receptor.Attribute("nombre");
                        CFDS.Nombre_Receptor = (att != null) ? att.Value.ToString() : "";
                    }

                    XElement complemento = comprobante.Element(cfdi + "Complemento");
                    if (complemento != null)
                    {
                        if (complemento.FirstNode != null)
                        {
                            XNamespace tfd = ((System.Xml.Linq.XElement)complemento.FirstNode).Name.Namespace;

                            XElement timbre = complemento.Element((tfd ?? "") + "TimbreFiscalDigital");
                            if (timbre != null)
                            {
                                XAttribute att = timbre.Attribute("UUID");
                                CFDS.Folio_Fiscal = (att != null) ? att.Value.ToString() : "";

                                att = timbre.Attribute("FechaTimbrado");
                                if (att != null)
                                {
                                    CFDS.Fecha_Fiscal = Convert.ToDateTime(att.Value);
                                }
                            }
                        }
                    }

                    XElement impuestos = comprobante.Element(cfdi + "Impuestos");
                    if (impuestos != null)
                    {
                        XElement traslados = impuestos.Element(cfdi + "Traslados");
                        if (traslados != null)
                        {
                            XElement traslado = traslados.Element(cfdi + "Traslado");
                            if (traslado != null)
                            {
                                XAttribute att = traslado.Attribute("impuesto");
                                CFDS.Impuesto = (att != null) ? att.Value.ToString() : "";

                                att       = traslado.Attribute("tasa");
                                CFDS.Tasa = (att != null) ? att.Value.ToString() : "";

                                att = traslado.Attribute("importe");
                                CFDS.Importe_IVA = CFDS.TipoCambio * ((att != null) ? Convert.ToDouble(att.Value) : 0.00);
                            }
                        }
                    }

                    XElement conceptos = comprobante.Element(cfdi + "Conceptos");
                    if (conceptos != null)
                    {
                        //CFDS_Gasto gasto = null;
                        CFDS_Producto producto = null;
                        foreach (XElement concepto in conceptos.Elements(cfdi + "Concepto"))
                        {
                            XAttribute att = concepto.Attribute("cantidad");
                            if (tipo == TIPO_FACTURA.GASTOS)
                            {
                                /*gasto = new CFDS_Gasto();
                                 * gasto.Cantidad = (att != null) ? Convert.ToDouble(att.Value) : 0.00;
                                 * att = concepto.Attribute("unidad");
                                 * gasto.Unidad = (att != null) ? att.Value.ToString() : "";
                                 * att = concepto.Attribute("noIdentificacion");
                                 * gasto.Numero_Identificacion = (att != null) ? att.Value.ToString() : "";
                                 *
                                 * att = concepto.Attribute("descripcion");
                                 * gasto.Descripcion = (att != null) ? att.Value.ToString() : "";
                                 *
                                 * att = concepto.Attribute("valorUnitario");
                                 * gasto.Valor_Unitario = CFDS.TipoCambio * ((att != null) ? Convert.ToDouble(att.Value) : 0.00);
                                 * att = concepto.Attribute("importe");
                                 * gasto.Importe = CFDS.TipoCambio * ((att != null) ? Convert.ToDouble(att.Value) : 0.00);*/
                            }
                            else
                            {
                                producto = new CFDS_Producto();
                                producto.Cantidad_Factura = (att != null) ? Convert.ToDouble(att.Value) : 0.00;
                                att             = concepto.Attribute("unidad");
                                producto.Unidad = (att != null) ? att.Value.ToString() : "";
                                att             = concepto.Attribute("noIdentificacion");
                                producto.Numero_Identificacion = (att != null) ? att.Value.ToString() : "";
                                producto.Codigo_Producto       = producto.Numero_Identificacion;

                                att = concepto.Attribute("descripcion");
                                producto.Descripcion = (att != null) ? att.Value.ToString() : "";

                                att = concepto.Attribute("valorUnitario");
                                producto.Valor_Unitario        = CFDS.TipoCambio * ((att != null) ? Convert.ToDouble(att.Value) : 0.00);
                                producto.ValorUnitarioOriginal = producto.Valor_Unitario;
                                att = concepto.Attribute("importe");
                                producto.Importe = CFDS.TipoCambio * ((att != null) ? Convert.ToDouble(att.Value) : 0.00);
                            }
                            //Provedor provedor = new Provedor();
                            provedor.RFC = (tipo == TIPO_FACTURA.ENTRADA || tipo == TIPO_FACTURA.GASTOS) ? CFDS.RFC_Emisor : CFDS.RFC_Receptor;

                            if ((tipo == TIPO_FACTURA.ENTRADA || tipo == TIPO_FACTURA.GASTOS) && found)// provedor.Cargar(provedor).Result)
                            {
                                if (tipo == TIPO_FACTURA.ENTRADA)
                                {
                                    if (producto.Producto_Id <= 0 && producto.Numero_Identificacion.Trim().Length > 0)
                                    {
                                        Diccionario diccionario = new Diccionario();
                                        Diccionario resultado   = null;
                                        resultado            = diccionario.Buscar(provedor.Provedor_Id, producto.Numero_Identificacion);
                                        producto.Producto_Id = resultado.Producto_Id;
                                    }

                                    if (producto.Producto_Id <= 0 && producto.Descripcion.Trim().Length > 0)
                                    {
                                        Diccionario diccionario = new Diccionario();
                                        Diccionario resultado   = null;
                                        resultado            = diccionario.Buscar(provedor.Provedor_Id, producto.Descripcion);
                                        producto.Producto_Id = resultado.Producto_Id;
                                    }
                                }

                                /*else
                                 * {
                                 *  if (gasto.Gasto_Id <= 0 && gasto.Numero_Identificacion.Trim().Length > 0)
                                 *  {
                                 *      DiccionarioGastos diccionario = new DiccionarioGastos();
                                 *      DiccionarioGastos resultado = null;
                                 *      resultado = diccionario.Buscar(provedor.Provedor_Id, gasto.Numero_Identificacion);
                                 *      gasto.Gasto_Id = resultado.Gasto_Id;
                                 *  }
                                 *
                                 *  if (gasto.Gasto_Id <= 0 && gasto.Descripcion.Trim().Length > 0)
                                 *  {
                                 *      DiccionarioGastos diccionario = new DiccionarioGastos();
                                 *      DiccionarioGastos resultado = null;
                                 *      resultado = diccionario.Buscar(provedor.Provedor_Id, gasto.Descripcion);
                                 *      gasto.Gasto_Id = resultado.Gasto_Id;
                                 *  }
                                 * }*/
                            }
                            if (tipo != TIPO_FACTURA.GASTOS)
                            {
                                if (producto.Producto_Id < 1)
                                {
                                    if (producto.Numero_Identificacion.Trim().Length > 0)
                                    {
                                        Productos prod = new Productos();
                                        if (producto.Numero_Identificacion.Trim().Length > 12)
                                        {
                                            prod.Codigo_de_Barras = producto.Numero_Identificacion.Trim();
                                        }
                                        else
                                        {
                                            prod.Codigo_de_Barras = "";
                                            prod.Codigo_Producto  = producto.Numero_Identificacion.Trim();
                                        }

                                        if (prod.Cargar().Result)
                                        {
                                            producto.ClearProducto();
                                            producto.Producto_Id = prod.Producto_Id;
                                        }
                                    }
                                }
                            }
                            if (tipo == TIPO_FACTURA.SALIDA)
                            {
                                if (producto.Numero_Identificacion.Trim().Length > 0)
                                {
                                    Productos prod = new Productos();
                                    prod.Codigo_Producto = producto.Numero_Identificacion.Trim();
                                    if (prod.Cargar().Result)
                                    {
                                        producto.ClearProducto();
                                        producto.Producto_Id = prod.Producto_Id;
                                    }
                                }
                            }
                            if (tipo == TIPO_FACTURA.GASTOS)
                            {
                                /*CFDS.Gastos.Add(gasto);
                                 * gasto = null;*/
                            }
                            else
                            {
                                CFDS.Productos.Add(producto);
                                producto = null;
                            }
                        }
                    }

                    XElement adenda = doc.Element(cfdi + "Addenda");
                    if (adenda != null)
                    {
                        XNamespace ecfd = adenda.Name.Namespace;

                        XElement ECFD = adenda.Element(ecfd + "ECFD");
                        if (ECFD != null)
                        {
                            XElement documento = adenda.Element(ecfd + "Documento");
                            if (documento != null)
                            {
                                foreach (XElement detalle in documento.Elements(ecfd + "Detalle"))
                                {
                                    XElement elemento  = detalle.Element(ecfd + "NroLinDet");
                                    int      nroLinDet = nroLinDet = elemento != null?Convert.ToInt32(elemento.Value) : 0;

                                    if (nroLinDet > 0)
                                    {
                                        try
                                        {
                                            if (tipo == TIPO_FACTURA.GASTOS)
                                            {
                                                /*CFDS_Gasto gasto = CFDS.Gastos[nroLinDet - 1];
                                                 *
                                                 * if (gasto.Descuento_Porciento <= 0)
                                                 * {
                                                 *  elemento = detalle.Element("DescuentoPct");
                                                 *  gasto.Descuento_Porciento = (elemento != null) ? Convert.ToDouble(elemento.Value) : 0.00;
                                                 * }
                                                 *
                                                 * if (gasto.Descuento_Monto <= 0)
                                                 * {
                                                 *  elemento = detalle.Element("DescuentoMonto");
                                                 *  gasto.Descuento_Monto = CFDS.TipoCambio * ((elemento != null) ? Convert.ToDouble(elemento.Value) : 0.00);
                                                 *
                                                 *  if (gasto.Descuento_Monto <= 0 && gasto.Descuento_Porciento > 0)
                                                 *  {
                                                 *      gasto.Descuento_Monto = gasto.Importe * (gasto.Descuento_Porciento / (double)100);
                                                 *  }
                                                 *
                                                 * }
                                                 *
                                                 * XElement impuestoDet = detalle.Element("ImpuestosDet");
                                                 * if (impuestoDet != null)
                                                 * {
                                                 *  if (gasto.Impuesto_Tasa <= 0)
                                                 *  {
                                                 *      elemento = impuestoDet.Element("TasaImp");
                                                 *      gasto.Impuesto_Tasa = (elemento != null) ? Convert.ToDouble(elemento.Value) : 0.00;
                                                 *  }
                                                 *
                                                 *  if (gasto.Impuesto_Monto <= 0)
                                                 *  {
                                                 *      elemento = impuestoDet.Element("MontoImp");
                                                 *      gasto.Impuesto_Monto = CFDS.TipoCambio * ((elemento != null) ? Convert.ToDouble(elemento.Value) : 0.00);
                                                 *  }
                                                 * }*/
                                            }
                                            else
                                            {
                                                CFDS_Producto producto = CFDS.Productos[nroLinDet - 1];

                                                if (producto.Descuento_Porciento <= 0)
                                                {
                                                    elemento = detalle.Element("DescuentoPct");
                                                    producto.Descuento_Porciento = (elemento != null) ? Convert.ToDouble(elemento.Value) : 0.00;
                                                }

                                                if (producto.Descuento_Monto <= 0)
                                                {
                                                    elemento = detalle.Element("DescuentoMonto");
                                                    producto.Descuento_Monto = CFDS.TipoCambio * ((elemento != null) ? Convert.ToDouble(elemento.Value) : 0.00);

                                                    if (producto.Descuento_Monto <= 0 && producto.Descuento_Porciento > 0)
                                                    {
                                                        producto.Descuento_Monto = producto.Importe * (producto.Descuento_Porciento / (double)100);
                                                    }
                                                }

                                                XElement impuestoDet = detalle.Element("ImpuestosDet");
                                                if (impuestoDet != null)
                                                {
                                                    if (producto.Impuesto_Tasa <= 0)
                                                    {
                                                        elemento = impuestoDet.Element("TasaImp");
                                                        producto.Impuesto_Tasa = (elemento != null) ? Convert.ToDouble(elemento.Value) : 0.00;
                                                    }

                                                    if (producto.Impuesto_Monto <= 0)
                                                    {
                                                        elemento = impuestoDet.Element("MontoImp");
                                                        producto.Impuesto_Monto = CFDS.TipoCambio * ((elemento != null) ? Convert.ToDouble(elemento.Value) : 0.00);
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception innerex)
                                        {
                                            Log.Logger.Error(innerex, innerex.Message);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                string RutaArchivoOrigen = RutaArchivo.Replace("TMP.xml", ".xml");

                string FolioA, SerieA;
                FolioA = "";
                SerieA = "";

                if (CFDS.Folio_Fiscal != "")
                {
                    FolioA = CFDS.Folio_Fiscal;
                    SerieA = "";
                }
                else if (CFDS.Serie == "" && CFDS.Folio == "")
                {
                    CFDS.Folio = FolioA;
                }
                else
                {
                    FolioA = CFDS.Folio;
                    SerieA = CFDS.Serie;
                }

                CFDS.Tipo_Id = (int)tipo;
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex, ex.Message);
                CFDS = null;
            }

            return(CFDS);
        }
Esempio n. 7
0
        public void Update(int Id, int COMUNAId, int CONVENIOId, int TIPO_PRESTACIONId, int TIPO_FACTURAId, string RUT, string NOMBRE, int?DESCUENTO = null, string DIRECCION = "", string FONO = "", string GIRO = "")
        {
            Init();
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioCLIENTE repositorio = new RepositorioCLIENTE(context);
                    CLIENTE            _CLIENTE    = repositorio.GetById(Id);
                    if (Equals(_CLIENTE, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado CLIENTE con Id =", Id.ToString()));
                    }

                    RepositorioCOMUNA _repositorioCOMUNA = new RepositorioCOMUNA(context);
                    COMUNA            _objCOMUNA         = _repositorioCOMUNA.GetById(COMUNAId);
                    if (Equals(_objCOMUNA, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado COMUNA con Id =", COMUNAId.ToString()));
                    }

                    RepositorioCONVENIO _repositorioCONVENIO = new RepositorioCONVENIO(context);
                    CONVENIO            _objCONVENIO         = _repositorioCONVENIO.GetById(CONVENIOId);
                    if (Equals(_objCONVENIO, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado CONVENIO con Id =", CONVENIOId.ToString()));
                    }

                    RepositorioTIPO_PRESTACION _repositorioTIPO_PRESTACION = new RepositorioTIPO_PRESTACION(context);
                    TIPO_PRESTACION            _objTIPO_PRESTACION         = _repositorioTIPO_PRESTACION.GetById(TIPO_PRESTACIONId);
                    if (Equals(_objTIPO_PRESTACION, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado TIPO_PRESTACION con Id =", TIPO_PRESTACIONId.ToString()));
                    }

                    RepositorioTIPO_FACTURA _repositorioTIPO_FACTURA = new RepositorioTIPO_FACTURA(context);
                    TIPO_FACTURA            _objTIPO_FACTURA         = _repositorioTIPO_FACTURA.GetById(TIPO_FACTURAId);
                    if (Equals(_objTIPO_FACTURA, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado TIPO_FACTURA con Id =", TIPO_FACTURAId.ToString()));
                    }

                    //properties

                    if (!string.IsNullOrEmpty(RUT))
                    {
                        _CLIENTE.RUT = RUT;
                    }
                    if (!string.IsNullOrEmpty(NOMBRE))
                    {
                        _CLIENTE.NOMBRE = NOMBRE;
                    }
                    if (DESCUENTO.HasValue)
                    {
                        _CLIENTE.DESCUENTO = DESCUENTO.Value;
                    }
                    if (!string.IsNullOrEmpty(DIRECCION))
                    {
                        _CLIENTE.DIRECCION = DIRECCION;
                    }
                    if (!string.IsNullOrEmpty(FONO))
                    {
                        _CLIENTE.FONO = FONO;
                    }
                    if (!string.IsNullOrEmpty(GIRO))
                    {
                        _CLIENTE.GIRO = GIRO;
                    }

                    //parents

                    _CLIENTE.COMUNA          = _objCOMUNA;
                    _CLIENTE.CONVENIO        = _objCONVENIO;
                    _CLIENTE.TIPO_PRESTACION = _objTIPO_PRESTACION;
                    _CLIENTE.TIPO_FACTURA    = _objTIPO_FACTURA;

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
Esempio n. 8
0
        public int Add(int COMUNAId, int CONVENIOId, int TIPO_PRESTACIONId, int TIPO_FACTURAId, string RUT, string NOMBRE, int?DESCUENTO = null, string DIRECCION = "", string FONO = "", string GIRO = "")
        {
            Init();
            try
            {
                using (LQCEEntities context = new LQCEEntities())
                {
                    RepositorioCOMUNA _repositorioCOMUNA = new RepositorioCOMUNA(context);
                    COMUNA            _objCOMUNA         = _repositorioCOMUNA.GetById(COMUNAId);
                    if (Equals(_objCOMUNA, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado COMUNA con Id =", COMUNAId.ToString()));
                    }

                    RepositorioCONVENIO _repositorioCONVENIO = new RepositorioCONVENIO(context);
                    CONVENIO            _objCONVENIO         = _repositorioCONVENIO.GetById(CONVENIOId);
                    if (Equals(_objCONVENIO, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado CONVENIO con Id =", CONVENIOId.ToString()));
                    }

                    RepositorioTIPO_PRESTACION _repositorioTIPO_PRESTACION = new RepositorioTIPO_PRESTACION(context);
                    TIPO_PRESTACION            _objTIPO_PRESTACION         = _repositorioTIPO_PRESTACION.GetById(TIPO_PRESTACIONId);
                    if (Equals(_objTIPO_PRESTACION, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado TIPO_PRESTACION con Id =", TIPO_PRESTACIONId.ToString()));
                    }

                    RepositorioTIPO_FACTURA _repositorioTIPO_FACTURA = new RepositorioTIPO_FACTURA(context);
                    TIPO_FACTURA            _objTIPO_FACTURA         = _repositorioTIPO_FACTURA.GetById(TIPO_FACTURAId);
                    if (Equals(_objTIPO_FACTURA, null))
                    {
                        throw new Exception(String.Concat("No se ha encontrado TIPO_FACTURA con Id =", TIPO_FACTURAId.ToString()));
                    }

                    CLIENTE _CLIENTE = new CLIENTE();

                    //properties

                    _CLIENTE.RUT       = RUT;
                    _CLIENTE.NOMBRE    = NOMBRE;
                    _CLIENTE.DESCUENTO = DESCUENTO;
                    _CLIENTE.DIRECCION = DIRECCION;
                    _CLIENTE.FONO      = FONO;
                    _CLIENTE.GIRO      = GIRO;
                    _CLIENTE.ACTIVO    = true;

                    //parents

                    _CLIENTE.COMUNA          = _objCOMUNA;
                    _CLIENTE.CONVENIO        = _objCONVENIO;
                    _CLIENTE.TIPO_PRESTACION = _objTIPO_PRESTACION;
                    _CLIENTE.TIPO_FACTURA    = _objTIPO_FACTURA;

                    context.AddObject("CLIENTE", _CLIENTE);
                    context.SaveChanges();

                    return(_CLIENTE.ID);
                }
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                Error = ex.Message;
                throw ex;
            }
        }
 public static TIPO_FACTURA CreateTIPO_FACTURA(int id, string rUT_FACTURA, string nOMBRE_FACTURA, bool aFECTO_IVA, bool aCTIVO, string nOMBRE_REPORTE_FACTURA)
 {
     TIPO_FACTURA tIPO_FACTURA = new TIPO_FACTURA();
     tIPO_FACTURA.ID = id;
     tIPO_FACTURA.RUT_FACTURA = rUT_FACTURA;
     tIPO_FACTURA.NOMBRE_FACTURA = nOMBRE_FACTURA;
     tIPO_FACTURA.AFECTO_IVA = aFECTO_IVA;
     tIPO_FACTURA.ACTIVO = aCTIVO;
     tIPO_FACTURA.NOMBRE_REPORTE_FACTURA = nOMBRE_REPORTE_FACTURA;
     return tIPO_FACTURA;
 }
 public void AddToTIPO_FACTURA(TIPO_FACTURA tIPO_FACTURA)
 {
     base.AddObject("TIPO_FACTURA", tIPO_FACTURA);
 }