1
📥
OCR receipt dataScan & extract receipt information
2
🔍
Compare to expense ledgerMatch receipts against entries
3
⚠️
Flag discrepanciesIdentify missing or mismatched entries
4
💡
Suggest correctionsGenerate action recommendations
import pytesseract, json, re, os
OCR_PATH = "/data/receipts/"
LEDGER_PATH = "/data/expenses.json"
def ocr_receipt(file):
text = pytesseract.image_to_string(file)
amount = re.search(r'RM\s*([\d,]+)', text)
return {"amount": int(amount.group(1).replace(',', ''))} if amount else None
def match_receipts():
matches = []
for r in os.listdir(OCR_PATH):
rcpt = ocr_receipt(OCR_PATH + r)
entry = next((e for e in ledger if e["receipt_id"] == r), None)
status = "Matched" if entry and entry["amount"] == rcpt["amount"] else "Discrepancy"
matches.append({"receipt": r, "entry": entry, "status": status})
return matches
matches = match_receipts()
print(json.dumps(matches, indent=2))