Skip to content

Commit 67f3e8e

Browse files
Add voidedDocuments, SummaryDocuments, Perception and Retention (#230)
* Add voidedDocuments, SummaryDocuments, Perception and Retention Signed-off-by: carlosthe19916 <2582866+carlosthe19916@users.noreply.github.com> * set versions Signed-off-by: carlosthe19916 <2582866+carlosthe19916@users.noreply.github.com> Signed-off-by: carlosthe19916 <2582866+carlosthe19916@users.noreply.github.com>
1 parent 0bb4085 commit 67f3e8e

31 files changed

+2098
-144
lines changed

application/pom.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@
5858
<dependency>
5959
<groupId>io.github.project-openubl</groupId>
6060
<artifactId>quarkus-xbuilder</artifactId>
61-
<version>2.0.0.Beta1</version>
61+
<version>2.0.0.Beta2</version>
6262
</dependency>
6363
<dependency>
6464
<groupId>io.github.project-openubl</groupId>
6565
<artifactId>quarkus-xsender</artifactId>
66-
<version>4.0.0.Beta4</version>
66+
<version>4.0.0.Beta5</version>
6767
</dependency>
6868

6969
<dependency>
@@ -379,6 +379,10 @@
379379
<className>io.github.project.openubl.xbuilder.content.models.standard.general.Invoice</className>
380380
<className>io.github.project.openubl.xbuilder.content.models.standard.general.CreditNote</className>
381381
<className>io.github.project.openubl.xbuilder.content.models.standard.general.DebitNote</className>
382+
<className>io.github.project.openubl.xbuilder.content.models.sunat.baja.VoidedDocuments</className>
383+
<className>io.github.project.openubl.xbuilder.content.models.sunat.resumen.SummaryDocuments</className>
384+
<className>io.github.project.openubl.xbuilder.content.models.sunat.percepcionretencion.Perception</className>
385+
<className>io.github.project.openubl.xbuilder.content.models.sunat.percepcionretencion.Retention</className>
382386
</classNames>
383387
<modules>
384388
<module>

application/src/main/java/io/github/project/openubl/ublhub/dto/DocumentInputDto.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ public class DocumentInputDto {
5555
public enum Kind {
5656
Invoice,
5757
CreditNote,
58-
DebitNote;
58+
DebitNote,
59+
VoidedDocuments,
60+
SummaryDocuments,
61+
Perception,
62+
Retention;
5963
}
6064

6165
@Data

application/src/main/java/io/github/project/openubl/ublhub/scheduler/vertx/VertxSchedulerConsumer.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import javax.inject.Inject;
4040
import javax.transaction.Transactional;
4141
import java.util.HashSet;
42+
import java.util.Optional;
4243

4344
@RequestScoped
4445
public class VertxSchedulerConsumer {
@@ -95,11 +96,13 @@ public void sendFile(Long documentId) {
9596
documentEntity.setSunatResponse(new SUNATResponseEntity());
9697
}
9798

98-
documentEntity.getSunatResponse().setCode(sunatResponse.getMetadata().getResponseCode());
99-
documentEntity.getSunatResponse().setDescription(sunatResponse.getMetadata().getDescription());
10099
documentEntity.getSunatResponse().setStatus(sunatResponse.getStatus() != null ? sunatResponse.getStatus().toString() : null);
101-
documentEntity.getSunatResponse().setNotes(sunatResponse.getMetadata().getNotes() != null ? new HashSet<>(sunatResponse.getMetadata().getNotes()) : null);
102100
documentEntity.getSunatResponse().setTicket(sunatResponse.getSunat() != null ? sunatResponse.getSunat().getTicket() : null);
101+
Optional.ofNullable(sunatResponse.getMetadata()).ifPresent(metadata -> {
102+
documentEntity.getSunatResponse().setCode(metadata.getResponseCode());
103+
documentEntity.getSunatResponse().setDescription(metadata.getDescription());
104+
documentEntity.getSunatResponse().setNotes(metadata.getNotes() != null ? new HashSet<>(metadata.getNotes()) : null);
105+
});
103106

104107
// Save CDR
105108
if (sunatResponse.getSunat() != null && sunatResponse.getSunat().getCdr() != null) {
@@ -163,11 +166,13 @@ public void checkTicket(Long documentId) {
163166
documentEntity.setSunatResponse(new SUNATResponseEntity());
164167
}
165168

166-
documentEntity.getSunatResponse().setCode(sunatResponse.getMetadata().getResponseCode());
167-
documentEntity.getSunatResponse().setDescription(sunatResponse.getMetadata().getDescription());
168169
documentEntity.getSunatResponse().setStatus(sunatResponse.getStatus() != null ? sunatResponse.getStatus().toString() : null);
169-
documentEntity.getSunatResponse().setNotes(sunatResponse.getMetadata().getNotes() != null ? new HashSet<>(sunatResponse.getMetadata().getNotes()) : null);
170170
documentEntity.getSunatResponse().setTicket(sunatResponse.getSunat().getTicket() != null ? sunatResponse.getSunat().getTicket() : null);
171+
Optional.ofNullable(sunatResponse.getMetadata()).ifPresent(metadata -> {
172+
documentEntity.getSunatResponse().setCode(metadata.getResponseCode());
173+
documentEntity.getSunatResponse().setDescription(metadata.getDescription());
174+
documentEntity.getSunatResponse().setNotes(metadata.getNotes() != null ? new HashSet<>(metadata.getNotes()) : null);
175+
});
171176

172177
// Save CDR
173178
if (sunatResponse.getSunat() != null && sunatResponse.getSunat().getCdr() != null) {

application/src/main/java/io/github/project/openubl/ublhub/ubl/builder/idgenerator/IDGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ public interface IDGenerator {
3232

3333
ID generateSummaryDocumentID(ProjectEntity project, String ruc);
3434

35+
ID generatePerceptionID(ProjectEntity project, String ruc, Map<String, String> config);
36+
ID generateRetentionID(ProjectEntity project, String ruc, Map<String, String> config);
37+
3538
}

application/src/main/java/io/github/project/openubl/ublhub/ubl/builder/idgenerator/impl/GeneratedIDGenerator.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ enum DocumentType {
6767
DEBIT_NOTE_FOR_BOLETA_TYPE("DebitNote_Boleta", "BD"),
6868
VOIDED_GENERIC_TYPE("VoidedDocument", "RA"),
6969
VOIDED_DOCUMENT_PERCEPCION_RETENCION_GUIA_TYPE("VoidedDocument", "RR"),
70-
SUMMARY_DOCUMENT_TYPE("SummaryDocument", "RC");
70+
SUMMARY_DOCUMENT_TYPE("SummaryDocument", "RC"),
71+
PERCEPTION("Perception", "P"),
72+
RETENTION("Retention", "R");
7173

7274
private final String name;
7375
private final String prefix;
@@ -232,4 +234,30 @@ public ID generateSummaryDocumentID(ProjectEntity project, String ruc) {
232234
return new ID(serie, numero);
233235
}
234236

237+
@Override
238+
public ID generatePerceptionID(ProjectEntity project, String ruc, Map<String, String> config) {
239+
int minSerie = Integer.parseInt(config.getOrDefault(PROP_MIN_SERIE, "1"));
240+
int minNumero = Integer.parseInt(config.getOrDefault(PROP_MIN_NUMERO, "1"));
241+
242+
DocumentType documentType = DocumentType.PERCEPTION;
243+
GeneratedIDEntity generatedIDEntity = generateNextID(project, ruc, documentType.name, minSerie, minNumero);
244+
245+
String serie = documentType.prefix + StringUtils.leftPad(String.valueOf(generatedIDEntity.getSerie()), 3, "0");
246+
int numero = generatedIDEntity.getNumero();
247+
return new ID(serie, numero);
248+
}
249+
250+
@Override
251+
public ID generateRetentionID(ProjectEntity project, String ruc, Map<String, String> config) {
252+
int minSerie = Integer.parseInt(config.getOrDefault(PROP_MIN_SERIE, "1"));
253+
int minNumero = Integer.parseInt(config.getOrDefault(PROP_MIN_NUMERO, "1"));
254+
255+
DocumentType documentType = DocumentType.RETENTION;
256+
GeneratedIDEntity generatedIDEntity = generateNextID(project, ruc, documentType.name, minSerie, minNumero);
257+
258+
String serie = documentType.prefix + StringUtils.leftPad(String.valueOf(generatedIDEntity.getSerie()), 3, "0");
259+
int numero = generatedIDEntity.getNumero();
260+
return new ID(serie, numero);
261+
}
262+
235263
}

application/src/main/java/io/github/project/openubl/ublhub/ubl/builder/idgenerator/impl/NoneIDGenerator.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,14 @@ public ID generateVoidedDocumentID(ProjectEntity project, String ruc, boolean is
5353
public ID generateSummaryDocumentID(ProjectEntity project, String ruc) {
5454
return null;
5555
}
56+
57+
@Override
58+
public ID generatePerceptionID(ProjectEntity project, String ruc, Map<String, String> config) {
59+
return null;
60+
}
61+
62+
@Override
63+
public ID generateRetentionID(ProjectEntity project, String ruc, Map<String, String> config) {
64+
return null;
65+
}
5666
}

application/src/main/java/io/github/project/openubl/ublhub/ubl/builder/xmlgenerator/XMLGeneratorManager.java

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323
import io.github.project.openubl.ublhub.ubl.builder.idgenerator.IDGenerator;
2424
import io.github.project.openubl.ublhub.ubl.builder.idgenerator.IDGeneratorManager;
2525
import io.github.project.openubl.ublhub.ubl.builder.idgenerator.IDGeneratorType;
26+
import io.github.project.openubl.xbuilder.content.catalogs.Catalog1;
2627
import io.github.project.openubl.xbuilder.content.models.standard.general.CreditNote;
2728
import io.github.project.openubl.xbuilder.content.models.standard.general.DebitNote;
2829
import io.github.project.openubl.xbuilder.content.models.standard.general.Invoice;
30+
import io.github.project.openubl.xbuilder.content.models.sunat.baja.VoidedDocuments;
31+
import io.github.project.openubl.xbuilder.content.models.sunat.percepcionretencion.Perception;
32+
import io.github.project.openubl.xbuilder.content.models.sunat.percepcionretencion.Retention;
33+
import io.github.project.openubl.xbuilder.content.models.sunat.resumen.SummaryDocuments;
2934
import io.github.project.openubl.xbuilder.enricher.ContentEnricher;
3035
import io.quarkus.qute.Template;
3136
import io.vertx.core.json.JsonObject;
@@ -73,6 +78,26 @@ public Object enrichDocument(DocumentInputDto inputDto) {
7378
enricher.enrich(debitNote);
7479
return debitNote;
7580
}
81+
case VoidedDocuments: {
82+
VoidedDocuments voidedDocuments = document.mapTo(VoidedDocuments.class);
83+
enricher.enrich(voidedDocuments);
84+
return voidedDocuments;
85+
}
86+
case SummaryDocuments: {
87+
SummaryDocuments summaryDocuments = document.mapTo(SummaryDocuments.class);
88+
enricher.enrich(summaryDocuments);
89+
return summaryDocuments;
90+
}
91+
case Perception: {
92+
Perception perception = document.mapTo(Perception.class);
93+
enricher.enrich(perception);
94+
return perception;
95+
}
96+
case Retention: {
97+
Retention perception = document.mapTo(Retention.class);
98+
enricher.enrich(perception);
99+
return perception;
100+
}
76101
default:
77102
throw new IllegalStateException("Document not supported for creating XML");
78103
}
@@ -99,6 +124,26 @@ public String renderDocument(DocumentInputDto inputDto) {
99124
Template template = xBuilder.getTemplate(XBuilder.Type.DEBIT_NOTE);
100125
return template.data(debitNote).render();
101126
}
127+
case VoidedDocuments: {
128+
VoidedDocuments voidedDocuments = document.mapTo(VoidedDocuments.class);
129+
Template template = xBuilder.getTemplate(XBuilder.Type.VOIDED_DOCUMENTS);
130+
return template.data(voidedDocuments).render();
131+
}
132+
case SummaryDocuments: {
133+
SummaryDocuments summaryDocuments = document.mapTo(SummaryDocuments.class);
134+
Template template = xBuilder.getTemplate(XBuilder.Type.SUMMARY_DOCUMENTS);
135+
return template.data(summaryDocuments).render();
136+
}
137+
case Perception: {
138+
Perception perception = document.mapTo(Perception.class);
139+
Template template = xBuilder.getTemplate(XBuilder.Type.PERCEPTION);
140+
return template.data(perception).render();
141+
}
142+
case Retention: {
143+
Retention retention = document.mapTo(Retention.class);
144+
Template template = xBuilder.getTemplate(XBuilder.Type.RETENTION);
145+
return template.data(retention).render();
146+
}
102147
default:
103148
throw new IllegalStateException("Document not supported for creating XML");
104149
}
@@ -137,6 +182,38 @@ public XMLResult createXMLString(ProjectEntity projectEntity, DocumentInputDto i
137182
.xml(xml)
138183
.build();
139184
}
185+
case VoidedDocuments: {
186+
VoidedDocuments voidedDocuments = document.mapTo(VoidedDocuments.class);
187+
String xml = getXML(projectEntity, voidedDocuments, idGenerator, idConfig);
188+
return XMLResult.builder()
189+
.ruc(voidedDocuments.getProveedor().getRuc())
190+
.xml(xml)
191+
.build();
192+
}
193+
case SummaryDocuments: {
194+
SummaryDocuments summaryDocuments = document.mapTo(SummaryDocuments.class);
195+
String xml = getXML(projectEntity, summaryDocuments, idGenerator, idConfig);
196+
return XMLResult.builder()
197+
.ruc(summaryDocuments.getProveedor().getRuc())
198+
.xml(xml)
199+
.build();
200+
}
201+
case Perception: {
202+
Perception perception = document.mapTo(Perception.class);
203+
String xml = getXML(projectEntity, perception, idGenerator, idConfig);
204+
return XMLResult.builder()
205+
.ruc(perception.getProveedor().getRuc())
206+
.xml(xml)
207+
.build();
208+
}
209+
case Retention: {
210+
Retention retention = document.mapTo(Retention.class);
211+
String xml = getXML(projectEntity, retention, idGenerator, idConfig);
212+
return XMLResult.builder()
213+
.ruc(retention.getProveedor().getRuc())
214+
.xml(xml)
215+
.build();
216+
}
140217
default:
141218
throw new IllegalStateException("Document not supported for creating XML");
142219
}
@@ -185,4 +262,65 @@ private String getXML(ProjectEntity projectEntity, DebitNote debitNote, IDGenera
185262
Template template = xBuilder.getTemplate(XBuilder.Type.DEBIT_NOTE);
186263
return template.data(debitNote).render();
187264
}
265+
266+
private String getXML(ProjectEntity projectEntity, VoidedDocuments voidedDocuments, IDGenerator idGenerator, Map<String, String> config) {
267+
boolean isPercepcionRetencionOrGuia = voidedDocuments.getComprobantes().stream().anyMatch(voidedDocumentsItem -> {
268+
return voidedDocumentsItem.getTipoComprobante().equals(Catalog1.PERCEPCION.getCode()) ||
269+
voidedDocumentsItem.getTipoComprobante().equals(Catalog1.RETENCION.getCode()) ||
270+
voidedDocumentsItem.getTipoComprobante().equals(Catalog1.GUIA_REMISION_TRANSPORTISTA.getCode());
271+
});
272+
ID id = idGenerator.generateVoidedDocumentID(projectEntity, voidedDocuments.getProveedor().getRuc(), isPercepcionRetencionOrGuia);
273+
if (id != null) {
274+
// voidedDocuments.setSerie(id.getSerie());
275+
voidedDocuments.setNumero(id.getNumero());
276+
}
277+
278+
ContentEnricher enricher = new ContentEnricher(xBuilder.getDefaults(), LocalDate::now);
279+
enricher.enrich(voidedDocuments);
280+
281+
Template template = xBuilder.getTemplate(XBuilder.Type.VOIDED_DOCUMENTS);
282+
return template.data(voidedDocuments).render();
283+
}
284+
285+
private String getXML(ProjectEntity projectEntity, SummaryDocuments summaryDocuments, IDGenerator idGenerator, Map<String, String> config) {
286+
ID id = idGenerator.generateSummaryDocumentID(projectEntity, summaryDocuments.getProveedor().getRuc());
287+
if (id != null) {
288+
// voidedDocuments.setSerie(id.getSerie());
289+
summaryDocuments.setNumero(id.getNumero());
290+
}
291+
292+
ContentEnricher enricher = new ContentEnricher(xBuilder.getDefaults(), LocalDate::now);
293+
enricher.enrich(summaryDocuments);
294+
295+
Template template = xBuilder.getTemplate(XBuilder.Type.SUMMARY_DOCUMENTS);
296+
return template.data(summaryDocuments).render();
297+
}
298+
299+
private String getXML(ProjectEntity projectEntity, Perception perception, IDGenerator idGenerator, Map<String, String> config) {
300+
ID id = idGenerator.generatePerceptionID(projectEntity, perception.getProveedor().getRuc(), config);
301+
if (id != null) {
302+
perception.setSerie(id.getSerie());
303+
perception.setNumero(id.getNumero());
304+
}
305+
306+
ContentEnricher enricher = new ContentEnricher(xBuilder.getDefaults(), LocalDate::now);
307+
enricher.enrich(perception);
308+
309+
Template template = xBuilder.getTemplate(XBuilder.Type.PERCEPTION);
310+
return template.data(perception).render();
311+
}
312+
313+
private String getXML(ProjectEntity projectEntity, Retention retention, IDGenerator idGenerator, Map<String, String> config) {
314+
ID id = idGenerator.generateRetentionID(projectEntity, retention.getProveedor().getRuc(), config);
315+
if (id != null) {
316+
retention.setSerie(id.getSerie());
317+
retention.setNumero(id.getNumero());
318+
}
319+
320+
ContentEnricher enricher = new ContentEnricher(xBuilder.getDefaults(), LocalDate::now);
321+
enricher.enrich(retention);
322+
323+
Template template = xBuilder.getTemplate(XBuilder.Type.RETENTION);
324+
return template.data(retention).render();
325+
}
188326
}

0 commit comments

Comments
 (0)