• HTML 77.6%
  • Python 11.1%
  • JavaScript 10.9%
  • Shell 0.4%
Find a file
Kimi (kimi-code CLI) e0e65b4740 2316: add sig_ctc_amount_paid (Amount Paid if CTC) + 2307 MP tidy, Designer toggle removal, 0619E/1601EQ rename migration artifacts
- 2316 CTC field: calibration 257d1768 + save v7 + regen'd static fallback, render-verified (kimi)
- scripts: add-field-2316-ctc-amount, regen-schema-2316-ctc, rename-fields/regen-schema (260727)
- state snapshots + reports/logs per RLC
2026-07-27 18:53:09 +08:00
.bin checkpoint: 260726-211341-kimi (kimi-1601EQ-v6-generic-comb) 2026-07-26 21:13:41 +08:00
backups checkpoint: 260726-211341-kimi (kimi-1601EQ-v6-generic-comb) 2026-07-26 21:13:41 +08:00
capacity feat(capacity): agent-loop 10x batch analysis + character capacity tables 2026-06-02 18:43:29 +08:00
exports EOD 260727: everything promoted to production; Justin's three bugs logged with evidence 2026-07-27 01:05:28 +08:00
handoff checkpoint: 260727-010817-kimi (kimi-1601EQ-EOD) 2026-07-27 01:08:17 +08:00
logs 2316: add sig_ctc_amount_paid (Amount Paid if CTC) + 2307 MP tidy, Designer toggle removal, 0619E/1601EQ rename migration artifacts 2026-07-27 18:53:09 +08:00
loopd checkpoint: 260726-211341-kimi (kimi-1601EQ-v6-generic-comb) 2026-07-26 21:13:41 +08:00
rca docs: full traced incident report + lessons learned for today's save/calibration saga (B1/B10/B2/B18/B19/B20/B21) 2026-07-16 23:29:13 +08:00
reports 2316: add sig_ctc_amount_paid (Amount Paid if CTC) + 2307 MP tidy, Designer toggle removal, 0619E/1601EQ rename migration artifacts 2026-07-27 18:53:09 +08:00
scripts 2316: add sig_ctc_amount_paid (Amount Paid if CTC) + 2307 MP tidy, Designer toggle removal, 0619E/1601EQ rename migration artifacts 2026-07-27 18:53:09 +08:00
stack feat(P0f): immutable save version chains + amount fields are 14-cell combs + Part III set up 2026-07-26 16:54:31 +08:00
state 2316: add sig_ctc_amount_paid (Amount Paid if CTC) + 2307 MP tidy, Designer toggle removal, 0619E/1601EQ rename migration artifacts 2026-07-27 18:53:09 +08:00
strategies feat(methodology): field-by-field calibration with live RCA loop 2026-06-02 20:03:32 +08:00
templates fix(2307): grid alignment, tax_agent maxWidth, e9/e10 rows + commit all 2026-07-23/24 session artifacts 2026-07-24 12:45:15 +08:00
.gitignore feat(export-pdf): headless versioned PDF generation + content audit; RCA on the preview-vs-export split 2026-07-26 20:14:46 +08:00
0619-E Jan 2018 rev final.pdf Add 0619-E, 1601-EQ, 1604-E forms to viewer and form filler 2026-06-01 20:33:15 +08:00
0619E.html calibrate: 0619-E, 1601-EQ, 1604-E positions via pdftotext bbox analysis 2026-06-01 21:04:47 +08:00
0619E_260726205845-1.png savepoint(v85): kerning split analysed — explicit positioning survives PDF export, kerning does not 2026-07-26 21:00:20 +08:00
0619E_260726205845.pdf savepoint(v85): kerning split analysed — explicit positioning survives PDF export, kerning does not 2026-07-26 21:00:20 +08:00
0619E_260726212056-1.png fix(v86): use the generic comb the app already had — items 9, 10A, 10B, 13 correct in the PDF 2026-07-26 21:22:16 +08:00
0619E_260726212056.pdf fix(v86): use the generic comb the app already had — items 9, 10A, 10B, 13 correct in the PDF 2026-07-26 21:22:16 +08:00
0619E_260726212801-1.png 0619E complete: items 1 and 2 converted to combs — audit clean, technique report written 2026-07-26 21:37:31 +08:00
0619E_260726212801.pdf 0619E complete: items 1 and 2 converted to combs — audit clean, technique report written 2026-07-26 21:37:31 +08:00
0619E_FILLED_1784901078042-260724-01.pdf savepoint(v85): kerning split analysed — explicit positioning survives PDF export, kerning does not 2026-07-26 21:00:20 +08:00
0619E_FILLED_1784901078042.pdf savepoint(v85): kerning split analysed — explicit positioning survives PDF export, kerning does not 2026-07-26 21:00:20 +08:00
0619E_FILLED_1785067413367-260726200422.pdf savepoint(v85): kerning split analysed — explicit positioning survives PDF export, kerning does not 2026-07-26 21:00:20 +08:00
0619E_FILLED_1785067413367.pdf savepoint(v85): kerning split analysed — explicit positioning survives PDF export, kerning does not 2026-07-26 21:00:20 +08:00
0619E_FILLED_1785070388020.pdf savepoint(v85): kerning split analysed — explicit positioning survives PDF export, kerning does not 2026-07-26 21:00:20 +08:00
0619E_FILLED_1785070466608.pdf savepoint(v85): kerning split analysed — explicit positioning survives PDF export, kerning does not 2026-07-26 21:00:20 +08:00
0619E_FULLY_FILLED.pdf fix(forms): complete field coverage for 0619E, 1601EQ, 1604E 2026-06-02 19:58:23 +08:00
0619E_verify-1.png verify: dummy fill visual check for 0619-E, 1601-EQ, 1604-E — all pass 2026-06-02 01:37:43 +08:00
1601-EQ January 2019 ENCS final.pdf Add 0619-E, 1601-EQ, 1604-E forms to viewer and form filler 2026-06-01 20:33:15 +08:00
1601EQ.html calibrate: 0619-E, 1601-EQ, 1604-E positions via pdftotext bbox analysis 2026-06-01 21:04:47 +08:00
1601EQ_FULLY_FILLED.pdf fix(forms): complete field coverage for 0619E, 1601EQ, 1604E 2026-06-02 19:58:23 +08:00
1601EQ_verify-1.png verify: dummy fill visual check for 0619-E, 1601-EQ, 1604-E — all pass 2026-06-02 01:37:43 +08:00
1604E Jan 2018 ENCS Final2.pdf Add 0619-E, 1601-EQ, 1604-E forms to viewer and form filler 2026-06-01 20:33:15 +08:00
1604E.html calibrate: 0619-E, 1601-EQ, 1604-E positions via pdftotext bbox analysis 2026-06-01 21:04:47 +08:00
1604E_260727150524-1.png 1604-E session 2 continued: Schedule 2, signature block, page-2 TIN/name written and gated; export-pdf.py page-2 audit bug fixed 2026-07-27 15:09:33 +08:00
1604E_260727150524.pdf 1604-E session 2 continued: Schedule 2, signature block, page-2 TIN/name written and gated; export-pdf.py page-2 audit bug fixed 2026-07-27 15:09:33 +08:00
1604E_260727160255-1.png 1604-E: Justin's v10-v12 review fixes applied + gated; RCA on recurring Field Details inconsistency; standardized notes convention 2026-07-27 16:11:12 +08:00
1604E_260727160255.pdf 1604-E: Justin's v10-v12 review fixes applied + gated; RCA on recurring Field Details inconsistency; standardized notes convention 2026-07-27 16:11:12 +08:00
1604E_260727162613-1.png 1604-E v14 review: 20 fixes gated clean, ruler-fill leftover sample-data bug fixed, concurrent-editing hazard confirmed, Schedule III/IV closed 2026-07-27 16:29:32 +08:00
1604E_260727162613.pdf 1604-E v14 review: 20 fixes gated clean, ruler-fill leftover sample-data bug fixed, concurrent-editing hazard confirmed, Schedule III/IV closed 2026-07-27 16:29:32 +08:00
1604E_260727164901-1.png 1604-E v20 review: self-inflicted Field-Details inconsistency found+fixed, 16 more fixes gated clean 2026-07-27 16:51:29 +08:00
1604E_260727164901.pdf 1604-E v20 review: self-inflicted Field-Details inconsistency found+fixed, 16 more fixes gated clean 2026-07-27 16:51:29 +08:00
1604E_260727171056-1.png 1604-E v24 review: Sample Text audit broadened to all fields (found real capacity violations), JUSTIFIED comb-alignment proposal, 5 more fixes 2026-07-27 17:12:56 +08:00
1604E_260727171056.pdf 1604-E v24 review: Sample Text audit broadened to all fields (found real capacity violations), JUSTIFIED comb-alignment proposal, 5 more fixes 2026-07-27 17:12:56 +08:00
1604E_260727182357-1.png 1604-E: Schedule 3/4 built (Sched 4 to its real 6 columns, per Justin's confirmation); JUSTIFIED dropdown question answered 2026-07-27 18:28:18 +08:00
1604E_260727182357.pdf 1604-E: Schedule 3/4 built (Sched 4 to its real 6 columns, per Justin's confirmation); JUSTIFIED dropdown question answered 2026-07-27 18:28:18 +08:00
1604E_FULLY_FILLED.pdf fix(forms): complete field coverage for 0619E, 1601EQ, 1604E 2026-06-02 19:58:23 +08:00
1604E_verify-1.png verify: dummy fill visual check for 0619-E, 1601-EQ, 1604-E — all pass 2026-06-02 01:37:43 +08:00
2306 Jan 2018 ENCS v4.pdf Add PDF viewer app with sample BIR forms 2026-04-28 21:37:51 +08:00
2306.html Add reference files, agent guidance, and repo analysis 2026-06-01 12:22:38 +08:00
2307 Jan 2018 ENCS v3.pdf Add PDF viewer app with sample BIR forms 2026-04-28 21:37:51 +08:00
2307.html Add reference files, agent guidance, and repo analysis 2026-06-01 12:22:38 +08:00
2307_dummy_filled.png Add reference files, agent guidance, and repo analysis 2026-06-01 12:22:38 +08:00
2307_preview.png Add reference files, agent guidance, and repo analysis 2026-06-01 12:22:38 +08:00
2316 Sep 2021 ENCS_Final_corrected.pdf Add PDF viewer app with sample BIR forms 2026-04-28 21:37:51 +08:00
2316.html Add reference files, agent guidance, and repo analysis 2026-06-01 12:22:38 +08:00
2316_260727181731-1.png 2316: add sig_ctc_amount_paid (Amount Paid if CTC) + 2307 MP tidy, Designer toggle removal, 0619E/1601EQ rename migration artifacts 2026-07-27 18:53:09 +08:00
2316_260727181731.pdf 2316: add sig_ctc_amount_paid (Amount Paid if CTC) + 2307 MP tidy, Designer toggle removal, 0619E/1601EQ rename migration artifacts 2026-07-27 18:53:09 +08:00
2316_260727181949-1.png 2316: add sig_ctc_amount_paid (Amount Paid if CTC) + 2307 MP tidy, Designer toggle removal, 0619E/1601EQ rename migration artifacts 2026-07-27 18:53:09 +08:00
2316_260727181949.pdf 2316: add sig_ctc_amount_paid (Amount Paid if CTC) + 2307 MP tidy, Designer toggle removal, 0619E/1601EQ rename migration artifacts 2026-07-27 18:53:09 +08:00
230416_2-Parsecs_from_Sol_13.5.pdf checkpoint: 260726-211341-kimi (kimi-1601EQ-v6-generic-comb) 2026-07-26 21:13:41 +08:00
260429 pdfexport_architecture_spec.docx Auto-commit before migration to citfj 2026-05-04 14:10:23 +08:00
agent-loop-log.md feat(capacity): agent-loop 10x batch analysis + character capacity tables 2026-06-02 18:43:29 +08:00
agent-loop-state.md feat(capacity): agent-loop 10x batch analysis + character capacity tables 2026-06-02 18:43:29 +08:00
agent-loop.jsonl feat(capacity): agent-loop 10x batch analysis + character capacity tables 2026-06-02 18:43:29 +08:00
AGENTS.md 1604-E session 2: item 1 + items 9/10 resolved, Schedule 1 verified, page-2 header measured; AGENTS.md fixes; measure-rules.py tick-detection bug fixes 2026-07-27 13:48:09 +08:00
BACKLOG.md 1604-E: Schedule 3/4 built (Sched 4 to its real 6 columns, per Justin's confirmation); JUSTIFIED dropdown question answered 2026-07-27 18:28:18 +08:00
BIR-FORMS-SUMMARY.md backlog(P0g): after 0619-E — technique analysis, a form-calibration skill, then DSV on 1601-EQ in parallel with Kimi on 1604-E 2026-07-26 16:56:01 +08:00
calibration-2307-2026-07-20-01.json checkpoint: 260723-1312-kimi (initial) 2026-07-23 13:12:07 +08:00
crop_0619E_amounts.png verify: dummy fill visual check for 0619-E, 1601-EQ, 1604-E — all pass 2026-06-02 01:37:43 +08:00
crop_0619E_payment.png verify: dummy fill visual check for 0619-E, 1601-EQ, 1604-E — all pass 2026-06-02 01:37:43 +08:00
crop_0619E_sig.png verify: dummy fill visual check for 0619-E, 1601-EQ, 1604-E — all pass 2026-06-02 01:37:43 +08:00
crop_1601EQ_amounts.png verify: dummy fill visual check for 0619-E, 1601-EQ, 1604-E — all pass 2026-06-02 01:37:43 +08:00
crop_1601EQ_header.png verify: dummy fill visual check for 0619-E, 1601-EQ, 1604-E — all pass 2026-06-02 01:37:43 +08:00
crop_1601EQ_sig.png verify: dummy fill visual check for 0619-E, 1601-EQ, 1604-E — all pass 2026-06-02 01:37:43 +08:00
crop_1604E_header.png verify: dummy fill visual check for 0619-E, 1601-EQ, 1604-E — all pass 2026-06-02 01:37:43 +08:00
crop_1604E_schedule.png verify: dummy fill visual check for 0619-E, 1601-EQ, 1604-E — all pass 2026-06-02 01:37:43 +08:00
crop_1604E_sig.png verify: dummy fill visual check for 0619-E, 1601-EQ, 1604-E — all pass 2026-06-02 01:37:43 +08:00
crop_2316_ctc_260727181731.png 2316: add sig_ctc_amount_paid (Amount Paid if CTC) + 2307 MP tidy, Designer toggle removal, 0619E/1601EQ rename migration artifacts 2026-07-27 18:53:09 +08:00
crop_2316_ctc_wide_260727181731.png 2316: add sig_ctc_amount_paid (Amount Paid if CTC) + 2307 MP tidy, Designer toggle removal, 0619E/1601EQ rename migration artifacts 2026-07-27 18:53:09 +08:00
crop_2316_ctc_wide_260727181949.png 2316: add sig_ctc_amount_paid (Amount Paid if CTC) + 2307 MP tidy, Designer toggle removal, 0619E/1601EQ rename migration artifacts 2026-07-27 18:53:09 +08:00
DOCUMENTATION.md docs: HITL alignment plan, ERPNext integration plan, form inventory 2026-06-01 20:48:05 +08:00
ERPNEXT-INTEGRATION-PLAN.md docs: HITL alignment plan, ERPNext integration plan, form inventory 2026-06-01 20:48:05 +08:00
FDR-001-Field-Designer.md refactor(designer): B18 remove File Management bar + Forgejo panel, DB-only calibration save 2026-07-16 22:25:05 +08:00
FRD-detailed.md Auto-commit before migration to citfj 2026-05-04 14:10:23 +08:00
FRD.md refactor(designer): B18 remove File Management bar + Forgejo panel, DB-only calibration save 2026-07-16 22:25:05 +08:00
HANDOFF-Louise.md docs: Louise handoff + live URL fix + gitignore 2026-06-14 18:24:46 +08:00
HITL-ALIGNMENT-PLAN.md docs: HITL alignment plan, ERPNext integration plan, form inventory 2026-06-01 20:48:05 +08:00
index.html 2316: add sig_ctc_amount_paid (Amount Paid if CTC) + 2307 MP tidy, Designer toggle removal, 0619E/1601EQ rename migration artifacts 2026-07-27 18:53:09 +08:00
kimi-export-session_-20260724-042930-BIRforms.md checkpoint: 260726-211341-kimi (kimi-1601EQ-v6-generic-comb) 2026-07-26 21:13:41 +08:00
METHODOLOGY.md feat(methodology): field-by-field calibration with live RCA loop 2026-06-02 20:03:32 +08:00
package-lock.json feat: quadrant-by-quadrant calibration workflow 2026-06-02 20:51:09 +08:00
package.json feat: add preview-quadrant.js for instant PNG previews 2026-06-02 21:02:39 +08:00
PROGRESS.md 0619E promoted to production — verified in the real PDF on both surfaces 2026-07-26 21:42:13 +08:00
README.md checkpoint: 260723-174433-kimi (phase2-all-forms) 2026-07-23 17:44:34 +08:00
REPO_ANALYSIS.md Add reference files, agent guidance, and repo analysis 2026-06-01 12:22:38 +08:00
SESSION_LOG.md verify: dummy fill visual check for 0619-E, 1601-EQ, 1604-E — all pass 2026-06-02 01:37:43 +08:00
SESSION_LOG_20260602.md log: session log 2026-06-02 — Field Designer + quadrant calibration 2026-06-03 01:28:43 +08:00
test_fill_all.js verify: dummy fill visual check for 0619-E, 1601-EQ, 1604-E — all pass 2026-06-02 01:37:43 +08:00

BIR Form Calibration Tool

Status: Phase 1 — PDF Field Mapping & Calibration (BIR Form 2307)
Live URL: https://forms.comfac-it.com
Target Platform: Local Web App (PC02) → ERPNext Philippines


The Goal

This is a form-calibration tool. Its primary purpose is to map flat government PDFs (starting with Philippine BIR forms) into machine-readable templates that external systems — especially ERPNext — can use to fill forms automatically.

The calibration tool produces a standardized field map for each form: coordinates, fonts, alignment rules, data transformations, and validation rules. Any application that understands this map can feed structured data into it and receive a correctly filled, print-ready PDF.

The Problem

In the Philippines, businesses must file BIR forms like 2307 (Certificate of Creditable Tax Withheld at Source) every time they pay suppliers subject to Expanded Withholding Tax (EWT). ERPNext — a leading open-source ERP — lacks the precision to fill flat PDF government forms without massive custom development. Rather than bending ERPNext into submission, we are building a form-aware calibration layer that can:

  1. Accept any flat PDF form (starting with BIR 2307).
  2. Use AI to detect, index, and label every field by its coordinates.
  3. Store a machine-readable "form template" (dimensions, coordinates, fonts, rules).
  4. Fill the form programmatically with correct fonts, alignment, spacing, and grouping.
  5. Export a print-ready, layered PDF — background layer + fillable field layer.
  6. Expose the calibrated template to ERPNext (or any system) via API so those systems can generate filled forms from their own data.

Team

Name Role Can Modify the App?
Clarise Duco Product / Compliance Lead — BIR compliance, form requirements, field calibration Yes — admin, can modify app
Olie Sano Operations / Admin — user management, form deletion, QA Yes — admin
Journie Reyes Engineering / Integration Lead — ERPNext, API, data mapping, architecture Yes — admin
Ameenah Guro Comfac IT Yes — admin
Shekinah "Shek" Rouise Tejada Business Analyst — IE Operations Yes — admin
Angela "Ela" Taylan Business Analyst — IE Operations Yes — admin
Christopher Gacad Dev, Comfac IT Yes — admin
Louise Anne Padilla Operations User — fills, saves, and exports BIR form drafts No — regular user account
Dominique Mauricio No — regular user account
Jun (Edmund) Valen IT Supervisor, Comfac IT No — regular user account
Christian Jamero ERPNext Generalist, ERPNext Team No — regular user account

Onboarded 2026-07-16 (Ameenah, Shek, Ela, Christopher, Louise-adjacent Dominique, Jun, Christian) — see logs/260716-pdfexport_log.md §10-11 for account creation/role details and the outstanding self-service password-change gap.

How the Team Works (Collaborative Development Model)

This is a team-owned, team-evolved application. The live app runs on an internal server at forms.comfac-it.com:

  1. Open a browser — the app is always available at https://forms.comfac-it.com
  2. Use Kimi or Claude — paste source files, describe changes, get improved code
  3. Commit to Forgejo — push changes; the live app updates automatically
  4. Track everything — QA issues, FRD updates, root cause analyses all live as Forgejo Issues and Wiki pages

See FRD.md §3 for the full Collaborative Development & Continuous Improvement specification.


Architecture Overview

┌──────────────────────────────────────────────────────────────────────────────┐
│                         BIR FORM AUTOMATION STACK                            │
├──────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│  ┌─────────────────┐    ┌─────────────────┐    ┌─────────────────────────┐    │
│  │   ERPNext /     │◄──►│   LOCAL API     │◄──►│   FORM FILL ENGINE      │    │
│  │   Any Data      │    │   (REST/tRPC)   │    │   (PDF-lib + Canvas)    │    │
│  │   Source        │    │                 │    │                         │    │
│  └─────────────────┘    └─────────────────┘    └─────────────────────────┘    │
│                              ▲                           │                   │
│                              │                           ▼                   │
│                              │                  ┌─────────────────┐           │
│                              │                  │  LAYERED PDF    │           │
│                              │                  │  OUTPUT         │           │
│                              │                  └─────────────────┘           │
│                              │                                               │
│  ┌───────────────────────────┴─────────────────────────────────────────┐     │
│  │                    TEMPLATE REPOSITORY (JSON/YAML)                   │     │
│  │  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐  ┌──────────┐ │     │
│  │  │ Form 2307   │  │ Form 2551Q  │  │ Form 1601EQ │  │ Form ... │ │     │
│  │  │ Template    │  │ Template    │  │ Template    │  │ Template │ │     │
│  │  │ - fields[]  │  │ - fields[]  │  │ - fields[]  │  │ - fields │ │     │
│  │  │ - rules[]   │  │ - rules[]   │  │ - rules[]   │  │ - rules  │ │     │
│  │  │ - fonts{}   │  │ - fonts{}   │  │ - fonts{}   │  │ - fonts  │ │     │
│  │  └─────────────┘  └─────────────┘  └─────────────┘  └──────────┘ │     │
│  └──────────────────────────────────────────────────────────────────┘     │
│                              ▲                                               │
│                              │                                               │
│  ┌───────────────────────────┴─────────────────────────────────────────┐     │
│  │                    AI FIELD DETECTION SERVICE                         │     │
│  │  (Kimi Moonshot / Local LLM / OCR Hybrid)                             │     │
│  │  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐                   │     │
│  │  │ PDF Upload  │  │  AI Indexer  │  │  Human Review│                   │     │
│  │  │             │  │  (draw boxes)  │  │  & Adjust   │                   │     │
│  │  └─────────────┘  └─────────────┘  └─────────────┘                   │     │
│  └──────────────────────────────────────────────────────────────────┘     │
│                                                                              │
│  ┌──────────────────────────────────────────────────────────────────┐     │
│  │                    FORGEJO PAGES HOSTING                            │     │
│  │  - Static web UI for template management                          │     │
│  │  - AI-assisted field labeling interface                           │     │
│  │  - Template preview & calibration                                 │     │
│  │  - Auto-deploys when team pushes changes                          │     │
│  └──────────────────────────────────────────────────────────────────┘     │
│                              ▲                                               │
│                              │                                               │
│  ┌───────────────────────────┴─────────────────────────────────────────┐     │
│  │                    TEAM DEV LOOP (Clarise + Journie + AI)             │     │
│  │  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌──────────┐            │     │
│  │  │  Report  │  │  AI Chat │  │   Edit   │  │   Push   │            │     │
│  │  │  Issue   │──►│  (Kimi/  │──►│  Source  │──►│  & Deploy│            │     │
│  │  │          │  │  Claude) │  │          │  │          │            │     │
│  │  └──────────┘  └──────────┘  └──────────┘  └──────────┘            │     │
│  └──────────────────────────────────────────────────────────────────┘     │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

Phase Roadmap

Phase Goal Status
Phase 0 Project scaffolding (README, FRD, repo structure) Complete
Phase 1 Calibration UI — Upload BIR forms → coordinate picker → calibrate positions → dummy fill preview Complete (2307, 2306, 2316)
Phase 2 Fill Engine — Auto-computation engine, ATC code lookup, PDF export via pdf-lib Complete (2307, 2306, 2316)
Phase 3 Expand Form Library — Add remittance return forms: 0619-E, 1601-EQ, 1604-E — schemas defined 🟡 In Progress — positions pending calibration
Phase 4 HITL Calibration Pipeline — AI-assisted coordinate calibration for new forms Planned (see HITL-ALIGNMENT-PLAN.md)
Phase 5 ERPNext Integration — Purchase Invoice → calibrated BIR 2307 template → one-click fill on etest Planned (see ERPNEXT-INTEGRATION-PLAN.md; direction as of 2026-07-23: surface each calibrated form as a native ERPNext Print Format via Print Designer — driven by the exported birparr_<form>-kimi.json — so 2307 etc. appear as ordinary "Print" options on Purchase Invoice, rather than a custom client-script button. Prototype with sample dummy invoices first.)
Phase 6 Aggregation Forms — 0619-E / 1601-EQ / 1604-E filled from multi-PI data via calibrated templates Planned (after Phase 5)
Phase 6b Batch Creation — generate filled BIR PDFs for multiple Purchase Invoices at once (e.g. all EWT payments in a period) Planned (after Phase 5, if needed)
Phase 7 Production Deploy — Deploy calibration tool + API to ecit + Accounting team onboarding Planned

Key Technical Decisions

Decision Rationale
Flat PDF → Layered PDF Government forms are non-fillable scans. We overlay a transparent fillable layer on top of the original background so the output looks identical to the official form when printed.
Template-as-Code Every calibrated form produces a JSON template containing field coordinates, fonts, rules, and data mappings. Templates are versioned, diffable, and portable across systems.
AI Field Detection Rather than manual coordinate entry, AI (Kimi Moonshot, local LLM, or hybrid OCR) suggests field bounding boxes by analyzing the PDF image. Humans review and adjust.
Forgejo Pages First Host the labeling UI on Forgejo Pages for zero-cost, self-hosted deployment. Later migrate to ERPNext-embedded pages.
Local Web App Bridge A lightweight local web app (React + Hono) sits between ERPNext and the form engine, handling authentication, data mapping, and batch generation.

Repository Structure

bir-form-automation/
├── README.md                 # This file
├── FRD.md                    # Functional Requirements Document
├── docs/
│   ├── architecture/         # System diagrams & ADRs
│   └── api/                  # API specifications
├── packages/
│   ├── web/                  # Forgejo Pages UI (field labeling, template mgmt)
│   ├── api/                  # Local API server (tRPC + Hono)
│   ├── pdf-engine/           # PDF manipulation layer (pdf-lib, canvas)
│   └── ai-service/           # AI field detection & OCR wrappers
├── templates/
│   └── bir/
│       └── 2307/
│           ├── 2307-template.json     # Field definitions & rules
│           ├── 2307-background.pdf    # Official blank form
│           └── 2307-sample-filled.pdf # Calibrated output sample
├── integrations/
│   └── erpnext/              # ERPNext connector & data mappers
└── tools/
    └── calibration/            # Font/size/kerning calibration scripts

Quick Start (Future)

# 1. Clone the repository
git clone <forgejo-repo-url>
cd bir-form-automation

# 2. Install dependencies
npm install

# 3. Start the local development server
npm run dev

# 4. Open the field labeling UI
open http://localhost:3000

# 5. Upload a BIR PDF and begin AI-assisted field mapping

Running Tests

The test system has three layers that run in sequence: fill → verify → audit. You can stop after any layer depending on what you need to check.


1. Configure an AI Provider (first time only)

The AI audit step requires a vision-capable AI provider. If you only want to run fill + value verification, skip this step.

  1. Start the local API server: npm run server

  2. Open the app in your browser: http://localhost:3000

  3. Go to Settings → AI Providers → Add Provider

  4. Fill in the form:

    Field Example values
    Display name Kimi Vision, Claude Sonnet, Local Ollama
    Type moonshot / anthropic / openai / ollama / custom
    Endpoint URL Pre-filled per type; edit if using a custom host
    Model ID moonshot-v1-8k, claude-sonnet-4-6, gpt-4o, llava
    API Key Enter your key — it writes to the server .env and is never shown again
  5. Click Test Connection. Wait for the Connected badge.

  6. Under Settings → AI Providers → Task Assignments, set:

    • Field Detection provider → your vision provider
    • AI Audit provider → same, or a different one to compare

You can add as many providers as you like. The API key for each lives in its own env var in the server .env file — never in the config files committed to the repo.

To use a provider without any API key (for offline work or CI), add a provider with type mock. It returns a realistic hardcoded response and requires nothing.


2. Open the test panel for a template

  1. From the dashboard (/), open any saved template.
  2. Click the Tests tab (top navigation, next to Calibration and Map).
  3. You will see the test case library for this template.

If no test cases exist yet, click New Test Case and fill in values for each field, or click Fill with Dummy to auto-populate all fields with pattern-based dummy data.


3. Run a single test

  1. In the test case library, click Run next to any test case.

  2. Three tabs appear in the result panel:

    Tab 1 — Generated PDF The filled PDF rendered inline. Use zoom and page navigation to inspect it visually. This is the same output that would be sent to BIR.

    Tab 2 — Value Report A row-per-field table comparing what you injected vs what was extracted from the PDF:

    Field Expected Extracted Result
    payee_tin 123-456-789-000 123-456-789-000 MATCH
    payee_name ACME SUPPLIES INC. ACME SUPPLIES IN ⚠ PARTIAL
    grand_total_income 300,000.00 (empty) MISSING
    • MATCH — value in the PDF is identical to what was injected.
    • PARTIAL — value was truncated (check the overflow setting for this field).
    • MISSING — no text was found in this field's bounding box (coordinate or rendering issue).
    • MISMATCH — text is present but different from the injected value.
    • ORPHAN rows at the bottom of the table — text found in the PDF that does not belong to any field (coordinate error or rendering bug).

    Tab 3 — AI Audit Click Run AI Audit to send the filled PDF to your configured vision provider. The AI reads the form as an independent reviewer — it does not know what values were injected, only what it can see on the page.

    Results appear as colored overlays on the PDF:

    • 🔴 Red border — CRITICAL violation (form would likely be rejected)
    • 🟡 Yellow border — WARNING (may cause issues, needs review)
    • 🔵 Blue border — INFO (cosmetic only)

    Each violation shows a description and a suggested fix on hover. Click any violation to open the calibration panel for that field immediately.


4. Run the full test suite

To run all test cases for a template at once:

Tests tab → "Run All Tests" button

A progress bar shows each test case as it runs. When complete, a summary table appears:

Test Case Fill Value Check AI Audit Critical Warnings
Base case 22/22 match PASS 0 0
Max length ⚠ 2 partial WARN 0 2
Minimal (required only) 10/10 match PASS 0 0
Special characters 1 mismatch FAIL 1 0

Click any row to expand the full field-level report for that test case.


5. Compare results across AI providers

To see how different AI models assess the same PDF:

  1. In the AI Audit tab of any test result, find the Provider dropdown (top right of the tab).
  2. Switch to a different provider and click Run AI Audit again. Results are stored separately for each provider.
  3. For a full side-by-side comparison: click Compare Providers. All your configured vision providers run on the same PDF and their violation lists appear as columns in a table.

Violations flagged by every provider = high confidence, fix immediately.
Violations flagged by only one provider = review manually, may be a false positive.


6. Fix a violation

Every violation card — whether in the Value Report or the AI Audit — has a Fix This button.

Clicking it:

  1. Opens the calibration panel for the affected field.
  2. Highlights the specific parameter the AI suggested adjusting (font size, bbox width, overflow setting, etc.).
  3. Keeps the test result in a sidebar so you can re-run with one click after making the change.

Common fixes by violation type:

Violation Where to look What to adjust
TEXT_OVERFLOW Calibration → Overflow Change to shrink_font or reduce font_size_pt
PARTIAL in value check Calibration → Max Length Increase max_length or change overflow to wrap
GROUPBOX_MISALIGNED Calibration → GROUP_BOXES Adjust box_width or use auto char_spacing recalculate
MISSING in value check Template editor Check bbox coordinates — field may be off the page
DATE_FORMAT_WRONG Data mapping → Transform Apply date_format(MM/DD/YYYY) transform
TIN_FORMAT_WRONG Data mapping → Transform Apply tin_format transform
ORPHAN_TEXT Template editor A field bbox is wrong; the text landed outside it

7. Run tests from the API (automated / CI)

All test operations are available as REST endpoints on the local API server:

# Fill a template with a specific test case
curl -X POST http://localhost:3001/api/test/fill \
  -H "Content-Type: application/json" \
  -d '{
    "template_id": "bir-2307-2018-encs",
    "test_case_id": "base-case",
    "payload": { ... }
  }'
# Returns: { fill_id, pdf_base64, fill_report }

# Run value verification on a completed fill
curl http://localhost:3001/api/test/{fill_id}/verify
# Returns: { fields_matched, fields_mismatched, fields_missing, orphan_text }

# Run AI audit on a completed fill
curl -X POST http://localhost:3001/api/test/{fill_id}/audit \
  -H "Content-Type: application/json" \
  -d '{ "provider_id": "kimi-vision" }'
# Returns: { audit_id, violations[], verdict, ai_model, duration_ms }

# Run the full test suite for a template
curl -X POST http://localhost:3001/api/test/run-suite \
  -H "Content-Type: application/json" \
  -d '{ "template_id": "bir-2307-2018-encs" }'
# Returns: { run_id, results[], summary: { passed, failed, warnings } }

For CI (Forgejo Actions), a workflow that blocks deployment on critical violations:

# .forgejo/workflows/test.yml
on: [push]
jobs:
  test-templates:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: npm install && npm run server:ci &
      - run: npm run test:suite -- --template bir-2307-2018-encs --provider mock
      - run: |
          RESULT=$(curl -s http://localhost:3001/api/test/last-run/summary)
          CRITICAL=$(echo $RESULT | jq '.critical_count')
          if [ "$CRITICAL" -gt "0" ]; then
            echo "❌ $CRITICAL critical violations — blocking deploy"
            exit 1
          fi

Note: Use --provider mock in CI so no API key is needed. The mock provider returns a realistic response and validates the fill + value verification layers without calling an external API.


8. Understand the overall test verdict

A template version is considered test-passing when:

  • All test cases show zero MISSING or MISMATCH in the value report.
  • The AI audit returns zero CRITICAL violations across all test cases.
  • WARNING violations exist in the report but are either resolved or declared as expected_violations in the test case definition (known cosmetic issues that do not affect BIR acceptance).

A ✅ test-passing badge appears on the template card in the dashboard once these conditions are met. The system will block a template commit to the repo if any CRITICAL violation exists — the block can be overridden with a written justification that is included in the commit message.


Contributing & Team Workflow

How We Improve This Application

Any team member can improve the app — no vendor dependency, no waiting for external developers:

  1. File an Issue (in Forgejo) — Bug? Feature request? Calibration problem? Open an issue with the appropriate label:

    • qa/bug — something is broken or misaligned
    • fr/feature-request — new capability needed
    • rca — root cause analysis of a misfilled form
    • frd-update — change to requirements
  2. Discuss & Investigate — Use the issue thread to attach sample PDFs, screenshots, and data. Use Kimi or Claude to help investigate.

  3. Implement — Open the source in an AI chat, describe the fix, apply the changes locally, test.

  4. Commit & Deploy — Push to Forgejo. Forgejo Pages auto-deploys. The whole team sees the update immediately.

  5. Update the FRD — If the change affects requirements, update FRD.md in the same commit.

Development Rules

  1. All form templates live in /templates and follow the FormTemplate schema (see FRD.md §8.1).
  2. Every field change must be reproducible: update the template JSON, not the PDF directly.
  3. Calibration changes (font, size, kerning) require a before/after PDF sample in the commit.
  4. Follow the phase roadmap — Phase 1 must produce a pixel-perfect BIR 2307 before expanding to other forms.
  5. Self-improvement is the default — when the AI misdetects a field, adjust the prompt in packages/ai-service/prompts/; when calibration is off, update the defaults; when a new edge case appears, add a validation rule.

License

MIT — This is an open-source tool for Philippine tax compliance automation.