Search in sources :

Example 11 with Paperclip

use of org.incode.module.document.dom.impl.paperclips.Paperclip in project estatio by estatio.

the class ForPrimaryDocOfInvoiceAttachToInvoiceAndAnyRelevantSupportingDocuments method doAdvise.

@Override
protected List<AttachmentAdvisor.PaperclipSpec> doAdvise(final DocumentTemplate documentTemplate, final Invoice invoice, final Document createdDocument) {
    final List<PaperclipSpec> paperclipSpecs = Lists.newArrayList();
    paperclipSpecs.add(new PaperclipSpec(null, invoice, createdDocument));
    // not every supporting doc type supports each type of primary document
    // for example, TAX_REGISTER supports invoices (but not PLs), whereas CALCULATION is other way around.
    // we therefore need to filter the supporting documents that we find attached to the invoice.
    // 
    // to start with, we get hold of the set of doc type (data)s that _do_ support the primary doc just created
    DocumentTypeData primaryDocTypeData = DocumentTypeData.docTypeDataFor(createdDocument);
    List<DocumentTypeData> supportingDocTypeDatasForThisPrimaryDoc = DocumentTypeData.supports(primaryDocTypeData);
    // copy over all relevant supporting attached to this primary document (invoice or prelim letter)
    final List<Paperclip> paperclips = paperclipRepository.findByAttachedTo(invoice);
    for (Paperclip paperclip : paperclips) {
        if (PaperclipRoleNames.SUPPORTING_DOCUMENT.equals(paperclip.getRoleName())) {
            final DocumentAbstract supportingDocAbs = paperclip.getDocument();
            if (supportingDocAbs instanceof Document) {
                final Document supportingDoc = (Document) supportingDocAbs;
                final DocumentTypeData supportingDocTypeData = DocumentTypeData.docTypeDataFor(supportingDoc);
                // (and here is where filter out to only attach those that are relevant)
                if (supportingDocTypeDatasForThisPrimaryDoc.contains(supportingDocTypeData)) {
                    // note that the supporting documents point to the primary doc, rather than the other way around
                    paperclipSpecs.add(new PaperclipSpec(PaperclipRoleNames.INVOICE_DOCUMENT_SUPPORTED_BY, createdDocument, supportingDoc));
                }
            }
        }
    }
    return paperclipSpecs;
}
Also used : Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) DocumentAbstract(org.incode.module.document.dom.impl.docs.DocumentAbstract) DocumentTypeData(org.estatio.module.invoice.dom.DocumentTypeData) Document(org.incode.module.document.dom.impl.docs.Document)

Example 12 with Paperclip

use of org.incode.module.document.dom.impl.paperclips.Paperclip in project estatio by estatio.

the class DocumentCommunicationSupportForDocumentsAttachedToInvoiceForLease method inferToHeader.

private <T extends CommunicationChannel> void inferToHeader(final Document document, final CommHeaderAbstract<T> header, final CommunicationChannelType channelType) {
    final List<Paperclip> paperclips = paperclipRepository.findByDocument(document);
    for (final Paperclip paperclip : paperclips) {
        final Object attachedTo = paperclip.getAttachedTo();
        if (attachedTo instanceof InvoiceForLease) {
            final InvoiceForLease invoice = (InvoiceForLease) attachedTo;
            addTo(invoice, header, channelType);
        }
    }
    if (header.getToChoices().isEmpty()) {
        header.setDisabledReason("Could not find a communication channel to use");
    }
}
Also used : Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease)

Example 13 with Paperclip

use of org.incode.module.document.dom.impl.paperclips.Paperclip in project estatio by estatio.

the class InvoiceForLease_attachSupportingDocument method findUnsentDocumentsFor.

