Commit graph

244 commits

Author SHA1 Message Date
9de60200f9 Merge pull request 'feat(po): cancel POs + optional supersede link (#53)' (#56) from feat/po-cancel-supersede into master
All checks were successful
Refresh staging / refresh (push) Successful in 7s
Deploy release to production / deploy (push) Successful in 1m7s
Reviewed-on: #56
2026-06-21 06:58:31 +00:00
a8d772d63b Merge branch 'master' into feat/po-cancel-supersede
All checks were successful
PR checks / checks (pull_request) Successful in 32s
PR checks / integration (pull_request) Successful in 27s
2026-06-21 06:56:39 +00:00
a197b966b1 Merge pull request 'ci: run integration tests on PRs + repair the suite (108/108)' (#54) from ci/integration-tests into master
All checks were successful
Refresh staging / refresh (push) Successful in 7s
Reviewed-on: #54
2026-06-21 06:56:28 +00:00
058ba1d12e Merge branch 'master' into ci/integration-tests
All checks were successful
PR checks / checks (pull_request) Successful in 33s
PR checks / integration (pull_request) Successful in 26s
2026-06-21 06:56:12 +00:00
0b10ba5e54 feat(po): cancel POs (manager/superuser) + optional supersede link (#53)
All checks were successful
PR checks / checks (pull_request) Successful in 32s
Managers and superusers can cancel a PO from any state via a confirmation modal
that requires typing "cancel" and a mandatory reason. A cancelled PO becomes a
terminal CANCELLED state and drops out of every spend tracker/graph (those filter
on POST_APPROVAL_STATUSES / explicit whitelists, none of which include CANCELLED).

A cancelled PO may optionally be linked to the existing PO that supersedes it
(by PO number); the replacement shows the reciprocal "supersedes" link. No
vessel/account/vendor match is enforced and the link can be added any time.

Cancelled POs remain visible (greyed in history) and exportable, with a diagonal
"CANCELLED" watermark on both the PDF and XLSX exports.

- schema: POStatus CANCELLED; cancelledAt/cancellationReason; self-referential
  supersededById relation; ActionType CANCELLED/SUPERSEDED (+ migration)
- state machine canCancel(); cancel_po permission (MANAGER + SUPERUSER)
- cancelPo / supersedePo server actions + PO_CANCELLED notification
- cancel modal + supersede form; cancelled banner with reciprocal links
- exhaustive CANCELLED entries in all status label/variant maps
- diagonal CANCELLED watermark embedded for PDF (CSS) and XLSX (image)
- integration tests (cancel from any state, reason/role guards, supersede)

Inventory reversal on cancel is deferred to #55 (inventory is feature-flagged off).

Closes #53

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 12:20:54 +05:30
fbdc7b2235 Merge pull request 'docs(release): make v-prefixed tag requirement prominent' (#52) from docs/release-tag-warning into master
All checks were successful
Refresh staging / refresh (push) Successful in 7s
Reviewed-on: #52
2026-06-20 21:15:43 +00:00
9e787fd15f Merge branch 'master' into ci/integration-tests
All checks were successful
PR checks / checks (pull_request) Successful in 31s
PR checks / integration (pull_request) Successful in 26s
2026-06-20 21:14:50 +00:00
8ee077e548 Merge branch 'master' into docs/release-tag-warning
All checks were successful
PR checks / checks (pull_request) Successful in 33s
2026-06-20 21:14:46 +00:00
991b7ca5dd ci: run integration tests on PRs (ephemeral Postgres)
All checks were successful
PR checks / checks (pull_request) Successful in 31s
PR checks / integration (pull_request) Successful in 37s
Adds an `integration` job to PR checks: spins up a throwaway postgres:16
container on a random host port (isolated from prod / pelagia_test / staging),
applies migrations, dev-seeds, and runs `pnpm test:integration` (108 tests).
Container is always torn down via an EXIT trap.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 02:40:59 +05:30
4c53aeecb0 test(integration): green the last 3 behavioural-drift tests (108/108)
- resubmit: updatePo distinguishes intent "resubmit" (from EDITS_REQUESTED)
  from "submit" (from DRAFT); test now sends "resubmit" (makePoForm widened).
- payment: MANAGER now holds process_payment, so the "wrong permission"
  negative test uses TECHNICAL (which lacks it).
- vendor: provideVendorId rejects on a missing vendorId *code*; seeded
  unverified vendors carry codes, so create a genuinely code-less vendor.

Full integration suite: 108/108 passing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 02:39:41 +05:30
b70eec261b test(integration): repair stale integration suite (wip: 97/108)
The integration suite had rotted against the app. Systematic fixes:
- seed refs: MV Ocean Pride/Sea Breeze/TECH-OPS → current seed entities
- helper appendLineItem set lineItems[i].description; createPo now keys on
  lineItems[i].name → zero line items. Fixed to .name.
- vendor gating: lifecycle setups (approval/payment/receipt) now attach the
  seeded verified vendor before approval.
- cleanup: POAction has no onDelete:Cascade, so deletePo(sByTitle) now removes
  POAction rows before the PO.
- import-api: fixture committed to tests/fixtures/Sample_PO.xlsx (was an
  absolute path to a non-existent dir).
- products-search: code search assertion .every → .some (search spans fields).

11 failures remain (behavioral drift — separate commit).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 02:34:07 +05:30
d9394e6afb docs(release): make the v-prefixed tag requirement prominent
All checks were successful
PR checks / checks (pull_request) Successful in 31s
deploy.yml only triggers on v* tags; bare semver tags (0.2.0/0.2.1/0.2.2) silently
do not deploy. Clarify: push the v* tag specifically (not 'master --tags').

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 02:09:18 +05:30
4712fafb4b Merge pull request 'feat(companies): move add/edit from dialog to dedicated pages' (#49) from feat/company-form-pages into master
All checks were successful
Refresh staging / refresh (push) Successful in 7s
Deploy release to production / deploy (push) Successful in 1m10s
Reviewed-on: #49
2026-06-20 20:38:10 +00:00
e388ec917e Merge branch 'master' into feat/company-form-pages
All checks were successful
PR checks / checks (pull_request) Successful in 31s
2026-06-20 20:37:37 +00:00
9d08ca1990 Merge pull request 'fix: On manager dashboard, overhaul approved spend card' (#51) from claude/issue-50 into master
All checks were successful
Refresh staging / refresh (push) Successful in 7s
Reviewed-on: #51
2026-06-20 20:35:53 +00:00
6137d11e5f test(companies): cover createCompany/updateCompany actions
All checks were successful
PR checks / checks (pull_request) Successful in 32s
Satisfies the contribution-policy test gate for the add/edit-page refactor.
Covers: createCompany returns the new id, code upper-casing, duplicate-code
rejection, updateCompany in-place edit, and manage_vessels_accounts gating.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 02:05:32 +05:30
Claude (auto-fix)
defd6e7a18 feat(dashboard): compact INR formatting for Total Approved Spend card
All checks were successful
PR checks / checks (pull_request) Successful in 31s
Overhaul the manager dashboard "Total Approved Spend" stat card per the
reporter's request:

- Swap the DollarSign lucide icon for IndianRupee (rupee symbol).
- Render the amount in the Indian short scale (lakh/crore) via a new
  `formatCompactINR` helper, e.g. ₹2 Cr, ₹49 L, ₹75 K, instead of the full
  ₹49,00,000.00.

`formatCompactINR` rounds to at most 2 decimals, trims trailing zeros, keeps
the ₹ prefix and sign. The DollarSign icon is retained for the Accounts
"Payment Queue Value" card; the precise `formatCurrency` is kept for tables.
Adds unit tests covering crore/lakh/thousand/sub-thousand, boundaries, zero,
string input, negatives and non-finite input.

Fixes #50

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 02:02:41 +05:30
bad67f66c4 feat(companies): move add/edit from dialog to dedicated pages
Some checks failed
PR checks / checks (pull_request) Failing after 3s
The company form outgrew the modal once the branding (logo/stamp) section
was added. Add/edit now live on their own routes:
- /admin/companies/new
- /admin/companies/[id]/edit

- createCompany returns the new id and the create flow lands on the edit
  page so logo/stamp can be uploaded immediately
- list "+ Add Company" is a link; row "Edit" navigates to the edit page
- branding is its own card on the edit page (independent uploads)
- list page no longer mints a presigned URL per company (moved to edit)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 01:45:59 +05:30
74d20cd452 Merge pull request 'feat(po): per-company logo, stamp & brand bar on exported POs' (#48) from feat/company-header-logo-branding into master
All checks were successful
Refresh staging / refresh (push) Successful in 8s
Reviewed-on: #48
2026-06-20 20:01:46 +00:00
467f0ddea4 Merge branch 'master' into feat/company-header-logo-branding
All checks were successful
PR checks / checks (pull_request) Successful in 32s
2026-06-20 20:01:32 +00:00
64fefd15a8 Merge pull request 'feat(staging): auto-refresh staging on every push to master' (#46) from feat/staging-auto-refresh into master
All checks were successful
Refresh staging / refresh (push) Successful in 7s
Reviewed-on: #46
2026-06-20 19:55:12 +00:00
1071cb226f feat(po): per-company logo, stamp & brand bar on exported POs
All checks were successful
PR checks / checks (pull_request) Successful in 31s
Companies can upload a logo and a stamp/seal (Admin → Companies → Edit →
Branding); both render on exported PDF and XLSX purchase orders. A fixed
brand-colour bar (#92D050, matching the sample PO) runs along the bottom of
every export.

- Company.logoKey / stampKey + migration
- buildCompanyAssetKey() deterministic storage keys (overwrite-in-place)
- uploadCompanyAsset / removeCompanyAsset server actions (≤4MB PNG/JPG/WebP,
  manage_vessels_accounts gated)
- CompanyBrandingUploader in the company edit dialog with live previews
- Export route embeds logo (top-left), stamp (signatory block) and brand bar
  in both ExcelJS and print-HTML paths
- Unit test (storage keys) + integration test (branding actions)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 01:17:23 +05:30
a0c6ccba3c Merge branch 'master' into feat/staging-auto-refresh
All checks were successful
PR checks / checks (pull_request) Successful in 30s
2026-06-20 19:39:45 +00:00
9f8297aa7e feat(staging): auto-refresh staging on every push to master
All checks were successful
PR checks / checks (pull_request) Successful in 30s
New .forgejo/workflows/staging.yml rebuilds ppms-staging to latest master on every
merge (push to master) on the host runner, so staging always mirrors the trunk;
concurrency-coalesced + workflow_dispatch. Also drops --update-env from staging-up.sh
(and unsets FORGEJO_*) so the runner's ephemeral token can't leak into ppms-staging.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 01:07:49 +05:30
783051933a Merge pull request 'fix: Add a PO line items units entry for months and year' (#45) from claude/issue-44 into master
Reviewed-on: #45
2026-06-20 19:05:08 +00:00
Claude (auto-fix)
e9e618fda8 feat(po): add week, month, year to line-item unit options
All checks were successful
PR checks / checks (pull_request) Successful in 31s
The PO line-items Unit of Measure dropdown only offered hr/day among
time-based units. Add week, month and year so durations beyond days can
be selected, as requested. UOM_OPTIONS is the single source of truth and
`unit` is validated as a free-form string, so no schema/validation change
is needed.

Fixes #44

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 00:32:39 +05:30
5bb3549142 Merge pull request 'fix(deploy): don't inject CI runner token into ppms' (#43) from fix/deploy-no-update-env into master
Reviewed-on: #43
2026-06-20 18:29:07 +00:00
2d6681014d fix(deploy): don't inject the CI runner token into ppms (drop --update-env)
All checks were successful
PR checks / checks (pull_request) Successful in 31s
The deploy job runs inside the Forgejo Actions runner, whose env includes an
ephemeral FORGEJO_TOKEN (per-job token, revoked when the job ends). 'pm2 restart
--update-env' injected it into ppms, where it shadowed the real PAT in .env
(Next.js won't override an already-set process.env var) — so the Report Issue
button 401'd once the job token expired. Plain restart keeps the daemon's clean env.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-20 23:57:01 +05:30
1feb43186d Merge pull request 'fix(automation): triage owns routing for every portal issue' (#39) from fix/triage-owns-portal-routing into master
All checks were successful
PR checks / checks (pull_request) Successful in 30s
Reviewed-on: #39
2026-06-19 08:45:21 +00:00
794bbf8e7e Merge branch 'master' into fix/triage-owns-portal-routing
All checks were successful
PR checks / checks (pull_request) Successful in 31s
2026-06-19 08:41:45 +00:00
520b1527e0 feat(automation): triage classifies bug vs feature
Triage now writes CLAUDE_TRIAGE_TYPE.txt (bug|feature) and the watcher applies the
matching label to every triaged issue (additive). Previously bug/feature labels were
never applied by the pipeline. Also shows the type in the triage comment.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 14:10:48 +05:30
aec6d2971f fix(automation): triage owns routing for every portal issue
The Report Issue button (older deployed build) stamps claude-queue at creation, so
triage skipped those issues and they went straight to auto-fix (e.g. #37, a large
localization feature that should be interactive).

Triage now claims a portal issue until it carries a new `triaged` marker (or is
in progress/done) — claude-queue is no longer a skip reason. On routing to
interactive it strips the stray claude-queue; on claude-queue it adds triaged.
Manual queue still works for NON-portal issues (triage never claims those).

Resilient regardless of which button build is deployed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 14:00:44 +05:30
064e4ebf66 Merge pull request 'docs: retire Docs/ to the project wiki' (#38) from docs/retire-docs-to-wiki into master
Reviewed-on: #38
2026-06-19 08:29:01 +00:00
56a947747c @
docs: retire Docs/ to the project wiki

The design, architecture, and test docs under Docs/ have been migrated to the
Forgejo wiki (the living reference). Remove them here and leave a tombstone
Docs/README.md mapping each old file to its wiki page.

Also gitignore the nested wiki working clone (pelagia-portal.wiki/), which is a
separate repo checked out beside this one.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@
2026-06-19 13:56:50 +05:30
0fe043e833 Merge pull request 'ci: PR policy enforcement (tests + docs) and checks' (#36) from ci/pr-checks into master
Reviewed-on: #36
2026-06-19 07:37:39 +00:00
8406397602 Merge branch 'master' into ci/pr-checks
All checks were successful
PR checks / checks (pull_request) Successful in 30s
2026-06-19 07:36:28 +00:00
938ff6df89 test+ci: green the test baseline and make type-check + unit tests hard gates
All checks were successful
PR checks / checks (pull_request) Successful in 30s
Green-lights the test suite so the PR checks can enforce it:
- Fix the NextAuth v5 auth() mock typing across all integration tests (cast to a
  simple async fn so mockResolvedValue accepts the session) — clears ~86 errors.
- Fix stale test values: intent 'resubmit'->'submit' / 'save'->'draft'; ParsedImportLine
  .description -> .name; approvepo -> approvePo; add missing beforeEach/beforeAll imports.
- permissions: MANAGER *can* process_payment (intentional since e1340b9) — update the
  stale assertion.
- po-import-parser: skip the Sample_PO.xlsx fixture tests when the file is absent (it
  lives outside the repo); synthetic-workbook tests still cover the parser.

type-check is now 0 errors and unit tests pass (167 passed, 13 skipped). pr-checks.yml
flips type-check (whole project) and unit tests to HARD gates.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 13:03:54 +05:30
debac55a8a ci: enforce PR policy (tests-present + app type-check) and PR template
All checks were successful
PR checks / checks (pull_request) Successful in 39s
All changes now land via PR. New .forgejo/workflows/pr-checks.yml runs on every PR
to master and (1) fails code PRs that lack a test change, (2) blocks new app-code type
errors. Unit tests are advisory until the baseline is green; lint is omitted (it needs
an interactive ESLint migration). PR template carries the docs/tests checklist.

Also makes the autofix watcher require a test (issue-12 style) + doc updates in every
fix, so its PRs satisfy the new gate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 12:49:32 +05:30
8a614878d2 Merge pull request 'docs: bring product docs up to date' (#35) from docs/sync-product-docs into master
Reviewed-on: #35
2026-06-19 07:17:36 +00:00
b0140cf7e1 Merge branch 'master' into docs/sync-product-docs 2026-06-19 07:17:23 +00:00
58a5a00594 docs: bring CLAUDE.md, README, Docs and CHANGELOG up to date with current product
Reflects this iteration's domain/feature changes across the docs set:
- Cost centre = Vessel only (labelled 'Cost Centre'); costCentreRef/Site removed
- Companies (multi-company invoicing) on POs and exports
- 3-level 6-digit accounting-code hierarchy; leaf-only PO selection
- Structured PO numbers COMPANY/VESSEL/ID/FY (ids from 9000)
- Compulsory payment date; editable poDate; export date = approval date
- Submitter vendor creation (unverified until proven); verifyVendor
- Import PO -> CLOSED with auto vendor/product creation
- Inventory flag; inventory added at approval; partial pay/receipt states
- Microsoft Entra SSO (nullable passwordHash); profile reachable by all roles
- README: roles, domain concepts, db:seed:prod, migrate-before-serve callout
- CHANGELOG: Added/Changed/Fixed for the above

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 12:43:24 +05:30
157b58daf5 Merge pull request 'fix: Approved this month for manager only shows POs that are currently in Approved state' (#34) from claude/issue-32 into master
Reviewed-on: #34
2026-06-19 07:10:18 +00:00
791e99f3fd Merge commit '859be8c8d0' into fix-pr34
# Conflicts:
#	App/app/(portal)/history/history-filters.tsx
2026-06-19 12:35:35 +05:30
859be8c8d0 Merge pull request 'fix: Suggestion - allow multiple statuses in the search for PO history' (#33) from claude/issue-31 into master
Reviewed-on: #33
2026-06-19 07:00:31 +00:00
b3e6f6181a Merge branch 'master' into claude/issue-31 2026-06-19 06:59:39 +00:00
7713601be7 Merge pull request 'fix: PO details: show all attachments, grouped by type' (#27) from claude/issue-10 into master
Reviewed-on: #27
2026-06-19 06:57:08 +00:00
f17df1ec6b docs: update design docs to the actual self-hosted architecture
The original design docs assumed Vercel + Supabase + GitHub Actions. Reality is a
single self-hosted pms1 server (Next.js under pm2, native PostgreSQL 16, Forgejo
Actions runner, Pangolin/Traefik tunnel).

- 02-architecture.md: CI/CD + Hosting rows, deployment diagram (section 10),
  CI/testing note, branch strategy, and secrets location.
- e2e-test-plan.md / e2e-test-framework.md: GitHub Actions -> Forgejo Actions.
- 03-open-questions.md: drop the Vercel-serverless aside.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 12:12:04 +05:30
e31014d45c docs: document the issue-to-deploy pipeline, staging, and test DB
- App/README.md: add FORGEJO_*/NEXT_PUBLIC_ENV_LABEL env vars and an
  'Operations & Automation' section pointing to automation/README.md.
- App/CLAUDE.md: complete the env var list (AZURE_AD_*, FORGEJO_*, GST_SERVICE_URL,
  NEXT_PUBLIC_ENV_LABEL) and note the prod-mirror test DB used by autofix/staging.
- .env.example: document NEXT_PUBLIC_ENV_LABEL.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 12:07:55 +05:30
Claude (auto-fix)
fdc3ebdac9 fix(dashboard): count all POs approved this month, not just current MGR_APPROVED
The manager dashboard "Approved This Month" card only counted POs whose
current status is MGR_APPROVED, so approvals that had already moved on to
payment, delivery, or closure dropped out of the count. Managers could not
see what happened to the POs they approved this month.

- Count every PO whose `approvedAt` falls in the current month across all
  post-approval statuses (MGR_APPROVED → ... → CLOSED). `approvedAt` is set
  once at approval and persists, so it is the correct anchor.
- Introduce a shared `POST_APPROVAL_STATUSES` constant (includes the
  previously-omitted PARTIALLY_CLOSED). This also fixes Total Approved Spend
  and the vessel/monthly breakdowns, which were silently dropping
  partially-received POs.
- Make the card a link into /history with an approval-date filter applied
  (?approvedFrom=<startOfMonth>) so a click shows the full set with each PO's
  current status, as requested.
- Add `approvedFrom`/`approvedTo` filtering to the history page, its filter
  UI, and the reports export route so the deep-link and exports stay in sync.

Scope note: the count remains org-wide, consistent with every other card on
the manager dashboard.

Adds an integration test covering the moved-on case and the date window.

Fixes #32
2026-06-19 12:07:53 +05:30
b472c149b4 feat(automation): lock staging to SSH tunnel + dev banner + desktop shortcut
- staging-up.sh binds the dev server to 127.0.0.1 (tunnel-only, no public access)
  and sets NEXT_PUBLIC_ENV_LABEL so the 'INTERNAL DEV / STAGING - NOT PRODUCTION'
  banner shows.
- staging-tunnel.cmd: Windows launcher that opens the SSH tunnel + browser
  (wired to a desktop shortcut).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 11:59:25 +05:30