Skip to content

A staffing agency's placements, pay and billing

The rule

A staffing agency employs workers and places them with clients. Each placement has a client, a site, a start and an end, a pay rate (what the worker is paid) and a bill rate (what the client is billed). The agency pays its workers every week and invoices each client for the hours worked there. Each client approves the hours it is billed, those of its own placement only; the agency’s payroll approves what the worker is paid. A worker can hold two placements at once, and says at the clock which one each shift is for.

Who uses it

Staffing and recruitment agencies, labour hire companies, professional employer organizations and any employer that pays one party and bills another for the same hours: in the US, Canada, the UK, Australia, Mexico and wherever agencies place temporary workers.

How the recipe does it

Placements are assignments. Each placement is one of the worker’s assignments, dated from its first day to its last, with its client and site as the assignment’s values:

[[assignment]]
id = "P-100"
from = "2026-10-05"
to = "2026-10-07"
defaults = { client = "northwind", site = "dallas" }

With one placement active on a day, the day’s work is on it. With two, the work code entered at the clock says which (an implication from the code to the placement); with no code, the shift is an assignment_ambiguous exception for someone to settle. A required client dimension makes work outside every placement an exception too.

Two sides. The policy works each timecard out twice (sides = ["pay", "bill"]): the pay side and the bill side each have their own overtime step (a step names its side with side), approvals and export. Rates of the kinds pay and bill are matched on the placement.

The policy is configuration: the package (package.toml) has one layer for everyone with four standard steps: weekly overtime on each side, the worker’s straight time, and the overtime premium at the week’s regular rate.

[[layer]]
id = "agency"
[[layer.step]]
id = "weekly"
uses = "standard/threshold"
params = { over = "40h", to = "overtime", window = "week" }
[[layer.step]]
id = "weekly-billed"
uses = "standard/threshold"
params = { over = "40h", to = "overtime", window = "week", side = "bill" }
[[layer.step]]
id = "wages"
uses = "standard/earnings"
params = { rate = "pay", measure = "wages", premiums = { work = 100, overtime = 100 }, window = "week" }
[[layer.step]]
id = "overtime-premium"
uses = "standard/regular_rate"
params = { rate = "pay", measure = "wages", premiums = { overtime = 50 } }

Earnings (wages) turn the worker’s hours into pay on the timecard: every hour, overtime included, is paid its straight time at its placement’s pay rate, as money in the money measure measure. The overtime premium is half the week’s regular rate (regular_rate): the week’s straight-time pay at every placement’s rate over its hours. A worker placed with two clients at different rates in one week is owed overtime on that blended rate, not on the rate of the client where the overtime fell; the bill side prices its overtime at each client’s bill rate, as the agency’s contracts with its clients say. The money is worked out once for each placement, category and rate over the whole period, so a week of 7 hours 20 minutes a day at 20.00 is 440.00, not three days of 146.66. A line no rate matches (work with no placement, or a placement nobody set a pay rate for) is a no_rate exception, and no money is made up for it. A raise from a day is a second rate from that day, and each day’s work is paid at its own.

Exports are the package’s own (main.lua): the one decision no standard step makes here is the layout of the agency’s payroll file and of its clients’ invoices. staffing_agency/payroll writes the pay side for payroll: one line per earning code with its hours and the money earnings worked out. staffing_agency/invoice writes the bill side for invoicing: one line per client, worker and category, with the hours billed and what they come to. An exporter reads the rate each line’s work is at (l.rates.bill), so the invoice prices the bill side’s hours at their bill rates itself: it adds each client’s and category’s time at each rate over the period and works the money out once with time.money, never line by line. The bill side needs no money step of its own. The pay side keeps earnings: the worker’s pay belongs on the timecard the worker and the agency’s payroll see and approve, and a placement without a pay rate is an exception there, before anyone exports. Both exports stop, naming what is missing, rather than write a guess: a person without a payroll id, a category without an earning code, work without a client or a bill rate.

Each client approves its own placement. Clients and their sites are a hierarchy (clients), and each placement names its site in it (organizations = { clients = "northwind-dallas" } on the assignment). The bill side is approved placement by placement (subject = "assignment"), each placement’s hours waiting on the client of its own site, the nearest organization above it labelled a client:

[[approval_rule]]
side = "bill"
subject = "assignment"
stages = ["client"]
blocked_by_exceptions = true
organizations = { client = { hierarchy = "clients", select = "kind = client" } }

A worker placed with Northwind and Contoso in one week has two subjects on the bill side, bill:assignment:P-100:2026-10-05 waiting on Northwind and bill:assignment:P-200:2026-10-05 on Contoso; each client approves only its own, and an exception on a Contoso day holds back only Contoso’s hours. The bill side’s timecard is approved once every placement’s hours are, as if it had been approved whole. The app the client signs in to says who decides for each client.

What your setup needs

Set up before you adopt the recipe; the recipe’s steps read them by name, and adopting it is refused, with a list of what is missing, until they exist.

  • A measure called gross: the amount the recipe adds up (money in a currency, or a count).
  • A measure called wages: the amount the recipe adds up (money in a currency, or a count).

The scenarios show each as it was set up for them.

Parameters

StepParameterMeaning
weekly, weekly-billedover, toThe regular hours a week may have, and where the rest goes.
weekly-billedsidebill: the bill side’s own count; default the pay side.
wagesrateThe kind of rate to pay at: pay.
wagesmeasureThe money measure the pay is added in (wages).
wagespremiumsThe categories paid their straight time: { work = 100, overtime = 100 }.
overtime-premiumpremiumsEach premium category’s per cent of the regular rate: { overtime = 50 }.
wageskindThe exception for a line no rate matches (no_rate).

payroll: id_attribute (the employment attribute holding the payroll id), measure (the pay side’s money measure), codes (the earning code of each category). invoice: rate (the kind of rate billed at: bill), premiums (each category billed with its premium in per cent: { work = 100, overtime = 150 }), and approved_only (only the hours approved: a client whose placement is approved is invoiced while another’s wait).

