#!/usr/bin/env python3 """CIPC Director Appointment Check -> PDF report. Reads a results JSON produced by the CIPC report run and renders it to a polished A4 PDF via the pdf skill's HTML->Playwright pipeline. python build_report.py --results results.json --work
| {esc(h)} | " for h in head] out.append("
|---|
None found ' "No appointments of this type were found.
") if kind == "new": pill = 'New company' action = "Add company" comp_label = "Company (CIPC)" else: pill = 'Link missing' action = "Link director" comp_label = "Company (in database)" head = ["ID Number", "Director", "Enterprise Number", comp_label, "Status", "Action"] widths = ["id", "first", "ent", "sur", "stat", "act"] body = [] for r in rows: director = " ".join(x for x in (r.get("first", ""), r.get("surname", "")) if x).strip() body.append([ f'Every director ID checked returned only appointments that are already " "recorded in the database. Nothing needs to be added or linked.
Complete Every ID number was ' "looked up successfully. There are no gaps in the coverage.
" ) return { "meta": { "title": "CIPC Director Appointment Check", "subtitle": "Director appointments recorded at CIPC that are not yet reflected " "in the Workflow client database.", "doc_type": "EXCEPTION REPORT", "version": run.get("generated_at", ""), "source_file": run.get("source_file", ""), "login_used": run.get("login_used", ""), "searches_used": run.get("searches_used", ""), "is_sample": bool(run.get("is_sample")), "ids_checked": run.get("ids_checked", 0), "lookups_ok": run.get("lookups_ok", 0), "lookups_failed": run.get("lookups_failed", 0), "clean_count": clean, "people_new": people_new, "people_link": people_link, "new_rows": len(new_rows), "link_rows": len(link_rows), "total_exc": total_exc, "no_exceptions": no_exceptions, "has_exceptions": has_exc, "method_page": method_page, "failures": failures, }, "toc_html": toc_html, "summary_block": summary_block, "affected_table": affected_table(new_rows, link_rows), "new_table": exception_table(new_rows, "new"), "link_table": exception_table(link_rows, "link"), "fail_block": fail_block, "toc": toc, } def render_html(c: dict) -> str: m = c["meta"] sample_banner = ( '' if m["is_sample"] else "" ) cover = f"""{esc(m['subtitle'])}
{sample_banner}Every SA ID number on the source list was looked up on CIPC BizPortal to find the companies that person is currently registered as a director of. Each returned company was then compared against the Workflow database. This report lists only the appointments we do not yet have on file.
Every appointment below is held at CIPC but is not yet reflected in the Workflow database. They are the only entries in this report - appointments we already have on file are not repeated.
Registered at CIPC as a director of a company that does not exist in the Workflow database.
{c['new_table']}Registered at CIPC as a director of a company we already hold, but the director is not linked to that company in the database.
{c['link_table']} {footer('CIPC Director Appointment Check', 'Page 3')}These ID numbers were not confirmed against CIPC, so this report is not complete for them. Re-run the check for this list before treating the result as final.
{c['fail_block']}Source list: {esc(m['source_file'])} · IDs checked:
{esc(m['ids_checked'])} · Lookups completed:
{esc(m['lookups_ok'])} · Lookups failed:
{esc(m['lookups_failed'])}
BizPortal login used: {esc(m['login_used'])} · Searches consumed:
{esc(m['searches_used'])} · Report generated:
{esc(m['version'])}