Search in sources :

Example 1 with IncomingInvoice

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

the class IncomingInvoiceBuilder method execute.

@Override
protected void execute(final ExecutionContext ec) {
    checkParam("officeAdministrator", ec, Person.class);
    checkParam("document", ec, Document.class);
    checkParam("buyer", ec, Organisation.class);
    checkParam("seller", ec, Organisation.class);
    checkParam("sellerBankAccount", ec, BankAccount.class);
    checkParam("property", ec, Property.class);
    checkParam("dueDate", ec, LocalDate.class);
    checkParam("invoiceDate", ec, LocalDate.class);
    checkParam("dateReceived", ec, LocalDate.class);
    checkParam("itemTax", ec, Tax.class);
    checkParam("item1InvoiceType", ec, IncomingInvoiceType.class);
    // checkParam("item1Project", ec, Project.class); // optional
    checkParam("item1Charge", ec, Charge.class);
    checkParam("item1Description", ec, String.class);
    checkParam("item1NetAmount", ec, BigDecimal.class);
    checkParam("item1VatAmount", ec, BigDecimal.class);
    checkParam("item1GrossAmount", ec, BigDecimal.class);
    checkParam("item1Period", ec, String.class);
    if (getItem2InvoiceType() != null) {
        checkParam("item2InvoiceType", ec, IncomingInvoiceType.class);
        // checkParam("item2Project", ec, Project.class); // optional
        checkParam("item2Charge", ec, Charge.class);
        checkParam("item2Description", ec, String.class);
        checkParam("item2NetAmount", ec, BigDecimal.class);
        checkParam("item2VatAmount", ec, BigDecimal.class);
        checkParam("item2GrossAmount", ec, BigDecimal.class);
        checkParam("item2Period", ec, String.class);
    }
    // checkParam("orderDocument", ec, Document.class); // optional
    if (order != null) {
        checkParam("orderItemLinkAmount", ec, BigDecimal.class);
    }
    if (propertyManager != null) {
        checkParam("propertyManager", ec, Person.class);
        checkParam("assetManager", ec, Person.class);
        checkParam("countryDirector", ec, Person.class);
        checkParam("treasurer", ec, Person.class);
    }
    sudoService.sudo(officeAdministrator.getUsername(), (Runnable) () -> wrap(mixin(Document_categoriseAsPropertyInvoice.class, document)).act(property, ""));
    final String documentName = document.getName();
    IncomingInvoice invoice = incomingInvoiceRepository.findIncomingInvoiceByDocumentName(documentName).get(0);
    invoice.setDateReceived(dateReceived);
    invoice.setSeller(seller);
    invoice.setBankAccount(sellerBankAccount);
    invoice.setBuyer(buyer);
    invoice.setType(invoiceType);
    invoice.setDueDate(dueDate);
    invoice.setInvoiceNumber(invoiceNumber);
    invoice.setPaymentMethod(paymentMethod);
    invoice.setInvoiceDate(invoiceDate);
    invoice.setNetAmount(netAmount);
    invoice.setGrossAmount(grossAmount);
    invoice.addItem(item1InvoiceType, item1Charge, item1Description, item1NetAmount, item1VatAmount, item1GrossAmount, itemTax, dueDate, item1Period, property, item1Project, null);
    if (order != null) {
        IncomingInvoiceItem invoiceItemToLink = (IncomingInvoiceItem) invoice.getItems().first();
        OrderItem orderItemToLink = order.getItems().first();
        mixin(IncomingInvoiceItem_createOrderItemLink.class, invoiceItemToLink).act(orderItemToLink, orderItemLinkAmount);
    }
    if (item2InvoiceType != null) {
        invoice.addItem(item2InvoiceType, item2Charge, item2Description, item2NetAmount, item2VatAmount, item2GrossAmount, itemTax, dueDate, item2Period, property, item2Project, null);
    }
    if (propertyManager != null) {
        // complete and approve invoice and verify bankaccount
        sudoService.sudo(propertyManager.getUsername(), (Runnable) () -> wrap(mixin(IncomingInvoice_complete.class, invoice)).act("PROPERTY_MANAGER", null, null));
        sudoService.sudo(assetManager.getUsername(), (Runnable) () -> wrap(mixin(IncomingInvoice_approve.class, invoice)).act("ASSET_MANAGER", null, null, false));
        sudoService.sudo(countryDirector.getUsername(), (Runnable) () -> wrap(mixin(IncomingInvoice_approveAsCountryDirector.class, invoice)).act(null, false));
        sudoService.sudo(treasurer.getUsername(), (Runnable) () -> wrap(mixin(BankAccount_verify.class, sellerBankAccount)).act(null));
    }
}
Also used : IncomingInvoiceItem_createOrderItemLink(org.estatio.module.capex.dom.orderinvoice.IncomingInvoiceItem_createOrderItemLink) OrderItem(org.estatio.module.capex.dom.order.OrderItem) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) ToString(lombok.ToString)

