How should I automate sorting and renaming invoice files?

0
1
Asked By MellowCedar47 On

I'm building a small program for a construction company to automate our invoice intake process. Outlook already sorts incoming invoices into a dedicated folder, but I currently download each file manually, determine which job it belongs to, rename it, and move it into the matching job folder on our shared server.

Most invoices are PDFs, although a small number arrive as Excel files. Some invoices also belong to change orders, which use job numbers such as 11111x01 or 11111x02 instead of the base job number 11111.

The process I'm considering is:
1. Download the invoice from Outlook.
2. Extract the job number and invoice number from the document.
3. Determine the company name and any change-order information.
4. Rename the file using a format such as `Porter - 154873.005` instead of `154873-005`.
5. Move it into the appropriate job folder.

Our shared directory contains an `Invoices` folder with subfolders such as `11111 - Washington HS`, `11112 - Adams MS`, and so on. Jobs are added and removed occasionally, so I'd prefer not to maintain a hard-coded JSON map that a nontechnical employee would have to update.

I have some JavaScript and TypeScript experience, so Node.js would be familiar, although I'm also open to learning Python. I initially assumed OCR would be required, but I'm wondering whether most PDFs already contain selectable text that can be extracted directly. What tools and overall approach would make this process reliable and easy for others to maintain?

2 Answers

Answered By RiverSlate29 On

Node.js should work well for this. Use filesystem utilities such as `fs` and `path` to scan the `Invoices` directory at runtime instead of keeping a manually maintained JSON map. When a new folder is created, the program can read its name, extract the job number from the beginning, and match that number against the invoice text. A job number like `11111x01` can be treated as a separate identifier while still being associated with base job `11111` if needed. Keep the steps separate: download, extract text, parse fields, validate the result, rename, and move. Add an exceptions folder or review queue for files where the job number, company, or invoice number cannot be identified confidently.

Answered By QuartzMango8 On

Before reaching for OCR, check whether the PDFs already contain a text layer. Many digitally generated invoices do, and a PDF text-extraction library can read them much faster and more reliably than OCR. In Node.js, tools such as `pdf-parse` or PDF.js are worth testing; in Python, `pypdf` is another option. Use OCR only as a fallback for scanned invoices or image-only pages. You can then use regular expressions or other rules to find the job number and invoice number.

MellowCedar47 -

That makes sense. I had assumed OCR was necessary, so I’ll test several sample invoices to see whether their text can be extracted directly before adding OCR.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.