Exemplo n.º 1
0
        public static void PrintArchivo(string path, string preFile, List <FacturaDTO> facturas)
        {
            StringBuilder sbFacturas = new StringBuilder();

            try
            {
                if (facturas.Count > 0)
                {
                    sbFacturas.AppendLine("Tipo, RFCEmisor, RFCReceptor, FechaDocto, FechaTimbrado, NoFactura, UUID, ImporteFactura, Moneda, TipodeCambio");

                    foreach (FacturaDTO fac in facturas)
                    {
                        sbFacturas.AppendLine(string.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", fac.tipo, fac.rfcEmisor, fac.rfcReceptor, fac.fechaDocto, fac.fechaTimbrado, fac.noFactura, fac.UUID, fac.importeFactura, fac.moneda, fac.tipoCambio));
                    }

                    using (StreamWriter writer = new StreamWriter(path + "\\" + preFile + "_" + DateTime.Now.ToString("dd-MM-yyyy-HHmmss") + ".csv", true))
                    {
                        writer.WriteLine(sbFacturas.ToString());
                        writer.Close();
                    }
                }
                else
                {
                    Bitacoras.Write("La lista de facturas viene vacía");
                }
            }
            catch (Exception ex)
            {
                LogErrores.Write("Ocurrio un error al Imprimir el archivo de facturas", ex);
            }
        }
Exemplo n.º 2
0
 public static void MoveFacturasXML(string path, List <string> facturasXML)
 {
     try
     {
         if (facturasXML.Count > 0)
         {
             foreach (string file in facturasXML)
             {
                 File.Move(file, path + "\\Procesadas\\" + Path.GetFileName(file));
             }
         }
         else
         {
             Bitacoras.Write("La lista de archivos viene vacía");
         }
     }
     catch (Exception ex)
     {
         LogErrores.Write("Ocurrio un error al mover los archivos de facturas procesados", ex);
     }
 }
Exemplo n.º 3
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);
            }
        }