// lic : GPL, v2 $page_name = "manage_bills.php"; $db_name = "procrec"; $record_name = "Manage Patient Bills"; include ("lib/freemed.php"); include ("lib/API.php"); freemed_open_db ($LoginCookie); freemed_display_html_top(); freemed_display_banner(); switch ($action) { // master action switch case "list": // procduce a list only. Don't acutally process any bills $query = "SELECT procrec.procbilled,procrec.procdtbilled, procrec.procbalcurrent,patient.ptlname,patient.ptfname, patient.id FROM procrec,patient WHERE procrec.procbalcurrent > '0' AND procrec.procpatient = patient.id ORDER BY patient.ptlname "; $result = $sql->query($query); if (!$result) DIE("Error
"); if ($result) { freemed_display_box_top($record_name); freemed_display_actionbar($page_name, $_ref); echo " "; // header of box $total_unpaid = 0.00; // setup control break $prev_patient="$$"; $patient_balance = 0.00; $billed = 1; $_alternate = freemed_bar_alternate_color (); while ($r = $sql->fetch_array($result)) { $id = $r["id" ] ; $ptlname = $r["ptlname" ] ; $ptfname = $r["ptfname" ] ; $procbalcurrent = $r["procbalcurrent"]; $procbilled = $r["procbilled"]; $procdtbilled = $r["procdtbilled"]; if ($prev_patient=="$$") // first time { $prev_patient = $id; $prev_lname = $ptlname; $prev_fname = $ptfname; $oldest_bill = "0000-00-00"; } // alternate the bar color if ($id != $prev_patient) { // alternate the bar color echo " "; if (!$billed) echo ""; else echo ""; echo ""; $total_unpaid += $patient_balance; // add to grand total echo ""; // reset control break $patient_balance = 0.00; //$oldest_bill = $procdtbilled; $oldest_bill = "0000-00-00"; $billed = 1; $prev_patient = $id; $prev_lname = $ptlname; $prev_fname = $ptfname; echo ""; } $patient_balance += $procbalcurrent; if ($procdtbilled > "0000-00-00") { if ($oldest_bill == "0000-00-00") $oldest_bill = $procdtbilled; else if ($procdtbilled < $oldest_bill) $oldest_bill = $procdtbilled; } // it only takes 1 unbilled to show NO if (!$procbilled) $billed = 0; } // while there are no more // process last record from control break; echo " "; if (!$billed) echo ""; else echo ""; echo ""; $total_unpaid += $patient_balance; // add to grand total echo ""; // end control break // process totals. echo " "; echo "
Name Billing Functions Procedures Billed Date Billed Balance
$prev_lname, $prev_fname View/Manage Patient Ledger View/Manage  NO YES$oldest_bill".bcadd($patient_balance,0,2)."
$prev_lname, $prev_fname View/Manage Patient Ledger View/Manage  NO YES$oldest_bill".bcadd($patient_balance,0,2)."
Total           ".bcadd($total_unpaid,0,2)."
"; freemed_display_box_bottom(); } // end of result set break; } // end action freemed_display_html_bottom (); freemed_close_db (); ?>