Build a Diary and Job Sheet for a One-Van Electrician
A self-employed electrician keeps her diary on paper and her prices in her head, and has booked two customers into the same hour. You will build the small diary and job sheet that refuses overlapping visits, adds up each job, and bills a finished job exactly once, in whatever language and shape you choose.
The brief
The client
I am an electrician. I work alone from a van, doing about five visits a day for homeowners and small shops: sockets, fuse boards, the odd rewire of one room.
My diary is a paper book and my prices live in my head. On a Thursday I wrote two customers into the 10:00 slot because one phoned while I was on a ladder, and I found out when both of them were standing on the doorstep at ten.
I also found a finished job I had never invoiced, and only because the customer asked for a receipt. I want one place that tells me what my day looks like, what each job costs, and which finished jobs still need a bill.
The problem
She writes visits in a paper diary and prices jobs from memory, so a phone call taken at the wrong moment books two customers into the same hour. Each double booking costs her a customer's trust and a rushed afternoon. A finished job leaves no trace that says "not billed yet", so some work is done and never charged, which is money for work she already did.
The client's name and figures are invented for this brief; the rules and the failures are ones that real businesses of this kind work with.
The spec
Requirements
- Record a customer and a job request for them, and list the jobs that are not yet booked.
- Book a visit for a job at a start time and a length in minutes, and refuse a visit that overlaps another active visit or falls outside working hours. A refused visit saves nothing.
- Show one day as a list of visits in time order, with the free gaps between them inside working hours.
- Cancel a visit so its time is free again and the job goes back to being a request. Cancel a job so it leaves the diary for good, and cancel its visit with it.
- Add job sheet lines to a job and show the job's total, worked out from the lines.
- Mark a booked job as done, and list the done jobs that still have no invoice.
- Bill a done job: it gets the next invoice number and its lines can no longer change. Billing the same job again returns the same number and creates nothing new. List the billed jobs with their invoice numbers.
Deliverables
- A program you can run on your own machine, in the language and shape you chose (a command-line tool, a web page, or an API that other programs call by sending requests), with a README that gets a reviewer from a fresh copy to a billed job in 10 minutes.
- The written diary and billing rules from the first Phase, kept in your repository.
- A test file for the diary, code that drives the program and checks its answers against what you expect, that covers the edges named in the second Phase.
- The written expected numbers and the final report for one full working week, saved in the README.
Out of scope
- Two people booking the same slot at the same moment. I take one call at a time; simultaneous bookers are a later problem for a firm with a dispatcher.
- Several technicians, skills and territories. One electrician keeps the diary to one calendar.
- The phone working without signal, and merging edits made offline. Everything here runs online.
- Stock in the van, parts reservations and suppliers. A part is a line with a price on the job sheet and nothing more.
- Quotes the customer accepts, variations on site, refunds and disputes. A job is priced from the lines I type.
- Taking payment and chasing it. Billing ends at an invoice number.
- Tax, VAT, gas work and inspection certificates. These differ by country and regulation, and one flat total in cents keeps the maths checkable.
- Texting or emailing the customer. Show the arrival time on screen or in the output.
- Travel time between visits and routing. Visits are separated by what I write, not by a map.
- Accounts and logins. One electrician uses the tool, so it has no sign-in. Do not put it on the internet, because anyone who can reach it can read and change every customer and invoice.
Architectural constraints
- Money is a whole number of cents, and every price and total is shown that way.
- A visit start is a date and a time of day in the electrician's one place, which is local time in Europe/Amsterdam. A visit at 10:00 on one day is a different visit from one at 10:00 on another day.
- Two visits where one ends at the minute the next one starts do not overlap.
- A job moves forward only: requested, booked, done, invoiced. A cancelled job stays cancelled, and any other change is refused.
- A refused action changes nothing. A booking never leaves a visit without a booked job, or a booked job without its visit.
- You choose the language, the framework and the shape. Everything this brief asks for is stated as what a person does and what they see or get back.
Prerequisites
You can write a small program in a language of your choice and you have saved data to a database or a file once. You do not need to know any framework, and you do not need to have written an automated test. You do not need to know how a one-van electrician runs her diary and bills her jobs; the first Phase explains the business and the words the brief uses.
Free to start. An account is what keeps track of the checkpoints you finish.
Know the jobs
Produces the written diary and billing rules, a program that stores customers and jobs, and job sheet lines with a total. No diary yet.
Acceptance criteria
You decide, for each limit of the diary, which visits fit just before the limit, at it and just after it, and write the answers in a document in your repository. The document also lists at least 6 rules, one sentence each, and a person who has never seen the code can read it. The limits are the working hours and days, which are Monday to Friday from 08:00 to 17:00 local time, and the shortest and longest visit, which are 15 and 240 minutes.
Each limit is worked as three cases, with the answer accepted or refused for each:
- Length, with the visit starting at 10:00: 14 minutes is refused, 15 and 16 are accepted, 239 and 240 are accepted, 241 is refused.
Acceptance criteria
After recording a customer "Mrs Okafor, phone 06 1234 5678, 12 Elm Row" and a job "replace a fuse board" for her, the list of open requests shows that job under her name with the status requested. Stopping the program, starting it again and listing again shows the same data.
A job with an empty description is refused with a message a person can read, and nothing is saved. A job for a customer that does not exist is refused the same way. A customer with an empty name is refused.
Two jobs for the same customer both appear in the list, and the list shows nothing for a job that is not requested.
Architectural guidance
A job saved with an empty description becomes a blank line on the electrician's list. A job for a customer who does not exist has no address to drive to, and she finds that out in the van. A refusal that does not say which field was wrong sends her back to guess. Data that is gone after a restart is worse than none, because she will have stopped writing it on paper.
Acceptance criteria
Adding the line "labour", quantity 2, price 6500 cents, and the line "consumer unit", quantity 1, price 14900 cents, to a job shows a job total of 27900 cents. Adding a third line "cable", quantity 3, price 300 cents, changes the total to 28800 cents.
A quantity of 0 is refused and a negative price is refused, and in both cases the total stays what it was. Prices are entered and shown as whole numbers of cents, so 6500 and not 65.00.
Changing the price of one line and asking for the total again shows the new total with no other step. The total shown for a job always equals quantity times price added up over its lines, after any sequence of additions and changes.
Architectural guidance
Some decimal amounts cannot be held exactly by a computer, so 0.1 plus 0.2 does not come out as 0.3, and a few lines of arithmetic can drift.
Architectural walkthrough
How a one-van electrician runs her day
A self-employed electrician works alone from a van. She does about five visits a day for homeowners and small shops: sockets, fuse boards, now and then the rewire of one room. Customers phone to ask for work, often while she is on a ladder, and she has to fit each one into her day on the spot.
A piece of work starts as a request from a customer. She books it as a visit at a start time for a number of minutes, does the work, and then bills it. The bill is built from the lines on the job sheet, which hold what she charged for, parts included, each with a price. After a billed job, the invoice number is what she and her customer both refer to, and her accountant sees the numbers too.
The words this brief uses:
Job: one piece of work for one customer. It moves from requested to booked, done and invoiced, and a cancelled job stays cancelled.
Visit: the time she is at the customer's door, from a start time for a length in minutes.
Working hours: the hours of the day she takes visits in.
Job sheet: the list of lines that make up the price of one job.
Job total: the sum of the lines on a job sheet, in cents.
Invoice number: the number a billed job gets, in sequence, used once.
Why the rules are written down first
The electrician's mistakes came from rules that lived in her head. A rule nobody wrote down gets applied differently each time it comes up, so the diary and the job sheet she ends up with disagree with the way she actually works. Touching visits are the case to settle early, because a one-minute difference decides whether a customer is turned away.
The second problem is the price of a job. A job sheet whose total disagrees with its lines means she quotes one figure and bills another. Amounts that are a cent out show up on an invoice, and a customer who finds one stops trusting the rest. Nothing in this Phase is hard to write, and each shortcut here shows up as a wrong number in the last Phase.
Fill the diary
Produces visits that book a job into the diary, a refusal when a visit does not fit, a day view with its free time, cancellation that frees time, and a test file that pins the edges. No billing yet.
Acceptance criteria
Booking "Tuesday 3 Nov 2026 at 10:00 for 90 minutes" for a requested job creates a visit that is shown as 10:00 to 11:30, and the job's status becomes booked. Both changes are visible together: the job shows the status booked and the visit 10:00 to 11:30.
A job that is already booked, done or cancelled cannot get a second visit, and the refusal says why. A length of 14 minutes is refused, 15 is accepted, 240 is accepted and 241 is refused. A visit for a job that does not exist is refused.
What you see always agrees: a job shown as booked has exactly one active visit, and a job shown as requested has none, including after a booking is refused or the program is stopped partway through. A visit at 10:00 on Tuesday and one at 10:00 on Wednesday are different visits.
Architectural guidance
A booking that is only half recorded leaves the diary and the job list telling different stories. The list says a customer is still waiting while a visit already sits in the diary, or the diary holds a visit for a job that still shows as requested, and she books that customer a second time. A check that looks only at the hour of the day passes on Tuesday and fails on Wednesday, so use dates in every example you try.
Acceptance criteria
With an active visit from 10:00 to 11:30 on Tuesday 3 Nov 2026, a visit from 11:00 to 12:00 that day is refused, nothing is saved, and the job stays a request. A visit from 11:30 to 12:30 is accepted, and so is one from 09:00 to 10:00.
A visit starting at 16:30 for 60 minutes is refused because working hours end at 17:00, and a visit from 16:00 to 17:00 is accepted. A visit starting at 07:30 is refused. A visit on Saturday 7 Nov 2026 is refused.
A visit that sits entirely inside another one is refused, and so is a visit with exactly the same start and length. A cancelled visit never causes a refusal.
Architectural guidance
A cancelled visit that still blocks its slot costs her a booking she could have had. A refused visit that leaves the job half booked hides the request from her list, so the customer is never called back.
Acceptance criteria
For a day with visits from 09:00 to 10:30 and from 13:00 to 14:00, the day view lists them in time order and shows the free gaps 08:00 to 09:00, 10:30 to 13:00 and 14:00 to 17:00. It shows free time of 390 minutes, which is the 540 working minutes minus the 150 visit minutes.
A day with no visits shows one free gap from 08:00 to 17:00. A Saturday shows no working hours and no free time. Booking one more visit and asking again shows the updated gaps without any other action.
Booking the 13:00 visit before the 09:00 visit gives the same day view as booking them in the other order. Cancelling a visit and asking again gives the new gaps with no other step.
Architectural guidance
If the day view disagrees with the visits, the diary offers a slot that is already taken or hides one that is free. The first sends two customers to the same door. The second leaves an hour empty that she could have sold. These faults appear after a cancellation and when visits were booked out of time order, so check both before you trust the view.
Acceptance criteria
Cancelling the 10:00 to 11:30 visit makes that span appear as free time on that day, the job's status goes back to requested, and the same slot can then be booked for a different job. Cancelling the same visit a second time changes nothing, and the program carries on normally.
Cancelling a booked job also cancels its visit and frees the time, and the job is marked cancelled and no longer appears in the open requests. Cancelling a requested job marks it cancelled. A cancelled job cannot be booked again.
A job that is done or invoiced cannot be cancelled, and the refusal says so. Cancelling a visit on a done or invoiced job is refused too.
Architectural guidance
A job that can jump to any status eventually does. A cancelled job gets marked done and billed, so a customer pays for work that never happened, or a done job loses its visit and the record shows work with nothing booked. A cancel sent twice, by a double tap or a repeated command, must neither fail nor disturb another job that has since taken the same slot.
Acceptance criteria
A test file runs on one command and prints a pass or fail for each case. It covers: two visits that exactly touch, one minute of overlap, a visit that contains another, a visit identical to another, a visit that ends exactly at 17:00, a visit that starts before 08:00, and cancel then rebook the same slot. All cases pass.
You then make the program wrongly refuse touching visits for a moment, run the tests, and at least one test fails. You show this by pasting the failing output into the README, then undo the change and the tests pass again.
Each test starts from an empty diary, and running the tests in reverse order gives the same results.
Architectural guidance
Diary mistakes sit at the boundaries: visits that touch, one minute over, closing time. A later change that quietly breaks one of them turns customers away or double books them, and nobody notices until a person is standing on a doorstep. A test that has never failed may not check what you think it checks. Tests that pass only because another test left data behind pass on one run and fail on the next, and the result tells her nothing.
Architectural walkthrough
A visit that ends at 10:00 and one that starts at 10:00 do not clash. A first version that refuses them turns away a booking the electrician would happily take, and one that misses a visit sitting inside another sends two customers to the same door. The Thursday double booking was exactly that failure, done by memory.
The day view and a booking that is only half recorded are the other two problems. Each leaves the diary and the job list telling different stories.
Finish and bill
Produces jobs marked done, a list of work not yet billed, one invoice number per job, and a full working week run that proves the whole. No payments.
Acceptance criteria
Marking a booked job done changes its status to done. Marking a requested job done is refused, and so is marking a cancelled job done, and the refusal names the job's current status.
The list of done jobs that are not yet billed shows exactly the done jobs. A job that is booked, requested or cancelled does not appear in it. After a job is invoiced in the next Checkpoint it drops out of the list.
Marking a job done does not need the visit to have started, so marking a job done on the morning of its visit works.
Architectural guidance
The electrician found a finished job she had never billed only because the customer asked for a receipt. If the list of unbilled work disagrees with the jobs, finished work is invisible again and she works for nothing. A cancelled or never visited job on that list means she bills a customer for work nobody did.
Acceptance criteria
Billing a done job gives it invoice number 1. Billing a second done job gives it number 2. Billing the first job again returns number 1, creates no new invoice, and the list of billed jobs still shows exactly two entries with the numbers 1 and 2.
Billing a booked job, a requested job or a cancelled job is refused, and the refusal uses no number: the next job to be billed still gets 3. After a job is invoiced, adding a job sheet line to it is refused and its total does not change.
Stopping the program and starting it again does not change any invoice number, and the next job billed continues the sequence. If the program is stopped partway through billing, the job afterwards is either invoiced with a number or still done with none, and no number is lost or shared.
The invoice number belongs to the job once given and is shown with the job. The job's status is invoiced.
Architectural guidance
A repeated invoice number, a gap in the numbers or one job billed twice is what her customers and her accountant notice. A double tap or a repeated command can ask a customer to pay twice. A bill that is refused because the job is not done must not use up a number, or the paper sequence shows a hole with nothing to explain it. A number already printed on an invoice must never come round again, whatever happened to the program in between.
Acceptance criteria
Before running anything, write down the expected results in the README: the billed totals per invoice, the one done job that is still unbilled, and the free hours left on one chosen day. Then run one week through the program, by script or by hand, that covers: five jobs requested, four of them booked across two days, one overlapping visit refused, one visit cancelled and booked again at another time, the fifth job cancelled, three jobs marked done, two of those billed, one of the two billed a second time, and the cancelled job refused when billed.
The final report lists each invoice number with its job and total, shows the done job that is not billed, and shows the free hours left on the chosen day. It matches the numbers you wrote down, and the invoice numbers are exactly 1 and 2 with no gap. The report is saved in the README.
Where the report differs from the written numbers, you find out which one is wrong and say so in the README.
Architectural guidance
If you only compare the program's output with what it printed last time, a wrong rule stays wrong and still passes. Faults between features, such as a cancelled visit that still blocks a slot or a refused bill that eats an invoice number, show up only in a run through a whole week in the order she would use it. Choose numbers that make a wrong answer obvious, and work them out by hand from the rules page you wrote in the first Phase. When the run and your hand calculation disagree, one of them is wrong, and finding which tells you whether the program or the rules page needs fixing.
Architectural walkthrough
A job must be billed once, only when it is done, with the next number in a sequence that has no repeats and no gaps.
The final Checkpoint adds a check you can run without reading the code: write the expected numbers first, then compare them with what the program prints.
Architectural walkthrough
One person cannot be in two places
The whole project turns on one rule: a visit that overlaps another visit, or falls outside working hours, is refused whole. If she has a visit from 10:00 to 11:30 and a customer asks for 11:00 to 12:00, the answer is no and nothing is saved. A visit from 11:30 to 12:30 is fine, because the first one has ended. Cancelling a visit gives its time back.
The Thursday double booking was this check, done by memory. Your program does it the same way every time, which is the only reason to build it.
Why a diary drifts
A diary that shows free time the visits do not support is the Thursday mistake again, now with a program to blame. It tends to appear after a cancellation, or when visits were entered out of time order, so those are the cases to try first. A job total or a list of unbilled work that disagrees with the jobs and lines behind it does the same damage: she quotes one price and bills another, or finished work drops out of sight and goes unpaid.
The overlap check has its own failures. A check that looks only at the hour of the day passes on Tuesday and fails on Wednesday. A check that treats a visit ending at 11:30 and one starting at 11:30 as a clash refuses a booking she would happily take. Try every rule with real dates, and with visits that touch.
Billing has its own failures
A cancelled job that can still be marked done and billed charges a customer for work that never happened. A repeated invoice number, or a gap in the numbers, is what her customers and her accountant notice first. A double tap or a repeated command can ask a customer to pay twice. A bill refused because the job is not done must not use up a number, and stopping the program partway through billing must not lose a number or hand it out twice. Check each of these in your own build, then restart the program and check them again.
What you chose not to build
You left out two bookers at the same moment, several electricians and a phone that works without signal. Those are where a diary stops being simple. The next project up from this one is Build an Offline Job System for a Plumbing and Heating Firm, which works with more than one person and more than one trade.
Where it shows if you cut a corner
Four symptoms show a cut corner. A diary that shows free time after a cancellation, or after visits entered out of time order, means the free time is kept apart from the visits. A booking refused on Wednesday that was accepted on Tuesday, or a visit from 11:30 refused after one that ends at 11:30, means the overlap check looks at the hour and not the date, or counts touching visits as a clash. A cancelled job that can still be marked done and billed means a customer pays for work that never happened. A repeated or missing invoice number, or a number used up by a refused bill or a restart, means numbering is kept apart from billing.