feat: wire copayment/adjustment into balance and collected calculations

Balance = totalBilled - mhPaidAmount - copayment - adjustment
Collected = mhPaidAmount + copayment (adjustment is a write-off)

- Frontend breakdown now shows Collected, Adjustment (if >0), and Balance
- Reports: totalCollected and totalOutstanding use the new formula
- Both date-range and staff summary queries updated

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Gitead
2026-05-06 21:36:04 -04:00
parent 4bd501250d
commit 49415bcfc4
2 changed files with 62 additions and 46 deletions

View File

@@ -634,7 +634,11 @@ export default function PaymentsRecentTable({
paymentsData?.payments.map((payment) => {
const totalBilled = Number(payment.totalBilled || 0);
const totalPaid = Number(payment.totalPaid || 0);
const totalDue = Number(payment.totalDue || 0);
const mhPaid = Number(payment.mhPaidAmount || 0);
const copayment = Number(payment.copayment || 0);
const adjustment = Number(payment.adjustment || 0);
const totalDue = Math.max(0, totalBilled - mhPaid - copayment - adjustment);
const totalCollected = mhPaid + copayment;
const displayName = getName(payment);
const submittedOn =
@@ -682,22 +686,25 @@ export default function PaymentsRecentTable({
</div>
</TableCell>
{/* 💰 Billed / Paid / Due breakdown */}
{/* 💰 Billed / Collected / Due breakdown */}
<TableCell>
<div className="flex flex-col gap-1">
<span>
<strong>Total Billed:</strong> $
{Number(totalBilled).toFixed(2)}
<strong>Total Billed:</strong> ${totalBilled.toFixed(2)}
</span>
<span>
<strong>Total Paid:</strong> ${totalPaid.toFixed(2)}
<strong>Collected:</strong> ${totalCollected.toFixed(2)}
</span>
{adjustment > 0 && (
<span>
<strong>Adjustment:</strong>{" "}
<span className="text-orange-600">-${adjustment.toFixed(2)}</span>
</span>
)}
<span>
<strong>Total Due:</strong>{" "}
<strong>Balance:</strong>{" "}
{totalDue > 0 ? (
<span className="text-yellow-600">
${totalDue.toFixed(2)}
</span>
<span className="text-yellow-600">${totalDue.toFixed(2)}</span>
) : (
<span className="text-green-600">Settled</span>
)}