use of org.estatio.module.capex.dom.invoice.IncomingInvoice in project estatio by estatio.
the class TaskIncomingDocumentPdfService method doLookupPdfFor.
private Blob doLookupPdfFor(final Task task) {
StateTransition<?, ?, ?, ?> stateTransition = stateTransitionService.findFor(task);
if (stateTransition == null) {
return null;
}
if (stateTransition instanceof IncomingDocumentCategorisationStateTransition) {
IncomingDocumentCategorisationStateTransition idcst = (IncomingDocumentCategorisationStateTransition) stateTransition;
final Document document = idcst.getDocument();
if (document == null) {
return null;
}
if (!Objects.equals(document.getMimeType(), "application/pdf")) {
return null;
}
return document.getBlob();
}
if (stateTransition instanceof OrderApprovalStateTransition) {
final OrderApprovalStateTransition oast = (OrderApprovalStateTransition) stateTransition;
final Order order = oast.getOrdr();
final Optional<Document> documentIfAny = lookupAttachedPdfService.lookupOrderPdfFrom(order);
return documentIfAny.map(DocumentAbstract::getBlob).orElse(null);
}
if (stateTransition instanceof IncomingInvoiceApprovalStateTransition) {
final IncomingInvoiceApprovalStateTransition iiast = (IncomingInvoiceApprovalStateTransition) stateTransition;
final IncomingInvoice invoice = iiast.getInvoice();
final Optional<Document> documentIfAny = lookupAttachedPdfService.lookupIncomingInvoicePdfFrom(invoice);
return documentIfAny.map(DocumentAbstract::getBlob).orElse(null);
}
if (stateTransition instanceof BankAccountVerificationStateTransition) {
final BankAccountVerificationStateTransition bavst = (BankAccountVerificationStateTransition) stateTransition;
final BankAccount bankAccount = bavst.getBankAccount();
final Optional<Document> documentIfAny = lookupAttachedPdfService.lookupIbanProofPdfFrom(bankAccount);
return documentIfAny.map(DocumentAbstract::getBlob).orElse(null);
}
return null;
}
use of org.estatio.module.capex.dom.invoice.IncomingInvoice in project estatio by estatio.
the class IncomingInvoiceMenu_Test method filterOrFindByGrossAmount_filter_works.
@Test
public void filterOrFindByGrossAmount_filter_works() {
IncomingInvoiceMenu.IncomingInvoiceFinder builder;
// given
builder = new IncomingInvoiceMenu.IncomingInvoiceFinder(mockInvoiceRepository, mockIncomingInvoiceRepository, mockPartyRepository);
IncomingInvoice invoice1 = new IncomingInvoice();
invoice1.setGrossAmount(new BigDecimal("9.50"));
IncomingInvoice invoice2 = new IncomingInvoice();
invoice2.setGrossAmount(new BigDecimal("9.49"));
builder.setResult(Arrays.asList(invoice1, invoice2));
final BigDecimal amountSearchedFor = new BigDecimal("10.00");
Assertions.assertThat(builder.getResult().size()).isEqualTo(2);
// when
builder.filterOrFindByGrossAmount(amountSearchedFor);
// then
Assertions.assertThat(builder.getResult().size()).isEqualTo(1);
Assertions.assertThat(builder.getResult()).contains(invoice1);
}
use of org.estatio.module.capex.dom.invoice.IncomingInvoice in project estatio by estatio.
the class IncomingInvoiceMenu_Test method filterOrFindInvoiceDate_find_works.
@Test
public void filterOrFindInvoiceDate_find_works() {
IncomingInvoiceMenu.IncomingInvoiceFinder builder;
// given
builder = new IncomingInvoiceMenu.IncomingInvoiceFinder(mockInvoiceRepository, mockIncomingInvoiceRepository, mockPartyRepository);
IncomingInvoice invoice1 = new IncomingInvoice();
IncomingInvoice invoice2 = new IncomingInvoice();
IncomingInvoice invoice3 = new IncomingInvoice();
invoice1.setInvoiceDate(new LocalDate(2017, 7, 15));
invoice2.setInvoiceDate(new LocalDate(2017, 7, 5));
invoice3.setInvoiceDate(new LocalDate(2017, 7, 16));
final LocalDate dateSearchedFor = new LocalDate(2017, 7, 10);
// expect
context.checking(new Expectations() {
{
oneOf(mockIncomingInvoiceRepository).listAll();
will(returnValue(Arrays.asList(invoice1, invoice2, invoice3)));
}
});
// when
builder.filterOrFindByInvoiceDate(dateSearchedFor);
// then
Assertions.assertThat(builder.getResult().size()).isEqualTo(2);
Assertions.assertThat(builder.getResult()).contains(invoice1);
Assertions.assertThat(builder.getResult()).contains(invoice2);
}
use of org.estatio.module.capex.dom.invoice.IncomingInvoice in project estatio by estatio.
the class UpcomingPaymentService_Test method getUpcomingPayments_works_when_bankAccount_found.
@Test
public void getUpcomingPayments_works_when_bankAccount_found() throws Exception {
// given
UpcomingPaymentService service = new UpcomingPaymentService();
service.incomingInvoiceRepository = mockIncomingInvoiceRepository;
service.debtorBankAccountService = mockDebtorBankAccountService;
IncomingInvoice completedInvoice = new IncomingInvoice();
completedInvoice.setApprovalState(IncomingInvoiceApprovalState.COMPLETED);
final BigDecimal amountForCompleted = new BigDecimal("1234.56");
completedInvoice.setGrossAmount(amountForCompleted);
IncomingInvoice approvedInvoice = new IncomingInvoice();
approvedInvoice.setApprovalState(IncomingInvoiceApprovalState.APPROVED);
final BigDecimal amountForApproved = new BigDecimal("1000.00");
approvedInvoice.setGrossAmount(amountForApproved);
BankAccount bankAccountForPending = new BankAccount();
IncomingInvoice pendingInvoice = new IncomingInvoice();
pendingInvoice.setApprovalState(IncomingInvoiceApprovalState.PENDING_BANK_ACCOUNT_CHECK);
final BigDecimal amountForPending = new BigDecimal("2000.00");
pendingInvoice.setGrossAmount(amountForPending);
// expect
context.checking(new Expectations() {
{
oneOf(mockIncomingInvoiceRepository).findByApprovalStateAndPaymentMethod(IncomingInvoiceApprovalState.COMPLETED, PaymentMethod.BANK_TRANSFER);
will(returnValue(Arrays.asList(completedInvoice)));
oneOf(mockIncomingInvoiceRepository).findByApprovalStateAndPaymentMethod(IncomingInvoiceApprovalState.APPROVED, PaymentMethod.BANK_TRANSFER);
will(returnValue(Arrays.asList(approvedInvoice)));
oneOf(mockIncomingInvoiceRepository).findByApprovalStateAndPaymentMethod(IncomingInvoiceApprovalState.PENDING_BANK_ACCOUNT_CHECK, PaymentMethod.BANK_TRANSFER);
will(returnValue(Arrays.asList(pendingInvoice)));
allowing(mockDebtorBankAccountService).uniqueDebtorAccountToPay(completedInvoice);
will(returnValue(null));
allowing(mockDebtorBankAccountService).uniqueDebtorAccountToPay(approvedInvoice);
will(returnValue(null));
allowing(mockDebtorBankAccountService).uniqueDebtorAccountToPay(pendingInvoice);
will(returnValue(bankAccountForPending));
}
});
// when
List<UpcomingPaymentTotal> result = service.getUpcomingPayments();
// then
assertThat(result.size()).isEqualTo(2);
UpcomingPaymentTotal totalWithoutBankAccount = result.get(0);
assertThat(totalWithoutBankAccount.getDebtorBankAccount()).isNull();
assertThat(totalWithoutBankAccount.getUpcomingAmountForCompleted()).isEqualTo(amountForCompleted);
assertThat(totalWithoutBankAccount.getUpcomingAmountForApprovedByManager()).isEqualTo(amountForApproved);
assertThat(totalWithoutBankAccount.getUpcomingAmountForPendingBankAccountCheck()).isNull();
assertThat(totalWithoutBankAccount.getTotalUpcomingAmount()).isEqualTo(new BigDecimal("2234.56"));
UpcomingPaymentTotal totalWithBankAccount = result.get(1);
assertThat(totalWithBankAccount.getDebtorBankAccount()).isEqualTo(bankAccountForPending);
assertThat(totalWithBankAccount.getUpcomingAmountForCompleted()).isNull();
assertThat(totalWithBankAccount.getUpcomingAmountForApprovedByManager()).isNull();
assertThat(totalWithBankAccount.getUpcomingAmountForPendingBankAccountCheck()).isEqualTo(amountForPending);
assertThat(totalWithBankAccount.getTotalUpcomingAmount()).isEqualTo(amountForPending);
}
use of org.estatio.module.capex.dom.invoice.IncomingInvoice in project estatio by estatio.
the class UpcomingPaymentService_Test method getUpcomingPayments_works_when_no_bankAccount_found.
@Test
public void getUpcomingPayments_works_when_no_bankAccount_found() throws Exception {
// given
UpcomingPaymentService service = new UpcomingPaymentService();
service.incomingInvoiceRepository = mockIncomingInvoiceRepository;
service.debtorBankAccountService = mockDebtorBankAccountService;
IncomingInvoice completedInvoice = new IncomingInvoice();
completedInvoice.setApprovalState(IncomingInvoiceApprovalState.COMPLETED);
final BigDecimal amountForCompleted = new BigDecimal("1234.56");
completedInvoice.setGrossAmount(amountForCompleted);
IncomingInvoice approvedInvoice = new IncomingInvoice();
approvedInvoice.setApprovalState(IncomingInvoiceApprovalState.APPROVED);
final BigDecimal amountForApproved = new BigDecimal("1000.00");
approvedInvoice.setGrossAmount(amountForApproved);
IncomingInvoice pendingInvoice = new IncomingInvoice();
pendingInvoice.setApprovalState(IncomingInvoiceApprovalState.PENDING_BANK_ACCOUNT_CHECK);
final BigDecimal amountForPending = new BigDecimal("2000.00");
pendingInvoice.setGrossAmount(amountForPending);
// expect
context.checking(new Expectations() {
{
oneOf(mockIncomingInvoiceRepository).findByApprovalStateAndPaymentMethod(IncomingInvoiceApprovalState.COMPLETED, PaymentMethod.BANK_TRANSFER);
will(returnValue(Arrays.asList(completedInvoice)));
oneOf(mockIncomingInvoiceRepository).findByApprovalStateAndPaymentMethod(IncomingInvoiceApprovalState.APPROVED, PaymentMethod.BANK_TRANSFER);
will(returnValue(Arrays.asList(approvedInvoice)));
oneOf(mockIncomingInvoiceRepository).findByApprovalStateAndPaymentMethod(IncomingInvoiceApprovalState.PENDING_BANK_ACCOUNT_CHECK, PaymentMethod.BANK_TRANSFER);
will(returnValue(Arrays.asList(pendingInvoice)));
allowing(mockDebtorBankAccountService).uniqueDebtorAccountToPay(completedInvoice);
will(returnValue(null));
allowing(mockDebtorBankAccountService).uniqueDebtorAccountToPay(approvedInvoice);
will(returnValue(null));
allowing(mockDebtorBankAccountService).uniqueDebtorAccountToPay(pendingInvoice);
will(returnValue(null));
}
});
// when
List<UpcomingPaymentTotal> result = service.getUpcomingPayments();
// then
assertThat(result.size()).isEqualTo(1);
UpcomingPaymentTotal totalWithoutBankAccount = result.get(0);
assertThat(totalWithoutBankAccount.getDebtorBankAccount()).isNull();
assertThat(totalWithoutBankAccount.getUpcomingAmountForCompleted()).isEqualTo(amountForCompleted);
assertThat(totalWithoutBankAccount.getUpcomingAmountForApprovedByManager()).isEqualTo(amountForApproved);
assertThat(totalWithoutBankAccount.getUpcomingAmountForPendingBankAccountCheck()).isEqualTo(amountForPending);
assertThat(totalWithoutBankAccount.getTotalUpcomingAmount()).isEqualTo(new BigDecimal("4234.56"));
}
Aggregations