Commit graph

838 commits

Author SHA1 Message Date
DEls
9a084abb72 test(workforce): spell out the non-breaking space the tiles contain
Intl renders en-ZA currency and numbers with U+00A0, so the tile helpers
normalise it before asserting. Written as a literal that byte is
invisible in the source and easy to "fix" into a plain space by accident.
An explicit escape says what it means.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 00:15:05 +02:00
DEls
0987dcc33a test(workforce): update the missing-rate overview for this-month figures
The overview test asserted the previous all-time sub-line wording and
that employee_rates was read with a site filter, both of which the cost
workforce commits changed on purpose.

Pins the clock so "this month" is a fixed window, and gives the unpriced
worker an October entry so the new month-scoped warning is actually
exercised rather than skipped. Added a case asserting rate history is
read unfiltered, which is what lets a worker who moved sites keep the
rate he was paid at.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 00:14:41 +02:00
DEls
373ff2c1d3 feat(financial): show what was received and owed this month
"POs (total)" repeated the number already shown under Open PO value and
said nothing about deliveries, so the page had no figure for what came in
this month or what that leaves owed to suppliers.

Replaced with "Received this month", computed with the shared
deliveryLineValues helper -- the same series behind the Suppliers page's
"Payable this period" -- filtered to the current SAST month. Under the
app's rule that we only pay what we received this month (see
src/lib/supplier-period.ts), delivered-this-month and owed-this-month
are the same number, so one tile answers both and cannot drift from the
Suppliers page. The sub-line names how many suppliers that is; with none,
it says so rather than showing a bare R0. The tile links through to
Suppliers with the current site selection preserved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 00:10:43 +02:00
DEls
cd0d84a520 fix(financial): count real orders only in this month's PO spend
PO spend summed total_value of anything uploaded this month, including
failed and still-processing placeholder rows -- money that was never
committed. It also ignored orders raised through the MCP create_purchase_order
tool, which carry no date_uploaded at all and so never appeared in any
month.

The tile now sums real orders only, matching the rule already used for
open value, and falls back to `created` when there is no upload date.
Month membership is a YYYY-MM prefix against the SAST month key. The
sub-line says how many orders that was, so a plausible-looking total can
be sanity-checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 00:10:01 +02:00
DEls
2c6a66182c fix(financial): subtract deliveries from open PO value
"Open PO value" summed total_value of every processed order ever and
never subtracted what had been delivered, so it grew without bound and
read as total committed rather than still owed. A R1 000 order with R400
delivered reported R1 000 open.

It now comes from computeSupplierLedger -- the same computation the
Suppliers page uses -- over the items of real in-scope POs and the
delivery lines belonging to them (by booking snapshot, or by parent PO
item for older unbooked receipts). Clamped per PO, so an over-delivered
order cannot net off another order's open balance and understate what is
still owed. The sub-line counts orders still actually open rather than
repeating the same number as a "total POs" figure elsewhere on the page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 00:09:13 +02:00
DEls
938b1784dd refactor(suppliers): share the delivery-line value computation
The Suppliers page built its per-delivery-line value series inline to
feed the "Payable this period" KPI. Extracted it to deliveryLineValues
so the Financial landing can show the same figure for a single month
without re-deriving the rules in a second place, where they could
quietly diverge.

Behaviour is unchanged: booking snapshot net wins, else qty_received x
the PO line's rate; receipt documents only; lines against POs outside the
page's scope are dropped; lines with no date_received are skipped. The
returned rows now also carry the PO id so callers can attribute a total
to a supplier.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 00:06:13 +02:00
DEls
8108640f87 fix(plant): count only fleet litres and spend on the Vehicles page
fuel_logs is site-scoped, so it holds equipment fill-ups as well as
fleet ones, and the "Total litres pumped" / "Total fuel spend" tiles —
labelled as fleet — were summing both. The same diesel was counted here
and again on Plant.

Fleet-ness now comes from the log's EXPANDED vehicle (the query already
expands "vehicle") rather than from membership of the site-filtered
vehicles list, so a truck that has since moved to another site still
counts at the site where it was actually fuelled. Unclassified equipment
counts for neither bucket. The flagged count follows the same rule.

