Skip to main content

Phase 3.1 — Use Cases

This page lists every flow that changes when every company spends only its own account.

WordMeaning
Own accountThe Billing::Account whose billing_accounts.org_company_id is this company
Root companyAn Org::Company with parent_company_id = NULL
Child companyAn Org::Company with parent_company_id set

Summary​

IDUse caseActorSegment
UC-1Create a company in JodSystem, on company create—
UC-2Sync a company from JodGigSystem, in the JodGig company sync—
UC-3Top up a child company's own accountFinance or Sales (Identities::Admin)Team Portal
UC-4A child company spends creditsHQ manager (Org::Membership) or a Jod adminEmployer Dashboard, Team Portal
UC-5A child company's HQ manager sees the balanceHQ manager of a child companyEmployer Dashboard
UC-6Backfill the missing accountsEngineerRake task

UC-1: Create a company in Jod​

FieldDetails
ActorSystem, inside Org::Companies::Shared::CreateService
TriggerA root company signs up, or a root company's HQ manager or a Jod admin creates a child company

System behaviour (one transaction):

  1. The system creates the Org::Company.
  2. The system creates its own Billing::Account and seeds one Billing::EntitlementBalance per entitlement.
    • Billing::Accounts::Shared::CreateService does 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​

FieldDetails
ActorSystem, inside JodGig::Companies::BillingAccountUpsertAllService
TriggerThe JodGig company sync copies a root company or a child company into Jod

System behaviour:

  1. The system finds the company's own account, if one exists.
  2. The system creates the account when it is missing, for a root company and a child company alike.
  3. The system copies the company's status to the account's status.
  4. The system creates the gig Billing::Agreement of 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​

FieldDetails
ActorFinance or Sales (Identities::Admin)
TriggerFairPrice North buys 1,000 placement credits, or Sales gives North trial credits

System behaviour:

  1. The admin opens the invoice create form, or the credit action form.
  2. The admin picks North's own account in the account picker.
  3. The rest is the normal flow, with no change:
  4. The grant creates an EntitlementLot on North's account.
  5. Only North spends it.

Business rules:

  • The invoice uses a Billing::BillToProfile on North's account.
  • The invoice uses a Billing::Agreement on North's account, if North has one.
    • Otherwise list prices apply.

UC-4: A child company spends credits​

FieldDetails
ActorHQ manager of the child company (Org::Membership), or a Jod admin on its behalf
TriggerSubmit an Ads campaign, and in Phase 4 also post a Careers job

System behaviour:

  1. The submit validator calls Billing::Accounts::Shared::ResolveService.execute(org_company: campaign.org_company).
  2. ResolveService returns org_company.billing_account, the company's own account.
    • It raises the clear 422 error when the company owns no account.
  3. The validator checks that the own account has enough available units.
  4. The submit manager calls ResolveService again inside the transaction.
  5. The submit manager calls Billing::EntitlementLotService.reserve on that account.
  6. Consume (daily job), cancel and reject follow the reserve ledger entry.
    • They do not call ResolveService.

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):

CaseMessage
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​

FieldDetails
ActorHQ manager of a child company
EndpointGET /employers/billing/entitlement_balances (exists, no change to the path or the response)

System behaviour:

  1. The manager reads the balances of the company's own account.
  2. The Employer Dashboard navbar shows that balance.

UC-6: Backfill the missing accounts​

FieldDetails
ActorEngineer
TriggerDeploy of the JodGig sync change, before the ResolveService change
Taskbin/rails billing:backfill_company_accounts, a dry run by default, and APPLY=1 to write

System behaviour:

  1. The task reads every Org::Company and finds the companies that own no account.
  2. The dry run prints a report.
  3. A person approves the report before APPLY=1.
  4. With APPLY=1, the task calls Billing::Accounts::Shared::CreateService for each company in the report.
    • The service creates the own account and seeds its balances.
  5. The task prints the same report again after the write.

The report lists:

Business rules:

  • The task never creates a second account for a company.
  • A second run with APPLY=1 writes 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.
  1. The engineer runs the backfill dry run (UC-6).
    • The report lists North and East, because they own no account.
  2. A person approves the report, and the engineer runs it with APPLY=1.
    • The task creates acct_N for North and acct_E for East, each with zero balances.
  3. Finance creates two invoices (UC-3):
    • North on acct_N, 1,000 credits;
    • East on acct_E, 2,000 credits.
  4. Each invoice is paid and posted, and each posting creates one EntitlementLot on its own account.
    • acct_N: units_available = 1000.
    • acct_E: units_available = 2000.
  5. North's HQ manager submits a campaign that costs 600 credits (UC-4).
    • ResolveService returns acct_N.
    • 600 ≤ 1,000, so reserve writes on acct_N: units_available = 400, units_reserved = 600.
  6. 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."
  7. East's 2,000 credits are never read.
    • This is the problem from the Overview, now stopped.
  8. North's first campaign runs.
    • The daily consume job reads acct_N from the reserve ledger entry and consumes from North's EntitlementLot.
  9. North's HQ manager opens the Employer Dashboard (UC-5).
    • The navbar shows 400 credits available.