Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@
<dependency>
<groupId>io.github.project-openubl</groupId>
<artifactId>quarkus-xbuilder</artifactId>
<version>2.0.0.Beta1</version>
<version>2.0.0.Beta2</version>
</dependency>
<dependency>
<groupId>io.github.project-openubl</groupId>
<artifactId>quarkus-xsender</artifactId>
<version>4.0.0.Beta4</version>
<version>4.0.0.Beta5</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -379,6 +379,10 @@
<className>io.github.project.openubl.xbuilder.content.models.standard.general.Invoice</className>
<className>io.github.project.openubl.xbuilder.content.models.standard.general.CreditNote</className>
<className>io.github.project.openubl.xbuilder.content.models.standard.general.DebitNote</className>
<className>io.github.project.openubl.xbuilder.content.models.sunat.baja.VoidedDocuments</className>
<className>io.github.project.openubl.xbuilder.content.models.sunat.resumen.SummaryDocuments</className>
<className>io.github.project.openubl.xbuilder.content.models.sunat.percepcionretencion.Perception</className>
<className>io.github.project.openubl.xbuilder.content.models.sunat.percepcionretencion.Retention</className>
</classNames>
<modules>
<module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ public class DocumentInputDto {
public enum Kind {
Invoice,
CreditNote,
DebitNote;
DebitNote,
VoidedDocuments,
SummaryDocuments,
Perception,
Retention;
}

@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import javax.inject.Inject;
import javax.transaction.Transactional;
import java.util.HashSet;
import java.util.Optional;

@RequestScoped
public class VertxSchedulerConsumer {
Expand Down Expand Up @@ -95,11 +96,13 @@ public void sendFile(Long documentId) {
documentEntity.setSunatResponse(new SUNATResponseEntity());
}

documentEntity.getSunatResponse().setCode(sunatResponse.getMetadata().getResponseCode());
documentEntity.getSunatResponse().setDescription(sunatResponse.getMetadata().getDescription());
documentEntity.getSunatResponse().setStatus(sunatResponse.getStatus() != null ? sunatResponse.getStatus().toString() : null);
documentEntity.getSunatResponse().setNotes(sunatResponse.getMetadata().getNotes() != null ? new HashSet<>(sunatResponse.getMetadata().getNotes()) : null);
documentEntity.getSunatResponse().setTicket(sunatResponse.getSunat() != null ? sunatResponse.getSunat().getTicket() : null);
Optional.ofNullable(sunatResponse.getMetadata()).ifPresent(metadata -> {
documentEntity.getSunatResponse().setCode(metadata.getResponseCode());
documentEntity.getSunatResponse().setDescription(metadata.getDescription());
documentEntity.getSunatResponse().setNotes(metadata.getNotes() != null ? new HashSet<>(metadata.getNotes()) : null);
});

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

documentEntity.getSunatResponse().setCode(sunatResponse.getMetadata().getResponseCode());
documentEntity.getSunatResponse().setDescription(sunatResponse.getMetadata().getDescription());
documentEntity.getSunatResponse().setStatus(sunatResponse.getStatus() != null ? sunatResponse.getStatus().toString() : null);
documentEntity.getSunatResponse().setNotes(sunatResponse.getMetadata().getNotes() != null ? new HashSet<>(sunatResponse.getMetadata().getNotes()) : null);
documentEntity.getSunatResponse().setTicket(sunatResponse.getSunat().getTicket() != null ? sunatResponse.getSunat().getTicket() : null);
Optional.ofNullable(sunatResponse.getMetadata()).ifPresent(metadata -> {
documentEntity.getSunatResponse().setCode(metadata.getResponseCode());
documentEntity.getSunatResponse().setDescription(metadata.getDescription());
documentEntity.getSunatResponse().setNotes(metadata.getNotes() != null ? new HashSet<>(metadata.getNotes()) : null);
});

// Save CDR
if (sunatResponse.getSunat() != null && sunatResponse.getSunat().getCdr() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ public interface IDGenerator {

ID generateSummaryDocumentID(ProjectEntity project, String ruc);

ID generatePerceptionID(ProjectEntity project, String ruc, Map<String, String> config);
ID generateRetentionID(ProjectEntity project, String ruc, Map<String, String> config);

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ enum DocumentType {
DEBIT_NOTE_FOR_BOLETA_TYPE("DebitNote_Boleta", "BD"),
VOIDED_GENERIC_TYPE("VoidedDocument", "RA"),
VOIDED_DOCUMENT_PERCEPCION_RETENCION_GUIA_TYPE("VoidedDocument", "RR"),
SUMMARY_DOCUMENT_TYPE("SummaryDocument", "RC");
SUMMARY_DOCUMENT_TYPE("SummaryDocument", "RC"),
PERCEPTION("Perception", "P"),
RETENTION("Retention", "R");

private final String name;
private final String prefix;
Expand Down Expand Up @@ -232,4 +234,30 @@ public ID generateSummaryDocumentID(ProjectEntity project, String ruc) {
return new ID(serie, numero);
}

@Override
public ID generatePerceptionID(ProjectEntity project, String ruc, Map<String, String> config) {
int minSerie = Integer.parseInt(config.getOrDefault(PROP_MIN_SERIE, "1"));
int minNumero = Integer.parseInt(config.getOrDefault(PROP_MIN_NUMERO, "1"));

DocumentType documentType = DocumentType.PERCEPTION;
GeneratedIDEntity generatedIDEntity = generateNextID(project, ruc, documentType.name, minSerie, minNumero);

String serie = documentType.prefix + StringUtils.leftPad(String.valueOf(generatedIDEntity.getSerie()), 3, "0");
int numero = generatedIDEntity.getNumero();
return new ID(serie, numero);
}

@Override
public ID generateRetentionID(ProjectEntity project, String ruc, Map<String, String> config) {
int minSerie = Integer.parseInt(config.getOrDefault(PROP_MIN_SERIE, "1"));
int minNumero = Integer.parseInt(config.getOrDefault(PROP_MIN_NUMERO, "1"));

DocumentType documentType = DocumentType.RETENTION;
GeneratedIDEntity generatedIDEntity = generateNextID(project, ruc, documentType.name, minSerie, minNumero);

String serie = documentType.prefix + StringUtils.leftPad(String.valueOf(generatedIDEntity.getSerie()), 3, "0");
int numero = generatedIDEntity.getNumero();
return new ID(serie, numero);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ public ID generateVoidedDocumentID(ProjectEntity project, String ruc, boolean is
public ID generateSummaryDocumentID(ProjectEntity project, String ruc) {
return null;
}

@Override
public ID generatePerceptionID(ProjectEntity project, String ruc, Map<String, String> config) {
return null;
}

@Override
public ID generateRetentionID(ProjectEntity project, String ruc, Map<String, String> config) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@
import io.github.project.openubl.ublhub.ubl.builder.idgenerator.IDGenerator;
import io.github.project.openubl.ublhub.ubl.builder.idgenerator.IDGeneratorManager;
import io.github.project.openubl.ublhub.ubl.builder.idgenerator.IDGeneratorType;
import io.github.project.openubl.xbuilder.content.catalogs.Catalog1;
import io.github.project.openubl.xbuilder.content.models.standard.general.CreditNote;
import io.github.project.openubl.xbuilder.content.models.standard.general.DebitNote;
import io.github.project.openubl.xbuilder.content.models.standard.general.Invoice;
import io.github.project.openubl.xbuilder.content.models.sunat.baja.VoidedDocuments;
import io.github.project.openubl.xbuilder.content.models.sunat.percepcionretencion.Perception;
import io.github.project.openubl.xbuilder.content.models.sunat.percepcionretencion.Retention;
import io.github.project.openubl.xbuilder.content.models.sunat.resumen.SummaryDocuments;
import io.github.project.openubl.xbuilder.enricher.ContentEnricher;
import io.quarkus.qute.Template;
import io.vertx.core.json.JsonObject;
Expand Down Expand Up @@ -73,6 +78,26 @@ public Object enrichDocument(DocumentInputDto inputDto) {
enricher.enrich(debitNote);
return debitNote;
}
case VoidedDocuments: {
VoidedDocuments voidedDocuments = document.mapTo(VoidedDocuments.class);
enricher.enrich(voidedDocuments);
return voidedDocuments;
}
case SummaryDocuments: {
SummaryDocuments summaryDocuments = document.mapTo(SummaryDocuments.class);
enricher.enrich(summaryDocuments);
return summaryDocuments;
}
case Perception: {
Perception perception = document.mapTo(Perception.class);
enricher.enrich(perception);
return perception;
}
case Retention: {
Retention perception = document.mapTo(Retention.class);
enricher.enrich(perception);
return perception;
}
default:
throw new IllegalStateException("Document not supported for creating XML");
}
Expand All @@ -99,6 +124,26 @@ public String renderDocument(DocumentInputDto inputDto) {
Template template = xBuilder.getTemplate(XBuilder.Type.DEBIT_NOTE);
return template.data(debitNote).render();
}
case VoidedDocuments: {
VoidedDocuments voidedDocuments = document.mapTo(VoidedDocuments.class);
Template template = xBuilder.getTemplate(XBuilder.Type.VOIDED_DOCUMENTS);
return template.data(voidedDocuments).render();
}
case SummaryDocuments: {
SummaryDocuments summaryDocuments = document.mapTo(SummaryDocuments.class);
Template template = xBuilder.getTemplate(XBuilder.Type.SUMMARY_DOCUMENTS);
return template.data(summaryDocuments).render();
}
case Perception: {
Perception perception = document.mapTo(Perception.class);
Template template = xBuilder.getTemplate(XBuilder.Type.PERCEPTION);
return template.data(perception).render();
}
case Retention: {
Retention retention = document.mapTo(Retention.class);
Template template = xBuilder.getTemplate(XBuilder.Type.RETENTION);
return template.data(retention).render();
}
default:
throw new IllegalStateException("Document not supported for creating XML");
}
Expand Down Expand Up @@ -137,6 +182,38 @@ public XMLResult createXMLString(ProjectEntity projectEntity, DocumentInputDto i
.xml(xml)
.build();
}
case VoidedDocuments: {
VoidedDocuments voidedDocuments = document.mapTo(VoidedDocuments.class);
String xml = getXML(projectEntity, voidedDocuments, idGenerator, idConfig);
return XMLResult.builder()
.ruc(voidedDocuments.getProveedor().getRuc())
.xml(xml)
.build();
}
case SummaryDocuments: {
SummaryDocuments summaryDocuments = document.mapTo(SummaryDocuments.class);
String xml = getXML(projectEntity, summaryDocuments, idGenerator, idConfig);
return XMLResult.builder()
.ruc(summaryDocuments.getProveedor().getRuc())
.xml(xml)
.build();
}
case Perception: {
Perception perception = document.mapTo(Perception.class);
String xml = getXML(projectEntity, perception, idGenerator, idConfig);
return XMLResult.builder()
.ruc(perception.getProveedor().getRuc())
.xml(xml)
.build();
}
case Retention: {
Retention retention = document.mapTo(Retention.class);
String xml = getXML(projectEntity, retention, idGenerator, idConfig);
return XMLResult.builder()
.ruc(retention.getProveedor().getRuc())
.xml(xml)
.build();
}
default:
throw new IllegalStateException("Document not supported for creating XML");
}
Expand Down Expand Up @@ -185,4 +262,65 @@ private String getXML(ProjectEntity projectEntity, DebitNote debitNote, IDGenera
Template template = xBuilder.getTemplate(XBuilder.Type.DEBIT_NOTE);
return template.data(debitNote).render();
}

private String getXML(ProjectEntity projectEntity, VoidedDocuments voidedDocuments, IDGenerator idGenerator, Map<String, String> config) {
boolean isPercepcionRetencionOrGuia = voidedDocuments.getComprobantes().stream().anyMatch(voidedDocumentsItem -> {
return voidedDocumentsItem.getTipoComprobante().equals(Catalog1.PERCEPCION.getCode()) ||
voidedDocumentsItem.getTipoComprobante().equals(Catalog1.RETENCION.getCode()) ||
voidedDocumentsItem.getTipoComprobante().equals(Catalog1.GUIA_REMISION_TRANSPORTISTA.getCode());
});
ID id = idGenerator.generateVoidedDocumentID(projectEntity, voidedDocuments.getProveedor().getRuc(), isPercepcionRetencionOrGuia);
if (id != null) {
// voidedDocuments.setSerie(id.getSerie());
voidedDocuments.setNumero(id.getNumero());
}

ContentEnricher enricher = new ContentEnricher(xBuilder.getDefaults(), LocalDate::now);
enricher.enrich(voidedDocuments);

Template template = xBuilder.getTemplate(XBuilder.Type.VOIDED_DOCUMENTS);
return template.data(voidedDocuments).render();
}

private String getXML(ProjectEntity projectEntity, SummaryDocuments summaryDocuments, IDGenerator idGenerator, Map<String, String> config) {
ID id = idGenerator.generateSummaryDocumentID(projectEntity, summaryDocuments.getProveedor().getRuc());
if (id != null) {
// voidedDocuments.setSerie(id.getSerie());
summaryDocuments.setNumero(id.getNumero());
}

ContentEnricher enricher = new ContentEnricher(xBuilder.getDefaults(), LocalDate::now);
enricher.enrich(summaryDocuments);

Template template = xBuilder.getTemplate(XBuilder.Type.SUMMARY_DOCUMENTS);
return template.data(summaryDocuments).render();
}

private String getXML(ProjectEntity projectEntity, Perception perception, IDGenerator idGenerator, Map<String, String> config) {
ID id = idGenerator.generatePerceptionID(projectEntity, perception.getProveedor().getRuc(), config);
if (id != null) {
perception.setSerie(id.getSerie());
perception.setNumero(id.getNumero());
}

ContentEnricher enricher = new ContentEnricher(xBuilder.getDefaults(), LocalDate::now);
enricher.enrich(perception);

Template template = xBuilder.getTemplate(XBuilder.Type.PERCEPTION);
return template.data(perception).render();
}

private String getXML(ProjectEntity projectEntity, Retention retention, IDGenerator idGenerator, Map<String, String> config) {
ID id = idGenerator.generateRetentionID(projectEntity, retention.getProveedor().getRuc(), config);
if (id != null) {
retention.setSerie(id.getSerie());
retention.setNumero(id.getNumero());
}

ContentEnricher enricher = new ContentEnricher(xBuilder.getDefaults(), LocalDate::now);
enricher.enrich(retention);

Template template = xBuilder.getTemplate(XBuilder.Type.RETENTION);
return template.data(retention).render();
}
}
Loading