Search in sources :

Example 36 with BankAccount

use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.

the class IncomingInvoiceApprovalStateSubscriber method on.

@Programmatic
@com.google.common.eventbus.Subscribe
@org.axonframework.eventhandling.annotation.EventHandler
public void on(BankAccountVerificationStateTransitionType.TransitionEvent ev) {
    final StateTransitionEvent.Phase phase = ev.getPhase();
    if (phase == StateTransitionEvent.Phase.TRANSITIONED) {
        final BankAccountVerificationStateTransitionType transitionType = ev.getTransitionType();
        final BankAccount bankAccount = ev.getDomainObject();
        switch(transitionType) {
            case INSTANTIATE:
                break;
            case VERIFY_BANK_ACCOUNT:
                final List<IncomingInvoice> incomingInvoices = findIncomingInvoicesUsing(bankAccount);
                for (IncomingInvoice incomingInvoice : incomingInvoices) {
                    stateTransitionService.trigger(incomingInvoice, CONFIRM_BANK_ACCOUNT_VERIFIED, null, null);
                }
                break;
            case REJECT_PROOF:
                break;
            case PROOF_UPDATED:
                break;
            case RESET:
                break;
        }
    }
}
Also used : IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) BankAccountVerificationStateTransitionType(org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationStateTransitionType) BankAccount(org.estatio.module.financial.dom.BankAccount) StateTransitionEvent(org.estatio.module.capex.dom.state.StateTransitionEvent) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 37 with BankAccount

use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.

the class IncomingInvoiceApprovalState_IntegTest method paid_by_credit_card_skips_bank_account_verification_and_creates_check_task_for_treasury.

@Test
public void paid_by_credit_card_skips_bank_account_verification_and_creates_check_task_for_treasury() {
    // given
    PartyRoleType typeForTreasurer = partyRoleTypeRepository.findByKey(PartyRoleTypeEnum.TREASURER.getKey());
    // workaround: clear MeService#me cache
    queryResultsCache.resetForNextTransaction();
    sudoService.sudo(Person_enum.JonathanPropertyManagerGb.getRef().toLowerCase(), (Runnable) () -> wrap(incomingInvoice).changePaymentMethod(PaymentMethod.CREDIT_CARD));
    sudoService.sudo(Person_enum.JonathanPropertyManagerGb.getRef().toLowerCase(), (Runnable) () -> wrap(mixin(IncomingInvoice_complete.class, incomingInvoice)).act("PROPERTY_MANAGER", null, null));
    // workaround: clear MeService#me cache
    queryResultsCache.resetForNextTransaction();
    sudoService.sudo(Person_enum.PeterPanProjectManagerGb.getRef().toLowerCase(), (Runnable) () -> wrap(mixin(IncomingInvoice_approve.class, incomingInvoice)).act("COUNTRY_DIRECTOR", null, null, false));
    List<Task> tasksForTreasury = taskRepository.findIncompleteByRole(typeForTreasurer);
    assertThat(tasksForTreasury).isEmpty();
    BankAccount bankAccount = incomingInvoice.getBankAccount();
    assertThat(bankAccount).isNotNull();
    BankAccountVerificationState state = stateTransitionService.currentStateOf(bankAccount, BankAccountVerificationStateTransition.class);
    assertThat(state).isEqualTo(BankAccountVerificationState.NOT_VERIFIED);
    // when
    // workaround: clear MeService#me cache
    queryResultsCache.resetForNextTransaction();
    sudoService.sudo(Person_enum.OscarCountryDirectorGb.getRef().toLowerCase(), (Runnable) () -> wrap(mixin(IncomingInvoice_approveAsCountryDirector.class, incomingInvoice)).act(null, false));
    // then
    assertThat(incomingInvoice.getApprovalState()).isEqualTo(IncomingInvoiceApprovalState.PAYABLE);
    List<IncomingInvoiceApprovalStateTransition> transitions = incomingInvoiceStateTransitionRepository.findByDomainObject(incomingInvoice);
    assertThat(transitions.size()).isEqualTo(7);
    assertThat(transitions.get(0).getTransitionType()).isEqualTo(IncomingInvoiceApprovalStateTransitionType.CHECK_PAYMENT);
    tasksForTreasury = taskRepository.findIncompleteByRole(typeForTreasurer);
    assertThat(tasksForTreasury.size()).isEqualTo(1);
    assertThat(tasksForTreasury.get(0).getDescription()).isEqualTo("Check Payment");
    // and still
    state = stateTransitionService.currentStateOf(bankAccount, BankAccountVerificationStateTransition.class);
    assertThat(state).isEqualTo(BankAccountVerificationState.NOT_VERIFIED);
    // and when
    // workaround: clear MeService#me cache
    queryResultsCache.resetForNextTransaction();
    sudoService.sudo(Person_enum.EmmaTreasurerGb.getRef().toLowerCase(), (Runnable) () -> wrap(mixin(IncomingInvoice_checkPayment.class, incomingInvoice)).act(null, false));
    // then
    assertThat(incomingInvoice.getApprovalState()).isEqualTo(IncomingInvoiceApprovalState.PAID);
}
Also used : Task(org.estatio.module.capex.dom.task.Task) BankAccountVerificationState(org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationState) IncomingInvoiceApprovalStateTransition(org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition) PartyRoleType(org.estatio.module.party.dom.role.PartyRoleType) BankAccount(org.estatio.module.financial.dom.BankAccount) BankAccountVerificationStateTransition(org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationStateTransition) Test(org.junit.Test)

Aggregations

BankAccount (org.estatio.module.financial.dom.BankAccount)37 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)14 Test (org.junit.Test)13 Party (org.estatio.module.party.dom.Party)12 Programmatic (org.apache.isis.applib.annotation.Programmatic)11 Expectations (org.jmock.Expectations)9 Organisation (org.estatio.module.party.dom.Organisation)7 ArrayList (java.util.ArrayList)5 Action (org.apache.isis.applib.annotation.Action)4 Property (org.estatio.module.asset.dom.Property)4 BankAccountVerificationStateTransition (org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationStateTransition)4 FinancialAccount (org.estatio.module.financial.dom.FinancialAccount)4 BigDecimal (java.math.BigDecimal)3 List (java.util.List)3 IncomingInvoiceApprovalStateTransition (org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition)3 Inject (javax.inject.Inject)2 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)2 Blob (org.apache.isis.applib.value.Blob)2 FixedAssetFinancialAccount (org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount)2 BankMandate (org.estatio.module.bankmandate.dom.BankMandate)2