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
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

import io.quarkus.qute.TemplateExtension;

import java.math.BigDecimal;
import java.math.RoundingMode;

@TemplateExtension
public class IntegerExtension {

public static int add(Integer value, int incremental) {
return value + incremental;
}

public static String format(Integer value, String pattern) {
return String.format(pattern, value);
}

}
2 changes: 1 addition & 1 deletion backend/src/main/resources/templates/Renderer/invoice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{#each document.formaDePagoCuotas.orEmpty}
<cac:PaymentTerms>
<cbc:ID>FormaPago</cbc:ID>
<cbc:PaymentMeansID>Cuota{it_index}</cbc:PaymentMeansID>
<cbc:PaymentMeansID>Cuota{it_index.add(1).format('%03d')}</cbc:PaymentMeansID>
<cbc:Amount currencyID="{moneda}">{it.importe.currency}</cbc:Amount>
<cbc:PaymentDueDate>{it.fechaPago}</cbc:PaymentDueDate>
</cac:PaymentTerms>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.project.openubl.ublhub.ubl.xmlbuilder.invoice;

import io.github.project.openubl.ublhub.ProfileManager;
import io.github.project.openubl.ublhub.ubl.XMLBuilder;
import io.github.project.openubl.ublhub.ubl.content.models.common.*;
import io.github.project.openubl.ublhub.ubl.content.models.standard.general.BoletaFactura;
import io.github.project.openubl.ublhub.ubl.content.models.standard.general.CuotaDePago;
import io.github.project.openubl.ublhub.ubl.content.models.standard.general.DocumentoDetalle;
import io.github.project.openubl.xmlbuilderlib.models.catalogs.Catalog6;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.smallrye.mutiny.helpers.test.UniAssertSubscriber;
import org.junit.jupiter.api.Test;

import javax.inject.Inject;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Month;
import java.util.Arrays;

import static io.github.project.openubl.ublhub.ubl.xmlbuilder.XMLAssertUtils.assertSendSunat;
import static io.github.project.openubl.ublhub.ubl.xmlbuilder.XMLAssertUtils.assertSnapshot;

@QuarkusTest
@TestProfile(ProfileManager.class)
public class InvoiceFormaPagoTest {

@Inject
XMLBuilder xmlBuilder;

@Test
public void testInvoiceWithFormaPagoContadoPorDefecto() throws Exception {
// Given
BoletaFactura input = new BoletaFactura();
input.serie = "F001";
input.numero = 1;

input.proveedor = new Proveedor();
input.proveedor.ruc = "12345678912";
input.proveedor.razonSocial = "Softgreen S.A.C.";

input.cliente = new Cliente();
input.cliente.nombre = "Carlos Feria";
input.cliente.numeroDocumentoIdentidad = "12121212121";
input.cliente.tipoDocumentoIdentidad = Catalog6.RUC.toString();

DocumentoDetalle detalle1 = new DocumentoDetalle();
detalle1.descripcion = "Item1";
detalle1.cantidad = new BigDecimal(10);
detalle1.precio = new BigDecimal(100);

DocumentoDetalle detalle2 = new DocumentoDetalle();
detalle2.descripcion = "Item2";
detalle2.cantidad = new BigDecimal(10);
detalle2.precio = new BigDecimal(100);

input.detalle = Arrays.asList(detalle1, detalle2);

// When
UniAssertSubscriber<String> subscriber = xmlBuilder.enrichAndRenderAsync(input).subscribe().withSubscriber(UniAssertSubscriber.create());

// Then
subscriber.assertCompleted();

String xml = subscriber.getItem();

assertSnapshot(xml, getClass(), "sinFormaPago.xml");
assertSendSunat(xml);
}

@Test
public void testInvoiceWithFormaPagoCredito() throws Exception {
// Given
BoletaFactura input = new BoletaFactura();
input.serie = "F001";
input.numero = 1;

input.proveedor = new Proveedor();
input.proveedor.ruc = "12345678912";
input.proveedor.razonSocial = "Softgreen S.A.C.";

input.cliente = new Cliente();
input.cliente.nombre = "Carlos Feria";
input.cliente.numeroDocumentoIdentidad = "12121212121";
input.cliente.tipoDocumentoIdentidad = Catalog6.RUC.toString();

DocumentoDetalle detalle1 = new DocumentoDetalle();
detalle1.descripcion = "Item1";
detalle1.cantidad = new BigDecimal(10);
detalle1.precio = new BigDecimal(100);

DocumentoDetalle detalle2 = new DocumentoDetalle();
detalle2.descripcion = "Item2";
detalle2.cantidad = new BigDecimal(10);
detalle2.precio = new BigDecimal(100);

input.detalle = Arrays.asList(detalle1, detalle2);


CuotaDePago cuota1 = new CuotaDePago();
cuota1.importe = new BigDecimal("10");
cuota1.fechaPago = LocalDate.of(2022, Month.JANUARY, 20);

CuotaDePago cuota2 = new CuotaDePago();
cuota2.importe = new BigDecimal("20");
cuota2.fechaPago = LocalDate.of(2022, Month.FEBRUARY, 20);

input.formaDePagoCuotas = Arrays.asList(cuota1, cuota2);

// When
UniAssertSubscriber<String> subscriber = xmlBuilder.enrichAndRenderAsync(input).subscribe().withSubscriber(UniAssertSubscriber.create());

// Then
subscriber.assertCompleted();

String xml = subscriber.getItem();

assertSnapshot(xml, getClass(), "conFormaPago.xml");
assertSendSunat(xml);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.project.openubl.ublhub.ubl.xmlbuilder.invoice;

import io.github.project.openubl.ublhub.ProfileManager;
import io.github.project.openubl.ublhub.ubl.XMLBuilder;
import io.github.project.openubl.ublhub.ubl.content.models.common.Cliente;
import io.github.project.openubl.ublhub.ubl.content.models.common.Proveedor;
import io.github.project.openubl.ublhub.ubl.content.models.standard.general.BoletaFactura;
import io.github.project.openubl.ublhub.ubl.content.models.standard.general.CuotaDePago;
import io.github.project.openubl.ublhub.ubl.content.models.standard.general.DocumentoDetalle;
import io.github.project.openubl.xmlbuilderlib.models.catalogs.Catalog6;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.smallrye.mutiny.helpers.test.UniAssertSubscriber;
import org.junit.jupiter.api.Test;

import javax.inject.Inject;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.Month;
import java.util.Arrays;
import java.util.List;

import static io.github.project.openubl.ublhub.ubl.xmlbuilder.XMLAssertUtils.assertSendSunat;
import static io.github.project.openubl.ublhub.ubl.xmlbuilder.XMLAssertUtils.assertSnapshot;

@QuarkusTest
@TestProfile(ProfileManager.class)
public class InvoiceIssue30Test {

@Inject
XMLBuilder xmlBuilder;

@Test
public void testInvoice_withPrecioUnitario() throws Exception {
// Given
BoletaFactura input = new BoletaFactura();
input.serie = "F001";
input.numero = 1;

input.proveedor = new Proveedor();
input.proveedor.ruc = "12345678912";
input.proveedor.razonSocial = "Project OpenUBL S.A.C.";

input.cliente = new Cliente();
input.cliente.nombre = "Carlos Feria";
input.cliente.numeroDocumentoIdentidad = "12121212121";
input.cliente.tipoDocumentoIdentidad = Catalog6.RUC.toString();

DocumentoDetalle detalle1 = new DocumentoDetalle();
detalle1.descripcion = "Item1";
detalle1.cantidad = new BigDecimal("10");
detalle1.precio = new BigDecimal("6.68");

input.detalle = List.of(detalle1);

// When
UniAssertSubscriber<String> subscriber = xmlBuilder.enrichAndRenderAsync(input).subscribe().withSubscriber(UniAssertSubscriber.create());

// Then
subscriber.assertCompleted();

String xml = subscriber.getItem();

assertSnapshot(xml, getClass(), "with-precioUnitario.xml");
assertSendSunat(xml);
}

@Test
public void testInvoice_withPrecioConIgv() throws Exception {
// Given
BoletaFactura input = new BoletaFactura();
input.serie = "F001";
input.numero = 1;

input.proveedor = new Proveedor();
input.proveedor.ruc = "12345678912";
input.proveedor.razonSocial = "Project OpenUBL S.A.C.";

input.cliente = new Cliente();
input.cliente.nombre = "Carlos Feria";
input.cliente.numeroDocumentoIdentidad = "12121212121";
input.cliente.tipoDocumentoIdentidad = Catalog6.RUC.toString();

DocumentoDetalle detalle1 = new DocumentoDetalle();
detalle1.descripcion = "Item1";
detalle1.cantidad = new BigDecimal("10");
detalle1.precio = new BigDecimal("7.88");
detalle1.precioConImpuestos = true;

input.detalle = List.of(detalle1);

// When
UniAssertSubscriber<String> subscriber = xmlBuilder.enrichAndRenderAsync(input).subscribe().withSubscriber(UniAssertSubscriber.create());

// Then
subscriber.assertCompleted();

String xml = subscriber.getItem();

assertSnapshot(xml, getClass(), "with-precioUnitarioConImpuestos.xml");
assertSendSunat(xml);
}

@Test
public void testInvoice_withPrecioUnitario_andICB() throws Exception {
// Given
BoletaFactura input = new BoletaFactura();
input.serie = "F001";
input.numero = 1;

input.proveedor = new Proveedor();
input.proveedor.ruc = "12345678912";
input.proveedor.razonSocial = "Project OpenUBL S.A.C.";

input.cliente = new Cliente();
input.cliente.nombre = "Carlos Feria";
input.cliente.numeroDocumentoIdentidad = "12121212121";
input.cliente.tipoDocumentoIdentidad = Catalog6.RUC.toString();

DocumentoDetalle detalle1 = new DocumentoDetalle();
detalle1.descripcion = "Item1";
detalle1.cantidad = new BigDecimal("10");
detalle1.precio = new BigDecimal("6.68");
detalle1.icbAplica = true;

input.detalle = List.of(detalle1);

// When
UniAssertSubscriber<String> subscriber = xmlBuilder.enrichAndRenderAsync(input).subscribe().withSubscriber(UniAssertSubscriber.create());

// Then
subscriber.assertCompleted();

String xml = subscriber.getItem();

assertSnapshot(xml, getClass(), "with-precioUnitario-ICB.xml");
assertSendSunat(xml);
}

@Test
public void testInvoice_withPrecioConIgv_andICB() throws Exception {
// Given
BoletaFactura input = new BoletaFactura();
input.serie = "F001";
input.numero = 1;

input.proveedor = new Proveedor();
input.proveedor.ruc = "12345678912";
input.proveedor.razonSocial = "Project OpenUBL S.A.C.";

input.cliente = new Cliente();
input.cliente.nombre = "Carlos Feria";
input.cliente.numeroDocumentoIdentidad = "12121212121";
input.cliente.tipoDocumentoIdentidad = Catalog6.RUC.toString();

DocumentoDetalle detalle1 = new DocumentoDetalle();
detalle1.descripcion = "Item1";
detalle1.cantidad = new BigDecimal("10");
detalle1.precio = new BigDecimal("7.88");
detalle1.precioConImpuestos = true;
detalle1.icbAplica = true;

input.detalle = List.of(detalle1);

// When
UniAssertSubscriber<String> subscriber = xmlBuilder.enrichAndRenderAsync(input).subscribe().withSubscriber(UniAssertSubscriber.create());

// Then
subscriber.assertCompleted();

String xml = subscriber.getItem();

assertSnapshot(xml, getClass(), "with-precioUnitario-conImpuestos-ICB.xml");
assertSendSunat(xml);
}

}
Loading