Phase 6: the Non-B extension pack, checked and printed as one PDF
CI / secret scan (push) Successful in 4s
CI / fmt, clippy, tests (push) Successful in 31s

The pack for an extension of stay based on work, item by item in the
officer's order, each with its state at the date of the application:
generated, has blanks, uploaded, missing, out of date, no date, or not
needed for this person.

- src/pack/mod.rs: the rules as a pure function of the records and the
  documents, a unit test per rule. Copies belong to their record (the
  current passport, the last arrival and its TDAC, the re-entry permit it
  came back on, every extension since the passport was issued, the last
  90-day report, the current address, the work permit); the company
  certificate and BOJ.5 count six months from their certification, the
  balance sheet 17 months from its year's end, PND.1, SPS 1-10 and PP.30
  the last three months, PND.91 the latest year; two photos of the office.
  Sources in docs/PLAN.md (thailand.go.th 006_008, Immigration Division 1).
- A Pack tab: the six parts, each item's files and form, and what fixes it
  (the upload with the kind and record chosen, through the new ?kind= on
  the Documents tab and on a company's page; a document's date; a record).
  The application's fields are the Forms tab's, and both tabs carry them.
- /people/{id}/pack.pdf (src/pack/pdf.rs): a cover sheet with the contents
  page by page and what to sign and bring, the five forms, then every copy:
  uploaded PDFs as they are (a PDF 2.0 upload makes the pack 2.0), images
  fitted on A4 and turned as their EXIF orientation says, a page in place of
  a file that cannot be read; bookmarks per item. krilla gains its
  raster-images feature. The audit logs the forms' codes and a view or
  download of each document that went in.
- A company's page shows its part of every employee's pack.
- The extension deadline links to the pack; at 390 px the six tabs fit, as
  "Visa and stay" reads "Stay" on phones.
- Demo data shows every state.
- The Forms tab showed "Back about" and "Purpose" empty: the template read
  app.back and app.purpose, which serialize as "return" and "for".

