public function getAccountSummary() { $visitId = (int) $this->visitId; $total = 0; $billed = 0; $writeoff = 0; $balance = 0; $baseFee = 0; $adjustedFee = 0; $miscCharge = MiscCharge::total(array('visitId' => $visitId)); $payment = Payment::total(array('visitId' => $visitId)); $payment += Payment::unpostedTotal($visitId); $writeoff += WriteOff::total(array('visitId' => $visitId)); if ($this->closed) { $iterator = ClaimLine::mostRecentClaims($visitId); foreach ($iterator as $claimLine) { $baseFee += (double) $claimLine->baseFee; $adjustedFee += (double) $claimLine->adjustedFee; } } else { $fees = $this->calculateFees(); $baseFee += $fees['total']; $adjustedFee = $fees['discounted']; if (!$writeoff > 0 && $adjustedFee > 0) { $writeoff += $baseFee - $adjustedFee; } } $total = $baseFee + $miscCharge; $billed = $miscCharge; if ($adjustedFee > 0) { $billed += $adjustedFee; } if (!$billed > 0) { $billed = $total; } $balance = abs($total) - ($payment + $writeoff); if ($balance == $total) { $balance = $billed; } // use total billed if balance equals to total $ret = array(); $ret['total'] = $total; $ret['billed'] = $billed; $ret['payment'] = $payment; $ret['balance'] = $balance; $ret['writeoff'] = $writeoff; $ret['baseFee'] = $baseFee; $ret['adjustedFee'] = $adjustedFee; $ret['miscCharge'] = $miscCharge; if (isset($claimLine)) { $ret['claimLine'] = $claimLine; } return $ret; }