use of org.estatio.module.capex.dom.payment.CreditTransfer 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.CreditTransfer in project estatio by estatio.
the class CreditTransferExportService_Test method isFirstUseBankAccount_works_when_no_incoming_invoices_found_for_bank_account.
@Test
public void isFirstUseBankAccount_works_when_no_incoming_invoices_found_for_bank_account() throws Exception {
// given
CreditTransferExportService service = new CreditTransferExportService();
service.incomingInvoiceRepository = mockIncomingInvoiceRepository;
CreditTransfer transfer = new CreditTransfer();
// expect
context.checking(new Expectations() {
{
oneOf(mockIncomingInvoiceRepository).findByBankAccount(transfer.getSellerBankAccount());
// when
will(returnValue(Arrays.asList()));
}
});
// then
Assertions.assertThat(service.isFirstUseBankAccount(transfer)).isTrue();
}
use of org.estatio.module.capex.dom.payment.CreditTransfer 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.CreditTransfer 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();
}
Aggregations