Search in sources :

Example 46 with IncomingInvoice

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

the class PaymentBatch method downloadReviewPdf.

@Action(semantics = SemanticsOf.SAFE)
@ActionLayout(contributed = Contributed.AS_ACTION)
public Blob downloadReviewPdf(final String documentName, @ParameterLayout(named = "How many first pages of each invoice's PDF?") final Integer numFirstPages, @ParameterLayout(named = "How many final pages of each invoice's PDF?") final Integer numLastPages) throws IOException {
    final List<File> pdfFiles = Lists.newArrayList();
    final List<CreditTransfer> transfers = this.getTransfers();
    for (CreditTransfer transfer : transfers) {
        final List<PaymentLine> lines = transfer.getLines();
        for (final PaymentLine line : lines) {
            final IncomingInvoice invoice = line.getInvoice();
            final BankAccount bankAccount = invoice.getBankAccount();
            final Optional<org.incode.module.document.dom.impl.docs.Document> invoiceDocIfAny = lookupAttachedPdfService.lookupIncomingInvoicePdfFrom(invoice);
            if (invoiceDocIfAny.isPresent()) {
                final org.incode.module.document.dom.impl.docs.Document invoiceDoc = invoiceDocIfAny.get();
                final byte[] invoiceDocBytes = invoiceDoc.asBytes();
                final Optional<org.incode.module.document.dom.impl.docs.Document> ibanProofDocIfAny = lookupAttachedPdfService.lookupIbanProofPdfFrom(bankAccount);
                List<String> leftLines = Lists.newArrayList();
                leftLines.add("xfer id: " + transfer.getEndToEndId() + " / " + line.getSequence());
                for (IncomingInvoice.ApprovalString approvalString : invoice.getApprovals()) {
                    leftLines.add(String.format("approved by: %s", approvalString.getCompletedBy()));
                    leftLines.add("on: " + approvalString.getCompletedOn());
                }
                final List<String> rightLines = Lists.newArrayList();
                rightLines.add(String.format("debtor IBAN: %s", line.getBatch().getDebtorBankAccount().getIban()));
                rightLines.add(String.format("crdtor IBAN: %s", line.getCreditorBankAccount().getIban()));
                rightLines.add(String.format("gross Amt  : %s", new DecimalFormat("0.00").format(line.getAmount())));
                boolean attachProof = false;
                final String proof;
                if (ibanProofDocIfAny.isPresent()) {
                    final org.incode.module.document.dom.impl.docs.Document ibanProofDoc = ibanProofDocIfAny.get();
                    if (DocumentTypeData.IBAN_PROOF.isDocTypeFor(ibanProofDoc)) {
                        proof = "Separate IBAN proof (next page)";
                        attachProof = true;
                    } else {
                        proof = "Invoice used as IBAN proof";
                    }
                } else {
                    proof = "No IBAN proof";
                }
                rightLines.add(proof);
                URI uri = deepLinkService.deepLinkFor(invoice);
                final Stamp stamp = new Stamp(leftLines, rightLines, uri.toString());
                final byte[] extractedInvoiceDocBytes = pdfManipulator.extractAndStamp(invoiceDocBytes, new ExtractSpec(numFirstPages, numLastPages), stamp);
                appendTempFile(extractedInvoiceDocBytes, documentName, pdfFiles);
                if (attachProof) {
                    final org.incode.module.document.dom.impl.docs.Document ibanProofDoc = ibanProofDocIfAny.get();
                    final byte[] ibanProofBytes = ibanProofDoc.asBytes();
                    final byte[] firstPageIbanProofDocBytes = pdfManipulator.extract(ibanProofBytes, ExtractSpec.FIRST_PAGE_ONLY);
                    appendTempFile(firstPageIbanProofDocBytes, documentName, pdfFiles);
                }
            }
        }
    }
    byte[] pdfMergedBytes = pdfBoxService.merge(pdfFiles);
    pdfFiles.stream().forEach(this::cleanup);
    return new Blob(documentName, DocumentConstants.MIME_TYPE_APPLICATION_PDF, pdfMergedBytes);
}
Also used : DecimalFormat(java.text.DecimalFormat) Document(iso.std.iso._20022.tech.xsd.pain_001_001.Document) URI(java.net.URI) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) Blob(org.apache.isis.applib.value.Blob) Stamp(org.estatio.module.capex.platform.pdfmanipulator.Stamp) BankAccount(org.estatio.module.financial.dom.BankAccount) ExtractSpec(org.estatio.module.capex.platform.pdfmanipulator.ExtractSpec) File(java.io.File) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 47 with IncomingInvoice

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

