Fix variable bill amount lost on paid toggle; revert gross/net protection

- PATCH paycheck-bills/:id/paid: variable bills now preserve amount_override
  rather than overwriting it with b.amount (which may be null/0). Fixed bills
  continue to lock in b.amount on paid and clear on unpaid.
- generatePaychecks: revert gross/net protection — refresh always updates
  gross/net from current settings as originally intended.
- CLAUDE.md: remove gross/net protection note; add td approve sub-agent rule.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-19 20:41:57 -04:00
parent 5aaa5cfed8
commit 6e771ad20b
2 changed files with 9 additions and 16 deletions

View File

@@ -159,20 +159,8 @@ async function generatePaychecks(year, month) {
VALUES ($1, $2, $3, $4, $5, $6)
ON CONFLICT (period_year, period_month, paycheck_number)
DO UPDATE SET pay_date = EXCLUDED.pay_date,
gross = CASE
WHEN EXISTS (
SELECT 1 FROM paycheck_bills pb
WHERE pb.paycheck_id = paychecks.id AND pb.paid = TRUE
) THEN paychecks.gross
ELSE EXCLUDED.gross
END,
net = CASE
WHEN EXISTS (
SELECT 1 FROM paycheck_bills pb
WHERE pb.paycheck_id = paychecks.id AND pb.paid = TRUE
) THEN paychecks.net
ELSE EXCLUDED.net
END
gross = EXCLUDED.gross,
net = EXCLUDED.net
RETURNING id`,
[year, month, num, payDate, gross || 0, net || 0]
);
@@ -474,7 +462,11 @@ router.patch('/paycheck-bills/:id/paid', async (req, res) => {
`UPDATE paycheck_bills pb
SET paid = $1,
paid_at = CASE WHEN $1 THEN NOW() ELSE NULL END,
amount_override = CASE WHEN $1 THEN b.amount ELSE NULL END
amount_override = CASE
WHEN b.variable_amount THEN pb.amount_override
WHEN $1 THEN b.amount
ELSE NULL
END
FROM bills b
WHERE pb.bill_id = b.id AND pb.id = $2
RETURNING pb.id, pb.paid, pb.paid_at, pb.amount_override`,