Fix tip rounding at every step and bar staff FOH pool participation#1
Conversation
- Round ccFees, kitchenPool, and barPool to the nearest dollar when roundToDollar:true so all displayed pool totals are whole dollars (no more $131.63 / $307.12 / $282.12 in the breakdown) - Bar staff now participate in the FOH pool split alongside FOH staff and receive fohShare + barPoolShare (previously received bar pool only) - Update FOH section header divisor to include bar staff count - Update tests to reflect new rounding values and bar behavior https://claude.ai/code/session_01XVxvLCrTE8DWaJHMGEcyrA
There was a problem hiding this comment.
Pull request overview
This PR updates the tip-splitting calculation to (1) round key intermediate amounts to whole dollars when roundToDollar: true and (2) include bar staff as participants in the FOH pool split (while still receiving their bar pool share).
Changes:
- Round CC fees, kitchen pool, and bar pool to the nearest dollar when
roundToDollaris enabled, producing whole-dollar pool totals and payouts. - Include Bar staff in the FOH pool participant set and adjust distribution logic so Bar receives
fohShare + barPoolShare. - Update UI + tests to reflect new FOH divisor and new distribution/rounding behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/routes/calculate/[id]/+page.svelte |
Updates FOH per-person header divisor to include bar staff count. |
src/lib/calculator.ts |
Implements whole-dollar rounding for intermediate amounts and includes bar staff in FOH pool participation; updates distribution logic accordingly. |
src/lib/calculator.test.ts |
Updates expectations to match new rounding behavior and bar participation in FOH pool. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for (let i = 0; i < barStaff.length; i++) { | ||
| const cents = barDollars[i] * 100; | ||
| const fohCents = fohDollars[fohStaff.length + i] * 100; | ||
| const barCents = barDollars[i] * 100; | ||
| distributions.push({ staffId: barStaff[i].id, name: barStaff[i].name, role: 'Bar', | ||
| fohShareCents: 0, barPoolShareCents: cents, kitchenShareCents: 0, totalCents: cents }); | ||
| fohShareCents: fohCents, barPoolShareCents: barCents, kitchenShareCents: 0, totalCents: fohCents + barCents }); | ||
| } |
There was a problem hiding this comment.
Bar distributions now set a non-zero fohShareCents, but the Distribution interface comment still says fohShareCents is 0 for Bar/Kitchen. Please update the type/interface docs to reflect the new model (Bar participates in FOH pool).
| it('5 FOH servers split $820.25 among 6 (FOH+Bar) → $136.70 each (floor $136, 5¢ remainder to first 5)', () => { | ||
| // fohPool = 82025 cents, 6 participants: floor(82025/6) = 13670, remainder = 82025 - 13670*6 = 5 | ||
| // first 5 get 13671, last gets 13670 | ||
| expect(foh).toHaveLength(5); | ||
| foh.forEach(d => expect(d.totalCents).toBe(16405)); // $164.05 | ||
| foh.forEach(d => { | ||
| expect(d.totalCents === 13671 || d.totalCents === 13670).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| it('bartender gets bar pool share only: $96.50', () => { | ||
| it('bartender gets FOH share + bar pool share: FOH $136.70ish + bar $96.50', () => { | ||
| expect(bar).toHaveLength(1); | ||
| expect(bar[0].totalCents).toBe(9650); // $96.50 | ||
| expect(bar[0].fohShareCents).toBe(0); | ||
| // bartender gets the 6th FOH share (13670 or 13671) + bar pool 9650 | ||
| expect(bar[0].fohShareCents === 13671 || bar[0].fohShareCents === 13670).toBe(true); | ||
| expect(bar[0].barPoolShareCents).toBe(9650); | ||
| expect(bar[0].totalCents).toBe(bar[0].fohShareCents + 9650); |
There was a problem hiding this comment.
In the roundToDollar: false fixture, distributePoolCents assigns the 5¢ remainder to the first 5 participants in order. Since fohPoolParticipants is [...fohStaff, ...barStaff], all 5 FOH should always receive 13671¢ and the bartender should always receive 13670¢. The current assertions (13670 || 13671) contradict the comment above and make the test less effective; consider asserting the exact expected cents for FOH and Bar here.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot apply changes based on the comments in this thread |
Agent-Logs-Url: https://github.com/bradydibble/tip-split/sessions/f6c66255-fb26-49cc-a1bd-d356c49fced3 Co-authored-by: bradydibble <12791097+bradydibble@users.noreply.github.com>
Applied all three review changes in commit c354b3d:
|
fohPoolParticipantCounttoCalculationResultinterfaceDistribution.fohShareCentscomment to reflect Bar participationfohStaffCounttest assertion (now correctly 5) and addfohPoolParticipantCounttest (correctly 6)roundToDollar: falsetest to use exact values (all 5 FOH = 13671¢, bartender = 13670¢)