Files
visa/templates/contract.html
T
grabowski 3dd9ab60e8
CI / secret scan (push) Successful in 6s
CI / fmt, clippy, tests (push) Successful in 1m27s
CI / release (push) Skipped
One shared draft a contract, locked when all agree (phase 13, step 2)
Until a contract is set, it is one open text for every side, as Alex
asked: our team edits it in the app, each other party on its link. Edits
are tracked changes in the author's color (crossed out, added,
highlighted with a comment) until the other side accepts or rejects
them. When no change or highlight is open and Lanna Desk and every party
agree, the text becomes a contract version that never changes, and the
draft locks.

- One side edits at a time: Edit takes the draft for 45 seconds, which
  every save renews; Done editing, leaving the page or silence gives it
  up. The editor saves 0.7 s after the last keystroke; the other pages
  ask for news every 3 s, so each side sees edits, who edits, agreements
  and the lock without reloading.
- A save may only touch the saver's own marks (reviews::check_save);
  accept, reject (or withdraw) and resolve are their own steps, journaled
  with the text concerned. A later change voids the agreements given.
- Notices: the other side's edits (one a half hour of editing), settled
  changes, agreements, the lock. The bell in the top bar counts the
  unseen (every 15 s); Notices lists them and marks them seen.
- The draft as a diff: the standing text against every open change taken.
- Migration 0015: contract_drafts, draft_saves and draft_agreements (both
  kept unchanged by a trigger), notices, notice_reads; drops step 1's
  review_rounds (only the demo held any). The review links stay as each
  party's way in.
- Property tests for the save rule and settling, the fuzz text target
  runs the parser, the save check and settling; integration tests play
  both sides to the lock. The demo's recording agreement has an open
  draft with the label's changes and a notice.
- PLAN: phase 13 rewritten; step 3 is the PDF and signing.
2026-11-23 16:14:14 +07:00

196 lines
15 KiB
HTML

