Search in sources :

Example 1 with DocumentTypeData

use of org.estatio.module.invoice.dom.DocumentTypeData 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 2 with DocumentTypeData

use of org.estatio.module.invoice.dom.DocumentTypeData in project estatio by estatio.

the class InvoiceForLease_attachSupportingDocument method $$.

@Action(semantics = SemanticsOf.NON_IDEMPOTENT, commandDtoProcessor = DeriveBlobFromDummyPdfArg1.class)
@ActionLayout(contributed = Contributed.AS_ACTION, cssClassFa = "paperclip")
public Invoice $$(final DocumentType supportingDocumentType, @Parameter(fileAccept = "application/pdf") @ParameterLayout(named = "Receipt (PDF)") final Blob blob, @Parameter(optionality = Optionality.OPTIONAL) final String fileName, final String roleName) throws IOException {
    // 
    // if appropriate, we will automatically attach the supporting doc (once created)
    // to any unsent documents for this Invoice
    // before we do anything, therefore, we get hold of those invoice documents.
    // 
    DocumentTypeData supportedBy = DocumentTypeData.supportedBy(supportingDocumentType);
    final List<DocumentAbstract> unsentDocuments = findUnsentDocumentsFor(invoiceForLease, supportedBy);
    // 
    // now we create the receiptDoc, and attach to the invoice
    // 
    String documentName = determineName(blob, fileName);
    // unlike documents that are generated from a template (where we call documentTemplate#render), in this case
    // we have the actual bytes; so we just set up the remaining state of the document manually.
    final Document supportingDoc = documentService.createAndAttachDocumentForBlob(supportingDocumentType, this.invoiceForLease.getAtPath(), documentName, blob, PaperclipRoleNames.SUPPORTING_DOCUMENT, this.invoiceForLease);
    // 
    for (DocumentAbstract unsentDocument : unsentDocuments) {
        paperclipRepository.attach(supportingDoc, roleName, unsentDocument);
    }
    return this.invoiceForLease;
}
Also used : 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) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Aggregations

DocumentTypeData (org.estatio.module.invoice.dom.DocumentTypeData)2 Document (org.incode.module.document.dom.impl.docs.Document)2 DocumentAbstract (org.incode.module.document.dom.impl.docs.DocumentAbstract)2 Action (org.apache.isis.applib.annotation.Action)1 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)1 Paperclip (org.incode.module.document.dom.impl.paperclips.Paperclip)1