public static FacturaDTO GenerarFactura(CfdiV33.Comprobante comprobante, string tipo)
        {
            FacturaDTO factura = new FacturaDTO();

            try
            {
                factura = new FacturaDTO()
                {
                    tipo           = tipo,
                    rfcEmisor      = comprobante.Emisor.Rfc,
                    rfcReceptor    = comprobante.Receptor.Rfc,
                    fechaDocto     = comprobante.Fecha,
                    fechaTimbrado  = comprobante.Complemento.Any[0].Attributes[1].Value,
                    noFactura      = comprobante.Folio,
                    UUID           = comprobante.Complemento.Any[0].Attributes[2].Value,
                    importeFactura = comprobante.Total,
                    moneda         = comprobante.Moneda.ToString(),
                    tipoCambio     = comprobante.TipoCambio.ToString()
                };
            }
            catch (Exception ex)
            {
                LogErrores.Write("Ocurrio un error al Generar la factura con la V3.3 con el folio: " + comprobante.Folio, ex);
            }

            return(factura);
        }
Esempio n. 2
0
        public static void ProcesarFacturas()
        {
            List <FacturaDTO> facturasCliente    = new List <FacturaDTO>();
            List <string>     facturasProcesadas = new List <string>();

            try
            {
                string[] facturas = Directory.GetFiles(pathFacturasClientes, "*.xml");

                if (facturas.Count() > 0)
                {
                    foreach (string file in facturas)
                    {
                        try
                        {
                            XmlSerializer       serielizer     = new XmlSerializer(typeof(CfdiV32.Comprobante));
                            XmlTextReader       reader         = new XmlTextReader(file);
                            CfdiV32.Comprobante comprobanteV32 = (CfdiV32.Comprobante)serielizer.Deserialize(reader);

                            FacturaDTO fac = CommonManagement.GenerarFactura(comprobanteV32, "C");

                            if (!string.IsNullOrEmpty(fac.noFactura))
                            {
                                facturasCliente.Add(fac);
                                facturasProcesadas.Add(file);
                            }

                            reader.Dispose();
                        }
                        catch (Exception e)
                        {
                            LogErrores.Write(string.Format("El archivo {0} no soporta la version 3.2", file), e);

                            try
                            {
                                XmlSerializer       serielizer     = new XmlSerializer(typeof(CfdiV33.Comprobante));
                                XmlTextReader       reader         = new XmlTextReader(file);
                                CfdiV33.Comprobante comprobanteV33 = (CfdiV33.Comprobante)serielizer.Deserialize(reader);
                                facturasCliente.Add(CommonManagement.GenerarFactura(comprobanteV33, "C"));
                                facturasProcesadas.Add(file);
                                reader.Dispose();
                            }
                            catch (Exception eV33)
                            {
                                LogErrores.Write(string.Format("El archivo {0} no soporta la version 3.3", file), eV33);
                            }
                        }
                    }

                    CommonManagement.PrintArchivo(pathOutClientes, "InvoiceClientes", facturasCliente);
                    CommonManagement.MoveFacturasXML(pathFacturasClientes, facturasProcesadas);
                }
                else
                {
                    Bitacoras.Write("No se encontraron Facturas de Clientes que procesar");
                }
            }
            catch (Exception ex)
            {
                LogErrores.Write("Ocurrio un error al Procesar las facturas de clientes", ex);
            }
        }