{% extends "base.html" %}
{% import "_fields.html" as fm %}
{% import "_agreement_text.html" as ag %}
{% import "_journal.html" as jn %}
{% import "_conflicts.html" as cf %}
{% block main %}
<div class="phead">
<div class="crumbs"><a href="/contracts">Contracts</a> <span class="sep">/</span> <a href="/clients/{{ head.client_id }}">{{ client_name }}</a></div>
<div class="pagehead">
<div>
<div class="ccode mono">{{ head.code }}</div>
<h1>{{ head.title }}</h1>
</div>
<div class="actions"><a class="btn sm" href="/contracts/{{ id }}/edit" id="edit-contract">Edit the facts</a></div>
</div>
<p class="meta">{% if artist %}<span class="tag gold">artist</span> {% endif %}{{ kind_label }}<span class="sep">·</span>for <a href="/clients/{{ head.client_id }}">{{ client_name }}</a>{% if shown.status %} <span class="chip {{ shown.status.level }}">{{ shown.status.label }}</span>{% endif %}</p>
</div>
<div class="cols">
<section class="card" id="details">
<header><h2>Facts</h2></header>
<dl class="kv">
{% for it in shown.items %}
<dt>{{ it.label }}</dt><dd class="{% if it.pre %}pre{% endif %}{% if it.mono %} mono{% endif %}">{% if it.href %}<a href="{{ it.href }}">{{ it.value }}</a>{% else %}{{ it.value }}{% endif %}</dd>
{% endfor %}
<dt>Opened</dt><dd>{{ opened }}{% if head.created_by %} by {{ head.created_by }}{% endif %}</dd>
</dl>
</section>
<section class="card" id="versions">
<header><h2>Versions</h2><span class="muted small">never changed once added</span></header>
{% for v in versions %}
<div class="item{% if reading and v.version != reading %} old{% endif %}" id="version-{{ v.version }}">
<div class="row"><b>Version {{ v.version }}</b>{% if loop.first %}<span class="tag">newest</span>{% endif %}<span class="muted small">{{ v.at }} · {{ v.by }}</span></div>
<div>{{ v.note }}</div>
<div class="vlinks small">
{% if v.has_text %}<a href="/contracts/{{ id }}?v={{ v.version }}#reading">Read the text</a> <span class="muted">({{ v.chars }} characters)</span>{% endif %}
{% if v.file %}<a href="{{ v.file }}" target="_blank" rel="noopener">{{ v.file_name }}</a> <a href="{{ v.file }}?download=1">download</a>{% endif %}
</div>
{% if v.body_sha %}<div class="muted small mono" title="SHA-256 of the text: {{ v.body_sha }}">text {{ v.body_sha[:16] }}…</div>{% endif %}
{% if v.file_sha %}<div class="muted small mono" title="SHA-256 of the file: {{ v.file_sha }}">file {{ v.file_sha[:16] }}…</div>{% endif %}
</div>
{% else %}
<p class="empty-inline">No version yet: add the first draft below, as a text, a file or both.</p>
{% endfor %}
</section>
</div>
<section class="card" id="parties">
<header><h2>Parties</h2><span class="muted small">each one added is checked for conflicts</span></header>
<ul class="parties">
<li><div class="prow"><span><a class="strong" href="/clients/{{ head.client_id }}">{{ client_name }}</a> <span class="tag gold">our client</span></span></div></li>
{% for p in parties %}
<li id="party-{{ p.id }}"{% if p.removed %} class="old"{% endif %}>
<div class="prow">
<span><b>{{ p.name }}</b>{% if p.name_th %} <span lang="th">{{ p.name_th }}</span>{% endif %}{% if p.role %} <span class="tag">{{ p.role }}</span>{% endif %}{% if p.removed %} <span class="chip plain">removed</span>{% endif %}</span>
{% if not p.removed %}<form method="post" action="/contracts/{{ id }}/parties/{{ p.id }}/remove" class="inline-form" data-confirm="Take {{ p.name }} off this contract? It stays on record, marked removed."><input type="hidden" name="csrf" value="{{ csrf }}"><button type="submit" class="btn sm ghost">Remove</button></form>{% endif %}
</div>
<div class="sub">{% if p.id_no %}<span class="mono">{{ p.id_no }}</span> · {% endif %}added {{ p.added }} by {{ p.by }}{% if p.removed %} · removed {{ p.removed }} by {{ p.removed_by }}{% endif %}</div>
</li>
{% endfor %}
</ul>
{% if not live_parties %}<p class="empty-inline">No other party yet: add the other side, and the check looks for it among everyone on record.</p>{% endif %}
<details class="addparty"{% if check.hits or party_errors %} open{% endif %}>
<summary class="btn sm" id="add-party-open">Add a party</summary>
<form method="post" action="/contracts/{{ id }}/parties" class="form" id="party-form">
<input type="hidden" name="csrf" value="{{ csrf }}">
{% if check.hits %}{{ cf.block(check) }}{% endif %}
<div class="grid">
{{ fm.text("party_name", "Name", party.name, err=party_errors.party_name, req=true, cls="wide", hint="As registered, or as in the ID card or passport.") }}
{{ fm.text("party_name_th", "Name in Thai", party.name_th, err=party_errors.party_name_th, cls="wide") }}
{{ fm.text("party_id_no", "ID, passport or registration number", party.id_no, err=party_errors.party_id_no, hint="The check compares numbers too.") }}
{{ fm.text("party_role", "Role", party.role, err=party_errors.party_role, list="roles", ph="Label, venue, landlord") }}
</div>
<div class="formactions"><button type="submit" class="btn pri" id="add-party">{% if check.ask %}Add the party{% else %}Check and add{% endif %}</button></div>
</form>
</details>
<datalist id="roles">{% for r in roles %}<option value="{{ r }}"></option>{% endfor %}</datalist>
</section>
<section class="card" id="draft">
<header><h2>Shared draft</h2><span class="muted small">one text for every side, with tracked changes, until all agree</span></header>
{% if draft.state == "open" %}
<p><b>Open for edits</b>, revision {{ draft.revision }}, last change {{ draft.changed }}.{% if draft.editing %} <span class="chip warn">{{ draft.editing }} is editing</span>{% endif %}</p>
<p>{% if draft.changes %}<span class="chip warn">{{ draft.changes }} open {% if draft.changes == 1 %}change{% else %}changes{% endif %}</span> {% endif %}{% if draft.highlights %}<span class="chip plain">{{ draft.highlights }} {% if draft.highlights == 1 %}highlight{% else %}highlights{% endif %}</span> {% endif %}<span class="chip {% if draft.have == draft.need %}ok{% else %}plain{% endif %}">{{ draft.have }} of {{ draft.need }} sides agree</span></p>
<div class="formactions"><a class="btn pri" href="/contracts/{{ id }}/draft" id="open-draft">Open the draft</a></div>
{% elif draft.state == "locked" %}
<p><span class="chip ok">Locked</span> Every side agreed; the text is <a href="/contracts/{{ id }}?v={{ draft.locked_version }}#reading">version {{ draft.locked_version }}</a>, which never changes. <a href="/contracts/{{ id }}/draft">See the draft</a>.</p>
{% endif %}
{% if draft.state != "open" %}
{% if text_versions %}
<form method="post" action="/contracts/{{ id }}/draft/open" class="form inline-form" id="draft-open-form">
<input type="hidden" name="csrf" value="{{ csrf }}">
<div class="grid">{{ fm.select("draft_version", "Start a shared draft from", text_versions[0][0], text_versions, req=true, blank="Choose") }}</div>
<div class="formactions"><button type="submit" class="btn pri" id="draft-open">{% if draft.state == "locked" %}Start a new draft{% else %}Start the shared draft{% endif %}</button></div>
</form>
{% else %}<p class="empty-inline">Add a version with a text to start a shared draft: the editor works on the text.</p>{% endif %}
{% endif %}
{% if draft.parties %}
<h3 class="minihead">The other parties' links</h3>
<ul class="rvrounds">
{% for p in draft.parties %}
<li id="party-link-{{ p.id }}"><b>{{ p.name }}</b>: {{ p.link_state }}
<form method="post" action="/contracts/{{ id }}/invites" class="inline-form"><input type="hidden" name="csrf" value="{{ csrf }}"><input type="hidden" name="party" value="{{ p.id }}"><button type="submit" class="btn sm ghost">{% if p.link %}New link{% else %}Make the link{% endif %}</button></form>
{% if p.link %}<form method="post" action="/contracts/{{ id }}/review-links/{{ p.link }}/close" class="inline-form" data-confirm="Close {{ p.name }}'s link? It stops working at once."><input type="hidden" name="csrf" value="{{ csrf }}"><button type="submit" class="btn sm ghost">Close the link</button></form>{% endif %}
</li>
{% endfor %}
</ul>
{% elif not live_parties %}<p class="empty-inline">Add the other parties above: each gets a link to the draft, and each must agree before it locks.</p>{% endif %}
</section>
{% if reading %}
<section class="card" id="reading">
<header><h2>{% if compare %}Version {{ reading }} against version {{ before }}{% else %}Version {{ reading }}{% endif %}{% if reading_note %}: {{ reading_note }}{% endif %}</h2>
{% if before %}{% if compare %}<a class="small" href="/contracts/{{ id }}?v={{ reading }}#reading">Show the text</a>{% else %}<a class="small" href="/contracts/{{ id }}?v={{ reading }}&amp;compare=1#reading" id="compare">Compare with version {{ before }}</a>{% endif %}{% endif %}
</header>
{% if compare %}
{% if diff %}
<p class="hint">Lines taken out are struck through in red, lines added are marked in green.</p>
<div class="diff">{% for l in diff %}<div class="dl {{ l.op }}">{% if l.op == "removed" %}<del>{{ l.text or " " }}</del>{% elif l.op == "added" %}<ins>{{ l.text or " " }}</ins>{% else %}{{ l.text or " " }}{% endif %}</div>{% endfor %}</div>
{% else %}<p class="empty-inline">The texts are too long to compare here.</p>{% endif %}
{% else %}
{{ ag.text(blocks) }}
{% if reading_sha %}<p class="muted small mono hashline">SHA-256 {{ reading_sha }}</p>{% endif %}
{% endif %}
</section>
{% endif %}
<form method="post" action="/contracts/{{ id }}/versions" enctype="multipart/form-data" class="form upload" id="version-form">
<input type="hidden" name="csrf" value="{{ csrf }}">
<section class="card">
<header><h2>Add version {{ next_version }}</h2></header>
<p class="hint lead">A new draft, the other side's changes, the final text, the scan of the signed paper: each is a version. Keep the text here, attach the file (PDF or a scan), or both. A version never changes once added; its fingerprints go into the journal.</p>
<div class="grid">
{{ fm.text("note", "What this version is", draft_note, err=errors.note, req=true, cls="wide", ph="Such as: first draft, the label's changes, signed by both sides") }}
{{ fm.area("body", "Text", draft_body, err=errors.body, rows=14, fcls="wide", hint="Paragraphs separated by an empty line, # before a heading, - before a list item. It starts as the last version's text; leave it as it is to add only a file.") }}
<div class="field wide{% if errors.file %} has-err{% endif %}">
<label for="f-file">File</label>
{% if uploads %}<input id="f-file" name="file" type="file" accept="application/pdf,image/jpeg,image/png,image/webp">
<p class="hint">PDF, JPEG, PNG or WebP, up to {{ file_mb }} MB. Stored encrypted, like every document.</p>{% else %}<p class="hint">This server keeps no files: add the text only.</p>{% endif %}
{% if errors.file %}<p class="err" id="e-file">{{ errors.file }}</p>{% endif %}
</div>
</div>
<div class="formactions"><button type="submit" class="btn pri" id="add-version">Add version {{ next_version }}</button></div>
</section>
</form>
<h2 class="sechead" id="papers">Paper copies</h2>
<p class="meta">Each paper gets an id to write on it, or a label to print. Its record says where it lies; every move goes into the journal.</p>
{% if papers %}
<div class="card flush">
<div class="tblwrap">
<table class="tbl" id="paper-list">
<thead><tr><th>Id</th><th>Paper</th><th>Where it is</th><th></th></tr></thead>
<tbody>
{% for p in papers %}
<tr id="paper-{{ p.id }}"{% if p.gone %} class="old"{% endif %}>
<td><span class="pcode mono">{{ p.code }}</span></td>
<td>{{ p.what }}{% if p.version %}<div class="sub">version {{ p.version }}</div>{% endif %}</td>
<td><span class="chip {% if p.state == "filed" %}ok{% elif p.state == "out" %}warn{% else %}plain{% endif %}">{{ p.state_label }}</span> {{ p.location }}{% if p.holder %}<div class="sub">with {{ p.holder }}</div>{% endif %}<div class="sub">since {{ p.moved }}</div></td>
<td class="pacts">
<a class="btn sm ghost" href="/papers/{{ p.id }}/label" target="_blank" rel="noopener">Label</a>
<details class="move"><summary class="btn sm ghost">Move</summary>
<form method="post" action="/papers/{{ p.id }}/move" class="form mini">
<input type="hidden" name="csrf" value="{{ csrf }}">
<label>Where it is now<input name="location" value="{{ p.location }}" list="locations" required></label>
<label>State<select name="state">{% for s in states %}<option value="{{ s[0] }}"{% if s[0] == p.state %} selected{% endif %}>{{ s[1] }}</option>{% endfor %}</select></label>
<label>With whom<input name="holder" value="{{ p.holder }}" placeholder="While it is out, or whom it went to"></label>
<label>Note<input name="note" placeholder="Such as: for the signing at the label"></label>
<button type="submit" class="btn sm pri">Save the move</button>
</form>
</details>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
<form method="post" action="/contracts/{{ id }}/papers" class="form" id="paper-form">
<input type="hidden" name="csrf" value="{{ csrf }}">
<section class="card">
<header><h2>Register a paper copy</h2></header>
<div class="grid">
{{ fm.text("what", "What it is", "", req=true, list="whats", ph="Signed original") }}
<div class="field">
<label for="f-version">Version</label>
<select id="f-version" name="version"><option value="">Not known</option>{% for v in versions %}<option value="{{ v.version }}"{% if loop.first %} selected{% endif %}>Version {{ v.version }}: {{ v.note }}</option>{% endfor %}</select>
</div>
{{ fm.text("location", "Where it is filed", "", req=true, list="locations", cls="wide", ph="Office, cabinet A, drawer 2, folder of the client") }}
</div>
<div class="formactions"><button type="submit" class="btn" id="add-paper">Register and give it an id</button></div>
</section>
</form>
<datalist id="whats">{% for w in whats %}<option value="{{ w }}"></option>{% endfor %}</datalist>
<datalist id="locations">{% for l in locations %}<option value="{{ l }}"></option>{% endfor %}</datalist>
<section class="card" id="contract-journal">
<header><h2>Journal of this contract</h2><a class="small" href="/journal">The whole journal, checked</a></header>
{% if entries %}{{ jn.list(entries) }}{% else %}<p class="empty-inline">Nothing yet.</p>{% endif %}
</section>
{% endblock %}