private List<DocumentAbstract> findUnsentDocumentsFor(final InvoiceForLease invoice, final DocumentTypeData docTypeData) {
    final DocumentType documentType = docTypeData.findUsing(documentTypeRepository, queryResultsCache);
    final List<DocumentAbstract> unsentDocuments = Lists.newArrayList();
    final List<Paperclip> existingInvoicePaperclips = paperclipRepository.findByAttachedTo(invoice);
    for (Paperclip paperclip : existingInvoicePaperclips) {
        final DocumentAbstract document = paperclip.getDocument();
        if (document.getType() == documentType) {
            boolean sent = whetherSent(document);
            if (!sent) {
                unsentDocuments.add(document);
            }
        }
    }
    return unsentDocuments;
}
Also used : DocumentAbstract(org.incode.module.document.dom.impl.docs.DocumentAbstract) Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) DocumentType(org.incode.module.document.dom.impl.types.DocumentType)

Example 14 with Paperclip

use of org.incode.module.document.dom.impl.paperclips.Paperclip in project estatio by estatio.

the class InvoiceForLease_sendByPost method choices0$$.

public List<Document> choices0$$() {
    final List<Paperclip> paperclips = paperclipRepository.findByAttachedTo(invoice);
    final List<Document> documents = Lists.newArrayList();
    for (Paperclip paperclip : paperclips) {
        final DocumentAbstract documentAbs = paperclip.getDocument();
        if (!(documentAbs instanceof Document)) {
            continue;
        }
        final Document document = (Document) documentAbs;
        if (document.getState() != DocumentState.RENDERED) {
            continue;
        }
        if (!DocumentTypeData.isPrimaryType(document)) {
            continue;
        }
        final Document_sendByPost document_sendByPost = document_sendByPost(document);
        if (document_sendByPost.disableAct() != null) {
            continue;
        }
        documents.add(document);
    }
    return documents;
}
Also used : Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) DocumentAbstract(org.incode.module.document.dom.impl.docs.DocumentAbstract) Document_sendByPost(org.incode.module.communications.dom.mixins.Document_sendByPost) Document(org.incode.module.document.dom.impl.docs.Document)

Example 15 with Paperclip

use of org.incode.module.document.dom.impl.paperclips.Paperclip in project estatio by estatio.

the class BankAccount_detachIbanProof method disableAct.

public String disableAct() {
    final List<Paperclip> ibanProofPaperclips = findIbanProofPaperclips();
    final int numProof = ibanProofPaperclips.size();
    switch(numProof) {
        case 0:
            return "No documents to detach";
        case 1:
            // otherwise get into the complication of having to move the IBAN back into unverified...
            final BankAccountVerificationState currentState = stateTransitionService.currentStateOf(bankAccount, BankAccountVerificationStateTransition.class);
            if (currentState == BankAccountVerificationState.VERIFIED) {
                return "Cannot remove only iban proof - attach other proof first";
            }
        default:
            return null;
    }
}
Also used : Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) BankAccountVerificationState(org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationState)

Aggregations

Paperclip (org.incode.module.document.dom.impl.paperclips.Paperclip)15 DocumentAbstract (org.incode.module.document.dom.impl.docs.DocumentAbstract)7 Document (org.incode.module.document.dom.impl.docs.Document)5 DemoInvoice (org.incode.platform.dom.communications.integtests.demo.dom.invoice.DemoInvoice)4 Action (org.apache.isis.applib.annotation.Action)2 DocumentTypeData (org.estatio.module.invoice.dom.DocumentTypeData)2 CommunicationChannel (org.incode.module.communications.dom.impl.commchannel.CommunicationChannel)2 CommChannelRole (org.incode.module.communications.dom.impl.comms.CommChannelRole)2 Communication (org.incode.module.communications.dom.impl.comms.Communication)2 Document_sendByEmail (org.incode.module.communications.dom.mixins.Document_sendByEmail)2 Document_sendByPost (org.incode.module.communications.dom.mixins.Document_sendByPost)2 DocumentType (org.incode.module.document.dom.impl.types.DocumentType)2 DemoObjectWithNotes (org.incode.platform.dom.communications.integtests.demo.dom.demowithnotes.DemoObjectWithNotes)2 Test (org.junit.Test)2 List (java.util.List)1 Objects (java.util.Objects)1 Predicate (java.util.function.Predicate)1 Inject (javax.inject.Inject)1 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)1 Mixin (org.apache.isis.applib.annotation.Mixin)1