What the scenarios show

  • placements-become-assignments: a placement ending Wednesday and the next starting Thursday put each day’s work on its client, paid at its placement’s rate.
  • work-outside-every-placement-is-flagged: work after the placement ended has no client, and is a context_missing exception; with no placement it has no pay rate either, a no_rate exception.
  • paid-at-the-pay-rate: a 45-hour week paid at 20.00, the 5 overtime hours 100.00 straight time and 50.00 premium, and the payroll export.
  • billed-at-the-bill-rate: the same week invoiced at 30.00, the bill side counting its own overtime, at 45.00.
  • an-invoice-works-the-money-out-once: 22 hours at 20.00 invoiced as 440.00.
  • an-invoice-stops-at-hours-without-a-bill-rate: no bill rate, no invoice: it names the work.
  • a-raise-mid-week-pays-each-day-at-its-rate: a raise from Wednesday.
  • a-bill-rate-raise-mid-week-bills-each-day-at-its-rate: a bill rate raised from Wednesday: the invoice prices Monday and Tuesday at the old rate and the rest at the new, each rate’s money worked out once.
  • money-is-worked-out-once-not-line-by-line: 22 hours are 440.00.
  • the-pay-goes-in-the-measure-named: a tenant layer naming another money measure puts the 440.00 there.
  • a-placement-without-a-rate-is-flagged: no rate, no money, a no_rate exception.
  • two-clients-in-one-week: two placements picked by work code, the week’s overtime at the client worked last, and each client invoiced for its own hours. 30 hours at 20.00 and 16 at 22.00: the 6 overtime hours are paid 132.00 straight time and 62.08, half the week’s regular rate of 20.6956, on top.
  • two-placements-and-no-work-code-asks: an assignment_ambiguous exception, and a no_rate one: work on no placement has no pay rate.
  • an-invoice-stops-at-work-without-a-client: the invoice export stops at work with no client.
  • the-bill-waits-for-the-client, the-client-approves-the-bill, the-clients-approval-is-the-bill-sides-alone: the client approves its placement’s hours on the bill side; the pay side waits for the agency’s payroll.
  • each-client-approves-its-own-placements-hours: Northwind approves its 30 hours, which are invoiced; Contoso’s 16 wait on Contoso.
  • the-bill-is-approved-once-every-client-has: both placements approved, the bill side’s timecard is approved, and the invoice has both clients, the week’s 6 hours of overtime at Contoso.
  • an-exception-holds-back-only-its-clients-hours: a missed punch on a Contoso day blocks Contoso’s hours, not Northwind’s.

Who pays overtime earned across two clients, and whether it may be billed to the client where it fell, is set by the agency’s contracts and the law where the work is done; some places also set how agency workers are paid next to the client’s own staff. Check with counsel where you operate.

Get the recipe

The recipe’s package and its scenarios are in the example packages repository: attendance/staffing_agency. Test it, or your own copy of it, with hourctl attend test, and publish it with hourctl attend pkg publish.

The policy package

The package’s layers, with the standard steps each one runs and their settings:

staffing_agency/package.toml
name = "staffing_agency"
version = "1.0.0"
description = "Placements as assignments, each side of the timecard with its own weekly overtime, the worker paid at the placement's pay rate, with the agency's payroll and invoice files."
# What the tenant must have set up for the recipe: the steps read these by name.
[needs]
measures = ["gross", "wages"]
# Everyone: weekly overtime past 40 hours on the pay side and, counted
# again on its own, on the bill side; then every hour of the pay side
# paid its straight time at the placement's pay rate, and each overtime
# hour half the week's regular rate on top: the hours at each placement's
# rate, over the week's hours.
[[layer]]
id = "agency"
[[layer.step]]
id = "weekly"
uses = "standard/threshold"
params = { over = "40h", to = "overtime", window = "week" }
[[layer.step]]
id = "weekly-billed"
uses = "standard/threshold"
params = { over = "40h", to = "overtime", window = "week", side = "bill" }
[[layer.step]]
id = "wages"
uses = "standard/earnings"
params = { rate = "pay", measure = "wages", premiums = { work = 100, overtime = 100 }, window = "week" }
[[layer.step]]
id = "overtime-premium"
uses = "standard/regular_rate"
params = { rate = "pay", measure = "wages", premiums = { overtime = 50 } }

Steps of its own, for what no standard step does (write a policy step):