docs/PLAN.md: phase 6 done, open question 2 settled (the office is the
application's), phase 7 planned from Alex's answers: the client link, the
MRZ from a phone photo, later the signed agreement; reminders move to 8.

Checks: cargo fmt, clippy -D warnings, 97 unit and 47 integration tests;
layout_check 0 problems (pack, company, forms, dashboard, person; light,
dark, desk, phone); the tabs measured at 390 and 360 px; the pack PDF
rendered and looked at, an EXIF-turned JPEG upright.
This commit is contained in:
grabowski committed 2026-11-20 16:04:13 +07:00
1 parent 990d5c88a4
commit fc8c1b6a44
26 files changed
+3367 -59

No files matched your search

+121 -9
View File
@@ -4,8 +4,9 @@
> 2026, all live at https://visa.buildfor.life. On November 19, 2026 the move
> of the documents from a directory on cnx01 into a bucket of cnx01's Garage
> was built (task 4.8) and checked in the fleet (task 4.9, cnx-network-clan
> PR #150); the documents move once that PR is deployed. **Resume here: phase
> 6, the Non-B extension pack.**
> PR #150); the documents move once that PR is deployed. Phase 6, the Non-B
> extension pack, was built on November 20, 2026. **Resume here: phase 7, the
> client link.**
visa.buildfor.life keeps the immigration records of the foreigners that B4L
looks after: their passports, addresses in Thailand, arrivals with the Thailand
@@ -35,6 +36,11 @@ The first round of questions was answered on November 17, 2026.
| Reminders | the dashboard first; later a Matrix room message and an email to the person concerned |
| Repository | public `B4L/visa` since Nov 17, 2026: it holds code and invented demo data only, so the fleet fetches it like proplan |
| Employers | companies are records of their own under Companies; a person's employer and a work permit's employer are chosen from them, and a company's page adds people to it |
| Which office (Nov 20) | part of each application: the field "Office" on the Pack and Forms tabs, Chiang Mai Immigration unless changed, so the pack's cover sheet names whichever office it goes to |
| Client link (Nov 20) | staff make a link for a person, often a new and empty record; the client fills in personal details, the passport (with the MRZ reader, also from a photo taken on the phone), the address in Thailand and contact, and uploads scans (passport pages, photo, TDAC) |
| Client input (Nov 20) | goes straight into the person's record, logged as coming from the link; staff check it |
| Link lifetime (Nov 20) | 14 days, or until the client presses Send or staff close the link |
| Client agreement (later) | a box on the client link where the client signs the agreement with B4L to keep and work with their data; its text comes from B4L |
Kanidm keeps persons, groups and OAuth2 clients in one namespace, so the
client cannot be called `visa` like the group. It is `visa-web`, as
@@ -146,7 +152,8 @@ downloads (bangkok.immigration.go.th/en/downloads_en); thailand.go.th,
For an extension of stay based on work, Chiang Mai Immigration asks for the
following. The pack lists each item with its state (generated, uploaded,
missing or out of date) and prints them in this order.
missing, out of date, or not needed for this person) and prints them in this
order.
1. TM.7 with a 4 x 6 cm photo, the acknowledgment of overstay penalties and
STM.2, all filled in from the records.
@@ -166,6 +173,46 @@ The company documents are shared by every employee's pack, so they are kept
once per company with their own expiry (a certification older than six months
counts as out of date).
How the app judges each item, at the date of the application (`src/pack/`,
a unit test per rule):
- **Forms** are generated from the records; one with blank lines is marked
"Has blanks" with links to what fills them.
- **Copies of records** (the passport's photo page, the visa, the last
arrival's stamp and TDAC, the re-entry permit when the last arrival used
one, the stamp of every extension approved since the passport was issued,
the last 90-day receipt, the TM.30 receipt of the current address, the work
permit): a document of the kind tied to that record, else one tied to no
record. A copy tied only to another record (an earlier passport or
arrival) is out of date. Arrivals before May 1, 2025 had no TDAC.
- **The photo** was taken within the six months before (the date on it, else
the day it was added). It is glued to TM.7, so it is brought along rather than printed.
- **The company certificate and BOJ.5** were certified by the registrar
within the six months before; the page says until when each counts.
- **The balance sheet with PND.50** is the latest year's: dated at the end of
the year it covers, it counts for 17 months, since the next year's are
filed within five months of its end.
- **PND.1, SPS 1-10 and PP.30** cover the last three months: the newest is
dated within the two months before, and every one of the last four months
goes into the pack, oldest first.
- **The applicant's PND.91** of the latest year is dated within the 15 months
before; someone whose first work permit was issued this year has none yet.
- **A map** is any; **photos of the office** are two or more (outside, with
the number and the name of the company; inside, with the staff at work).
- A document whose date matters but is not recorded goes into the pack, and
the page asks for its date.
The PDF starts with a cover sheet: the contents with the page of each item,
what is still missing, and what to do before handing it in (print two sets,
the signatures, the company's seal on every page of the employer's
documents, the photo, the fee of 1,900 THB and the originals to bring).
Sources: thailand.go.th, "Business visa extension for foreigners working in
Thailand" (guide-book-detail/006_008); Immigration Division 1, "List of
documents required to support an application by a foreigner for extension of
a Non-Immigrant Visa Category B" (counter M); Ministry of Foreign Affairs,
Non-Immigrant Visa B (a photo taken within the past six months).
## Phases
Each phase ends with the tests, clippy, formatting, screenshots in light and
@@ -178,9 +225,10 @@ dark at desktop and phone width, a commit and a push.
| 3 | On cnx01: flake package, fleet module, Kanidm client and group, bkk01 site, backups; real data from here on | live Nov 17, 2026 |
| 4 | Documents: encrypted uploads (passport pages, TDAC, receipts, photo) in a bucket of cnx01's Garage (first on the dataset `zroot/visa`) with a key var, viewing and download, all audited; the office's GPS position and photo | live Nov 18, 2026; Garage built Nov 19, 2026 |
| 5 | Filled-in forms: TM.7, STM.2, the overstay acknowledgment (STM.9), STM.11, STM.1, TM.47 and TM.8 as PDF | built Nov 18, 2026 |
| 6 | The Non-B extension pack: B4L's company documents, the checklist, one PDF to print | |
| 7 | Reminders by Matrix room message and by email | |
| later | Thai user interface, agency cases and fees, a view for clients, other visa categories' packs | |
| 6 | The Non-B extension pack: B4L's company documents, the checklist, one PDF to print | built Nov 20, 2026 |
| 7 | The client link: a client fills in their own record on a phone, the MRZ read from a photo; later the signed agreement | planned Nov 20, 2026 |
| 8 | Reminders by Matrix room message and by email | |
| later | Thai user interface, agency cases and fees, other visa categories' packs | |
### Phase 1: app, login, people
@@ -352,10 +400,74 @@ one `Kind`.
dependencies' build stays the same; a build in a checkout asks git.
Live with the release after `a2cedcd`.
### Phase 6: the Non-B extension pack
- [x] 6.1 The rules (`src/pack/mod.rs`): every item of the pack in the
officer's order with its state at the date of the application, as a
pure function of the records and the documents, with a unit test per
rule ("The Non-B extension pack" above).
- [x] 6.2 A Pack tab on each person: the six parts with each item's state,
what it holds (the form, the files with their dates), and what fixes
it: the upload with the kind and the record chosen (`?for=` and the new
`?kind=` on the Documents tab and on a company's page), a document's
date, or a record to add. The application's fields are those of the
Forms tab, and the two tabs carry them to each other.
- [x] 6.3 One PDF to print (`/people/{id}/pack.pdf`, `src/pack/pdf.rs`): the
cover sheet, the five forms, then every copy in the pack's order. An
uploaded PDF goes in page by page as it is (a PDF 2.0 file makes the
pack 2.0), an image is fitted on an A4 page of its own orientation and
turned as its EXIF tag says, and a file that cannot be read gets a page
that says so. Bookmarks lead to each item. Opening or saving it logs the
forms' codes and a view or download of every document that went in.
- [x] 6.4 A company's page shows its part of every employee's pack, with
until when each certification counts and what to upload.
- [x] 6.5 The extension's deadline (Deadlines page, a person's deadlines)
links to the pack when the person has an employer. The tabs fit a 390
px phone: "Visa and stay" reads "Stay" there.
- [x] 6.6 Demo data: copies of Erika's visa, arrival stamp, extension stamp,
re-entry permit and work permit, and the employer's balance sheet,
three months of PND.1, an undated SPS 1-10 and a map, so every state
shows (the BOJ.5 is out of date, PP.30 missing, one office photo).
- [x] 6.7 Settled: which office (decisions table).
### Phase 7: the client link
Planned on November 20, 2026, from Alex's answers (decisions table).
- [ ] 7.1 Links: staff make a link on a person's page, and "+ New client" in
the people list makes an empty record with its link. The app keeps only
the SHA-256 of the link's token, as with sessions: it shows the link
once, to copy or as a QR code to show on a phone, and a new link closes
the person's earlier one. The person's page lists the links with their
state (open, used, sent, closed, expired), and staff close one.
- [ ] 7.2 The client's pages at `/c/<token>`, the one part of the app open
without a login: about you, the passport, the address in Thailand,
contact, the documents, and Send. Plain English, phone first, each part
saved on its own; the link's own form token and the same-site check;
nothing about anyone else. After Send, or 14 days, or once staff close
it, the link shows only that it is closed.
- [ ] 7.3 The passport from a photo: on a phone the camera takes the MRZ
(`<input type="file" accept="image/*" capture="environment">`); the
two lines it reads go into the MRZ field, whose check digits then fill
in the form. The same on the staff's new person and new passport forms.
To settle when building it: reading in the browser (the photo stays on
the phone; Tesseract.js with a model trained for the MRZ, served by the
app, needs `'wasm-unsafe-eval'` in the policy) or on the server.
- [ ] 7.4 Uploads from the client into the encrypted store: the passport's
photo page, the photo, the TDAC and other scans, each tied to its record
where there is one.
- [ ] 7.5 Audit: every view and change through a link is logged with the
actor `link <id>` and the names of the fields; making, using, sending
and closing a link too. The person's page says when the client sent the
form and links to what changed.
- [ ] 7.6 Later: the agreement. A box where the client signs, drawn on the
screen, the agreement with B4L to keep and work with their data; the
signed agreement is kept as an encrypted document (a PDF with the
signature, the agreement's version and the time).
## Open questions
1. B4L's BOI application: once B4L is promoted, its staff extend their stay
through the BOI's One Start One Stop center, which changes phase 6's pack.
2. Which Chiang Mai office handles B4L's cases (the main office at 71 Moo 3
Airport Road or the branch at Central Chiangmai) only matters for the
cover sheet; to be settled in phase 6.
2. The agreement's text for the client link (task 7.6) comes from B4L; a
lawyer may want to check it.