the class IncomingInvoice_approveAsCorporateManager method act.

@Action(domainEvent = IncomingInvoice_next.ActionDomainEvent.class, semantics = SemanticsOf.IDEMPOTENT)
@ActionLayout(cssClassFa = "fa-thumbs-o-up")
public Object act(@Nullable final String comment, final boolean goToNext) {
    final IncomingInvoice next = nextAfterPendingIfRequested(goToNext);
    trigger(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 48 with IncomingInvoice

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

the class IncomingInvoice_approveLocalAsCountryDirector method act.

@Action(domainEvent = ActionDomainEvent.class, semantics = SemanticsOf.IDEMPOTENT)
@ActionLayout(cssClassFa = "fa-thumbs-up")
public Object act(@Nullable final String comment, final boolean goToNext) {
    final IncomingInvoice next = nextAfterPendingIfRequested(goToNext);
    trigger(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 49 with IncomingInvoice

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

the class Document_categoriseAsPropertyInvoice method act.

@Action(domainEvent = ActionDomainEvent.class, semantics = SemanticsOf.IDEMPOTENT)
@ActionLayout(cssClassFa = "folder-open-o")
public Object act(final Property property, @Nullable final String comment) {
    final Document document = getDomainObject();
    document.setType(DocumentTypeData.INCOMING_INVOICE.findUsing(documentTypeRepository));
    LocalDate dateReceived = document.getCreatedAt().toLocalDate();
    LocalDate dueDate = document.getCreatedAt().toLocalDate().plusDays(30);
    final IncomingInvoice incomingInvoice = incomingInvoiceRepository.create(// EST-1508: the users prefer no default
    null, // invoiceNumber
    null, property, document.getAtPath(), // buyer
    buyerFinder.buyerDerivedFromDocumentName(document), // seller
    null, // invoiceDate
    null, dueDate, null, InvoiceStatus.NEW, dateReceived, // bankAccount
    null, // approval state... will cause state transition to be created automatically by subscriber
    null);
    paperclipRepository.attach(document, null, incomingInvoice);
    trigger(comment, null);
    return incomingInvoice;
}
Also used : IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) Document(org.incode.module.document.dom.impl.docs.Document) LocalDate(org.joda.time.LocalDate) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 50 with IncomingInvoice

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

the class Document_categoriseAsOtherInvoice method act.

@Action(domainEvent = ActionDomainEvent.class, semantics = SemanticsOf.IDEMPOTENT)
@ActionLayout(cssClassFa = "folder-open-o")
public Object act(final IncomingInvoiceType incomingInvoiceType, @Nullable final String comment) {
    final Document document = getDomainObject();
    document.setType(DocumentTypeData.INCOMING_INVOICE.findUsing(documentTypeRepository));
    LocalDate dateReceived = document.getCreatedAt().toLocalDate();
    LocalDate dueDate = document.getCreatedAt().toLocalDate().plusDays(30);
    final IncomingInvoice incomingInvoice = incomingInvoiceRepository.create(incomingInvoiceType, // invoiceNumber
    null, // property
    null, document.getAtPath(), // buyer
    buyerFinder.buyerDerivedFromDocumentName(document), // seller
    null, // invoiceDate
    null, dueDate, null, InvoiceStatus.NEW, dateReceived, // bankAccount
    null, // approval state... will cause state transition to be created automatically by subscriber
    null);
    paperclipRepository.attach(document, null, incomingInvoice);
    trigger(comment, null);
    return incomingInvoice;
}
Also used : IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) Document(org.incode.module.document.dom.impl.docs.Document) LocalDate(org.joda.time.LocalDate) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

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