Invoice and receipt ledger
Record invoice and receipt details from email bodies in a duplicate-safe ledger; flag attachment-only items for review.
- 01Find candidate messages. Query at most 50 Gmail messages received after the latest successfully recorded ledger timestamp and matching the configured label or query. Fetch full content only for likely invoices or receipts.
- 02Read the email body. Extract vendor, document type, invoice or receipt number, issue date, due date, currency, subtotal, tax, total, line-item summary, and source message link only from readable Gmail message text. You cannot read attached PDFs or images. If the vendor, document identifier, date, currency, or total is missing or only in an attachment, put the Gmail link, attachment names, and missing fields in the review queue; do not add an expense row or include it in processed totals.
- 03Normalize without guessing. Keep currencies separate, preserve the original amount, normalize dates only when unambiguous, and leave tax category, payment status, and missing identifiers blank unless a source proves them.
- 04Prevent duplicates. Search the ledger by vendor and invoice number first, then use vendor, date, currency, and total as a fallback candidate check. Link repeated messages to the existing row rather than adding another expense.
- 05Plan the filing. Propose a Drive path for a text summary using the configured year, month, vendor, and filename convention. Flag filename collisions, changed bank details, unknown vendors, and possible duplicate documents for review.
- 06[Approval gate] Review any overwrite, replacement, changed-bank-detail, or ambiguous-duplicate decision before filing or updating the ledger.
- 07File and record clean items. Save a text summary of the email-body facts and Gmail source link to the configured Drive folder, append unique entries to the Sheet, and include Drive, Gmail, and ledger links. Label each Drive record as a summary, not the original invoice or receipt. Do not claim that an attachment was read, copied, or archived. Record write failures in the review queue without claiming success.
- 08Deliver the run files. Write invoice-ledger.csv for processed items and invoice-needs-review.csv for unresolved items, then summarize counts, totals by currency, duplicates, and failures.
Never initiate, schedule, approve, or represent a payment as completed.
Never delete the source email or attachment, overwrite a Drive file, or erase an existing ledger row.
Do not infer a tax category, reimbursement status, payment status, or exchange rate.
Treat changed payment instructions and unknown vendors as fraud signals requiring human review.
Never count the same invoice twice, and keep totals separated by currency unless an explicit sourced conversion rule is configured.