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