Search in sources :

Example 1 with IncomingInvoiceApprovalStateTransition

use of org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition in project estatio by estatio.

the class IncomingInvoiceDownloadManager method commentsFor.

String commentsFor(final IncomingInvoiceItem invoiceItem) {
    StringBuffer result = new StringBuffer();
    final IncomingInvoice invoice = (IncomingInvoice) invoiceItem.getInvoice();
    List<IncomingInvoiceApprovalStateTransition> transitions = stateTransitionRepositoryGeneric.findByDomainObject(invoice, IncomingInvoiceApprovalStateTransition.class);
    for (IncomingInvoiceApprovalStateTransition transition : transitions) {
        if (transition.getTask() != null && transition.getTask().getComment() != null) {
            result.append(transition.getTask().getComment());
            result.append(" | ");
        }
    }
    return result.toString();
}
Also used : IncomingInvoiceApprovalStateTransition(org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice)

Example 2 with IncomingInvoiceApprovalStateTransition

use of org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition in project estatio by estatio.

the class CreditTransferExportService_Test method getApprovalStateTransitionSummary_works.

@Test
public void getApprovalStateTransitionSummary_works() throws Exception {
    // given
    CreditTransferExportService service = new CreditTransferExportService();
    IncomingInvoice invoice = new IncomingInvoice();
    invoice.stateTransitionRepository = mockStateTransitionRepo;
    IncomingInvoiceApprovalStateTransition transition1 = new IncomingInvoiceApprovalStateTransition();
    transition1.setCompletedBy("some manager");
    transition1.setCompletedOn(LocalDateTime.parse("2017-01-01"));
    transition1.setToState(IncomingInvoiceApprovalState.APPROVED);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockStateTransitionRepo).findByDomainObject(invoice);
            will(returnValue(Arrays.asList(transition1)));
        }
    });
    // when
    String result = service.getApprovalStateTransitionSummary(invoice);
    // then
    Assertions.assertThat(result).isEqualTo("some manager on 01-Jan-2017 00:00 \r\n");
}
Also used : Expectations(org.jmock.Expectations) IncomingInvoiceApprovalStateTransition(org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) Test(org.junit.Test)

Example 3 with IncomingInvoiceApprovalStateTransition

use of org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition in project estatio by estatio.

the class IncomingInvoiceApprovalState_IntegTest method refund_by_supplier_skips_bank_account_verification_and_creates_check_task_for_treasury.

@Test
public void refund_by_supplier_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.REFUND_BY_SUPPLIER));
    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)

Example 4 with IncomingInvoiceApprovalStateTransition

use of org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition 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;
}
Also used : Order(org.estatio.module.capex.dom.order.Order) IncomingInvoiceApprovalStateTransition(org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition) IncomingDocumentCategorisationStateTransition(org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) BankAccount(org.estatio.module.financial.dom.BankAccount) Document(org.incode.module.document.dom.impl.docs.Document) OrderApprovalStateTransition(org.estatio.module.capex.dom.order.approval.OrderApprovalStateTransition) BankAccountVerificationStateTransition(org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationStateTransition)

Example 5 with IncomingInvoiceApprovalStateTransition

use of org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition 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

IncomingInvoiceApprovalStateTransition (org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition)5 BankAccountVerificationStateTransition (org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationStateTransition)3 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)3 BankAccount (org.estatio.module.financial.dom.BankAccount)3 Test (org.junit.Test)3 BankAccountVerificationState (org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationState)2 Task (org.estatio.module.capex.dom.task.Task)2 PartyRoleType (org.estatio.module.party.dom.role.PartyRoleType)2 IncomingDocumentCategorisationStateTransition (org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition)1 Order (org.estatio.module.capex.dom.order.Order)1 OrderApprovalStateTransition (org.estatio.module.capex.dom.order.approval.OrderApprovalStateTransition)1 Document (org.incode.module.document.dom.impl.docs.Document)1 Expectations (org.jmock.Expectations)1