agentleFS
jacksjpjacksjp/agentSkills/.agents/skills/invoice-generator/SKILL.md

invoice-generator

Skill0 starsChanged 7 months agoMITView on GitHub

Reads time sheet data for invoices directly from the Excel workbook, calculates the amounts, fills the HTML template, and converts it to PDF using html_to_pdf.py when the users requests for invoices to be generated.

  • Installs packages

9 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

24 rules. 0 are common, 18 are distinctive, and 6 are very specific to this project.

  • 0

    Common

    Most of the 9 edited versions we read keep these.

  • 18

    Distinctive

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when the user asks to generate, create, or print an invoice.

    line 9
  2. Distinctive:

    Create and activate a virtual environment (once per machine):

    line 20
  3. Distinctive:

    If the user did not specify a month/year, use this logic:

    line 39
  4. Distinctive:

    All other days → bill for the current month

    line 43
  5. Distinctive:

    Always ask the user directly before generating the invoice:

    line 52
  6. Very specific:

    remove characters invalid in Windows filenames (< > : " / \ | ?

    line 62
  7. Very specific:

    keep only letters, numbers, -, and _

    line 63
  8. Very specific:

    Use corporation_name in the invoice HTML and corporation_slug in the PDF filename.

    line 65
  9. Distinctive:

    Do NOT write a Python script to do this: Run the one-liner directly in the terminal (or use your built-in file-reading tools) to extract …

    line 74
  10. Distinctive:

    If Total Hours is present, use it directly.

    line 101
  11. Very specific:

    If Total Hours is missing, calculate: hours = Amount ÷ hourly_rate

    line 102
  12. Distinctive:

    If multiple rows match the same month across different years, prefer the nearest year to today.

    line 103
  13. Distinctive:

    Default hourly rate: $150.00 CAD/hr (senior AI engineer contractor rate in Ontario).

    line 113
  14. Distinctive:

    Use this unless the user provides a different rate — do not ask.

    line 114
  15. Distinctive:

    Do NOT write a Python script to do this: Read the template file directly with your file-reading tools, do the string replacements in …

    line 128
  16. Distinctive:

    Run the helper script (the only script in this skill).

    line 169
  17. Distinctive:

    Before cleaning up, confirm the PDF was successfully generated:

    line 189
  18. Distinctive:

    If the check passes (exit code 0), proceed to Step 9.

    line 204
  19. Distinctive:

    If the check fails (exit code 1), stop and report the error to the user.

    line 205
  20. Distinctive:

    Do not delete the HTML file.

    line 206
  21. Distinctive:

    Delete the intermediate HTML file only after the PDF has been validated:

    line 212
  22. Distinctive:

    No other scripts are needed — the agent handles data extraction, calculation, and template filling directly from the instructions above.

    line 229
  23. Very specific:

    If the workbook is open in Excel, use the copy at .agents/skills/invoice-generator/references/Invoice Raised vs Received.xlsx.

    line 237
  24. Very specific:

    Update references/invoice_template.html with your own business details before first use.

    line 240

“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Invoice Generator Skill

Use this skill when the user asks to generate, create, or print an invoice.

Important: Do NOT create any Python files or helper scripts in the project root or anywhere else. The only allowed script is html_to_pdf.py which already exists. Do all data reading, calculation, and file editing directly using your built-in tools.


Step 1 — Set up the environment

Create and activate a virtual environment (once per machine):

python -m venv .venv

Install the one dependency needed to read the Excel file:

python -m pip install openpyxl

weasyprint is optional. If it is not installed, html_to_pdf.py falls back to Chrome/Edge headless automatically.


Step 2 — Determine the billing period

If the user did not specify a month/year, use this logic:

  • Last 7 days of the current month → bill for the current month
  • First 7 days of the current month → bill for the previous month
  • All other days → bill for the current month

Step 3 — Prompt for corporation name

The corporation name appears in two places: the company name in the invoice header and the PDF filename. It must match in both.

Always ask the user directly before generating the invoice:

What is the exact corporation name to show on this invoice?

Then derive:

  • corporation_name — exact user-provided value for the invoice header (for example: 987123 ONTARIO INC.)
  • corporation_slug — filename-safe value built from corporation_name:
    • replace whitespace with -
    • remove characters invalid in Windows filenames (< > : " / \ | ? *)
    • keep only letters, numbers, -, and _

Use corporation_name in the invoice HTML and corporation_slug in the PDF filename.


Step 4 — Read the Excel workbook

File: .agents/skills/invoice-generator/assets/Invoice Raised vs Received.xlsx

Do NOT write a Python script to do this. Run the one-liner directly in the terminal (or use your built-in file-reading tools) to extract the values:

python -c "
import openpyxl, datetime
wb = openpyxl.load_workbook('.agents/skills/invoice-generator/assets/Invoice Raised vs Received.xlsx', data_only=True)
for sheet in wb.sheetnames:
    ws = wb[sheet]
    headers = [str(c.value).strip() if c.value else '' for c in next(ws.iter_rows(min_row=1, max_row=1))]
    print(sheet, headers)
    for row in ws.iter_rows(min_row=2, values_only=True):
        print(row)
"

Scan every sheet for the target billing month. Look for these columns:

ColumnAccepted header names
DateDate
Invoice numberInv No, Invoice #, Invoice Number
HoursTotal Hours
AmountAmount

Find the row where the Date falls in the target month and year.

  • If Total Hours is present, use it directly.
  • If Total Hours is missing, calculate: hours = Amount ÷ hourly_rate
  • If multiple rows match the same month across different years, prefer the nearest year to today; break ties by favouring the past over the future.

Extract:

  • invoice_number — from the Invoice column
  • hours_worked — from the Hours column (or calculated above)
  • invoice_date — today's date

Step 5 — Calculate the amounts

Default hourly rate: $150.00 CAD/hr (senior AI engineer contractor rate in Ontario). Use this unless the user provides a different rate — do not ask.

subtotal = hours_worked × hourly_rate
hst      = subtotal × 0.13          # 13% HST (Ontario)
total    = subtotal + hst

Step 6 — Fill the HTML template

Template file: .agents/skills/invoice-generator/references/invoice_template.html

Do NOT write a Python script to do this. Read the template file directly with your file-reading tools, do the string replacements in memory, and write the result out with your file-writing tools.

The template uses two types of elements — <input> fields (replace the value="..." attribute) and <td> / <div> display cells (replace the text content between the tags). Do not prompt the user for client or end-client details; those are already set in the template.

<div> text content — replace text between the tags:

Element class / selectorValue to insert
.company-name (the <div> in the header)corporation_name

<input> fields — replace value="...":

Element idValue to insert
invoiceNumberinvoice_number
invoiceDatetoday's date in YYYY-MM-DD format
payPeriodFromStartDate
payPeriodToEndDate
hourshours_worked (2 decimal places)
ratehourly_rate (2 decimal places, default 150.00)

<td> display cells — replace text content between the tags:

Element idValue to insert
amount$subtotal (e.g. $1900.00)
subtotal-display$subtotal
hst$hst (e.g. $247.00)
total$total (e.g. $2147.00)

Save the filled HTML to the project root as invoice_<invoice_number>.html.


Step 7 — Convert to PDF

Run the helper script (the only script in this skill). Always use absolute paths — Chrome headless silently discards output when given a relative PDF path.

$root = (Get-Location).Path
python .agents/skills/invoice-generator/scripts/html_to_pdf.py `
  "$root\invoice_<invoice_number>.html" `
  "$root\Inv-<invoice_number>-<corporation_slug>-<Mon>-<YYYY>.pdf"

PDF naming convention: Inv-<InvoiceNumber>-<CorporationSlug>-<Mon>-<YYYY>.pdf

  • CorporationSlug — derived in Step 3 from the exact corporation name
  • Mon — three-letter month abbreviation, e.g. Apr
  • YYYY — four-digit year

Step 8 — Validate the PDF

Before cleaning up, confirm the PDF was successfully generated:

$root = (Get-Location).Path
python -c "
import os, sys
pdf = r'$root\Inv-<invoice_number>-<corporation_slug>-<Mon>-<YYYY>.pdf'
if os.path.isfile(pdf) and os.path.getsize(pdf) > 0:
    print(f'OK: {pdf} ({os.path.getsize(pdf):,} bytes)')
else:
    print(f'ERROR: PDF not found or empty — {pdf}')
    sys.exit(1)
"
  • If the check passes (exit code 0), proceed to Step 9.
  • If the check fails (exit code 1), stop and report the error to the user. Do not delete the HTML file.

Step 9 — Clean up

Delete the intermediate HTML file only after the PDF has been validated:

Remove-Item -Path "invoice_<invoice_number>.html" -ErrorAction SilentlyContinue

About html_to_pdf.py

This is the one script in the skill. It converts an HTML file to PDF using WeasyPrint if available, or falls back to Chrome/Edge headless:

python .agents/skills/invoice-generator/scripts/html_to_pdf.py <input.html> <output.pdf>

No other scripts are needed — the agent handles data extraction, calculation, and template filling directly from the instructions above.


Notes

  • Ignore workbook lock files that start with ~$.
  • If the workbook is open in Excel, use the copy at .agents/skills/invoice-generator/references/Invoice Raised vs Received.xlsx.
  • Replace [YOUR_HOURLY_RATE] with your actual rate when running commands.
  • Update references/invoice_template.html with your own business details before first use.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.