staffing_agency/main.lua
-- A staffing agency's two file layouts: the worker's pay for its payroll
-- (`payroll`) and each client's invoice (`invoice`). The worker's pay is
-- worked out on the timecard by the standard `earnings` and `regular_rate`
-- steps the package's layer (package.toml) runs, where the worker and the
-- agency's payroll see it; the invoice prices the bill side's hours at
-- their bill rates as it is written.
local M = {}
-- Hours as text, in the tenant's decimals ("8.25", "-0.50"), as a whole
-- number of its last decimal (825, -50) and how many decimals it has. The
-- lines' hours are carried, so adding them up this way comes to the
-- total exactly, with nothing rounded again.
local function units(hours)
local whole, fraction = string.match(hours, "^(-?%d+)%.?(%d*)$")
return tonumber(whole .. fraction), #fraction
end
-- A whole number of the last of `places` decimals as text: 825 and 2 are
-- "8.25". Money is minor units with 2 places.
local function decimal(n, places)
if places == 0 then
return string.format("%d", n)
end
local scale = 10 ^ places
local sign = ""
if n < 0 then
sign, n = "-", -n
end
return string.format("%s%d.%0" .. places .. "d", sign, n // scale, n % scale)
end
-- A value every export needs, from `t[name]`: one missing stops the export
-- rather than send hours or money under a guess.
local function required(t, name, what)
local value = t[name]
if value == nil then
error(what .. " has no " .. name)
end
return value
end
-- The keys of a table, sorted, so a file is the same each time.
local function sorted_keys(t)
local keys = {}
for k in pairs(t) do
table.insert(keys, k)
end
table.sort(keys)
return keys
end
-- The worker's pay for the period, for payroll: one CSV line per earning
-- code with its hours and the money the steps worked out in the
-- money measure `measure`.
-- employee,period_end,code,hours,amount
-- Params: { id_attribute = "payroll_id", measure = "wages",
-- codes = { work = "REG", overtime = "OT" } }
M.payroll = {
stage = "export",
content_type = "text/csv",
extension = "csv",
header = function(p)
return csv({ "employee", "period_end", "code", "hours", "amount" })
end,
person = function(x, p)
local id = required(x.attributes, p.id_attribute, "person " .. x.person)
local amounts = {}
for _, q in ipairs(x.quantities) do
if q.measure == p.measure then
amounts[q.category] = (amounts[q.category] or 0) + q.quantity
end
end
local out = {}
for _, category in ipairs(sorted_keys(x.categories)) do
local used = x.category_use[category]
if used == nil or used.paid then
local code = p.codes[category] or (used and used.code)
if code == nil then
error("category " .. category .. " has no earning code")
end
local amount = decimal(amounts[category] or 0, 2)
table.insert(out, csv({ id, x.last, code, x.categories[category], amount }))
end
end
return table.concat(out)
end,
}
-- The client's invoice lines for the period, from the bill side: one CSV
-- line per client, worker and category with the hours billed and what they
-- come to at the rate of the kind `rate` each line's work is at (the
-- placement's bill rate), times its category's premium in per cent. The
-- money is worked out once for each client, category and rate over the
-- whole period, never line by line. The client is the line's context value
-- `client` (the placement's). Work with no client, no rate or a category
-- with no premium stops the invoice, naming what is missing. With
-- `approved_only`, only the hours approved are written: a client that
-- approved its placement's hours is invoiced while another's still wait.
-- client,worker,period_end,category,hours,amount
-- Params: { rate = "bill", premiums = { work = 100, overtime = 150 },
-- approved_only = true }
M.invoice = {
stage = "export",
content_type = "text/csv",
extension = "csv",
header = function(p)
return csv({ "client", "worker", "period_end", "category", "hours", "amount" })
end,
person = function(x, p)
if x.side ~= "bill" then
error("an invoice is written from the bill side, not " .. x.side)
end
local rows = {}
local places = 0
for _, l in ipairs(x.lines) do
if l.paid and (l.approved or not p.approved_only) then
local work = "work of person " .. x.person .. " on " .. l.workday
local client = required(l.context, "client", work)
local rate = required(l.rates, p.rate, work)
required(p.premiums, l.category, "the invoice's premiums for category " .. l.category)
local key = client .. "|" .. l.category
local r = rows[key]
if r == nil then
r = { client = client, category = l.category, hours = 0, time_at = {} }
rows[key] = r
end
local n
n, places = units(l.hours)
r.hours = r.hours + n
r.time_at[rate.amount] = (r.time_at[rate.amount] or 0) + l.time
end
end
local out = {}
for _, key in ipairs(sorted_keys(rows)) do
local r = rows[key]
local amount = 0
for _, rate in ipairs(sorted_keys(r.time_at)) do
amount = amount + math.floor(time.money(r.time_at[rate], rate * p.premiums[r.category]) / 100)
end
table.insert(out, csv({ r.client, x.person, x.last, r.category, decimal(r.hours, places), decimal(amount, 2) }))
end
return table.concat(out)
end,
}
return M

Scenarios

Each scenario gives a person’s punches and setup and the timecard they must produce, worked out with this package adopted (the format).

The placement's bill rate goes from 30.00 to 33.00 an hour on Wednesday. Monday and Tuesday's 14 hours 40 minutes bill at 30.00 (440.00) and the rest of the week's 22 hours at 33.00 (726.00): the invoice adds the time at each rate first and works each rate's money out once, 1166.00, where priced a day at a time it would be 1165.95
scenarios/a-bill-rate-raise-mid-week-bills-each-day-at-its-rate.toml
description = "The placement's bill rate goes from 30.00 to 33.00 an hour on Wednesday. Monday and Tuesday's 14 hours 40 minutes bill at 30.00 (440.00) and the rest of the week's 22 hours at 33.00 (726.00): the invoice adds the time at each rate first and works each rate's money out once, 1166.00, where priced a day at a time it would be 1165.95"
punch = [
{ at = "2026-10-05 08:00", kind = "in" }, { at = "2026-10-05 15:20", kind = "out" },
{ at = "2026-10-06 08:00", kind = "in" }, { at = "2026-10-06 15:20", kind = "out" },
{ at = "2026-10-07 08:00", kind = "in" }, { at = "2026-10-07 15:20", kind = "out" },
{ at = "2026-10-08 08:00", kind = "in" }, { at = "2026-10-08 15:20", kind = "out" },
{ at = "2026-10-09 08:00", kind = "in" }, { at = "2026-10-09 15:20", kind = "out" },
]
[policy]
zone = "America/Chicago"
sides = ["pay", "bill"]
pay_periods = { every_days = 7, from = "2026-10-05" }
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
[[rate]]
kind = "bill"
matches = { assignment = "P-100" }
amount = 3000
currency = "USD"
to = "2026-10-06"
[[rate]]
kind = "bill"
matches = { assignment = "P-100" }
amount = 3300
currency = "USD"
from = "2026-10-07"
[expect.export]
uses = "staffing_agency/invoice"
params = { rate = "bill", premiums = { work = 100, overtime = 150 } }
side = "bill"
day = "2026-10-05"
file = """
client,worker,period_end,category,hours,amount
northwind,person,2026-10-11,work,36.66,1166.00
"""
A placement nobody set a pay rate for: its work is kept and paid nothing yet, and a no_rate exception on its first line asks for the rate, rather than pay a guess
scenarios/a-placement-without-a-rate-is-flagged.toml
description = "A placement nobody set a pay rate for: its work is kept and paid nothing yet, and a no_rate exception on its first line asks for the rate, rather than pay a guess"
punch = [
{ at = "2026-10-05 08:00", kind = "in" }, { at = "2026-10-05 16:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
pay_periods = { every_days = 7, from = "2026-10-05" }
[[measure]]
id = "wages"
kind = "money"
currency = "USD"
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
[expect]
week = "2026-10-05"
allocations = ["2026-10-05 08:00-16:00 work 8.00 assignment=P-100 client=northwind"]
quantities = []
exceptions = [{ kind = "no_rate", at = "2026-10-05 08:00" }]
The worker's pay rate on the placement goes from 20.00 to 21.00 an hour on Wednesday: Monday and Tuesday's 16 hours pay 320.00 and the rest of the week's 24 hours 504.00, each at the rate of its day
scenarios/a-raise-mid-week-pays-each-day-at-its-rate.toml
description = "The worker's pay rate on the placement goes from 20.00 to 21.00 an hour on Wednesday: Monday and Tuesday's 16 hours pay 320.00 and the rest of the week's 24 hours 504.00, each at the rate of its day"
punch = [
{ at = "2026-10-05 08:00", kind = "in" }, { at = "2026-10-05 16:00", kind = "out" },
{ at = "2026-10-06 08:00", kind = "in" }, { at = "2026-10-06 16:00", kind = "out" },
{ at = "2026-10-07 08:00", kind = "in" }, { at = "2026-10-07 16:00", kind = "out" },
{ at = "2026-10-08 08:00", kind = "in" }, { at = "2026-10-08 16:00", kind = "out" },
{ at = "2026-10-09 08:00", kind = "in" }, { at = "2026-10-09 16:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
pay_periods = { every_days = 7, from = "2026-10-05" }
[[measure]]
id = "wages"
kind = "money"
currency = "USD"
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
[[rate]]
kind = "pay"
matches = { assignment = "P-100" }
amount = 2000
currency = "USD"
to = "2026-10-06"
[[rate]]
kind = "pay"
matches = { assignment = "P-100" }
amount = 2100
currency = "USD"
from = "2026-10-07"
[expect]
week = "2026-10-05"
quantities = [
"2026-10-06 wages 320.00 USD work assignment=P-100 client=northwind",
"2026-10-09 wages 504.00 USD work assignment=P-100 client=northwind",
]
Contoso approves only hours with nothing wrong in them: Thursday at Contoso the worker started lunch and never punched back, so Contoso's hours are blocked until someone puts it right or excuses it. Northwind's hours, on other days, are not held back: Northwind approved them, and they are invoiced
scenarios/an-exception-holds-back-only-its-clients-hours.toml
description = "Contoso approves only hours with nothing wrong in them: Thursday at Contoso the worker started lunch and never punched back, so Contoso's hours are blocked until someone puts it right or excuses it. Northwind's hours, on other days, are not held back: Northwind approved them, and they are invoiced"
punch = [
{ at = "2026-10-05 07:00", kind = "in", values = { work_code = "1" } }, { at = "2026-10-05 17:00", kind = "out" },
{ at = "2026-10-06 07:00", kind = "in", values = { work_code = "1" } }, { at = "2026-10-06 17:00", kind = "out" },
{ at = "2026-10-07 07:00", kind = "in", values = { work_code = "1" } }, { at = "2026-10-07 17:00", kind = "out" },
{ at = "2026-10-08 08:00", kind = "in", values = { work_code = "2" } }, { at = "2026-10-08 12:00", kind = "lunch_start" }, { at = "2026-10-08 16:00", kind = "out" },
{ at = "2026-10-09 08:00", kind = "in", values = { work_code = "2" } }, { at = "2026-10-09 16:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
sides = ["pay", "bill"]
pay_periods = { every_days = 7, from = "2026-10-05" }
# Two placements at once, each at its client's site, picked by work code.
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
organizations = { clients = "northwind-dallas" }
[[assignment]]
id = "P-200"
defaults = { client = "contoso" }
organizations = { clients = "contoso-fort-worth" }
[[implication]]
when = { work_code = "1" }
then = { assignment = "P-100" }
[[implication]]
when = { work_code = "2" }
then = { assignment = "P-200" }
[[rate]]
kind = "bill"
matches = { assignment = "P-100" }
amount = 3000
currency = "USD"
[[rate]]
kind = "bill"
matches = { assignment = "P-200" }
amount = 3300
currency = "USD"
[[organization]]
hierarchy = "clients"
id = "northwind"
labels = { kind = "client" }
[[organization]]
hierarchy = "clients"
id = "northwind-dallas"
parent = "northwind"
labels = { kind = "site" }
[[organization]]
hierarchy = "clients"
id = "contoso"
labels = { kind = "client" }
[[organization]]
hierarchy = "clients"
id = "contoso-fort-worth"
parent = "contoso"
labels = { kind = "site" }
# Hours with an exception not excused on their days wait until it is
# settled.
[[approval_rule]]
side = "bill"
subject = "assignment"
stages = ["client"]
blocked_by_exceptions = true
organizations = { client = { hierarchy = "clients", select = "kind = client" } }
[[approval]]
subject = "bill:assignment:P-100:2026-10-05"
stage = "client"
decision = "approve"
by = "northwind:kim"
recorded = "2026-10-12 09:00"
[expect.period]
day = "2026-10-05"
side = "bill"
exceptions = [{ kind = "missing_lunch_end", at = "2026-10-08 16:00" }]
approvals = [
"bill:assignment:P-100:2026-10-05 approved",
"bill:assignment:P-200:2026-10-05 blocked",
]
approved = false
# Invoicing what is approved: Northwind's hours, while Contoso's wait.
[expect.export]
uses = "staffing_agency/invoice"
params = { rate = "bill", premiums = { work = 100, overtime = 150 }, approved_only = true }
side = "bill"
day = "2026-10-05"
file = """
client,worker,period_end,category,hours,amount
northwind,person,2026-10-11,work,30.00,900.00
"""
A placement nobody set a bill rate for: the invoice stops, naming the work with no bill rate, rather than bill it at a guess or leave it out
scenarios/an-invoice-stops-at-hours-without-a-bill-rate.toml
description = "A placement nobody set a bill rate for: the invoice stops, naming the work with no bill rate, rather than bill it at a guess or leave it out"
punch = [
{ at = "2026-10-05 08:00", kind = "in" }, { at = "2026-10-05 15:20", kind = "out" },
{ at = "2026-10-06 08:00", kind = "in" }, { at = "2026-10-06 15:20", kind = "out" },
{ at = "2026-10-07 08:00", kind = "in" }, { at = "2026-10-07 15:20", kind = "out" },
]
[policy]
zone = "America/Chicago"
sides = ["pay", "bill"]
pay_periods = { every_days = 7, from = "2026-10-05" }
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
[[rate]]
kind = "pay"
matches = { assignment = "P-100" }
amount = 2000
currency = "USD"
[expect]
error = "work of person person on 2026-10-05 has no bill"
[expect.export]
uses = "staffing_agency/invoice"
params = { rate = "bill", premiums = { work = 100, overtime = 150 } }
side = "bill"
day = "2026-10-05"
file = ""
Work after the placement ended has no client: the invoice export stops, saying whose work has none, rather than bill it to a guess
scenarios/an-invoice-stops-at-work-without-a-client.toml
description = "Work after the placement ended has no client: the invoice export stops, saying whose work has none, rather than bill it to a guess"
punch = [
{ at = "2026-10-08 07:00", kind = "in" }, { at = "2026-10-08 15:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
sides = ["pay", "bill"]
[[assignment]]
id = "P-100"
from = "2026-10-05"
to = "2026-10-07"
defaults = { client = "northwind" }
[expect]
error = "work of person person on 2026-10-08 has no client"
[expect.export]
uses = "staffing_agency/invoice"
params = { rate = "bill", premiums = { work = 100, overtime = 150 } }
side = "bill"
day = "2026-10-05"
file = ""
Three days of 7 hours 20 minutes billed at 20.00 an hour are 22 hours, 440.00. Priced a line at a time, each day would be 146.66 and the invoice 439.98: the invoice adds the time at each rate first and works the money out once, so not a cent is lost
scenarios/an-invoice-works-the-money-out-once.toml
description = "Three days of 7 hours 20 minutes billed at 20.00 an hour are 22 hours, 440.00. Priced a line at a time, each day would be 146.66 and the invoice 439.98: the invoice adds the time at each rate first and works the money out once, so not a cent is lost"
punch = [
{ at = "2026-10-05 08:00", kind = "in" }, { at = "2026-10-05 15:20", kind = "out" },
{ at = "2026-10-06 08:00", kind = "in" }, { at = "2026-10-06 15:20", kind = "out" },
{ at = "2026-10-07 08:00", kind = "in" }, { at = "2026-10-07 15:20", kind = "out" },
]
[policy]
zone = "America/Chicago"
sides = ["pay", "bill"]
pay_periods = { every_days = 7, from = "2026-10-05" }
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
[[rate]]
kind = "bill"
matches = { assignment = "P-100" }
amount = 2000
currency = "USD"
[expect.export]
uses = "staffing_agency/invoice"
params = { rate = "bill", premiums = { work = 100, overtime = 150 } }
side = "bill"
day = "2026-10-05"
file = """
client,worker,period_end,category,hours,amount
northwind,person,2026-10-11,work,22.00,440.00
"""
The placement bills the client 30.00 an hour. The bill side counts its own overtime, so the week of five 9-hour days bills 40 hours at 30.00 and 5 of overtime at 45.00: the invoice reads each line's bill rate and works the money out as it writes the file, with no money step on the bill side's timecard
scenarios/billed-at-the-bill-rate.toml
description = "The placement bills the client 30.00 an hour. The bill side counts its own overtime, so the week of five 9-hour days bills 40 hours at 30.00 and 5 of overtime at 45.00: the invoice reads each line's bill rate and works the money out as it writes the file, with no money step on the bill side's timecard"
punch = [
{ at = "2026-10-05 07:00", kind = "in" }, { at = "2026-10-05 16:00", kind = "out" },
{ at = "2026-10-06 07:00", kind = "in" }, { at = "2026-10-06 16:00", kind = "out" },
{ at = "2026-10-07 07:00", kind = "in" }, { at = "2026-10-07 16:00", kind = "out" },
{ at = "2026-10-08 07:00", kind = "in" }, { at = "2026-10-08 16:00", kind = "out" },
{ at = "2026-10-09 07:00", kind = "in" }, { at = "2026-10-09 16:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
sides = ["pay", "bill"]
pay_periods = { every_days = 7, from = "2026-10-05" }
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
[[rate]]
kind = "pay"
matches = { assignment = "P-100" }
amount = 2000
currency = "USD"
[[rate]]
kind = "bill"
matches = { assignment = "P-100" }
amount = 3000
currency = "USD"
[expect.export]
uses = "staffing_agency/invoice"
params = { rate = "bill", premiums = { work = 100, overtime = 150 } }
side = "bill"
day = "2026-10-05"
file = """
client,worker,period_end,category,hours,amount
northwind,person,2026-10-11,overtime,5.00,225.00
northwind,person,2026-10-11,work,40.00,1200.00
"""
A worker placed with Northwind and Contoso in one week: each client approves only its own placement's hours on the bill side. Northwind approved its 30 hours, so they are approved and invoiced; Contoso's 16 still wait on Contoso, and the bill side's timecard is not approved until they are
scenarios/each-client-approves-its-own-placements-hours.toml
description = "A worker placed with Northwind and Contoso in one week: each client approves only its own placement's hours on the bill side. Northwind approved its 30 hours, so they are approved and invoiced; Contoso's 16 still wait on Contoso, and the bill side's timecard is not approved until they are"
punch = [
{ at = "2026-10-05 07:00", kind = "in", values = { work_code = "1" } }, { at = "2026-10-05 17:00", kind = "out" },
{ at = "2026-10-06 07:00", kind = "in", values = { work_code = "1" } }, { at = "2026-10-06 17:00", kind = "out" },
{ at = "2026-10-07 07:00", kind = "in", values = { work_code = "1" } }, { at = "2026-10-07 17:00", kind = "out" },
{ at = "2026-10-08 08:00", kind = "in", values = { work_code = "2" } }, { at = "2026-10-08 16:00", kind = "out" },
{ at = "2026-10-09 08:00", kind = "in", values = { work_code = "2" } }, { at = "2026-10-09 16:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
sides = ["pay", "bill"]
pay_periods = { every_days = 7, from = "2026-10-05" }
# Two placements at once, each at its client's site, picked by work code.
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
organizations = { clients = "northwind-dallas" }
[[assignment]]
id = "P-200"
defaults = { client = "contoso" }
organizations = { clients = "contoso-fort-worth" }
[[implication]]
when = { work_code = "1" }
then = { assignment = "P-100" }
[[implication]]
when = { work_code = "2" }
then = { assignment = "P-200" }
[[rate]]
kind = "bill"
matches = { assignment = "P-100" }
amount = 3000
currency = "USD"
[[rate]]
kind = "bill"
matches = { assignment = "P-200" }
amount = 3300
currency = "USD"
[[organization]]
hierarchy = "clients"
id = "northwind"
labels = { kind = "client" }
[[organization]]
hierarchy = "clients"
id = "northwind-dallas"
parent = "northwind"
labels = { kind = "site" }
[[organization]]
hierarchy = "clients"
id = "contoso"
labels = { kind = "client" }
[[organization]]
hierarchy = "clients"
id = "contoso-fort-worth"
parent = "contoso"
labels = { kind = "site" }
[[approval_rule]]
side = "bill"
subject = "assignment"
stages = ["client"]
organizations = { client = { hierarchy = "clients", select = "kind = client" } }
[[approval]]
subject = "bill:assignment:P-100:2026-10-05"
stage = "client"
decision = "approve"
by = "northwind:kim"
recorded = "2026-10-12 09:00"
[expect.period]
day = "2026-10-05"
side = "bill"
approvals = [
"bill:assignment:P-100:2026-10-05 approved",
"bill:assignment:P-200:2026-10-05 pending client at contoso",
]
approved = false
# Invoicing what is approved: Northwind's hours, while Contoso's wait.
[expect.export]
uses = "staffing_agency/invoice"
params = { rate = "bill", premiums = { work = 100, overtime = 150 }, approved_only = true }
side = "bill"
day = "2026-10-05"
file = """
client,worker,period_end,category,hours,amount
northwind,person,2026-10-11,work,30.00,900.00
"""
Three days of 7 hours 20 minutes at 20.00 an hour are 22 hours, 440.00. Worked out a line at a time, each day would be 146.66 and the week 439.98: the money is worked out once for the period, so not a cent is lost
scenarios/money-is-worked-out-once-not-line-by-line.toml
description = "Three days of 7 hours 20 minutes at 20.00 an hour are 22 hours, 440.00. Worked out a line at a time, each day would be 146.66 and the week 439.98: the money is worked out once for the period, so not a cent is lost"
punch = [
{ at = "2026-10-05 08:00", kind = "in" }, { at = "2026-10-05 15:20", kind = "out" },
{ at = "2026-10-06 08:00", kind = "in" }, { at = "2026-10-06 15:20", kind = "out" },
{ at = "2026-10-07 08:00", kind = "in" }, { at = "2026-10-07 15:20", kind = "out" },
]
[policy]
zone = "America/Chicago"
pay_periods = { every_days = 7, from = "2026-10-05" }
[[measure]]
id = "wages"
kind = "money"
currency = "USD"
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
[[rate]]
kind = "pay"
matches = { assignment = "P-100" }
amount = 2000
currency = "USD"
[expect]
week = "2026-10-05"
quantities = ["2026-10-07 wages 440.00 USD work assignment=P-100 client=northwind"]
A placement pays the worker 20.00 an hour. A week of five 9-hour days pays all 45 hours their straight time at 20.00 and the 5 of overtime half the week's regular rate on top (20.00, the one rate worked): 100.00 and 50.00, 150.00 for the overtime, worked out on the pay side's timecard, and the payroll export writes it under the payroll's earning codes, with the money
scenarios/paid-at-the-pay-rate.toml
description = "A placement pays the worker 20.00 an hour. A week of five 9-hour days pays all 45 hours their straight time at 20.00 and the 5 of overtime half the week's regular rate on top (20.00, the one rate worked): 100.00 and 50.00, 150.00 for the overtime, worked out on the pay side's timecard, and the payroll export writes it under the payroll's earning codes, with the money"
punch = [
{ at = "2026-10-05 07:00", kind = "in" }, { at = "2026-10-05 16:00", kind = "out" },
{ at = "2026-10-06 07:00", kind = "in" }, { at = "2026-10-06 16:00", kind = "out" },
{ at = "2026-10-07 07:00", kind = "in" }, { at = "2026-10-07 16:00", kind = "out" },
{ at = "2026-10-08 07:00", kind = "in" }, { at = "2026-10-08 16:00", kind = "out" },
{ at = "2026-10-09 07:00", kind = "in" }, { at = "2026-10-09 16:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
sides = ["pay", "bill"]
pay_periods = { every_days = 7, from = "2026-10-05" }
[[measure]]
id = "wages"
kind = "money"
currency = "USD"
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
[[employment]]
effective = "2026-09-28"
kind = "hired"
attributes = { payroll_id = "E1042" }
[[rate]]
kind = "pay"
matches = { assignment = "P-100" }
amount = 2000
currency = "USD"
[[rate]]
kind = "bill"
matches = { assignment = "P-100" }
amount = 3000
currency = "USD"
[expect]
week = "2026-10-05"
quantities = [
"2026-10-09 wages 50.00 USD overtime",
"2026-10-09 wages 100.00 USD overtime assignment=P-100 client=northwind",
"2026-10-09 wages 800.00 USD work assignment=P-100 client=northwind",
]
[expect.export]
uses = "staffing_agency/payroll"
params = { id_attribute = "payroll_id", measure = "wages", codes = { work = "REG", overtime = "OT" } }
day = "2026-10-05"
file = """
employee,period_end,code,hours,amount
E1042,2026-10-11,OT,5.00,150.00
E1042,2026-10-11,REG,40.00,800.00
"""
Each placement is one of the worker's assignments, from its first day to its last, with its client and site as values: a week that ends one placement on Wednesday and starts the next on Thursday puts each day's work on the client of the day, with nothing to pick at the clock. Each day is paid at its own placement's pay rate
scenarios/placements-become-assignments.toml
description = "Each placement is one of the worker's assignments, from its first day to its last, with its client and site as values: a week that ends one placement on Wednesday and starts the next on Thursday puts each day's work on the client of the day, with nothing to pick at the clock. Each day is paid at its own placement's pay rate"
[policy]
zone = "America/Chicago"
# The placements: one with Northwind to Wednesday, then one with Contoso.
[[assignment]]
id = "P-100"
from = "2026-10-05"
to = "2026-10-07"
defaults = { client = "northwind", site = "dallas" }
[[assignment]]
id = "P-200"
from = "2026-10-08"
defaults = { client = "contoso", site = "fort-worth" }
[[measure]]
id = "wages"
kind = "money"
currency = "USD"
# Each placement's pay rate.
[[rate]]
kind = "pay"
matches = { assignment = "P-100" }
amount = 2000
currency = "USD"
[[rate]]
kind = "pay"
matches = { assignment = "P-200" }
amount = 2200
currency = "USD"
[[punch]]
at = "2026-10-07 07:00"
kind = "in"
[[punch]]
at = "2026-10-07 15:30"
kind = "out"
[[punch]]
at = "2026-10-08 09:00"
kind = "in"
[[punch]]
at = "2026-10-08 17:00"
kind = "out"
[expect]
week = "2026-10-05"
allocations = [
"2026-10-07 07:00-15:30 work 8.50 assignment=P-100 client=northwind site=dallas",
"2026-10-08 09:00-17:00 work 8.00 assignment=P-200 client=contoso site=fort-worth",
]
quantities = [
"2026-10-07 wages 170.00 USD work assignment=P-100 client=northwind site=dallas",
"2026-10-08 wages 176.00 USD work assignment=P-200 client=contoso site=fort-worth",
]
contexts = [
"work 2026-10-07 07:00 assignment=P-100 [only_assignment] client=northwind [assignment:P-100] site=dallas [assignment:P-100]",
"work 2026-10-08 09:00 assignment=P-200 [only_assignment] client=contoso [assignment:P-200] site=fort-worth [assignment:P-200]",
]
Both clients approve their own placement's hours: every placement of the week approved, the bill side's timecard is approved as a whole, as if it had been approved at once, and the invoice of what is approved has both clients. The bill side counts its own overtime: the week's 46 hours are 6 past 40, the last, at Contoso
scenarios/the-bill-is-approved-once-every-client-has.toml
description = "Both clients approve their own placement's hours: every placement of the week approved, the bill side's timecard is approved as a whole, as if it had been approved at once, and the invoice of what is approved has both clients. The bill side counts its own overtime: the week's 46 hours are 6 past 40, the last, at Contoso"
punch = [
{ at = "2026-10-05 07:00", kind = "in", values = { work_code = "1" } }, { at = "2026-10-05 17:00", kind = "out" },
{ at = "2026-10-06 07:00", kind = "in", values = { work_code = "1" } }, { at = "2026-10-06 17:00", kind = "out" },
{ at = "2026-10-07 07:00", kind = "in", values = { work_code = "1" } }, { at = "2026-10-07 17:00", kind = "out" },
{ at = "2026-10-08 08:00", kind = "in", values = { work_code = "2" } }, { at = "2026-10-08 16:00", kind = "out" },
{ at = "2026-10-09 08:00", kind = "in", values = { work_code = "2" } }, { at = "2026-10-09 16:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
sides = ["pay", "bill"]
pay_periods = { every_days = 7, from = "2026-10-05" }
# Two placements at once, each at its client's site, picked by work code.
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
organizations = { clients = "northwind-dallas" }
[[assignment]]
id = "P-200"
defaults = { client = "contoso" }
organizations = { clients = "contoso-fort-worth" }
[[implication]]
when = { work_code = "1" }
then = { assignment = "P-100" }
[[implication]]
when = { work_code = "2" }
then = { assignment = "P-200" }
[[rate]]
kind = "bill"
matches = { assignment = "P-100" }
amount = 3000
currency = "USD"
[[rate]]
kind = "bill"
matches = { assignment = "P-200" }
amount = 3300
currency = "USD"
[[organization]]
hierarchy = "clients"
id = "northwind"
labels = { kind = "client" }
[[organization]]
hierarchy = "clients"
id = "northwind-dallas"
parent = "northwind"
labels = { kind = "site" }
[[organization]]
hierarchy = "clients"
id = "contoso"
labels = { kind = "client" }
[[organization]]
hierarchy = "clients"
id = "contoso-fort-worth"
parent = "contoso"
labels = { kind = "site" }
[[approval_rule]]
side = "bill"
subject = "assignment"
stages = ["client"]
organizations = { client = { hierarchy = "clients", select = "kind = client" } }
[[approval]]
subject = "bill:assignment:P-100:2026-10-05"
stage = "client"
decision = "approve"
by = "northwind:kim"
recorded = "2026-10-12 09:00"
[[approval]]
subject = "bill:assignment:P-200:2026-10-05"
stage = "client"
decision = "approve"
by = "contoso:lee"
recorded = "2026-10-12 11:00"
[expect.period]
day = "2026-10-05"
side = "bill"
approvals = [
"bill:assignment:P-100:2026-10-05 approved",
"bill:assignment:P-200:2026-10-05 approved",
]
approved = true
# Invoicing what is approved: both clients' hours.
[expect.export]
uses = "staffing_agency/invoice"
params = { rate = "bill", premiums = { work = 100, overtime = 150 }, approved_only = true }
side = "bill"
day = "2026-10-05"
file = """
client,worker,period_end,category,hours,amount
contoso,person,2026-10-11,overtime,6.00,297.00
contoso,person,2026-10-11,work,10.00,330.00
northwind,person,2026-10-11,work,30.00,900.00
"""
The bill side's hours wait for the client to approve them, at the client of the placement they were worked on: the stage says which organization the decision waits on, and the client's portal (the app) says who decides for it
scenarios/the-bill-waits-for-the-client.toml
description = "The bill side's hours wait for the client to approve them, at the client of the placement they were worked on: the stage says which organization the decision waits on, and the client's portal (the app) says who decides for it"
punch = [
{ at = "2026-10-05 08:00", kind = "in" }, { at = "2026-10-05 16:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
sides = ["pay", "bill"]
# The placement, at Northwind's Dallas site.
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
organizations = { clients = "northwind-dallas" }
# Clients, and their sites under them, as a hierarchy.
[[organization]]
hierarchy = "clients"
id = "northwind"
labels = { kind = "client" }
[[organization]]
hierarchy = "clients"
id = "northwind-dallas"
parent = "northwind"
labels = { kind = "site" }
# Each client approves what it is billed for its own placement: the bill
# side is approved placement by placement, each waiting on the client of
# its placement's site. The agency's payroll approves the pay side.
[[approval_rule]]
side = "bill"
subject = "assignment"
stages = ["client"]
organizations = { client = { hierarchy = "clients", select = "kind = client" } }
[[approval_rule]]
subject = "period"
stages = ["payroll"]
[expect.period]
day = "2026-10-05"
side = "bill"
approvals = ["bill:assignment:P-100:2026-10-05 pending client at northwind"]
approved = false
The client approves its placement's hours on the bill side: the worker's only placement approved, the bill side's timecard is approved
scenarios/the-client-approves-the-bill.toml
description = "The client approves its placement's hours on the bill side: the worker's only placement approved, the bill side's timecard is approved"
punch = [
{ at = "2026-10-05 08:00", kind = "in" }, { at = "2026-10-05 16:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
sides = ["pay", "bill"]
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
organizations = { clients = "northwind-dallas" }
[[organization]]
hierarchy = "clients"
id = "northwind"
labels = { kind = "client" }
[[organization]]
hierarchy = "clients"
id = "northwind-dallas"
parent = "northwind"
labels = { kind = "site" }
[[approval_rule]]
side = "bill"
subject = "assignment"
stages = ["client"]
organizations = { client = { hierarchy = "clients", select = "kind = client" } }
[[approval_rule]]
subject = "period"
stages = ["payroll"]
[[approval]]
subject = "bill:assignment:P-100:2026-10-05"
stage = "client"
decision = "approve"
by = "northwind:kim"
recorded = "2026-10-12 09:00"
[expect.period]
day = "2026-10-05"
side = "bill"
approvals = ["bill:assignment:P-100:2026-10-05 approved"]
approved = true
The client approved its placement's hours on the bill side; the pay side's timecard is the agency's, and still waits for its payroll stage
scenarios/the-clients-approval-is-the-bill-sides-alone.toml
description = "The client approved its placement's hours on the bill side; the pay side's timecard is the agency's, and still waits for its payroll stage"
punch = [
{ at = "2026-10-05 08:00", kind = "in" }, { at = "2026-10-05 16:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
sides = ["pay", "bill"]
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
organizations = { clients = "northwind-dallas" }
[[measure]]
id = "wages"
kind = "money"
currency = "USD"
[[rate]]
kind = "pay"
matches = { assignment = "P-100" }
amount = 2000
currency = "USD"
[[organization]]
hierarchy = "clients"
id = "northwind"
labels = { kind = "client" }
[[organization]]
hierarchy = "clients"
id = "northwind-dallas"
parent = "northwind"
labels = { kind = "site" }
[[approval_rule]]
side = "bill"
subject = "assignment"
stages = ["client"]
organizations = { client = { hierarchy = "clients", select = "kind = client" } }
[[approval_rule]]
subject = "period"
stages = ["payroll"]
[[approval]]
subject = "bill:assignment:P-100:2026-10-05"
stage = "client"
decision = "approve"
by = "northwind:kim"
recorded = "2026-10-12 09:00"
[expect.period]
day = "2026-10-05"
approvals = ["period:2026-10-05 pending payroll"]
approved = false
The same 22 hours at 20.00 with the earnings step paying into the money measure gross: the 440.00 is in gross, the measure the policy names, and none in wages
scenarios/the-pay-goes-in-the-measure-named.toml
description = "The same 22 hours at 20.00 with the earnings step paying into the money measure gross: the 440.00 is in gross, the measure the policy names, and none in wages"
punch = [
{ at = "2026-10-05 08:00", kind = "in" }, { at = "2026-10-05 15:20", kind = "out" },
{ at = "2026-10-06 08:00", kind = "in" }, { at = "2026-10-06 15:20", kind = "out" },
{ at = "2026-10-07 08:00", kind = "in" }, { at = "2026-10-07 15:20", kind = "out" },
]
[policy]
zone = "America/Chicago"
pay_periods = { every_days = 7, from = "2026-10-05" }
[[measure]]
id = "gross"
kind = "money"
currency = "USD"
[[measure]]
id = "wages"
kind = "money"
currency = "USD"
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
[[rate]]
kind = "pay"
matches = { assignment = "P-100" }
amount = 2000
currency = "USD"
# The worker's pay in the money measure gross.
[[layer]]
id = "gross"
order = 20
[[layer.step]]
id = "wages"
change = "params"
params = { measure = "gross" }
[expect]
week = "2026-10-05"
quantities = ["2026-10-07 gross 440.00 USD work assignment=P-100 client=northwind"]
A worker placed with two clients at once says at the clock which one each shift is for, by work code. Three 10-hour days at Northwind and two 8-hour days at Contoso are 46 hours: overtime is the week's last 6 hours, at Contoso. Paid, each hour is its straight time at its placement's rate, and the 6 overtime hours half the week's regular rate on top: 952.00 for 46 hours, 20.6956 an hour, 62.08; not half of Contoso's 22.00. Each client is billed its own hours at its own rates, and the invoice export writes a line per client and category
scenarios/two-clients-in-one-week.toml
description = "A worker placed with two clients at once says at the clock which one each shift is for, by work code. Three 10-hour days at Northwind and two 8-hour days at Contoso are 46 hours: overtime is the week's last 6 hours, at Contoso. Paid, each hour is its straight time at its placement's rate, and the 6 overtime hours half the week's regular rate on top: 952.00 for 46 hours, 20.6956 an hour, 62.08; not half of Contoso's 22.00. Each client is billed its own hours at its own rates, and the invoice export writes a line per client and category"
punch = [
{ at = "2026-10-05 07:00", kind = "in", values = { work_code = "1" } }, { at = "2026-10-05 17:00", kind = "out" },
{ at = "2026-10-06 07:00", kind = "in", values = { work_code = "1" } }, { at = "2026-10-06 17:00", kind = "out" },
{ at = "2026-10-07 07:00", kind = "in", values = { work_code = "1" } }, { at = "2026-10-07 17:00", kind = "out" },
{ at = "2026-10-08 08:00", kind = "in", values = { work_code = "2" } }, { at = "2026-10-08 16:00", kind = "out" },
{ at = "2026-10-09 08:00", kind = "in", values = { work_code = "2" } }, { at = "2026-10-09 16:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
sides = ["pay", "bill"]
pay_periods = { every_days = 7, from = "2026-10-05" }
[[measure]]
id = "wages"
kind = "money"
currency = "USD"
# Two placements at once, each with the work code its shifts are punched
# with.
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
[[assignment]]
id = "P-200"
defaults = { client = "contoso" }
[[implication]]
when = { work_code = "1" }
then = { assignment = "P-100" }
[[implication]]
when = { work_code = "2" }
then = { assignment = "P-200" }
[[rate]]
kind = "pay"
matches = { assignment = "P-100" }
amount = 2000
currency = "USD"
[[rate]]
kind = "bill"
matches = { assignment = "P-100" }
amount = 3000
currency = "USD"
[[rate]]
kind = "pay"
matches = { assignment = "P-200" }
amount = 2200
currency = "USD"
[[rate]]
kind = "bill"
matches = { assignment = "P-200" }
amount = 3300
currency = "USD"
[expect]
week = "2026-10-05"
allocations = [
"2026-10-05 07:00-17:00 work 10.00 assignment=P-100 client=northwind work_code=1",
"2026-10-06 07:00-17:00 work 10.00 assignment=P-100 client=northwind work_code=1",
"2026-10-07 07:00-17:00 work 10.00 assignment=P-100 client=northwind work_code=1",
"2026-10-08 08:00-16:00 work 8.00 assignment=P-200 client=contoso work_code=2",
"2026-10-09 08:00-10:00 work 2.00 assignment=P-200 client=contoso work_code=2",
"2026-10-09 10:00-16:00 overtime 6.00 assignment=P-200 client=contoso work_code=2",
]
quantities = [
"2026-10-07 wages 600.00 USD work assignment=P-100 client=northwind work_code=1",
"2026-10-09 wages 62.08 USD overtime",
"2026-10-09 wages 132.00 USD overtime assignment=P-200 client=contoso work_code=2",
"2026-10-09 wages 220.00 USD work assignment=P-200 client=contoso work_code=2",
]
[expect.export]
uses = "staffing_agency/invoice"
params = { rate = "bill", premiums = { work = 100, overtime = 150 } }
side = "bill"
day = "2026-10-05"
file = """
client,worker,period_end,category,hours,amount
contoso,person,2026-10-11,overtime,6.00,297.00
contoso,person,2026-10-11,work,10.00,330.00
northwind,person,2026-10-11,work,30.00,900.00
"""
A worker placed with two clients punches without a work code: the shift could be either client's, so it is kept with no placement and an assignment_ambiguous exception asks someone to say which, rather than bill a guess. With no placement, no pay rate matches it either: no_rate asks for one, and nothing is paid at a guess
scenarios/two-placements-and-no-work-code-asks.toml
description = "A worker placed with two clients punches without a work code: the shift could be either client's, so it is kept with no placement and an assignment_ambiguous exception asks someone to say which, rather than bill a guess. With no placement, no pay rate matches it either: no_rate asks for one, and nothing is paid at a guess"
punch = [
{ at = "2026-10-05 07:00", kind = "in" }, { at = "2026-10-05 15:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
[[assignment]]
id = "P-100"
defaults = { client = "northwind" }
[[assignment]]
id = "P-200"
defaults = { client = "contoso" }
[[implication]]
when = { work_code = "1" }
then = { assignment = "P-100" }
[[implication]]
when = { work_code = "2" }
then = { assignment = "P-200" }
[expect]
week = "2026-10-05"
allocations = ["2026-10-05 07:00-15:00 work 8.00"]
exceptions = [
{ kind = "assignment_ambiguous", at = "2026-10-05 07:00" },
{ kind = "no_rate", at = "2026-10-05 07:00" },
]
Work on a day no placement covers (the placement ended Wednesday, and the worker punched in on Thursday) has no client to bill: it is kept as punched, with no assignment, and an exception asks someone to say which client it was for. With no placement, no pay rate matches it either: no_rate asks for one
scenarios/work-outside-every-placement-is-flagged.toml
description = "Work on a day no placement covers (the placement ended Wednesday, and the worker punched in on Thursday) has no client to bill: it is kept as punched, with no assignment, and an exception asks someone to say which client it was for. With no placement, no pay rate matches it either: no_rate asks for one"
[policy]
zone = "America/Chicago"
[[dimension]]
id = "client"
required = true
[[assignment]]
id = "P-100"
from = "2026-10-05"
to = "2026-10-07"
defaults = { client = "northwind", site = "dallas" }
[[punch]]
at = "2026-10-08 07:00"
kind = "in"
[[punch]]
at = "2026-10-08 15:00"
kind = "out"
[expect]
week = "2026-10-05"
allocations = ["2026-10-08 07:00-15:00 work 8.00"]
exceptions = [
{ kind = "context_missing", at = "2026-10-08 07:00" },
{ kind = "no_rate", at = "2026-10-08 07:00" },
]