AgentSkillsCN

invoice-receipt-processor

当用户需要处理工作空间中来自PDF文件的发票收据,并更新采购发票数据库以追踪付款情况时,此技能会自动扫描工作空间目录中的PDF收据,提取发票数据(发票ID、供应商、金额、采购方邮箱、日期、付款状态),将记录插入数据库表,设置带有未付标志的付款追踪,识别未付或部分支付的发票,并向相关采购经理发送邮件通知,附上需要重点关注的特定文件名。关键触发条件包括处理收据、更新发票数据库、追踪未付账款、发送付款提醒邮件,以及处理带有付款状态标识的PDF发票文件。

SKILL.md
--- frontmatter
name: invoice-receipt-processor
description: When the user needs to process invoice receipts from PDF files in a workspace and update a purchase invoice database with payment tracking. This skill automatically scans workspace directories for PDF receipts, extracts invoice data (invoice ID, supplier, amount, purchaser email, date, payment status), inserts records into database tables, sets up payment tracking with outstanding flags, identifies unpaid or partially paid invoices, and sends email notifications to relevant purchasing managers with specific filenames requiring attention. Key triggers include processing receipts, updating invoice databases, tracking outstanding payments, sending payment reminder emails, and handling PDF invoice files with payment status indicators.

Instructions

1. Initialize and Explore

  • Explore Workspace: List the contents of the /workspace/dumps/workspace directory to locate the files folder containing PDF receipts.
  • Explore Database: List schemas in the PURCHASE_INVOICE database, then list tables in the PUBLIC schema.
  • Examine Tables: Describe the structure of the INVOICES and INVOICE_PAYMENTS tables. Read sample data to understand existing records and column formats.

2. Extract Data from PDF Receipts

  • Scan Files: List all PDF files in the workspace's files directory.
  • Read PDFs: For each PDF file, extract text from the first page. Parse the following key fields:
    • Invoice ID: Look for patterns like "Invoice:", "Invoice ID:", "Document ID:", or text near the filename.
    • Supplier Name: Typically under "Supplier:", "Vendor:", or "VENDOR INFORMATION:".
    • Invoice Amount: Look for "Amount:", "Total Amount:", or "Total:" followed by a dollar amount.
    • Purchaser Email: Look for "Contact:", "Bill To:", or "DEPARTMENT INFORMATION:" followed by an email address.
    • Invoice Date: Look for "Date:", "Processing Date:", or "Invoice Date:".
    • Payment Status: Identify status keywords:
      • PAID or checkmark (✓): Fully paid.
      • PARTIAL or square (■): Partially paid. Extract the paid amount if available.
      • UNPAID, Awaiting payment, Pending, Verification in process: Outstanding (unpaid).
      • Default to outstanding if status is unclear.

3. Update Database Tables

  • Insert Invoices: For each extracted receipt, insert a record into PURCHASE_INVOICE.PUBLIC.INVOICES with columns: INVOICE_ID, SUPPLIER_NAME, INVOICE_AMOUNT, PURCHASER_EMAIL, INVOICE_DATE.
  • Insert Payments: For each invoice, insert a corresponding record into PURCHASE_INVOICE.PUBLIC.INVOICE_PAYMENTS:
    • INVOICE_ID: The extracted invoice ID.
    • PAYMENT_AMOUNT:
      • If status is PAID: Set to the full invoice amount.
      • If status is PARTIAL: Set to the extracted paid amount.
      • Otherwise: Set to 0.
    • OUTSTANDING_FLAG:
      • 0 if status is PAID.
      • 1 for all other statuses (PARTIAL, UNPAID, Awaiting, Pending, Verification).
  • Set Column Description: Execute an ALTER TABLE statement to set the comment/description for the OUTSTANDING_FLAG column in INVOICE_PAYMENTS to exactly: 0=Paid, 1=Outstanding. Verify the description was applied.

4. Identify and Notify on Outstanding Invoices

  • Query Outstanding Invoices: Perform a JOIN between INVOICES and INVOICE_PAYMENTS where OUTSTANDING_FLAG = 1. Group results by PURCHASER_EMAIL.
  • Map to Filenames: For each outstanding invoice, map the INVOICE_ID back to the original PDF filename (e.g., INV-2024-013INV-2024-013.pdf).
  • Send Emails: For each unique purchasing manager email (PURCHASER_EMAIL):
    • Subject: Process Outstanding Invoices
    • Body: List the filenames of all outstanding invoices for that manager. Use a clear, professional format.
    • Send the email.

5. Final Verification and Summary

  • Provide a concise summary report including:
    • Count of receipts processed and inserted.
    • Count of outstanding vs. paid invoices.
    • List of managers notified and the number of files each needs to process.
    • Confirmation that the column description was set.