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;
}
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");
}
}
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;
}
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;
}
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;
}
}
Aggregations