Invoice recognition and text extraction – system description

Steps of the shared recognition process, bulk queuing, the two background jobs (recognition, PDF text) and the rights of the text endpoints.

Invoice recognition runs through one shared entry point (recognition library run()), by hand for one document or as a background job for many. A new invoice is created only through the finance module's addInvoice() method.

Data model

Table names carry the installation's own prefix in the database.

TableRole
docrecog_status, recog_note, content_text, text_status
doc_linkdocument ↔ invoice link (invoice_image type)
invoicethe recognised invoice (with lines, through the finance model)
companypartner data completion
cron_queuedoc_recognise, doc_text jobs

Recognition steps

  1. Scope check; merging earlier copies of the same file.
  2. If a linked invoice exists, no new one is created (for a technical customer only a customer swap, on a linked invoice completion).
  3. Text: text layer → local OCR → a paid language model if needed; pro forma detection (does not become an invoice); invoice pre-check.
  4. Reading; if complete (verified): match an existing invoice or create one via finance/invoice::addInvoice(), doc_link + invoice_image type, partner data completion, mirror invoice sync.
  5. Result: structured answer (status, doc_id, invoice_id, changes), log, setRecogResult on the document.

Background jobs

  • bulkrecognise: max. 2000 documents; missing, trashed or out-of-scope ones are skipped (logged); a recognition row per company (queueRecognition) and one doc_recognise job with the doc_ids list.
  • doc_recognise (one-off, per company): batches of 25 within a time budget, the shared run() in a restricted system context (only the job company's documents, no deletion, classify pre-filter); success to the system log, errors to the error log; notification at the end of a bulk run.
  • doc_text (one-off, per document; queued by the upload): downloads the PDF from local path or Drive, extracts with a PDF parser, saves into content_text; text_status 1 = extracted, 2 = no extractable text; the temporary file is deleted.

Text endpoints

  • extracttext: one or more documents (the client sends batches); textOf() → saveExtractedText(); counts in counts.
  • textcontent: the stored text; a meaningful message on JSON encoding errors; without the right the badge is a plain label.

Permissions

  • recogniseinvoice (UNMAPPED) + core modify; bulk canBulkAction(recogniseinvoice).
  • The library receives from the caller: scope companies, document delete, finance/invoice repoint and statusdelete (rebuild), company/company edit.
  • textextract (not in the catalogue), bulk canBulkAction(textextract); textview (BASE); scope per document.
  • Prerequisite: OCR and language model settings for paid reading.