Skip to content

Commit

Permalink
Merge pull request openemr#7456 from stephenwaite/mobill
Browse files Browse the repository at this point in the history
couple billing commits for rel-702
  • Loading branch information
stephenwaite authored May 24, 2024
2 parents 7588b4f + ee4fcd1 commit 01cbcee
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
31 changes: 29 additions & 2 deletions interface/reports/front_receipts_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
// The OnClick handler for receipt display.
function show_receipt(pid,timestamp) {
dlgopen('../patient_file/front_payment.php?receipt=1&patient=' + encodeURIComponent(pid) +
'&time=' + encodeURIComponent(timestamp), '_blank', 550, 400, '', '', {
'&time=' + encodeURIComponent(timestamp), '_blank', 850, 550, '', '', {
onClosed: 'reload'
});
}
Expand Down Expand Up @@ -208,7 +208,7 @@ function show_receipt(pid,timestamp) {
if (!empty($_POST['form_refresh']) || !empty($_POST['form_orderby'])) {
?>
<div id="report_results">
<table class='table'>
<table class='table table-striped'>
<thead class='thead-light'>
<th> <?php echo xlt('Time'); ?> </th>
<th> <?php echo xlt('Patient'); ?> </th>
Expand Down Expand Up @@ -288,6 +288,15 @@ function show_receipt(pid,timestamp) {
<?php
$total1 += $row['amount1'];
$total2 += $row['amount2'];
$method = $row['method'];
if (empty($total1_by_method[$method])) {
$total1_by_method[$method] = 0;
}
$total1_by_method[$method] += $row['amount1'];
if (empty($total2_by_method[$method])) {
$total2_by_method[$method] = 0;
}
$total2_by_method[$method] += $row['amount2'];
}
?>

Expand All @@ -297,6 +306,24 @@ function show_receipt(pid,timestamp) {
</td>
</tr>

<?php
$method_keys = array_keys(array_unique(array_merge($total1_by_method, $total2_by_method)));
foreach ($method_keys as $method_key) { ?>
<tr class="report_totals_by_method">
<td colspan='5'>
<?php echo xlt('Totals by Method') . ' ' . text($method_key); ?>
<td align='right'>
<?php echo text(FormatMoney::getBucks($total1_by_method[$method_key])); ?>
</td>
<td align='right'>
<?php echo text(FormatMoney::getBucks($total2_by_method[$method_key])); ?>
</td>
<td align='right'>
<?php echo text(FormatMoney::getBucks($total1_by_method[$method_key] + $total2_by_method[$method_key])); ?>
</td>
</tr>
<?php } ?>

<tr class="report_totals">
<td colspan='5'>
<?php echo xlt('Totals'); ?>
Expand Down
21 changes: 16 additions & 5 deletions library/patient.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ function getAllinsurances($pid)
* @param int Optional encounter id. If value is passed, will fetch only bills from specified encounter.
* @return number The balance.
*/
function get_patient_balance($pid, $with_insurance = false, $eid = false)
function get_patient_balance($pid, $with_insurance = false, $eid = false, $in_collection = false)
{
$balance = 0;
$bindarray = array($pid);
Expand All @@ -1609,6 +1609,11 @@ function get_patient_balance($pid, $with_insurance = false, $eid = false)
$sqlstatement .= " AND encounter = ?";
array_push($bindarray, $eid);
}

if ($in_collection) {
$sqlstatement .= " AND in_collection = ?";
array_push($bindarray, 1);
}
$feres = sqlStatement($sqlstatement, $bindarray);
while ($ferow = sqlFetchArray($feres)) {
$encounter = $ferow['encounter'];
Expand Down Expand Up @@ -1641,10 +1646,16 @@ function get_patient_balance($pid, $with_insurance = false, $eid = false)
$balance += $ptbal;
}
} else {
// Including insurance or not out to insurance, everything is due.
$brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
"pid = ? AND encounter = ? AND " .
"activity = 1", array($pid, $encounter));
if (!$with_insurance && $ferow['last_level_closed'] >= $inscount && $in_collection) {
$brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
"pid = ? AND encounter = ? AND " .
"activity = 1", array($pid, $encounter));
} else {
// Including insurance or not out to insurance, everything is due.
$brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
"pid = ? AND encounter = ? AND " .
"activity = 1", array($pid, $encounter));
}
$drow = sqlQuery("SELECT SUM(pay_amount) AS payments, " .
"SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
"deleted IS NULL AND pid = ? AND encounter = ?", array($pid, $encounter));
Expand Down
2 changes: 2 additions & 0 deletions src/Patient/Cards/BillingViewCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private function setupBillingData()
$insurancebalance = get_patient_balance($pid, true) - $patientbalance;
$totalbalance = $patientbalance + $insurancebalance;
$unallocated_amt = get_unallocated_patient_balance($pid);
$collectionbalance = get_patient_balance($pid, false, false, true);

$id = self::CARD_ID . "_ps_expand";
$dispatchResult = $ed->dispatch(new RenderEvent('billing'), RenderEvent::EVENT_HANDLE);
Expand All @@ -79,6 +80,7 @@ private function setupBillingData()
'patientBalance' => $patientbalance,
'insuranceBalance' => $insurancebalance,
'totalBalance' => $totalbalance,
'collectionBalance' => $collectionbalance,
'unallocated' => $unallocated_amt,
'forceAlwaysOpen' => $forceBillingExpandAlways,
'prependedInjection' => $dispatchResult->getPrependedInjection(),
Expand Down
7 changes: 7 additions & 0 deletions templates/patient/card/billing.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
</div>
{% endif %}

{% if collectionBalance > 0 %}
<div class="row alert-danger">
<div class="col-4">{{ "Collection Balance"|xlt }}</div>
<div class="col">{{ collectionBalance|money|text }}</font></div>
</div>
{% endif %}

{% if billingNote %}
<div class="row">
<div class="col-4">{{ "Billing Note"|xlt }}</div>
Expand Down

0 comments on commit 01cbcee

Please sign in to comment.