Extracted into a pure helper next to the page so it is testable without
standing up the PocketBase reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 00:04:50 +02:00
DEls
a3e042cd76 fix(workforce): keep a worker's hours at the site he worked them
Timesheet entries are stamped with the site they were worked at and are
never joined to the worker's current home site, but both the cost loop
and employee_rates were filtered by employee.site. A worker who moved
from A to B therefore lost his A hours when viewing A (he was no longer
on A's roster) and never had them counted when viewing B — the hours
only reappeared under "All sites".

Hours and cost now iterate the in-scope timesheet entries and price each
employee through an unfiltered lookup, so they follow the site the work
happened at. An employee id missing from that map keeps its hours but
counts as unpriced. The roster stays site-filtered and still drives the
figures that are about who works here now: headcount, permanent/casual,
idle 30d, missing rates and the inactive filter on clock events.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 00:04:05 +02:00
DEls
3dfa28f0c6 fix(workforce): show this-month cost and hours instead of all-time
The workforce KPI row showed total cost (all-time) and hours this week,
with nothing about the current month — the two figures a cost-to-date
conversation actually starts from.

Cost (this month) sums hours x resolveEmployeeRate over entries whose
date falls in the current SAST calendar month (YYYY-MM prefix, so
PocketBase's "2026-10-01 00:00:00.000Z" needs no parsing). It still
prices through the dated rate history, and its sub-line falls back to
the all-time total so the longer view is not lost. Hours (this month)
is the matching hours figure, with the week alongside it as sub-line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 00:03:27 +02:00
DEls
4e7583256d feat(dn): Set aside list with Restore, next to Completed
Set-aside delivery documents were kept but shown nowhere, so they looked
lost (e.g. The Waste Group slip T025511, set aside 'Waiting for
invoice'). The inbox now has a Set aside button: every set-aside
document with why (in plain words) and when, a link to its page, and a
Restore button that puts it back in the inbox through the same restore
the agents use, recorded with who and why.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 22:18:50 +02:00
DEls
6f21803573 feat(dn): deletion flags open as Needs attention cards at the top of the inbox
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 21:57:20 +02:00
DEls
84da8eceac feat(dn): a page to see and decide a deletion flag
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 21:56:07 +02:00
DEls
7c1a7f74fc feat(dn): route to delete or keep a flagged record
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 21:54:14 +02:00
DEls
77dbdeb160 feat(dn): rules for deciding deletion flags (delete with a saved copy, keep, never evidence)
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 21:52:53 +02:00
DEls
0113d1a1fa docs(dn): plan for deletion flags a person can act on
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 20:26:05 +02:00
DEls
c4f2fd7f56 fix(dn): tell the clerk to re-match when the slip itself changed
The automatic refresh already handles a PO that moved on; when the
banner still shows, only Try matching again helps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 20:18:00 +02:00
DEls
48df4cf026 feat(dn): inbox cards show the booking value and the PO position
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 20:14:53 +02:00
DEls
e6e41d3c22 fix(dn): an out-of-date match refreshes and keeps saved decisions instead of asking for a re-match
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 20:13:31 +02:00
DEls
91ac705536 feat(dn): New/Classic switch for the delivery review (DN_REVIEW_DEFAULT_VIEW, per-browser override)
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 20:09:39 +02:00
DEls
304d4b3e31 feat(dn): review cards — slip line over its PO line, green/amber, totals vs PO, Post when all green
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 20:07:56 +02:00
DEls
6cfc343625 feat(dn): review model — one card per PO line, green/amber with working, totals vs PO
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 20:07:06 +02:00
DEls
ba06cee545 feat(dn): explain a slip price against the PO rate (length, VAT, per 1000, kits)
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 20:06:25 +02:00
DEls
529028b8d1 docs(dn): phase 1 plan — the delivery review page
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 19:59:39 +02:00
DEls
4493bbc0db feat(clock): pay against the real work schedule
Mon-Thu 07:00-16:30, Friday 07:00-15:00, last Friday of the month
07:00-12:00 (weekends use the Mon-Thu bands). Each shift end has a
10-minute band either side; arrivals up to 07:10 pay from 07:00.
Lunch now phases in from 5h to 5h30 instead of a 30-minute cliff, so
a normal day pays 9 / 7.5 / 5 hours.

The worker calendar judges each day against that day's expected hours,
so a normal Friday is green, and the worker page shows the schedule.
The recalc script recognises rows already rewritten by the first rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 19:51:24 +02:00
DEls
1e55fea2c2 docs(dn): explain-or-ask design (smarter in-app matching, line colours, rulebook)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 19:50:35 +02:00
DEls
295f31fce6 fix(clock): recalc re-run counts already-paid rows as unchanged
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 19:32:50 +02:00
DEls
75b178dd33 feat(clock): store paid hours, not the raw scan span
A scan in up to 07:10 pays from 07:00; a scan out between 16:20 and
16:40 pays to 16:30; a session over five hours loses a 30-minute lunch.
A normal day is therefore exactly 9 hours (green on the calendar and
matrix); late arrivals, early exits and overtime use the real times.
Applied on clock-out, in missed-scan corrections and their preview.
The calendar keeps the raw scan times and labels hours "Paid hours".

Includes a dry-run-first script to recalculate existing QR entries; it
only rewrites rows still equal to their raw scan total.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 19:01:17 +02:00
DEls
e66ac520dc fix(dn): agent board shows only the open site question; Foreman skill lessons from run 1
- inbox_board: while a site question is open, blocking lists only that
  question (the reader's older doubts were misleading Foreman, e.g. the
  corrected FH Chamberlain order). next now points agents at
  prepare_delivery, and at the site manager for Ready-to-post slips;
  agents no longer book.
- Foreman skill: describe parked documents only from the open question;
  VERDICT counts only what is new this run (still-waiting items become a
  count line); quote refusals and their hint instead of guessing a cause;
  candidate_closed on regrouping means a document in the batch is set
  aside or posted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 18:42:18 +02:00
DEls
009ac0e30f docs(dn): Foreman inbox-clerk skill and the Claude review skill
Foreman (MiniMax) works the delivery-note inbox: checks every slip
against its photo and PO, fixes misreads, groups kits, prepares clean
slips with prepare_delivery (Ready to post, never booked) and asks the
site about the rest. The review skill spot-checks his work, moves
answered site questions on to Ready to post and applies site-confirmed
receipt corrections. The site manager pulls the trigger.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 17:49:18 +02:00
DEls
0307d2cb35 feat(mcp): prepare_delivery stages a slip for the site manager without booking it
Agents can now save a whole receiving plan (lines by number, kits, NIL
auto-close) and leave the slip in Ready to post; the site manager checks
the totals and presses Confirm delivery, which posts exactly what was
saved. Quantities over the PO need acceptExcess (site-approved) and a
slip with an open site question is refused.

Confirm delivery on the web now refreshes a slip whose match went stale
because another slip on the same PO was booked, re-applying the saved
decisions instead of sending the user back to an AI re-match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 17:47:35 +02:00
DEls
2014a02db5 Merge main into feat/dn-stage-3b 2026-10-09 13:37:42 +02:00
DEls
6736c7e20d fix(mcp): reassign_receipt refuses to revalue a po_rate booking without a rate
Keeping the old value when the quantity or line changes would book, say,
162.5 m at the value of 65 m. Adds hints for both value refusals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 13:37:34 +02:00
DEls
a176f1e90e feat(mcp): reassign_receipt also fixes line-posted receipts and keeps their bookings in step
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 13:36:14 +02:00
DEls
c2dbafcaa2 fix(dn): strip each of the slip's own numbers before looking for a second document
The joined 'DOC|ALT' string never matched the evidence text, so a slip
with alternate numbers counted its own numbers as a second document and
stayed held in grouping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 13:32:48 +02:00
DEls
eca2cb845c fix(dn): a fragment of background paper no longer holds a page in grouping
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 13:30:11 +02:00
DEls
fbc1f4f5c6 feat(mcp): split_or_crop_page uploads crops and keeps the original
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 13:28:16 +02:00
DEls
083cf849c8 feat(mcp): merge_suppliers repoints a duplicate supplier and flags it for deletion
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 13:23:02 +02:00
DEls
9ac2aa5428 feat(mcp): reassign_receipt fixes a wrong booking without deleting it
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 13:19:41 +02:00
DEls
6101ca8f2e feat(mcp): agents flag records for deletion instead of deleting
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 13:14:17 +02:00
DEls
ddb6391fa6 Merge branch 'feat/clock-fix-missing-in'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 13:10:56 +02:00
DEls
d94d29f0a2 docs: Stage 3b plan (request_deletion, reassign_receipt, merge_suppliers, split_or_crop_page, background fragments)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 13:07:56 +02:00
DEls
b32ad0bc8b feat(clock): fix a missing clock-in from Needs attention
When nobody scanned a worker in, the evening scan was stored as the IN
and the correction dialog only allowed a leaving time after it. The
dialog now shows an editable arrival and leaving time, with a one-click
"this scan was actually the clock-out" swap. Late scans (16:00+) get a
hint on the card. A corrected arrival is stored as the optional
actual_in_at on the correction row (migration script included, not
applied); the original QR scan is untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 12:57:09 +02:00
DEls
82c6f95878 fix(dn): run a queued agent job only on ticks with no inbox batch
Both are page reads; two in one tick can pass the 300s ceiling and get a
batch reclaimed and read twice. The job waits for the next tick instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 12:54:46 +02:00
DEls
4c437cd320 fix(dn): keep the site's open question through a grouping change
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 12:50:04 +02:00
DEls
f1e3c43de5 fix(dn): the n8n tick also runs queued agent batch jobs
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 12:47:04 +02:00
DEls
29135bdc57 fix(mcp): post_delivery refreshes a stale preview after other receipts on the PO
Co-Authored-By: MiniMax Code <noreply@minimax.io>
2026-10-09 12:45:24 +02:00
DEls
35c18c32a3 docs: Stage 3a plan (stale preview refresh, MCP job drain, site question through regroup)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 12:42:40 +02:00
DEls
7b23d23ed7 feat(dn): Waiting for site column on the delivery-note inbox
Documents with an open site question move out of Identify/Match into
their own column, and each card shows the question itself in an amber
box instead of a generic badge, so the site sees what it has to answer
without opening the slip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 12:07:49 +02:00
DEls
e97bf93c7d chore: add foreman scheduler mod; keep it out of the app type-check
foreman/ is a Claude Code mod (job runner + hooks) that imports the
claude-code runtime types, so tsc over the app failed on it. Excluding
it from tsconfig keeps the Next build green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 12:05:50 +02:00
DEls
3cd4101ca6 fix(dn): show an open site question as the headline in Needs attention
The inbox list took its reason from documentProgress, which listed the
model's old identity doubts ("Is MEGCPO9376 correct?", "No matching PO
found") ahead of the question an agent asked the site. While a site
question is open it is now the only reason, labelled 'Waiting for site'
with the action 'Answer the site question'; once answered the normal
reasons return.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 11:54:54 +02:00