Recording a payout · Dr Okafor
Illustrative amounts · real refusal
This month the doctor is owed less than they owe back. Somebody presses the button
anyway.
The batch, as assembled
unpaid payable
$150.00
refund adjustments
− $240.00
net to pay the doctor
$0.00 floored
AssembledWrite
Rolled back — the batch row was never inserted
$90.00
of doctor debt would have disappeared. Not written off, not
collected, not recorded anywhere — just gone, because a subtraction cannot go
below zero and the adjustment would have been marked settled regardless.
What it says instead, word for word
Refund adjustments (240.00) exceed the unpaid payable (150.00) for the selected
payments. A residual doctor debt of 90.00 CAD would be silently forgiven. Collect
it and record a debt settlement first, or include more unpaid payments in this payout.
The safest bug is the one nobody would ever have found.
So it refuses the whole transaction.
The net a payout pays out cannot be negative, so it floors at zero. On its own that
is correct — you do not hand a doctor a negative cheque. But the pass that
runs immediately afterwards marks every pending refund adjustment as settled, and
those two facts together are a hole: the $90.00 the doctor still owed would have
been cleared from the ledger while nothing was collected and nothing was written
down. No error, no warning, no row. It would simply have stopped being true.
So the guard does not adjust the number or log a note and carry on. It calls
tx.Rollback() — the batch insert, the payment stamps and the
adjustment clearing all go back as though the button had never been pressed
— and returns a message that names both amounts, states the residual in your
own currency, and gives you the two legitimate ways forward: collect the debt and
record it as a settlement, or add more unpaid payments to the payout so there is
enough to absorb it.
It is a small amount of money and an unlikely month. That is rather the point
— it is exactly the kind of case that is never noticed, never reported and
never fixed, because the only person who could have spotted it is the doctor, and
they would have had to be checking.