2323import io .github .project .openubl .ublhub .ubl .builder .idgenerator .IDGenerator ;
2424import io .github .project .openubl .ublhub .ubl .builder .idgenerator .IDGeneratorManager ;
2525import io .github .project .openubl .ublhub .ubl .builder .idgenerator .IDGeneratorType ;
26+ import io .github .project .openubl .xbuilder .content .catalogs .Catalog1 ;
2627import io .github .project .openubl .xbuilder .content .models .standard .general .CreditNote ;
2728import io .github .project .openubl .xbuilder .content .models .standard .general .DebitNote ;
2829import 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 ;
2934import io .github .project .openubl .xbuilder .enricher .ContentEnricher ;
3035import io .quarkus .qute .Template ;
3136import 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