Phase 3.1 — Use Cases
This page lists every flow that changes when every company spends only its own account.
- The rule is Billing D16 — A company spends only its own billing account, never its parent's.
- The rules table and the code that changes are on the Design Plan.
| Word | Meaning |
|---|---|
| Own account | The Billing::Account whose billing_accounts.org_company_id is this company |
| Root company | An Org::Company with parent_company_id = NULL |
| Child company | An Org::Company with parent_company_id set |
Summary
| ID | Use case | Actor | Segment |
|---|---|---|---|
| UC-1 | Create a company in Jod | System, on company create | — |
| UC-2 | Sync a company from JodGig | System, in the JodGig company sync | — |
| UC-3 | Top up a child company's own account | Finance or Sales (Identities::Admin) | Team Portal |
| UC-4 | A child company spends credits | HQ manager (Org::Membership) or a Jod admin | Employer Dashboard, Team Portal |
| UC-5 | A child company's HQ manager sees the balance | HQ manager of a child company | Employer Dashboard |
| UC-6 | Backfill the missing accounts | Engineer | Rake task |
UC-1: Create a company in Jod
| Field | Details |
|---|---|
| Actor | System, inside Org::Companies::Shared::CreateService |
| Trigger | A root company signs up, or a root company's HQ manager or a Jod admin creates a child company |
System behaviour (one transaction):
- The system creates the
Org::Company. - The system creates its own
Billing::Accountand seeds oneBilling::EntitlementBalanceper entitlement.Billing::Accounts::Shared::CreateServicedoes this, for a root company and a child company alike.
Postconditions:
- The company owns one account and spends it.
- This flow does not change in Phase 3.1.
UC-2: Sync a company from JodGig
| Field | Details |
|---|---|
| Actor | System, inside JodGig::Companies::BillingAccountUpsertAllService |
| Trigger | The JodGig company sync copies a root company or a child company into Jod |
System behaviour:
- The system finds the company's own account, if one exists.
- The system creates the account when it is missing, for a root company and a child company alike.
- The system copies the company's status to the account's
status. - The system creates the gig
Billing::Agreementof each account from the JodGig data.- A root company gets its gig agreement the same way today.
Business rules:
- The sync never creates a second account for a company.
Postconditions:
- Every synced company owns one account.
UC-3: Top up a child company's own account
| Field | Details |
|---|---|
| Actor | Finance or Sales (Identities::Admin) |
| Trigger | FairPrice North buys 1,000 placement credits, or Sales gives North trial credits |
System behaviour:
- The admin opens the invoice create form, or the credit action form.
- The admin picks North's own account in the account picker.
- The rest is the normal flow, with no change:
- an invoice is paid and posted (Billing use cases 3.0);
- or a
Billing::CreditActionof typetrial_grantorgoodwill_grantis created (Billing::CreditAction).
- The grant creates an
EntitlementLoton North's account. - Only North spends it.
Business rules:
- The invoice uses a
Billing::BillToProfileon North's account.- Its
company_nameis whatever NTUC wants on the invoice (see the Design Plan open questions).
- Its
- The invoice uses a
Billing::Agreementon North's account, if North has one.- Otherwise list prices apply.
UC-4: A child company spends credits
| Field | Details |
|---|---|
| Actor | HQ manager of the child company (Org::Membership), or a Jod admin on its behalf |
| Trigger | Submit an Ads campaign, and in Phase 4 also post a Careers job |
System behaviour:
- The submit validator calls
Billing::Accounts::Shared::ResolveService.execute(org_company: campaign.org_company). ResolveServicereturnsorg_company.billing_account, the company's own account.- It raises the clear 422 error when the company owns no account.
- The validator checks that the own account has enough available units.
- The submit manager calls
ResolveServiceagain inside the transaction. - The submit manager calls
Billing::EntitlementLotService.reserveon that account. - Consume (daily job), cancel and reject follow the reserve ledger entry.
- They do not call
ResolveService.
- They do not call
Business rules:
- A Careers job posted by a parent HQ manager for a child company is paid by the child's own account.
- The job belongs to the child.
Error messages (both exist today and do not change):
| Case | Message |
|---|---|
| Not enough credits | "You need <cost> placement credits to submit this campaign, but you only have <available> available. Please top up your placement credits before submitting." |
| No account | "The company '<company>' has no billing account yet, so it cannot use credits. Please contact Jod support to set up the billing account." |
UC-5: A child company's HQ manager sees the balance
| Field | Details |
|---|---|
| Actor | HQ manager of a child company |
| Endpoint | GET /employers/billing/entitlement_balances (exists, no change to the path or the response) |
System behaviour:
- The manager reads the balances of the company's own account.
- The Employer Dashboard navbar shows that balance.
UC-6: Backfill the missing accounts
| Field | Details |
|---|---|
| Actor | Engineer |
| Trigger | Deploy of the JodGig sync change, before the ResolveService change |
| Task | bin/rails billing:backfill_company_accounts, a dry run by default, and APPLY=1 to write |
System behaviour:
- The task reads every
Org::Companyand finds the companies that own no account. - The dry run prints a report.
- A person approves the report before
APPLY=1. - With
APPLY=1, the task callsBilling::Accounts::Shared::CreateServicefor each company in the report.- The service creates the own account and seeds its balances.
- The task prints the same report again after the write.
The report lists:
- counts of companies with and without an account, split into root and child companies;
- every company that owns no account, with id, name and parent id;
- every open reserve whose account owner is not the deliverable's company.
- Phase 1-3 billing data is reset, so this list should be empty (Billing D13 — No Phase-3 grant backfill: Phase 1-3 billing data is reset).
Business rules:
- The task never creates a second account for a company.
- A second run with
APPLY=1writes nothing.
Worked example: FairPrice divisions
Start: NTUC FairPrice (root) owns acct_FP, and North and East are child companies synced from JodGig.
- Placement credits cost 1 credit = SGD 1.
- The engineer runs the backfill dry run (UC-6).
- The report lists North and East, because they own no account.
- A person approves the report, and the engineer runs it with
APPLY=1.- The task creates
acct_Nfor North andacct_Efor East, each with zero balances.
- The task creates
- Finance creates two invoices (UC-3):
- North on
acct_N, 1,000 credits; - East on
acct_E, 2,000 credits.
- North on
- Each invoice is paid and posted, and each posting creates one
EntitlementLoton its own account.acct_N:units_available = 1000.acct_E:units_available = 2000.
- North's HQ manager submits a campaign that costs 600 credits (UC-4).
ResolveServicereturnsacct_N.- 600 ≤ 1,000, so reserve writes on
acct_N:units_available = 400,units_reserved = 600.
- North submits a second campaign that costs 900 credits.
- The validator reads
acct_N: 900 > 400. - Submit fails: "You need 900 placement credits to submit this campaign, but you only have 400 available. Please top up your placement credits before submitting."
- The validator reads
- East's 2,000 credits are never read.
- This is the problem from the Overview, now stopped.
- North's first campaign runs.
- The daily consume job reads
acct_Nfrom the reserve ledger entry and consumes from North'sEntitlementLot.
- The daily consume job reads
- North's HQ manager opens the Employer Dashboard (UC-5).
- The navbar shows 400 credits available.