Skip to content

Commit 2091844

Browse files
committed
Version 5.0.4 Metadata suport added
1 parent 38d7089 commit 2091844

File tree

5 files changed

+334
-5
lines changed

5 files changed

+334
-5
lines changed

Common/Models/Comprobante.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,11 @@ public string Confirmacion
342342
public AllComplements AllComplements { get; set; } = new();
343343

344344

345-
345+
/// <summary>
346+
/// Raw content in Base64 format.
347+
/// </summary>
348+
[XmlIgnore]
349+
public string? Base64Content { get; set; }
346350

347351
public void DeserializeComplements()
348352
{

Common/Models/MetaItem.cs

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Xml.Serialization;
8+
9+
namespace Fiscalapi.XmlDownloader.Common.Models
10+
{
11+
public class MetaItem
12+
{
13+
/// <summary>
14+
/// Folio de la factura - UUID
15+
/// </summary>
16+
public string InvoiceUuid { get; set; }
17+
18+
/// <summary>
19+
/// RFC del emisor del comprobante - RfcEmisor
20+
/// </summary>
21+
[Required]
22+
[StringLength(13)]
23+
public string IssuerTin { get; set; }
24+
25+
/// <summary>
26+
/// Nombre o razón social del emisor - NombreEmisor
27+
/// </summary>
28+
[Required]
29+
public string IssuerName { get; set; }
30+
31+
/// <summary>
32+
/// RFC del receptor del comprobante - RfcReceptor
33+
/// </summary>
34+
[Required]
35+
[StringLength(13)]
36+
public string RecipientTin { get; set; }
37+
38+
/// <summary>
39+
/// Nombre o razón social del receptor - NombreReceptor
40+
/// </summary>
41+
[Required]
42+
public string RecipientName { get; set; }
43+
44+
/// <summary>
45+
/// RFC del Proveedor Autorizado de Certificación (PAC) - RfcPac
46+
/// </summary>
47+
[Required]
48+
[StringLength(13)]
49+
public string PacTin { get; set; }
50+
51+
/// <summary>
52+
/// Fecha y hora de emisión del comprobante - FechaEmision
53+
/// </summary>
54+
public DateTime InvoiceDate { get; set; }
55+
56+
/// <summary>
57+
/// Fecha y hora de certificación por el SAT - FechaCertificacionSat
58+
/// </summary>
59+
public DateTime? SatCertificationDate { get; set; }
60+
61+
/// <summary>
62+
/// Monto total del comprobante - Monto
63+
/// </summary>
64+
[Range(0, double.MaxValue)]
65+
public decimal Amount { get; set; }
66+
67+
/// <summary>
68+
/// Tipo de comprobante (I = Ingreso, E = Egreso, T = Traslado, N = Nómina, P = Pago) - EfectoComprobante
69+
/// </summary>
70+
[Required]
71+
[StringLength(1)]
72+
public string InvoiceType { get; set; }
73+
74+
/// <summary>
75+
/// Estatus del comprobante (1 = Vigente, 0 = Cancelado) - Estatus
76+
/// </summary>
77+
public int Status { get; set; }
78+
79+
/// <summary>
80+
/// Fecha de cancelación del comprobante (si aplica) - FechaCancelacion
81+
/// </summary>
82+
public DateTime? CancellationDate { get; set; }
83+
84+
85+
/// <summary>
86+
/// Constructor con parámetros
87+
/// </summary>
88+
public MetaItem(string invoiceUuid, string issuerTin, string issuerName, string recipientTin,
89+
string recipientName, string pacTin, DateTime invoiceDate,
90+
DateTime? satCertificationDate, decimal amount, string invoiceType,
91+
int status, DateTime? cancellationDate = null)
92+
{
93+
InvoiceUuid = invoiceUuid;
94+
IssuerTin = issuerTin;
95+
IssuerName = issuerName;
96+
RecipientTin = recipientTin;
97+
RecipientName = recipientName;
98+
PacTin = pacTin;
99+
InvoiceDate = invoiceDate;
100+
SatCertificationDate = satCertificationDate;
101+
Amount = amount;
102+
InvoiceType = invoiceType;
103+
Status = status;
104+
CancellationDate = cancellationDate;
105+
}
106+
107+
/// <summary>
108+
/// Método para parsear una línea de texto separada por ~ al objeto MetaItem
109+
/// </summary>
110+
public static MetaItem CreateFromString(string metadataTextLine)
111+
{
112+
if (string.IsNullOrWhiteSpace(metadataTextLine))
113+
throw new ArgumentException("Los datos no pueden estar vacíos", nameof(metadataTextLine));
114+
115+
var fields = metadataTextLine.Split('~');
116+
117+
if (fields.Length < 11)
118+
throw new ArgumentException("Formato de datos inválido. Se requieren al menos 11 campos",
119+
nameof(metadataTextLine));
120+
121+
return new MetaItem(
122+
invoiceUuid: fields[0],
123+
issuerTin: fields[1],
124+
issuerName: fields[2],
125+
recipientTin: fields[3],
126+
recipientName: fields[4],
127+
pacTin: fields[5],
128+
invoiceDate: DateTime.Parse(fields[6]),
129+
satCertificationDate: string.IsNullOrEmpty(fields[7]) ? null : DateTime.Parse(fields[7]),
130+
amount: decimal.Parse(fields[8]),
131+
invoiceType: fields[9],
132+
status: int.Parse(fields[10]),
133+
cancellationDate: fields.Length > 11 && !string.IsNullOrEmpty(fields[11])
134+
? DateTime.Parse(fields[11])
135+
: null
136+
);
137+
}
138+
139+
/// <summary>
140+
/// Convierte el objeto a string con formato separado por ~
141+
/// </summary>
142+
public override string ToString()
143+
{
144+
return $"{InvoiceUuid}~{IssuerTin}~{IssuerName}~{RecipientTin}~{RecipientName}~{PacTin}~" +
145+
$"{InvoiceDate:yyyy-MM-dd HH:mm:ss}~{SatCertificationDate?.ToString("yyyy-MM-dd HH:mm:ss")}~" +
146+
$"{Amount}~{InvoiceType}~{Status}~{CancellationDate?.ToString("yyyy-MM-dd HH:mm:ss")}";
147+
}
148+
149+
/// <summary>
150+
/// Indica si el comprobante está vigente
151+
/// </summary>
152+
public bool IsActive => Status == 1;
153+
154+
/// <summary>
155+
/// Indica si el comprobante está cancelado
156+
/// </summary>
157+
public bool IsCancelled => Status == 0;
158+
159+
160+
/// <summary>
161+
/// Raw content in Base64 format.
162+
/// </summary>
163+
[XmlIgnore]
164+
public string? Base64Content { get; set; }
165+
}
166+
}

IXmlDownloaderService.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Fiscalapi.XmlDownloader.Download.Models;
2121
using Fiscalapi.XmlDownloader.Query.Models;
2222
using Fiscalapi.XmlDownloader.Verify.Models;
23+
using System.Runtime.CompilerServices;
2324

2425
namespace Fiscalapi.XmlDownloader;
2526

@@ -142,4 +143,33 @@ IAsyncEnumerable<Comprobante> GetComprobantesAsync(byte[] packageBytes,
142143
/// <returns>List of Comprobantes objects</returns>
143144
IAsyncEnumerable<Comprobante> GetComprobantesAsync(DownloadResponse downloadResponse,
144145
CancellationToken cancellationToken = default);
146+
147+
148+
/// <summary>
149+
/// Retrieves a list of MetaItems from a package represented by its extracted directory path.
150+
/// </summary>
151+
/// <param name="fullFilePath">Package .zip file path</param>
152+
/// <param name="extractToPath">Path where to extract the zip file</param>
153+
/// <param name="cancellationToken">CancellationToken</param>
154+
/// <returns>A <see cref="IAsyncEnumerable{MetaItem}"/> of <see cref="MetaItem"/> objects.</returns>
155+
IAsyncEnumerable<MetaItem> GetMetadataAsync(string fullFilePath, string extractToPath,
156+
CancellationToken cancellationToken = default);
157+
158+
/// <summary>
159+
/// Retrieves a list of MetaItems from a package represented by its byte array.
160+
/// </summary>
161+
/// <param name="packageBytes">Package Bytes</param>
162+
/// <param name="cancellationToken">CancellationToken</param>
163+
/// <returns>A <see cref="IAsyncEnumerable{MetaItem}"/> of <see cref="MetaItem"/> objects.</returns>
164+
IAsyncEnumerable<MetaItem> GetMetadataAsync(byte[] packageBytes,
165+
CancellationToken cancellationToken = default);
166+
167+
/// <summary>
168+
/// Retrieves a list of MetaItems from a package represented by its DownloadResponse.
169+
/// </summary>
170+
/// <param name="downloadResponse">DownloadResponse</param>
171+
/// <param name="cancellationToken">CancellationToken</param>
172+
/// <returns>A <see cref="IAsyncEnumerable{MetaItem}"/> of <see cref="MetaItem"/> objects.</returns>
173+
IAsyncEnumerable<MetaItem> GetMetadataAsync(DownloadResponse downloadResponse,
174+
CancellationToken cancellationToken = default);
145175
}

XmlDownloader.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<Version>5.0.3</Version>
7+
<Version>5.0.4</Version>
88
<AssemblyVersion>$(Version)</AssemblyVersion>
99
<FileVersion>$(Version)</FileVersion>
1010
<PackageVersion>$(Version)</PackageVersion>

0 commit comments

Comments
 (0)