Search in sources :

Example 1 with InvoiceDto

use of org.estatio.canonical.invoice.v1.InvoiceDto in project estatio by estatio.

the class InvoiceForLeaseDtoFactory method newDto.

@Programmatic
public InvoiceDto newDto(final InvoiceForLease invoiceForLease) {
    InvoiceDto dto = new InvoiceDto();
    dto.setSelf(mappingHelper.oidDtoFor(invoiceForLease));
    dto.setAtPath(invoiceForLease.getApplicationTenancyPath());
    dto.setBuyerParty(mappingHelper.oidDtoFor(invoiceForLease.getBuyer()));
    dto.setSellerParty(mappingHelper.oidDtoFor(invoiceForLease.getSeller()));
    dto.setDueDate(asXMLGregorianCalendar(invoiceForLease.getDueDate()));
    dto.setInvoiceDate(asXMLGregorianCalendar(invoiceForLease.getInvoiceDate()));
    dto.setInvoiceNumber(invoiceForLease.getInvoiceNumber());
    dto.setPaymentMethod(toDto(invoiceForLease.getPaymentMethod()));
    dto.setCollectionNumber(invoiceForLease.getCollectionNumber());
    final Lease lease = invoiceForLease.getLease();
    if (lease != null) {
        dto.setAgreementReference(lease.getReference());
        final BankMandate paidBy = lease.getPaidBy();
        if (paidBy != null) {
            dto.setPaidByMandate(mappingHelper.oidDtoFor(paidBy));
            dto.setBuyerBankAccount(mappingHelper.oidDtoFor(paidBy.getBankAccount()));
        }
    }
    final Optional<FixedAsset> fixedAssetIfAny = Optional.ofNullable(invoiceForLease.getFixedAsset());
    if (fixedAssetIfAny.isPresent()) {
        final FixedAsset fixedAsset = fixedAssetIfAny.get();
        dto.setFixedAssetReference(fixedAsset.getReference());
        dto.setFixedAssetExternalReference(fixedAsset.getExternalReference());
        // there should be only one
        dto.setSellerBankAccount(mappingHelper.oidDtoFor(invoiceForLease.getSellerBankAccount()));
    }
    invoiceForLease.getItems().stream().forEach(item -> dto.getItems().add(invoiceItemForLeaseDtoFactory.newDto(item)));
    dto.setNetAmount(dto.getItems().stream().map(x -> valueElseZero(x.getNetAmount())).reduce(BigDecimal.ZERO, BigDecimal::add));
    dto.setGrossAmount(dto.getItems().stream().map(x -> valueElseZero(x.getGrossAmount())).reduce(BigDecimal.ZERO, BigDecimal::add));
    dto.setVatAmount(dto.getItems().stream().map(x -> valueElseZero(x.getVatAmount())).reduce(BigDecimal.ZERO, BigDecimal::add));
    return dto;
}
Also used : InvoiceDto(org.estatio.canonical.invoice.v1.InvoiceDto) Lease(org.estatio.module.lease.dom.Lease) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) FixedAsset(org.estatio.module.asset.dom.FixedAsset) BankMandate(org.estatio.module.bankmandate.dom.BankMandate) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 2 with InvoiceDto

use of org.estatio.canonical.invoice.v1.InvoiceDto in project estatio by estatio.

the class InvoiceForLeaseDtoFactory_Test method happy_case.

@Test
public void happy_case() throws Exception {
    // given
    invoice = new InvoiceForLease();
    invoice.setInvoiceDate(new LocalDate(2016, 1, 1));
    invoice.setPaymentMethod(org.estatio.module.invoice.dom.PaymentMethod.DIRECT_DEBIT);
    invoice.getItems().add(newItem(invoice, "1.01", "2.02", "3.03"));
    invoice.getItems().add(newItem(invoice, "10.10", "20.20", "30.30"));
    invoice.getItems().add(newItem(invoice, "100.00", "200.00", "300.00"));
    // when
    final InvoiceDto invoiceDto = invoiceForLeaseDtoFactory.newDto(invoice);
    // then
    assertThat(invoiceDto.getNetAmount()).isEqualTo(new BigDecimal("111.11"));
    assertThat(invoiceDto.getGrossAmount()).isEqualTo(new BigDecimal("222.22"));
    assertThat(invoiceDto.getVatAmount()).isEqualTo(new BigDecimal("333.33"));
    assertThat(invoiceDto.getInvoiceDate().toString()).isEqualTo("2016-01-01T00:00:00.000Z");
    assertThat(invoiceDto.getPaymentMethod()).isEqualTo(PaymentMethod.DIRECT_DEBIT);
}
Also used : InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) InvoiceDto(org.estatio.canonical.invoice.v1.InvoiceDto) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

InvoiceDto (org.estatio.canonical.invoice.v1.InvoiceDto)2 InvoiceForLease (org.estatio.module.lease.dom.invoicing.InvoiceForLease)2 BigDecimal (java.math.BigDecimal)1 Programmatic (org.apache.isis.applib.annotation.Programmatic)1 FixedAsset (org.estatio.module.asset.dom.FixedAsset)1 BankMandate (org.estatio.module.bankmandate.dom.BankMandate)1 Lease (org.estatio.module.lease.dom.Lease)1 LocalDate (org.joda.time.LocalDate)1 Test (org.junit.Test)1