Take a look at this report file.
That's how the original programmer formatted it. Almost every mistake imaginable is in there. While I fix the thing I've posted the original for everyone to point and laugh.PHP Code:<?
class agingReport {
function run() {
$facility = $_SESSION['facility'];
$records = $GLOBALS['db']->dbQuery("select *,patientmedicineledgers.id as id, patients.id as patid from patientmedicineledgers left join patients on plpatientid = patients.id left join patientmedications on patientmedications.id = plmedid left join patientcoverage on ppinscoid1 = patientcoverage.id left join insco on insco.id = patientcoverage.pcinsco where facilityid = $facility order by insco.insconame,patients.lastname,patients.firstname");
$transactions = array();
$transactions["0-30"] = 0;
$transactions["31-60"]=0;
$transactions["61-90"] = 0;
$transactions["90"] = 0;
$billing = array();
foreach ($records as $record) {
$billdate = $record['procbilldate'];
if (!$billdate) {
$billdate = $record['ppdateofprocedure'];
}
if ($billdate) {
$time = time();
$result = $time-$billdate;
$days = $result/86400;
} else {
$days=0;
}
$transactionType = $record['pltransactiontype'];
$days = round($days);
//print_r($record);
if ($days >= 0 && $days <= 30) {
$key = "0-30";
} elseif($days >= 31 && $days <= 60) {
$key = "31-60";
} elseif($days >= 61 && $days <= 90) {
$key = "61-90";
} elseif($days > 90) {
$key = "90";
}
$insconame = $record['insconame'];
$patient = $record['lastname'] . ', '.$record['firstname']. ", ".$record['middlename'];
$patid = $record['patid'];
$amt = $record['pltransactionamt'];
if ($patid == 903) {
//print "$key - $billdate $amt <br>";
}
if (!isset($billing[$insconame][$patid])) {
if (!isset($billing[$insconame])) {
$billing[$insconame] =array();
}
$billing[$insconame][$patid] = array();
//$billing[$insconame]["insconame"] =$insconame;
$billing[$insconame][$patid]["0-30"] = 0;
$billing[$insconame][$patid]["31-60"]=0;
$billing[$insconame][$patid]["61-90"] = 0;
$billing[$insconame][$patid]["90"] = 0;
$billing[$insconame][$patid]["name"] = $patient;
$billing[$insconame][$patid]["insconame"] = $insconame;
//$patid = $record['patid'];
$billing[$insconame][$patid]["patientid"] = $patid;
}
$amount = $record['pltransactionamt'];
//print $key;
//if ($record['pltransactionamt'] !='0.00' && $record['insconame'] == "" ) {
//print_r($record);
//$id = $record['id'];
//print "{$record['id']}<br>";
//}
switch ($transactionType) {
case 2:
$billing[$insconame][$patid][$key] -= $amount;
break;
case 3:
$billing[$insconame][$patid][$key] -= $amount;
break;
case 4:
$billing[$insconame][$patid][$key] -= $amount;
break;
case 5:
$billing[$insconame][$patid][$key] += $amount;
break;
case 8:
$billing[$insconame][$patid][$key] += $amount;
//print "{$record['product']} p<br>";
//print "{$record['ppdateofprocedure']}<br>";
// print_r($record);
break;
}
}
$buffer = '';
$grands = array();
$grands["0-30"] =0;
$grands["31-60"] =0;
$grands["61-90"] =0;
$grands["90"] =0;
//print_r($billing);
foreach ($billing as $bill) {
/*
$buffer .='<tr><td class="reportviewl">'.$bill['name'].'</td>'.
'<td class="reportviewl30">$'.$pbill['0-30'].'</td>'.
'<td class="reportviewl31">$'.$pbill['31-60'].'</td>'.
'<td class="reportviewl61">$'.$pbill['61-90'].'</td>'.
'<td class="reportviewl91">$'.$pbill['91'].'</td></tr>';
*/
$t30day =0;
$t31day=0;
$t61day=0;
$t91day =0;
foreach ($bill as $pbill) {
$grands["0-30"] += $pbill['0-30'];
$grands["31-60"] += $pbill['31-60'];
$grands["61-90"] += $pbill['61-90'];
$grands["90"] += $pbill['90'];
$currentTotal = $pbill['0-30']+$pbill['31-60']+$pbill['61-90']+$pbill['90'];
if ($currentTotal != 0) {
$t30day+=$pbill['0-30'];
$t31day+=$pbill['31-60'];
$t61day+=$pbill['61-90'];
$t91day+=$pbill['90'];
$pbill['0-30'] = sprintf("%2f",$pbill['0-30']);
$pbill['31-60'] = sprintf("%2f",$pbill['31-60']);
$pbill['61-90'] = sprintf("%2f",$pbill['61-90']);
$pbill['90'] = sprintf("%2f",$pbill['90']);
$pbill['0-30'] = number_format($pbill['0-30'],2);
$pbill['31-60'] = number_format($pbill['31-60'],2);
$pbill['61-90'] = number_format($pbill['61-90'],2);
$pbill['90'] = number_format($pbill['90'],2);
$currentTotal = number_format($currentTotal,2);
$patientid = $pbill['patientid'];
$buffer .='<tr><td class="reportviewl">'.$pbill['insconame'].'</td>'.
'<td class="reportviewl"><a class="adminlink" href="'.$_SERVER["PHP_SELF"].'?module=MedLedger&func=ledgermanager&id='.$patientid.'">'.$pbill['name'].'</a></td>'.
'<td class="reportviewl30">$'.$pbill['0-30'].'</td>'.
'<td class="reportviewl31">$'.$pbill['31-60'].'</td>'.
'<td class="reportviewl61">$'.$pbill['61-90'].'</td>'.
'<td class="reportviewl91">$'.$pbill['90'].'</td>
<td class="reportviewl">$'.$currentTotal.'</td>
</tr>';
}
$ftotal = $t30day+$t31day+$t61day+$t91day;
$t30day = sprintf("%.2f",$t30day);
$t31day = sprintf("%.2f",$t31day);
$t61day = sprintf("%.2f",$t61day);
$t91day = sprintf("%.2f",$t91day);
$ftotal = number_format($ftotal,2);
}
//if ($currentTotal != 0) {
$buffer .='<tr><td class="reportviewl" colspan=2 align=center>INSURANCE TOTAL:</td>'.
'<td class="reportviewl30">$'.$t30day.'</td>'.
'<td class="reportviewl31">$'.$t31day.'</td>'.
'<td class="reportviewl61">$'.$t61day.'</td>'.
'<td class="reportviewl91">$'.$t91day.'</td>
<td class="reportviewl">$'.$ftotal.'</td>
</tr>';
// }
}
$total = $grands["0-30"] + $grands["31-60"] + $grands["61-90"] + $grands["90"];
$grands["31-60"] = sprintf("%.2f",$grands["31-60"]);
$grands["0-30"] = number_format($grands["0-30"],2);
$grands["31-60"] = number_format($grands["31-60"],2);
$grands["61-90"] = number_format($grands["61-90"],2);
$grands["90"] = number_format($grands["90"],2);
$total = number_format($total,2);
$buffer .='<tr><td class="reportviewl" colspan="2" align=center>TOTALS:</td>
<td class="reportviewl30">$'.$grands["0-30"].'</td>'.
'<td class="reportviewl31">$'.$grands["31-60"].'</td>'.
'<td class="reportviewl61">$'.$grands["61-90"].'</td>'.
'<td class="reportviewl91">$'.$grands["90"].'</td></tr><tr><td><b>Grand: $'.$total.'</b></td></tr>';
return $buffer;
}
function agingReport() {
}
}










Bookmarks