Example 2 with IncomingInvoice

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

the class EstatioAppHomePage_verifyBankAccounts method act.

@Action(semantics = SemanticsOf.IDEMPOTENT, restrictTo = RestrictTo.PROTOTYPING)
@ActionLayout(position = ActionLayout.Position.PANEL)
public EstatioAppHomePage act(final List<IncomingInvoice> invoices, @Nullable final String comment) {
    for (IncomingInvoice invoice : invoices) {
        final BankAccount bankAccount = invoice.getBankAccount();
        factoryService.mixin(BankAccount_verify.class, bankAccount).act(comment);
        factoryService.mixin(IncomingInvoice_checkApprovalState.class, invoice).act();
    }
    return homePage;
}
Also used : BankAccount_verify(org.estatio.module.capex.dom.bankaccount.verification.triggers.BankAccount_verify) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) BankAccount(org.estatio.module.financial.dom.BankAccount) IncomingInvoice_checkApprovalState(org.estatio.module.capex.dom.invoice.approval.tasks.IncomingInvoice_checkApprovalState) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 3 with IncomingInvoice

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

the class IncomingInvoice_approve method act.

@Action(domainEvent = ActionDomainEvent.class, semantics = SemanticsOf.IDEMPOTENT)
@ActionLayout(cssClassFa = "fa-thumbs-o-up")
public Object act(final String role, @Nullable final Person personToAssignNextTo, @Nullable final String comment, final boolean goToNext) {
    final IncomingInvoice next = nextAfterPendingIfRequested(goToNext);
    trigger(personToAssignNextTo, comment, null);
    return objectToReturn(next);
}
Also used : IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 4 with IncomingInvoice

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

the class BankAccount_attachInvoiceAsIbanProof method choices0Act.

public List<Document> choices0Act() {
    final List<Document> documents = Lists.newArrayList();
    final List<IncomingInvoice> invoices = incomingInvoiceRepository.findByBankAccount(bankAccount);
    for (IncomingInvoice invoice : invoices) {
        final List<Document> attachedDocuments = lookupAttachedPdfService.lookupIncomingInvoicePdfsFrom(invoice);
        documents.addAll(attachedDocuments);
    }
    final List<Document> documentsCurrentlyAttachedAsIbanProof = paperclipRepository.findByAttachedToAndRoleName(bankAccount, ROLE_NAME_FOR_IBAN_PROOF).stream().map(Paperclip::getDocument).filter(Document.class::isInstance).map(Document.class::cast).collect(Collectors.toList());
    documents.removeAll(documentsCurrentlyAttachedAsIbanProof);
    return documents;
}
Also used : IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) Document(org.incode.module.document.dom.impl.docs.Document)

Example 5 with IncomingInvoice

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

the class IncomingInvoiceMenu_Test method filterOrFindByGrossAmount_find_works.

@Test
public void filterOrFindByGrossAmount_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.setGrossAmount(new BigDecimal("9.50"));
    invoice2.setGrossAmount(new BigDecimal("10.50"));
    invoice3.setGrossAmount(new BigDecimal("10.51"));
    final BigDecimal amountSearchedFor = new BigDecimal("10.00");
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockIncomingInvoiceRepository).listAll();
            will(returnValue(Arrays.asList(invoice1, invoice2, invoice3)));
        }
    });
    // when
    builder.filterOrFindByGrossAmount(amountSearchedFor);
    // then
    Assertions.assertThat(builder.getResult().size()).isEqualTo(2);
    Assertions.assertThat(builder.getResult()).contains(invoice1);
    Assertions.assertThat(builder.getResult()).contains(invoice2);
}
Also used : Expectations(org.jmock.Expectations) IncomingInvoiceMenu(org.estatio.module.capex.app.IncomingInvoiceMenu) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)57 Test (org.junit.Test)27 Expectations (org.jmock.Expectations)20 BankAccount (org.estatio.module.financial.dom.BankAccount)14 Action (org.apache.isis.applib.annotation.Action)11 BigDecimal (java.math.BigDecimal)9 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)9 Organisation (org.estatio.module.party.dom.Organisation)9 Party (org.estatio.module.party.dom.Party)9 IncomingInvoiceMenu (org.estatio.module.capex.app.IncomingInvoiceMenu)8 IncomingInvoiceItem (org.estatio.module.capex.dom.invoice.IncomingInvoiceItem)7 Document (org.incode.module.document.dom.impl.docs.Document)7 LocalDate (org.joda.time.LocalDate)7 ArrayList (java.util.ArrayList)5 Programmatic (org.apache.isis.applib.annotation.Programmatic)5 Property (org.estatio.module.asset.dom.Property)3 UpcomingPaymentTotal (org.estatio.module.capex.app.invoice.UpcomingPaymentTotal)3 BuyerFinder (org.estatio.module.capex.dom.documents.BuyerFinder)3 IncomingInvoiceApprovalStateTransition (org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition)3 OrderItem (org.estatio.module.capex.dom.order.OrderItem)3