Skip to content

Commit f7fb570

Browse files
committed
invoice models updated
1 parent f9536c1 commit f7fb570

14 files changed

+1379
-182
lines changed

src/main/java/com/fiscalapi/Main.java

Lines changed: 935 additions & 154 deletions
Large diffs are not rendered by default.

src/main/java/com/fiscalapi/common/AuditableDto.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.time.LocalDateTime;
44

55
public class AuditableDto extends SerializableDto {
6+
67
private LocalDateTime createdAt;
78
private LocalDateTime updatedAt;
89

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.fiscalapi.models.invoicing;
2+
3+
/**
4+
* Modelo para el envío de facturas por correo
5+
*/
6+
public class EmailInvoiceRequest {
7+
private String invoiceId;
8+
private String toEmail;
9+
private String bandColor;
10+
private String fontColor;
11+
private String base64Logo;
12+
13+
public String getInvoiceId() {
14+
return invoiceId;
15+
}
16+
17+
public void setInvoiceId(String invoiceId) {
18+
this.invoiceId = invoiceId;
19+
}
20+
21+
public String getToEmail() {
22+
return toEmail;
23+
}
24+
25+
public void setToEmail(String toEmail) {
26+
this.toEmail = toEmail;
27+
}
28+
29+
public String getBandColor() {
30+
return bandColor;
31+
}
32+
33+
public void setBandColor(String bandColor) {
34+
this.bandColor = bandColor;
35+
}
36+
37+
public String getFontColor() {
38+
return fontColor;
39+
}
40+
41+
public void setFontColor(String fontColor) {
42+
this.fontColor = fontColor;
43+
}
44+
45+
public String getBase64Logo() {
46+
return base64Logo;
47+
}
48+
49+
public void setBase64Logo(String base64Logo) {
50+
this.base64Logo = base64Logo;
51+
}
52+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.fiscalapi.models.invoicing;
2+
3+
/**
4+
* Modelo de respuesta para generación de PDF o recuperación de XML
5+
*/
6+
public class FileResponse {
7+
private String base64File;
8+
private String fileName;
9+
private String fileExtension;
10+
11+
public String getBase64File() {
12+
return base64File;
13+
}
14+
15+
public void setBase64File(String base64File) {
16+
this.base64File = base64File;
17+
}
18+
19+
public String getFileName() {
20+
return fileName;
21+
}
22+
23+
public void setFileName(String fileName) {
24+
this.fileName = fileName;
25+
}
26+
27+
public String getFileExtension() {
28+
return fileExtension;
29+
}
30+
31+
public void setFileExtension(String fileExtension) {
32+
this.fileExtension = fileExtension;
33+
}
34+
}

src/main/java/com/fiscalapi/models/invoicing/Invoice.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,16 @@
1111
import java.util.List;
1212
import java.time.format.DateTimeFormatter;
1313

14+
import static com.fiscalapi.models.invoicing.InvoiceConstants.SAT_DATE_FORMAT_IN;
15+
import static com.fiscalapi.models.invoicing.InvoiceConstants.SAT_DATE_FORMAT_OUT;
16+
1417

1518
/**
1619
* Modelo anémico que representa una factura electrónica.
1720
* Contiene toda la información de una factura, como datos del emisor, receptor,
1821
* productos/servicios, importes, método de pago, tipo de factura, entre otros.
1922
*/
2023
public class Invoice extends BaseDto{
21-
// Formato para serialización (siempre debe ser exactamente yyyy-MM-ddTHH:mm:ss)
22-
private static final DateTimeFormatter SAT_DATE_FORMAT_OUT = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
23-
24-
// Formato flexible para deserialización (soporta varios formatos de entrada)
25-
private static final DateTimeFormatter SAT_DATE_FORMAT_IN = new DateTimeFormatterBuilder()
26-
.appendPattern("yyyy-MM-dd'T'HH:mm:ss")
27-
.optionalStart()
28-
.appendFraction(ChronoField.NANO_OF_SECOND, 0, 7, true)
29-
.optionalEnd()
30-
.optionalStart()
31-
.appendOffset("+HH:MM", "Z")
32-
.optionalEnd()
33-
.toFormatter();
34-
35-
3624

3725
private String versionCode;
3826
private String series;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.fiscalapi.models.invoicing;
2+
3+
4+
import java.util.List;
5+
6+
/**
7+
* Modelo para la cancelación de facturas
8+
*/
9+
public class InvoiceCancellationRequest {
10+
private String id;
11+
private String invoiceUuid;
12+
private String tin;
13+
private String cancellationReasonCode;
14+
private String replacementUuid;
15+
private List<TaxCredential> taxCredentials;
16+
17+
public String getId() {
18+
return id;
19+
}
20+
21+
public void setId(String id) {
22+
this.id = id;
23+
}
24+
25+
public String getInvoiceUuid() {
26+
return invoiceUuid;
27+
}
28+
29+
public void setInvoiceUuid(String invoiceUuid) {
30+
this.invoiceUuid = invoiceUuid;
31+
}
32+
33+
public String getTin() {
34+
return tin;
35+
}
36+
37+
public void setTin(String tin) {
38+
this.tin = tin;
39+
}
40+
41+
public String getCancellationReasonCode() {
42+
return cancellationReasonCode;
43+
}
44+
45+
public void setCancellationReasonCode(String cancellationReasonCode) {
46+
this.cancellationReasonCode = cancellationReasonCode;
47+
}
48+
49+
public String getReplacementUuid() {
50+
return replacementUuid;
51+
}
52+
53+
public void setReplacementUuid(String replacementUuid) {
54+
this.replacementUuid = replacementUuid;
55+
}
56+
57+
public List<TaxCredential> getTaxCredentials() {
58+
return taxCredentials;
59+
}
60+
61+
public void setTaxCredentials(List<TaxCredential> taxCredentials) {
62+
this.taxCredentials = taxCredentials;
63+
}
64+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fiscalapi.models.invoicing;
2+
3+
import java.util.Map;
4+
5+
/**
6+
* Modelo de respuesta de cancelación de facturas
7+
*/
8+
public class InvoiceCancellationResponse {
9+
private String base64CancellationAcknowledgement;
10+
private Map<String, String> invoiceUuids;
11+
12+
public String getBase64CancellationAcknowledgement() {
13+
return base64CancellationAcknowledgement;
14+
}
15+
16+
public void setBase64CancellationAcknowledgement(String base64CancellationAcknowledgement) {
17+
this.base64CancellationAcknowledgement = base64CancellationAcknowledgement;
18+
}
19+
20+
public Map<String, String> getInvoiceUuids() {
21+
return invoiceUuids;
22+
}
23+
24+
public void setInvoiceUuids(Map<String, String> invoiceUuids) {
25+
this.invoiceUuids = invoiceUuids;
26+
}
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fiscalapi.models.invoicing;
2+
3+
import java.time.format.DateTimeFormatter;
4+
import java.time.format.DateTimeFormatterBuilder;
5+
import java.time.temporal.ChronoField;
6+
7+
public class InvoiceConstants {
8+
// Formato para serialización (siempre debe ser exactamente yyyy-MM-ddTHH:mm:ss)
9+
public static final DateTimeFormatter SAT_DATE_FORMAT_OUT = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
10+
11+
// Formato flexible para deserialización (soporta varios formatos de entrada)
12+
public static final DateTimeFormatter SAT_DATE_FORMAT_IN = new DateTimeFormatterBuilder()
13+
.appendPattern("yyyy-MM-dd'T'HH:mm:ss")
14+
.optionalStart()
15+
.appendFraction(ChronoField.NANO_OF_SECOND, 0, 7, true)
16+
.optionalEnd()
17+
.optionalStart()
18+
.appendOffset("+HH:MM", "Z")
19+
.optionalEnd()
20+
.toFormatter();
21+
}

src/main/java/com/fiscalapi/models/invoicing/InvoicePayment.java

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
package com.fiscalapi.models.invoicing;
22

3+
import com.fasterxml.jackson.annotation.JsonIgnore;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
import java.time.LocalDateTime;
7+
import java.time.ZonedDateTime;
8+
import java.time.format.DateTimeParseException;
39
import java.util.List;
410

11+
import static com.fiscalapi.models.invoicing.InvoiceConstants.SAT_DATE_FORMAT_IN;
12+
import static com.fiscalapi.models.invoicing.InvoiceConstants.SAT_DATE_FORMAT_OUT;
13+
14+
515
// Pago o pagos para liquidar una factura previa
616
public class InvoicePayment {
7-
private String paymentDate;
17+
@JsonIgnore
18+
private LocalDateTime paymentDate;
819
private String paymentFormCode;
920
private String currencyCode;
1021
private Double exchangeRate;
@@ -15,12 +26,70 @@ public class InvoicePayment {
1526
private String targetBankAccount;
1627
private List<PaidInvoice> paidInvoices;
1728

18-
public String getPaymentDate() {
29+
30+
/**
31+
* @return Fecha y hora de expedición del comprobante fiscal
32+
*/
33+
@JsonIgnore
34+
public LocalDateTime getPaymentDate() {
1935
return paymentDate;
2036
}
21-
public void setPaymentDate(String paymentDate) {
22-
this.paymentDate = paymentDate;
37+
38+
/**
39+
* @param date Fecha y hora de expedición como objeto LocalDateTime
40+
*/
41+
@JsonIgnore
42+
public void setPaymentDate(LocalDateTime date) {
43+
this.paymentDate = date;
44+
}
45+
46+
/**
47+
* Obtiene la fecha en formato SAT para serialización JSON.
48+
* Este método se serializa como "date" en el JSON resultante.
49+
* Siempre se formatea exactamente como 'yyyy-MM-ddTHH:mm:ss' (sin fracciones ni zona)
50+
*
51+
* @return Fecha y hora de expedición formateada según el estándar del SAT
52+
*/
53+
@JsonProperty("paymentDate")
54+
public String getSatDate() {
55+
if (paymentDate == null) {
56+
return null;
57+
}
58+
return paymentDate.format(SAT_DATE_FORMAT_OUT);
2359
}
60+
61+
/**
62+
* Establece la fecha a partir de una cadena en formato SAT.
63+
* Este método deserializa el campo "date" del JSON recibido.
64+
* Acepta varios formatos de entrada (con milisegundos, con zona horaria, etc.)
65+
*
66+
* @param satDate Fecha y hora en formato de texto del SAT
67+
*/
68+
@JsonProperty("paymentDate")
69+
public void setSatDate(String satDate) {
70+
if (satDate == null || satDate.isEmpty()) {
71+
this.paymentDate = null;
72+
return;
73+
}
74+
75+
try {
76+
// Intenta primero parsearlo como LocalDateTime
77+
this.paymentDate = LocalDateTime.parse(satDate, SAT_DATE_FORMAT_IN);
78+
} catch (DateTimeParseException e) {
79+
try {
80+
// Si falla, intenta parsearlo como ZonedDateTime y convertirlo a LocalDateTime
81+
ZonedDateTime zdt = ZonedDateTime.parse(satDate);
82+
this.paymentDate = zdt.toLocalDateTime();
83+
} catch (DateTimeParseException e2) {
84+
// Si todo falla, lanza la excepción original
85+
throw new IllegalArgumentException("Formato de fecha inválido: " + satDate +
86+
" (debe ser compatible con el formato yyyy-MM-ddTHH:mm:ss)", e);
87+
}
88+
}
89+
}
90+
91+
92+
2493
public String getPaymentFormCode() {
2594
return paymentFormCode;
2695
}

0 commit comments

Comments
 (0)