use of org.estatio.module.capex.dom.payment.PaymentLine in project estatio by estatio.
the class PaymentBatchManager method removeNegativeTransfers.
/**
* Removes (deletes) all {@link PaymentLine line}s that correspond to a transfer which is a net negative.
*/
private void removeNegativeTransfers(PaymentBatch paymentBatch) {
final List<PaymentLine> paymentLines = paymentBatch.getTransfers().stream().filter(x -> x.getAmount().compareTo(BigDecimal.ZERO) <= 0).map(CreditTransfer::getLines).flatMap(Collection::stream).collect(Collectors.toList());
// seems to be necessary to flush everything through both before and after, presumably to deal with the
// dependent collection (else get DN error about having added a deleted object to the batch's lines collection)
flushTransaction();
// this is sufficient, because PaymentBatch#lines is a dependent collection
for (PaymentLine paymentLine : paymentLines) {
paymentBatch.getLines().remove(paymentLine);
}
// see discussion above.
flushTransaction();
if (paymentBatch.getLines().isEmpty()) {
paymentBatch.remove();
}
}
use of org.estatio.module.capex.dom.payment.PaymentLine in project estatio by estatio.
the class EstatioAppHomePage method findIncomingInvoicesWithin.
private List<IncomingInvoice> findIncomingInvoicesWithin(final List<PaymentBatch> batches) {
final List<IncomingInvoice> invoices = Lists.newArrayList();
for (PaymentBatch completedBatch : batches) {
invoices.addAll(Lists.newArrayList(completedBatch.getLines()).stream().map(PaymentLine::getInvoice).collect(Collectors.toList()));
}
invoices.sort(Ordering.natural().nullsLast().onResultOf(IncomingInvoice::getInvoiceDate));
return invoices;
}
use of org.estatio.module.capex.dom.payment.PaymentLine in project estatio by estatio.
the class CreditTransferExportService_Test method isFirstUseBankAccount_works_when_just_invoices_in_transfer_found.
@Test
public void isFirstUseBankAccount_works_when_just_invoices_in_transfer_found() throws Exception {
// given
CreditTransferExportService service = new CreditTransferExportService();
service.incomingInvoiceRepository = mockIncomingInvoiceRepository;
CreditTransfer transfer = new CreditTransfer();
// when
IncomingInvoice invoiceInPaymentLine1 = new IncomingInvoice();
IncomingInvoice invoiceInPaymentLine2 = new IncomingInvoice();
PaymentLine line1 = new PaymentLine();
line1.setInvoice(invoiceInPaymentLine1);
PaymentLine line2 = new PaymentLine();
line2.setInvoice(invoiceInPaymentLine2);
transfer.setLines(Arrays.asList(line1, line2));
// expect
context.checking(new Expectations() {
{
oneOf(mockIncomingInvoiceRepository).findByBankAccount(transfer.getSellerBankAccount());
// when ..
will(returnValue(Arrays.asList(invoiceInPaymentLine1, invoiceInPaymentLine2)));
}
});
// then
Assertions.assertThat(service.isFirstUseBankAccount(transfer)).isTrue();
}
use of org.estatio.module.capex.dom.payment.PaymentLine in project estatio by estatio.
the class CreditTransferExportService_Test method isFirstUseBankAccount_works_when_other_invoices_than_in_transfer_found.
@Test
public void isFirstUseBankAccount_works_when_other_invoices_than_in_transfer_found() throws Exception {
// given
CreditTransferExportService service = new CreditTransferExportService();
service.incomingInvoiceRepository = mockIncomingInvoiceRepository;
CreditTransfer transfer = new CreditTransfer();
// when
IncomingInvoice invoiceInPaymentLine1 = new IncomingInvoice();
IncomingInvoice invoiceInPaymentLine2 = new IncomingInvoice();
PaymentLine line1 = new PaymentLine();
line1.setInvoice(invoiceInPaymentLine1);
PaymentLine line2 = new PaymentLine();
line2.setInvoice(invoiceInPaymentLine2);
transfer.setLines(Arrays.asList(line1, line2));
IncomingInvoice otherInvoice = new IncomingInvoice();
// expect
context.checking(new Expectations() {
{
oneOf(mockIncomingInvoiceRepository).findByBankAccount(transfer.getSellerBankAccount());
// when ..
will(returnValue(Arrays.asList(invoiceInPaymentLine1, invoiceInPaymentLine2, otherInvoice)));
}
});
// then
Assertions.assertThat(service.isFirstUseBankAccount(transfer)).isFalse();
}
use of org.estatio.module.capex.dom.payment.PaymentLine in project estatio by estatio.
the class IncomingInvoice_reject method act.
@Action(domainEvent = IncomingInvoice_next.ActionDomainEvent.class, semantics = SemanticsOf.IDEMPOTENT)
@ActionLayout(cssClassFa = "fa-thumbs-o-down", cssClass = "btn-warning")
public Object act(final String role, @Nullable final Person personToAssignNextTo, final String reason) {
final List<PaymentLine> paymentLines = paymentLineRepository.findByInvoice(incomingInvoice);
// because of the disableXxx guard, this should return either 0 or 1 lines.
for (PaymentLine paymentLine : paymentLines) {
final PaymentBatch paymentBatch = paymentLine.getBatch();
paymentBatch.removeLineFor(incomingInvoice);
}
trigger(personToAssignNextTo, reason, reason);
return objectToReturn();
}
Aggregations