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;
}
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);
}
Aggregations