Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // includes/functions/global.php
- // functions that are essential to any and all pages.
- function checkcode($code, $surname, $firstname)
- {
- // This function takes a licence code and compares it to a doctor name to see if it is valid
- // Possible responses
- // 1 - Improperly formatted code or doctor name
- // 2 - Invalid code / doctor combination
- // 3 - Valid code / doctor but has expired
- // DATE RETURNED - Valid and not yet expired Gives date of expiry.
- $doctor = strtolower($surname . $firstname);
- $code = strtolower($code);
- if (strlen($code) != 17 or strlen(doctor) == 0) {
- $ret = 1;
- }
- if ($ret != 1) {
- $rdte = substr($code, 3, 5) . substr($code, -6, 3);
- $dte = strrev($rdte);
- $hsh = md5($dte . $doctor . $_SESSION['seed']);
- if (substr($code, 0, 3) != substr($hsh, 0, 3)) {
- $ret = 2;
- }
- if (substr($code, -3, 3) != substr($hsh, -3, 3)) {
- $ret = 2;
- }
- if (substr($code, 8, 3) != substr($hsh, 9, 3)) {
- $ret = 2;
- }
- }
- if ($ret != 1 and $ret != 2) {
- $tod = date("Y") . date("m") . date("d");
- if ($tod > $dte) {
- $ret = 3;
- }
- if ($tod <= $dte) {
- $ret = $dte;
- }
- }
- return $ret;
- }
- function checkdigit($num){
- $tot=0;
- for ($i=strlen($num)-1;$i>-1;$i--){
- $m=substr($num,$i,1);
- if ($i % 2 != 0){
- $m=$m*2;
- }
- if ($m > 9){
- $m=$m-9;
- }
- $tot=$tot+$m;
- }
- $u=10-($tot % 10);
- if ($u==10){
- $u=0;
- }
- return $u;
- }
- function ccval($number){
- $number=preg_replace('/\D/', '', $number);
- $number_length=strlen($number);
- $parity=$number_length % 2;
- $total=0;
- for ($i=0; $i<$number_length; $i++) {
- $digit=$number[$i];
- if ($i % 2 == $parity) {
- $digit*=2;
- if ($digit > 9) {
- $digit-=9;
- }
- }
- $total+=$digit;
- }
- return ($total % 10 == 0) ? TRUE : FALSE;
- }
- function checkdigit2($str){
- if (is_string($str)){
- for ($i=0;$i<strlen($str); $i++){
- $out = $out . Ord(substr($str,$i,1));
- }
- } else {
- $out=$str;
- }
- if ((int)(strlen($out)/2) == (int)((strlen($out)/2)+0.9))
- $m=0;
- else
- $m=1;
- for ($i=0;$i<strlen($out); $i++){
- $m=($m==1)?2:1;
- $v=$m*substr($out, $i, 1);
- if ($v>9)
- $v=(substr($v, 0, 1)+substr($v, 1, 1));
- $sum = $sum + $v;
- }
- $cd=(round($sum/10+0.49)*10) - $sum;
- return $cd;
- }
- function writelog($event){
- // figure out the filename first
- $logname = date("Ymd D, M j, Y") . ".log";
- $log = fopen($_SESSION['loglocation'] . $logname, "a");
- $stamp = date("Y:m:d H:i:s");
- if (isset($_SESSION['username'])) {
- $user = $_SESSION['username'];
- } else {
- $user = "No active user";
- }
- $user = str_pad(substr($user, 0, 15), 15, " ");
- $ip = str_pad($_SERVER['REMOTE_ADDR'], 15, " ");
- fwrite($log, $stamp . " " . $user . " " . $ip . " " . $event . PHP_EOL);
- fclose($log);
- }
- function convertdate($dte)
- {
- $month = array("", "January", "February", "March", "April", "May", "June",
- "July", "August", "September", "October", "November", "December");
- $yr = (int)substr($dte, 0, 4);
- $mo = (int)substr($dte, 4, 2);
- $dy = (int)substr($dte, 6, 2);
- $m = $month[$mo];
- return $m . " " . $dy . ", " . $yr;
- }
- function newcode()
- {
- $a = uniqid();
- $b = "abcdefghijklmnopqrstuvwxyz123456789";
- $c = $a . substr(str_shuffle($b), 0, 4);
- return $c;
- }
- function reducedate($inp)
- {
- $a = substr($inp, 6, 4) . substr($inp, 3, 2) . substr($inp, 0, 2);
- return $a;
- }
- function makebarcode($cd){
- $nm=$cd;
- include $_SESSION['pathToRoot']."setup/settings.php";
- // Function creates a barcode using input data $inp
- // and saves it to the default images/barcode directory
- // Filename is BC$cd.png
- // barcode is 150 X 30 pixels, black and white.
- // This is enough for 10 digits.
- $codestring="";
- $sum=104; // value of codeB start char
- for ($j=0;$j<strlen($cd);$j++) {
- $c=substr($cd,$j,1); // get a single chracter
- $a=ord($c)-32; // subtract 32 - printable charset starts at 32
- if ($a<0||$a>102) {
- // we have an unprintable character
- $a=31;
- }
- $c=chr($a+16);
- $codestring.=$c;
- // now the calc
- $sum+=($a*($j+1));
- }
- // finished with string, calc checsum
- $checksum=$sum % 103;
- $checksum+=16;
- $cd=chr(104+16) . $codestring . chr($checksum) . chr(106+16);
- $im = @imagecreate(150, 30) or die("Cannot Initialize new GD image stream");
- $background_color = imagecolorallocate($im, 255,255,255);
- $black = imagecolorallocate($im, 0, 0, 0);
- imagettftext($im, 25, 0, 0,28, $black, $fontpath."K128.TTF", $cd);
- imagepng($im,$barcodes."BC$nm.png");
- imagedestroy($im);
- }
- function insurerlist($order)
- {
- // This function creates an array that is a list of insurers and their codes.
- // If "order" is "a" the list is sorted alphabetically.
- // if "order" is "p" the list is sorted by insurer's popularity'
- // in "order" is "all" then all insurers are included, not just active ones.
- include $_SESSION['pathToRoot']."setup/settings.php";
- $query = "SELECT * FROM insurer WHERE insurerstatus=1";
- $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect error making insurer list.");
- $result = mysqli_query($con, $query) or die("SQL Query Error getting list of insurers.");
- $res = mysqli_num_rows($result);
- unset($lst);
- if ($res > 0) {
- while ($row = mysqli_fetch_assoc($result)) {
- extract($row);
- $lst[$cnt] = array("insname" => $insurername, "inscode" => $insurercode);
- $cnt += 1;
- }
- }
- return $lst;
- }
- function surgeonlist($doctor)
- {
- // This function creates an array that is a list of surgeons and thier codes.
- // The array contains ALL the active surgeons in the surgeon table.
- // If $doctor is specified (as a code, not as a name) the list is sorted according to
- // the popularity of that surgeon with that doctor.
- // ie. examine the last 1000 accounts this doctor has issued and see which surgeon is listed.
- // Rank the list according to the frequency of occurrence on this list.
- // Otherwise they are sorted alphabetically by surname.
- include "setup/settings.php";
- $query = "SELECT * FROM surgeon WHERE surgeonstatus=1";
- $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect error making surgeon list.");
- $result = mysqli_query($con, $query) or die("SQL Query Error getting list of surgeons.");
- $res = mysqli_num_rows($result);
- unset($lst);
- if ($res > 0) {
- while ($row = mysqli_fetch_assoc($result)) {
- extract($row);
- $lst[] = array("sname" => $surgeontitle . " " . $surgeonfirstname . " " . $surgeonlastname,
- "scode" => $insurercode);
- }
- }
- return $lst;
- }
- function hospitallist($doctor)
- {
- // This function creates an array that is a list of hospital and thier codes.
- // The array contains ALL the active hospital in the hospitals table.
- include "setup/settings.php";
- $query = "SELECT * FROM hospital WHERE hospitalstatus=1";
- $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect error making hospital list.");
- $result = mysqli_query($con, $query) or die("SQL Query Error getting list of hospital.");
- $res = mysqli_num_rows($result);
- unset($lst);
- if ($res > 0) {
- while ($row = mysqli_fetch_assoc($result)) {
- extract($row);
- $lst[] = array("hname" => $hospitalname, "hcode" => $hospitalcode);
- }
- }
- return $lst;
- }
- function doctorlist($option) {
- // This function creates an array that is a list of active doctors and thier codes.
- // The array contains ALL the active doctors in the doctors table.
- // IF $option is "exclude" then doctors that have no practices are excluded from the list.
- include "setup/settings.php";
- $query = "SELECT * FROM doctor WHERE doctorstatus=1";
- $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect error making doctor list.");
- $result = mysqli_query($con, $query) or die("SQL Query Error getting list of hospital.");
- $res = mysqli_num_rows($result);
- unset($lst);
- if ($res > 0) {
- while ($row = mysqli_fetch_assoc($result)) {
- extract($row);
- $query2 = "SELECT * FROM dplink WHERE dplinkdoctor=\"$doctorcode\" AND dplinkstatus=\"1\"";
- $result2 = mysqli_query($con, $query2) or die("SQL Query Error getting list of hospital.");
- if (mysqli_num_rows($result2) != 0 || $option != "exclude") {
- $lst[] = array("dname" => "$doctorfirstname $doctorlastname",
- "dcode" => $doctorcode);
- }
- }
- }
- return $lst;
- }
- function workingschedule ($date, $ins, $stt){
- // finds which schedule was in operation for an insurer, on a date, in a state
- // date should be YYYYMMDD format
- // insurer should be 17 digit code
- // state can be a number 1-9 or abbreviation like SA, ACT, WA
- include $_SESSION['pathToRoot']."setup/settings.php";
- include $_SESSION['pathToRoot']."setup/arrays.php";
- $err=0;
- if ($ins=="mbs"){
- $ins="mbs00000000000000";
- }
- // check bounds conditions for state
- if($stt==0){
- $stt=$statebynumber[$stt];
- }
- if ($stt == 0 || $stt > 8){
- $err=1;
- }
- $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect checking insurer.");
- // check bounds conditions for insurer, ie does the insurer exist?
- if ($ins != "mbs00000000000000"){
- $query = "SELECT * FROM insurer WHERE insurercode=\"$ins\"";
- $result = mysqli_query($con, $query) or die("SQL Query Error checking insurer.");
- $res = mysqli_num_rows($result);
- if ($res == 0){
- $err=1;
- }
- }
- // check bounds conditions for date - ie is it a valid date?
- if (strlen($date) != 8 || $date < 20060000 || $date > 20350000){
- $err=1;
- }
- $winner="none";
- if (!$err){
- // All inputs are valid, so start processing
- $query="SHOW TABLES LIKE \"is$ins%\"";
- $result = mysqli_query($con, $query) or die("SQL Query Error checking insurer.");
- $res = mysqli_num_rows($result);
- if ($res > 0){
- // There is at least 1 table for this insurer
- $diff=100000000;
- while($row=mysqli_fetch_array($result)){
- if(substr($row[0],19,1) == $stt || substr($row[0],19,1) == 9){
- //we have a compatible state. What about the date?
- $dt=substr($row[0],20,8);
- $datediff=$date-$dt;
- if ($datediff >= 0){
- // only consider tables starting ON OR BEFORE the specified date
- if ($datediff < $diff){
- // Only consider tables bettering the current match
- // Then we have a new winner. Record it.
- $diff=$datediff; // The new record to beat
- $winner=$row[0]; // The new winning table
- }
- }
- }
- }
- }
- } else {
- $winner="error";
- }
- return $winner;
- }
- function doctorschedule ($date, $doc){
- // finds which schedule was in operation for an insurer, on a date, in a state
- // date should be YYYYMMDD format
- // insurer should be 17 digit code
- // state can be a number 1-9 or abbreviation like SA, ACT, WA
- include $_SESSION['pathToRoot']."setup/settings.php";
- include $_SESSION['pathToRoot']."setup/arrays.php";
- $err=0;
- $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect checking doctor.");
- // check bounds conditions for doctor, ie does the doctor exist?
- $query = "SELECT * FROM doctor WHERE doctorcode=\"$doc\"";
- $result = mysqli_query($con, $query) or die("SQL Query Error checking doctor.");
- $res = mysqli_num_rows($result);
- if ($res == 0){
- $err=1;
- }
- // check bounds conditions for date - ie is it a valid date?
- if (strlen($date) != 8 || $date < 20060000 || $date > 20350000){
- $err=1;
- }
- $winner="none";
- if (!$err){
- // All inputs are valid, so start processing
- $query="SHOW TABLES LIKE \"ds$doc%\"";
- $result = mysqli_query($con, $query) or die("SQL Query Error checking doctor.");
- $res = mysqli_num_rows($result);
- if ($res > 0){
- // There is at least 1 table for this doctor
- $diff=100000000;
- while($row=mysqli_fetch_array($result)){
- $dt=substr($row[0],19,8);
- $datediff=$date-$dt;
- if ($datediff >= 0){
- // only consider tables starting ON OR BEFORE the specified date
- if ($datediff < $diff){
- // Only consider tables bettering the current match
- // Then we have a new winner. Record it.
- $diff=$datediff; // The new record to beat
- $winner=$row[0]; // The new winning table
- }
- }
- }
- }
- } else {
- $winner="error";
- }
- return $winner;
- }
- function calculateinvoice($invDate, $procStart, $procEnd, $procDuration, $procState, $docCode, $dplCode, $insCode, $feePercent, $discPercent, $discDuration, $feeType, $dollarsPerUnit, $dollarsPerHour, $billTo, $gst, $itemNumber, $itemValue){
- unset($btb);
- // complex function takes multiple inputs and (if they are valid) returns an array with billing data.
- // Validation of input....
- // Validate invoice date
- // $fe is the flag for FATAL ERROR
- include $_SESSION['pathToRoot']."setup/settings.php";
- include $_SESSION['pathToRoot']."setup/arrays.php";
- include_once$_SESSION['pathToRoot']."includes/functions/global.php";
- $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect error calculating invoice.");
- $fe="";
- $er="";
- $timeNow=strtotime("now");
- // ASSESS INVOICE DATE
- $invDate=strtotime($invDate);
- if ($invDate-$timeNow > 63072000 || $invDate-$timeNow < -63072000){
- $er=$er."a|";
- $btb[71]=$btb[71]."Invalid invoice date.BUM";
- }
- // ASSESS START TIME
- if (($procStart*60)-$timeNow > 63072000 || ($procStart*60)-$timeNow < -63072000){
- $er=$er."b|";
- $btb[71]=$btb[71]."Invalid procedure start date.BUM";
- }
- // ASSESS END TIME
- if ($procEnd-$timeNow > 63072000 || $procEnd-$timeNow < -63072000){
- $er=$er."c|";
- }
- // ASSESS PROCEDURE DURATION
- if ($procDuration == 0){
- $procDuration=($procEnd-$procStart)/60;
- }
- if ($procDuration < 0 || $procDuration > 1440){
- $er=$er."d|";
- }
- // ASSESS PROCEDURE STATE..if state is set, use it. If not, check provider number. If not, use default state.
- $st=$defaultstate;
- $q1="SELECT dplinkpractice FROM dplink WHERE dplinkcode=\"$dplCode\"";
- $r1 = mysqli_query($con, $q1) or die(mysqli_error());
- if (mysqli_num_rows($r1) == 1){
- $row=mysqli_fetch_array($r1);
- $q2="SELECT practicestate FROM practice WHERE practicecode=\"$row[0]\"";
- $r2 = mysqli_query($con, $q2) or die(mysqli_error());
- if (mysqli_num_rows($r2) == 1){
- $row=mysqli_fetch_array($r2);
- if ($statebynumber[$row[0]] >0 && $statebynumber[$row[0]] < 9){
- $st=$row[0];
- }
- }
- }
- if ($statebynumber[$procState] > 0 && $statebynumber[$procState] < 9){
- $st=$procState;
- }
- $procState=$st;
- // ASSESS FEE PERCENT
- if ($feePercent < 1){
- $er=$er."e|";
- }
- // ASSESS Discount PERCENT
- if ($discPercent <0 || $discPercent > 99){
- $er=$er."f|";
- }
- // ASSESS DISCOUNT DURATION
- if ($discDuration < 0 || $discDuration > 365){
- $er=$er."g|";
- }
- // ASSESS DOLLARS PER UNIT
- if ($dollarsPerUnit < .01){
- $er=$er."h|";
- }
- // ASSESS DOLLARS PER HOUR
- if ($dollarsPerHour < .01){
- $er=$er."i";
- }
- // ASSESS BILLTO
- if ($billTo != "patient" && $billTo != "insurer" && $billTo !="both"){
- $er=$er."j|";
- $fe=$fe."j|";
- }
- if ($billTo == "insurer"){
- $discDuration=0;
- $discPercent=0;
- }
- // ONLY DO ANY OF THIS IF THERE ARE NO FATAL ERRORS
- if ($fe==""){
- // OH Good...no fatal errors so far.
- // Convert the procedure start date/time into a YYMMDD format. Call it $psd
- $psd=date("Ymd",$procStart*60);
- // Check if the feetype insurer has a table valid on the procedure date. If so, call it $insTable
- if ($feeType !="doctor" && $feeType !="mbs" && $feeType !="dpu" && $feeType !="dph" && $feeType !="ama" && $feeType !="manual"){
- $res=workingschedule($psd,$feeType,$procState);
- if ($res !="error" && $res !="none"){
- $insTable=$res;
- } else {
- // Flag a fatal error
- $btb[71]=$btb[71]."Selected insurer has no fee table for procedure date.BUM";
- }
- }
- // Check if the patient's insurer does GAP-COVER. If so, $knowngap=1
- $gapcover=0;
- if ($insCode !=""){
- $q1="SELECT insurerknowngap FROM insurer WHERE insurercode=\"$insCode\"";
- $r1 = mysqli_query($con, $q1) or die(mysqli_error());
- if (mysqli_num_rows($r1) == 1){
- $row1=mysqli_fetch_array($r1);
- $knowngap=$row1[0];
- }
- }
- // check if the patient's insurer has a fee table on this date. If so, call it $patInsTable
- if ($insCode !=""){
- $res=workingschedule($psd,$insCode,$procState);
- if ($res !="error" && $res !="none"){
- $patInsTable=$res;
- } else {
- // Flag a non fatal error
- $btb[72]=$btb[72]."Patients insurer has no fee table for procedure date.BUM";
- }
- }
- // Find the Medicare table active on the procedure date. Call is $medicareTable
- $res=workingschedule($psd,"mbs",$procState);
- if ($res !="error" && $res !="none"){
- $medicareTable=$res;
- }
- // Find the doctor's fee table on the procedure date. If found, call it $doctorTable
- $res=doctorschedule($psd,$docCode);
- if ($res !="error" && $res !="none"){
- $doctorTable=$res;
- }
- } else {
- // CRAP IF WE ARE HERE THEN THERE IS A FATAL ERROR.
- }
- // OK...lets start calculating the TOTAL fee for each item number.
- switch($feeType){
- case "manual":
- // Not much to do here. The values don't change
- break;
- case "doctor":
- // Need to look up values in doctor's billing schedule
- if ($doctorTable != ""){
- // Good we have a doctors table of fees
- // First iteration populates all fees that actually have a value
- for ($i4=1;$i4<21;$i4+=1){
- if ($itemNumber[$i4] != ""){
- $q3="SELECT * from $doctorTable WHERE scheduleitemnumber=\"$itemNumber[$i4]\"";
- if ($itemNumber[$i4] !=0){
- $q3="SELECT * from $doctorTable WHERE scheduleitemnumber=$itemNumber[$i4]";
- }
- $r3 = mysqli_query($con, $q3) or die(mysqli_error());
- if (mysqli_num_rows($r3) == 1){
- $row3=mysqli_fetch_array($r3);
- $itemValue[$i4]=$row3[1]*$feePercent/100;
- }
- }
- }
- // Second iteration looks for derived fees and calculates those, based on the OTHER values
- for ($i4=1;$i4<21;$i4+=1){
- if ($itemNumber[$i4] == 25025){
- for($i5=1;$i5<21;$i5+=1){
- if (($itemNumber[$i5]>=20100 && $itemNumber[$i5]<=21997) || ($itemNumber[$i5]>=23010 && $itemNumber[$i5]<=24136) || ($itemNumber[$i5]>=25000 && $itemNumber[$i5]<=25015) || ($itemNumber[$i5]>=22001 && $itemNumber[$i5]<=22051) ||$itemNumber[$i5]==22900){
- $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
- }
- }
- }
- if ($itemNumber[$i4] == 25030 ){
- for($i5=1;$i5<21;$i5+=1){
- if (($itemNumber[$i5]>=25200 && $itemNumber[$i5]<=25205) || ($itemNumber[$i5]>=23010 && $itemNumber[$i5]<=24136) || ($itemNumber[$i5]>=25000 && $itemNumber[$i5]<=25015) || ($itemNumber[$i5]>=22001 && $itemNumber[$i5]<=22051)){
- $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
- }
- }
- }
- if ($itemNumber[$i4] == 25050 ){
- for($i5=1;$i5<21;$i5+=1){
- if (($itemNumber[$i5]==22060 || ($itemNumber[$i5]>=23010 && $itemNumber[$i5]<=24136) || ($itemNumber[$i5]>=25000 && $itemNumber[$i5]<=25015) || $itemNumber[$i5]>=22001 && $itemNumber[$i5]<=22051) || ($itemNumber[$i5]>=22065 && $itemNumber[$i5]<=22075)){
- $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
- }
- }
- }
- }
- } else {
- // There is no doctors table of fees so flag a fatal error
- $btb[71]=$btb[71]."No doctors fee table for procedure date.BUM";
- }
- break;
- case "dph":
- if ($dollarsPerHour > 0){
- if ($procDuration > 0 && $procDuration <=1440){
- $itemValue[1]=$procDuration*$dollarsPerHour/60;
- } else {
- $btb[71]=$btb[71]."Invalid procedure duration.BUM";
- }
- } else {
- $btb[71]=$btb[71]."Invalid value for dollars per hour.BUM";
- }
- break;
- case "dpu":
- if ($dollarsPerUnit > 0){
- for ($i1=1;$i1<21;$i1+=1){
- if ($itemNumber[$i1] != ""){
- $q1="SELECT itemunits FROM item WHERE itemitemnumber=\"$itemNumber[$i1]\"";
- if ($itemNumber[$i1] !=0){
- $q1="SELECT itemunits FROM item WHERE itemitemnumber=$itemNumber[$i1]";
- }
- $r1 = mysqli_query($con, $q1) or die(mysqli_error());
- if (mysqli_num_rows($r1) == 1){
- $row1=mysqli_fetch_array($r1);
- if ($row1[0] > 0){
- $itemValue[$i1]=$dollarsPerUnit*$row1[0];
- }
- }
- }
- }
- for ($i4=1;$i4<21;$i4+=1){
- if ($itemNumber[$i4] == 25025){
- for($i5=1;$i5<21;$i5+=1){
- if (($itemNumber[$i5]>=20100 && $itemNumber[$i5]<=21997) || ($itemNumber[$i5]>=23010 && $itemNumber[$i5]<=24136) || ($itemNumber[$i5]>=25000 && $itemNumber[$i5]<=25015) || ($itemNumber[$i5]>=22001 && $itemNumber[$i5]<=22051) ||$itemNumber[$i5]==22900){
- $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
- }
- }
- }
- if ($itemNumber[$i4] == 25030 ){
- for($i5=1;$i5<21;$i5+=1){
- if (($itemNumber[$i5]>=25200 && $itemNumber[$i5]<=25205) || ($itemNumber[$i5]>=23010 && $itemNumber[$i5]<=24136) || ($itemNumber[$i5]>=25000 && $itemNumber[$i5]<=25015) || ($itemNumber[$i5]>=22001 && $itemNumber[$i5]<=22051)){
- $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
- }
- }
- }
- if ($itemNumber[$i4] == 25050 ){
- for($i5=1;$i5<21;$i5+=1){
- if (($itemNumber[$i5]==22060 || ($itemNumber[$i5]>=23010 && $itemNumber[$i5]<=24136) || ($itemNumber[$i5]>=25000 && $itemNumber[$i5]<=25015) || $itemNumber[$i5]>=22001 && $itemNumber[$i5]<=22051) || ($itemNumber[$i5]>=22065 && $itemNumber[$i5]<=22075)){
- $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
- }
- }
- }
- }
- } else {
- $btb[71]=$btb[71]."Invalid dollar value per unit.BUM";
- }
- break;
- case "mbs":
- // Need to look up values in mbs billing schedule
- if ($medicareTable != ""){
- // Good we have a mbs table of fees
- // Get the value of a unit from item 23010 call it $mbsUnitValue - in case we need it for item 25200 or 25205
- $q1="SELECT insurerschedulevalue FROM $medicareTable WHERE insurerscheduleitemnumber=23010";
- $r1 = mysqli_query($con, $q1) or die(mysqli_error());
- $row1=mysqli_fetch_array($r1);
- $mbsUnitValue=$row1[0];
- // First iteration populates all fees that actually have a value
- for ($i4=1;$i4<21;$i4+=1){
- if ($itemNumber[$i4] != ""){
- $q3="SELECT * FROM $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i4]\"";
- if ($itemNumber[$i4] !=0){
- $q3="SELECT * FROM $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i4]";
- }
- $r3 = mysqli_query($con, $q3) or die(mysqli_error());
- if (mysqli_num_rows($r3) == 1){
- $row3=mysqli_fetch_array($r3);
- $itemValue[$i4]=$row3[1]*$feePercent/100;
- if ($itemNumber[$i4]==25200 || $itemNumber[$i4]==25205){
- $itemValue[$i4]=$mbsUnitValue*5*$feePercent/100;
- }
- }
- }
- }
- // Second iteration looks for derived fees and calculates those, based on the OTHER values
- for ($i4=1;$i4<21;$i4+=1){
- if ($itemNumber[$i4] == 25025){
- for($i5=1;$i5<21;$i5+=1){
- if (($itemNumber[$i5]>=20100 && $itemNumber[$i5]<=21997) || ($itemNumber[$i5]>=23010 && $itemNumber[$i5]<=24136) || ($itemNumber[$i5]>=25000 && $itemNumber[$i5]<=25015) || ($itemNumber[$i5]>=22001 && $itemNumber[$i5]<=22051) ||$itemNumber[$i5]==22900){
- $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
- }
- }
- }
- if ($itemNumber[$i4] == 25030 ){
- for($i5=1;$i5<21;$i5+=1){
- if (($itemNumber[$i5]>=25200 && $itemNumber[$i5]<=25205) || ($itemNumber[$i5]>=23010 && $itemNumber[$i5]<=24136) || ($itemNumber[$i5]>=25000 && $itemNumber[$i5]<=25015) || ($itemNumber[$i5]>=22001 && $itemNumber[$i5]<=22051)){
- $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
- }
- }
- }
- if ($itemNumber[$i4] == 25050 ){
- for($i5=1;$i5<21;$i5+=1){
- if (($itemNumber[$i5]==22060 || ($itemNumber[$i5]>=23010 && $itemNumber[$i5]<=24136) || ($itemNumber[$i5]>=25000 && $itemNumber[$i5]<=25015) || $itemNumber[$i5]>=22001 && $itemNumber[$i5]<=22051) || ($itemNumber[$i5]>=22065 && $itemNumber[$i5]<=22075)){
- $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
- }
- }
- }
- }
- } else {
- // There is no medicare table of fees so flag a fatal error
- $btb[71]=$btb[71]."No medicare fee table for procedure date.BUM";
- }
- break;
- case "ama":
- break;
- default:
- if ($insTable !=""){
- // Calculate using insurer's table...
- // Get the mbs value of a unit from item 23010 call it $mbsUnitValue - in case we need it for item 25200 or 25205
- $q1="SELECT insurerschedulevalue FROM $medicareTable WHERE insurerscheduleitemnumber=23010";
- $r1 = mysqli_query($con, $q1) or die(mysqli_error());
- $row1=mysqli_fetch_array($r1);
- $mbsUnitValue=$row1[0];
- // Get the insurer's value of a unit from item 23010 call it $insUnitValue - in case we need it for item 25200 or 25205
- $q1="SELECT insurerschedulevalue FROM $insTable WHERE insurerscheduleitemnumber=23010";
- $r1 = mysqli_query($con, $q1) or die(mysqli_error());
- $row1=mysqli_fetch_array($r1);
- $insUnitValue=$row1[0];
- // First iteration populates all fees that actually have a value
- for ($i4=1;$i4<21;$i4+=1){
- if ($itemNumber[$i4] != ""){
- $q3="SELECT * FROM $insTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i4]\"";
- if ($itemNumber[$i4] != 0){
- $q3="SELECT * FROM $insTable WHERE insurerscheduleitemnumber=$itemNumber[$i4]";
- }
- $r3 = mysqli_query($con, $q3) or die(mysqli_error());
- if (mysqli_num_rows($r3) == 1){
- $row3=mysqli_fetch_array($r3);
- $itemValue[$i4]=$row3[1]*$feePercent/100;
- if ($itemNumber[$i4]==25200 || $itemNumber[$i4]==25205){
- // Correct the percentage...if less than 100, make it more.
- if ($row3[2] !=0 && $row3[2] < 100){
- $row3[2]=$row3[2]+100;
- }
- if ($row3[2] > 0){
- // If there IS a percent, then it's a percent of MEDICARE...so do that'
- $itemValue[$i4]=$mbsUnitValue*5*$feePercent/100*$row3[2]/100;
- } else {
- // If there IS NOT a percent, then it's a percent of the internal table fee.
- $itemValue[$i4]=$insUnitValue*5*$feePercent/100;
- }
- }
- }
- }
- }
- // SECOND ITERATION. LOOK FOR 25025, 25030 25050
- for ($i1=1;$i1<21;$i1+=1){
- if ($itemNumber[$i1] == 25025){
- // OK Get the percentage for item 25025
- $q1="SELECT insurerschedulepercent FROM $insTable WHERE insurerscheduleitemnumber=25025";
- $r1 = mysqli_query($con, $q1) or die(mysqli_error());
- $row1=mysqli_fetch_array($r1);
- // CORRECT THE PERCENTAGE IF LESS THAN 100 and CALL IT $row1[2]
- if ($row1[0] !=0 && $row1[0] < 100){
- $row1[0]=$row1[0]+100;
- }
- for ($i2=1;$i2<21;$i2+=1){
- if (($itemNumber[$i2]>=20100 && $itemNumber[$i2]<=21997) || $itemNumber[$i2]==22900 || ($itemNumber[$i2]>=23010 && $itemNumber[$i2]<=24136) || ($itemNumber[$i2]>=25000 && $itemNumber[$i2]<=25015) || ($itemNumber[$i2]>=22001 && $itemNumber[$i2]<=22051)){
- if ($row1[0] > 0){
- // If there IS a percent, then it's a percent off MEDICARE...so do that'
- // Look up the MEDICARE Value of this item....
- $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i2]\"";
- if ($itemNumber[$i2] !=0){
- $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i2]";
- }
- $r2 = mysqli_query($con, $q2) or die(mysqli_error());
- $row2=mysqli_fetch_array($r2);
- $itemValue[$i1]=$itemValue[$i1]+$feePercent/100*$row1[0]/100*$row2[0]*.5;
- } else {
- // If there IS NOT a percent, then it's a percent of the internal table fee.
- $itemValue[$i1]=$row1[0]/100*$feePercent/100*$itemValue[$i2]*.5;
- }
- }
- }
- }
- if ($itemNumber[$i1] == 25030){
- // OK Get the percentage for item 25030
- $q1="SELECT insurerschedulepercent FROM $insTable WHERE insurerscheduleitemnumber=25030";
- $r1 = mysqli_query($con, $q1) or die(mysqli_error());
- $row1=mysqli_fetch_array($r1);
- // CORRECT THE PERCENTAGE IF LESS THAN 100 and CALL IT $row1[2]
- if ($row1[0] !=0 && $row1[0] < 100){
- $row1[0]=$row1[0]+100;
- }
- for ($i2=1;$i2<21;$i2+=1){
- if (($itemNumber[$i2]>=25200 && $itemNumber[$i2]<=225205) || ($itemNumber[$i2]>=23010 && $itemNumber[$i2]<=24136) || ($itemNumber[$i2]>=25000 && $itemNumber[$i2]<=25015) || ($itemNumber[$i2]>=22001 && $itemNumber[$i2]<=22051)){
- if ($row1[0] > 0){
- // If there IS a percent, then it's a percent off MEDICARE...so do that'
- // Look up the MEDICARE Value of this item....
- $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i2]\"";
- if ($itemNumber[$i2] !=0){
- $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i2]";
- }
- $r2 = mysqli_query($con, $q2) or die(mysqli_error());
- $row2=mysqli_fetch_array($r2);
- $itemValue[$i1]=$itemValue[$i1]+$feePercent/100*$row1[0]/100*$row2[0]*.5;
- } else {
- // If there IS NOT a percent, then it's a percent of the internal table fee.
- $itemValue[$i1]=$row1[0]/100*$feePercent/100*$itemValue[$i2]*.5;
- }
- }
- }
- }
- if ($itemNumber[$i1] == 25050){
- // OK Get the percentage for item 25050
- $q1="SELECT insurerschedulepercent FROM $insTable WHERE insurerscheduleitemnumber=25050";
- $r1 = mysqli_query($con, $q1) or die(mysqli_error());
- $row1=mysqli_fetch_array($r1);
- // CORRECT THE PERCENTAGE IF LESS THAN 100 and CALL IT $row1[2]
- if ($row1[0] !=0 && $row1[0] < 100){
- $row1[0]=$row1[0]+100;
- }
- for ($i2=1;$i2<21;$i2+=1){
- if ($itemNumber[$i2]==22060 || ($itemNumber[$i2]>=23010 && $itemNumber[$i2]<=24136) || ($itemNumber[$i2]>=25000 && $itemNumber[$i2]<=25015) || ($itemNumber[$i2]>=22001 && $itemNumber[$i2]<=22051) || ($itemNumber[$i2]>=22065 && $itemNumber[$i2]<=22075)){
- if ($row1[0] > 0){
- // If there IS a percent, then it's a percent off MEDICARE...so do that'
- // Look up the MEDICARE Value of this item....
- $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i2]\"";
- if ($itemNumber[$i2] !=0){
- $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i2]";
- }
- $r2 = mysqli_query($con, $q2) or die(mysqli_error());
- $row2=mysqli_fetch_array($r2);
- $itemValue[$i1]=$itemValue[$i1]+$feePercent/100*$row1[0]/100*$row2[0]*.5;
- } else {
- // If there IS NOT a percent, then it's a percent of the internal table fee.
- $itemValue[$i1]=$row1[0]/100*$feePercent/100*$itemValue[$i2]*.5;
- }
- }
- }
- }
- }
- } else {
- // No insurer fee table. Cant do calcs
- }
- break;
- }
- // Figure out expected Medicare Rebates...
- // Need to look up values in mbs billing schedule
- if ($medicareTable != ""){
- // Good we have a mbs table of fees
- // Get the value of a unit from item 23010 call it $mbsUnitValue - in case we need it for item 25200 or 25205
- $q1="SELECT insurerschedulevalue FROM $medicareTable WHERE insurerscheduleitemnumber=23010";
- $r1 = mysqli_query($con, $q1) or die(mysqli_error());
- $row1=mysqli_fetch_array($r1);
- $mbsUnitValue=$row1[0];
- // First iteration populates all fees that actually have a value
- for ($i4=1;$i4<21;$i4+=1){
- if ($itemNumber[$i4] != ""){
- $q3="SELECT * FROM $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i4]\"";
- if ($itemNumber[$i4] !=0){
- $q3="SELECT * FROM $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i4]";
- }
- $r3 = mysqli_query($con, $q3) or die(mysqli_error());
- if (mysqli_num_rows($r3) == 1){
- $row3=mysqli_fetch_array($r3);
- $btb[40+$i4]=$row3[1]*$mcRebatePercent/100;
- if ($itemNumber[$i4]==25200 || $itemNumber[$i4]==25205){
- $btb[40+$i4]=$mbsUnitValue*5*$mcRebatePercent/100;
- }
- }
- }
- }
- // Second iteration looks for derived fees and calculates those, based on the OTHER values
- for ($i4=1;$i4<21;$i4+=1){
- if ($itemNumber[$i4] == 25025){
- for($i5=1;$i5<21;$i5+=1){
- if (($itemNumber[$i5]>=20100 && $itemNumber[$i5]<=21997) || ($itemNumber[$i5]>=23010 && $itemNumber[$i5]<=24136) || ($itemNumber[$i5]>=25000 && $itemNumber[$i5]<=25015) || ($itemNumber[$i5]>=22001 && $itemNumber[$i5]<=22051) ||$itemNumber[$i5]==22900){
- $btb[40+$i4]=$btb[40+$i4]+($btb[40+$i5]*.5);
- }
- }
- }
- if ($itemNumber[$i4] == 25030 ){
- for($i5=1;$i5<21;$i5+=1){
- if (($itemNumber[$i5]>=25200 && $itemNumber[$i5]<=25205) || ($itemNumber[$i5]>=23010 && $itemNumber[$i5]<=24136) || ($itemNumber[$i5]>=25000 && $itemNumber[$i5]<=25015) || ($itemNumber[$i5]>=22001 && $itemNumber[$i5]<=22051)){
- $btb[40+$i4]=$btb[40+$i4]+($btb[40+$i5]*.5);
- }
- }
- }
- if ($itemNumber[$i4] == 25050 ){
- for($i5=1;$i5<21;$i5+=1){
- if (($itemNumber[$i5]==22060 || ($itemNumber[$i5]>=23010 && $itemNumber[$i5]<=24136) || ($itemNumber[$i5]>=25000 && $itemNumber[$i5]<=25015) || $itemNumber[$i5]>=22001 && $itemNumber[$i5]<=22051) || ($itemNumber[$i5]>=22065 && $itemNumber[$i5]<=22075)){
- $btb[40+$i4]=$btb[40+$i4]+($btb[40+$i5]*.5);
- }
- }
- }
- }
- } else {
- // There is no medicare table of fees so can't be done. Never mind. Dont flag an error.
- }
- // Figure out expected insurer rebates....
- if ($patInsTable !=""){
- // Calculate using insurer's table...
- // Get the mbs value of a unit from item 23010 call it $mbsUnitValue - in case we need it for item 25200 or 25205
- $q1="SELECT insurerschedulevalue FROM $medicareTable WHERE insurerscheduleitemnumber=23010";
- $r1 = mysqli_query($con, $q1) or die(mysqli_error());
- $row1=mysqli_fetch_array($r1);
- $mbsUnitValue=$row1[0];
- // Get the insurer's value of a unit from item 23010 call it $insUnitValue - in case we need it for item 25200 or 25205
- $q1="SELECT insurerschedulevalue FROM $patInsTable WHERE insurerscheduleitemnumber=23010";
- $r1 = mysqli_query($con, $q1) or die(mysqli_error());
- $row1=mysqli_fetch_array($r1);
- $insUnitValue=$row1[0];
- // First iteration populates all fees that actually have a value
- for ($i4=1;$i4<21;$i4+=1){
- if ($itemNumber[$i4] != ""){
- $q3="SELECT * FROM $patInsTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i4]\"";
- if ($itemNumber[$i4] != 0){
- $q3="SELECT * FROM $patInsTable WHERE insurerscheduleitemnumber=$itemNumber[$i4]";
- }
- $r3 = mysqli_query($con, $q3) or die(mysqli_error());
- if (mysqli_num_rows($r3) == 1){
- $row3=mysqli_fetch_array($r3);
- $btb[80+$i4]=$row3[1];
- if ($itemNumber[$i4]==25200 || $itemNumber[$i4]==25205){
- // Correct the percentage...if less than 100, make it more.
- if ($row3[2] !=0 && $row3[2] < 100){
- $row3[2]=$row3[2]+100;
- }
- if ($row3[2] > 0){
- // If there IS a percent, then it's a percent of MEDICARE...so do that'
- $btb[80+$i4]=$mbsUnitValue*5*$row3[2]/100;
- } else {
- // If there IS NOT a percent, then it's a percent of the internal table fee.
- $btb[80+$i4]=$insUnitValue*5;
- }
- }
- }
- }
- }
- // SECOND ITERATION. LOOK FOR 25025, 25030 25050
- for ($i1=1;$i1<21;$i1+=1){
- if ($itemNumber[$i1] == 25025){
- // OK Get the percentage for item 25025
- $q1="SELECT insurerschedulepercent FROM $patInsTable WHERE insurerscheduleitemnumber=25025";
- $r1 = mysqli_query($con, $q1) or die(mysqli_error());
- $row1=mysqli_fetch_array($r1);
- // CORRECT THE PERCENTAGE IF LESS THAN 100 and CALL IT $row1[2]
- if ($row1[0] !=0 && $row1[0] < 100){
- $row1[0]=$row1[0]+100;
- }
- for ($i2=1;$i2<21;$i2+=1){
- if (($itemNumber[$i2]>=20100 && $itemNumber[$i2]<=21997) || $itemNumber[$i2]==22900 || ($itemNumber[$i2]>=23010 && $itemNumber[$i2]<=24136) || ($itemNumber[$i2]>=25000 && $itemNumber[$i2]<=25015) || ($itemNumber[$i2]>=22001 && $itemNumber[$i2]<=22051)){
- if ($row1[0] > 0){
- // If there IS a percent, then it's a percent off MEDICARE...so do that'
- // Look up the MEDICARE Value of this item....
- $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i2]\"";
- if ($itemNumber[$i2] !=0){
- $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i2]";
- }
- $r2 = mysqli_query($con, $q2) or die(mysqli_error());
- $row2=mysqli_fetch_array($r2);
- $btb[80+$i1]=$btb[80+$i1]+$row1[0]/100*$row2[0]*.5;
- } else {
- // If there IS NOT a percent, then it's a percent of the internal table fee.
- $btb[80+$i1]=$row1[0]/100*$btb[80+$i2]*.5;
- }
- }
- }
- }
- if ($itemNumber[$i1] == 25030){
- // OK Get the percentage for item 25030
- $q1="SELECT insurerschedulepercent FROM $patInsTable WHERE insurerscheduleitemnumber=25030";
- $r1 = mysqli_query($con, $q1) or die(mysqli_error());
- $row1=mysqli_fetch_array($r1);
- // CORRECT THE PERCENTAGE IF LESS THAN 100 and CALL IT $row1[2]
- if ($row1[0] !=0 && $row1[0] < 100){
- $row1[0]=$row1[0]+100;
- }
- for ($i2=1;$i2<21;$i2+=1){
- if (($itemNumber[$i2]>=25200 && $itemNumber[$i2]<=225205) || ($itemNumber[$i2]>=23010 && $itemNumber[$i2]<=24136) || ($itemNumber[$i2]>=25000 && $itemNumber[$i2]<=25015) || ($itemNumber[$i2]>=22001 && $itemNumber[$i2]<=22051)){
- if ($row1[0] > 0){
- // If there IS a percent, then it's a percent off MEDICARE...so do that'
- // Look up the MEDICARE Value of this item....
- $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i2]\"";
- if ($itemNumber[$i2] !=0){
- $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i2]";
- }
- $r2 = mysqli_query($con, $q2) or die(mysqli_error());
- $row2=mysqli_fetch_array($r2);
- $btb[80+$i1]=$btb[80+$i1]+$row1[0]/100*$row2[0]*.5;
- } else {
- // If there IS NOT a percent, then it's a percent of the internal table fee.
- $btb[80+$i1]=$row1[0]/100*$btb[80+$i2]*.5;
- }
- }
- }
- }
- if ($itemNumber[$i1] == 25050){
- // OK Get the percentage for item 25050
- $q1="SELECT insurerschedulepercent FROM $patInsTable WHERE insurerscheduleitemnumber=25050";
- $r1 = mysqli_query($con, $q1) or die(mysqli_error());
- $row1=mysqli_fetch_array($r1);
- // CORRECT THE PERCENTAGE IF LESS THAN 100 and CALL IT $row1[2]
- if ($row1[0] !=0 && $row1[0] < 100){
- $row1[0]=$row1[0]+100;
- }
- for ($i2=1;$i2<21;$i2+=1){
- if ($itemNumber[$i2]==22060 || ($itemNumber[$i2]>=23010 && $itemNumber[$i2]<=24136) || ($itemNumber[$i2]>=25000 && $itemNumber[$i2]<=25015) || ($itemNumber[$i2]>=22001 && $itemNumber[$i2]<=22051) || ($itemNumber[$i2]>=22065 && $itemNumber[$i2]<=22075)){
- if ($row1[0] > 0){
- // If there IS a percent, then it's a percent off MEDICARE...so do that'
- // Look up the MEDICARE Value of this item....
- $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i2]\"";
- if ($itemNumber[$i2] !=0){
- $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i2]";
- }
- $r2 = mysqli_query($con, $q2) or die(mysqli_error());
- $row2=mysqli_fetch_array($r2);
- $btb[80+$i1]=$btb[80+$i1]+$row1[0]/100*$row2[0]*.5;
- } else {
- // If there IS NOT a percent, then it's a percent of the internal table fee.
- $btb[80+$i1]=$row1[0]/100*$btb[80+$i2]*.5;
- }
- }
- }
- }
- }
- if ($knowngap==0){
- for ($i2=1;$i2<21;$i2+=1){
- if ($itemValue[$i2]>$btb[$i2+80]){
- $tmp=$btb[$i2+40]/($mcRebatePercent/100);
- $btb[80+$i2]=$tmp;
- }
- }
- }
- } else {
- // BAD LUCK...No insurer table....don't flag an error. Rebate is just zero
- }
- // Package all the results for returning
- // Add pretty zeros for item values.
- for($i2=1;$i2<21;$i2+=1){
- if ($itemValue[$i2]){
- $btb[$i2]=sprintf("%01.2f", $itemValue[$i2]);
- $invTotal=$invTotal+$itemValue[$i2];
- }
- }
- // Calculate the GST if applicable
- $btb[63]=0;
- if ($gst == "true" || $gst == 1){
- for($i2=1;$i2<21;$i2+=1){
- $btb[63]=$btb[63]+($itemValue[$i2]*$GSTPercent/100);
- }
- }
- // Calculate the discount if applicable
- if ($discPercent > 0){
- $btb[65]=($invTotal+$btb[63])*$discPercent/100;
- }
- if ($btb[71] !=""){
- $btb[71]=substr($btb[71],0,(strlen($btb[71])-3));
- }
- if ($btb[72] !=""){
- $btb[72]=substr($btb[72],0,(strlen($btb[72])-3));
- }
- return $btb;
- }
- //////////////////////////////////////////////////////////////////////////////////INVOICEPDF
- function invoicepdf($inum,$pwd="",$nme=""){
- include $_SESSION['pathToRoot']."setup/settings.php";
- // include_once"includes/classes/fpdf/fpdf_protection.php";
- // function to create a PDF for invoice number $inum
- // Returns "error" the invoice number does not exist.
- // Otherwise returns "1" for success, and creates in invoice in the default
- // PDF folder, with the name "Invoice-XXXXXX.pdf" where XXXXXX is the invoice number
- $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect error.");
- $query="SELECT * FROM invoice WHERE invoicecode=\"$inum\"";
- $res = mysqli_query($con, $query) or die(mysqli_error());
- if (mysqli_num_rows($res) == 1){
- $inv=mysqli_fetch_assoc($res);
- extract($inv);
- $query="SELECT * FROM operation WHERE operationcode=\"$invoiceoperationcode\"";
- $res = mysqli_query($con, $query) or die(mysqli_error());
- if (mysqli_num_rows($res) == 1){
- $op=mysqli_fetch_assoc($res);
- extract($op);
- $query="SELECT * FROM patient WHERE patientcode=\"$operationpatientcode\"";
- $res = mysqli_query($con, $query) or die(mysqli_error());
- if (mysqli_num_rows($res) == 1){
- $pat=mysqli_fetch_assoc($res);
- extract($pat);
- $query="SELECT * FROM doctor WHERE doctorcode=\"$operationdoctorcode\"";
- $res = mysqli_query($con, $query) or die(mysqli_error());
- if (mysqli_num_rows($res) == 1){
- $doc=mysqli_fetch_assoc($res);
- extract($doc);
- $query="SELECT * from dplink where dplinkcode=\"$operationdplinkcode\"";
- $res = mysqli_query($con, $query) or die(mysqli_error());
- if (mysqli_num_rows($res) == 1){
- $dpl=mysqli_fetch_assoc($res);
- extract($dpl);
- $query="SELECT * FROM practice WHERE practicecode=\"$dplinkpractice\"";
- $res = mysqli_query($con, $query) or die(mysqli_error());
- if (mysqli_num_rows($res) == 1){
- $pra=mysqli_fetch_assoc($res);
- extract($pra);
- $surgeon=$operationsurgeonname;
- $query="SELECT * FROM surgeon WHERE surgeoncode=\"$operationsurgeoncode\"";
- $res = mysqli_query($con, $query) or die(mysqli_error());
- if (mysqli_num_rows($res) == 1){
- $sur=mysqli_fetch_assoc($res);
- extract($sur);
- $surgeon="$surgeonfirstname $surgeonlastname";
- }
- $hospital=$operationhospitalname;
- $query="SELECT * FROM hospital WHERE hospitalcode=\"$operationhospitalcode\"";
- $res = mysqli_query($con, $query) or die(mysqli_error());
- if (mysqli_num_rows($res) == 1){
- $hos=mysqli_fetch_assoc($res);
- extract($hos);
- }
- } else {
- return "error - practice $dplinkpractice does not exist";
- }
- } else {
- return "error - dplink $operationdplinkcode does not exist";
- }
- } else {
- return "error - doctor $operationdoctorcode does not exist";
- }
- } else {
- return "error - patient $operationpatientcode does not exist";
- }
- } else {
- return "error - operation $invoiceoperationcode does not exist";
- }
- } else {
- return "error - invoice $inum does not exist";
- }
- // Landing here means we have correctly extracted all the details we need...So create PDF
- //$pdf=new FPDF();
- $pdf=new FPDF_Protection();
- $pdf->SetProtection(array('print','copy'),$pwd,$pwd);
- $pdf->SetAuthor($_SESSION['pdfAccountAuthor']);
- $pdf->SetCreator($_SESSION['pdfAccountCreator']);
- $pdf->SetSubject($_SESSION['pdfAccountSubject']);
- $pdf->SetTitle($_SESSION['pdfAccountTitle']);
- $pdf->SetDisplayMode($_SESSION['pdfAccountDisplayMode']);
- $pdf->AddPage();
- // Folding Guide
- $pdf->Line(10,99,201,99);
- // Box for logo
- $x=70;
- $y=20;
- //$pdf->Rect($x,$y,50,30);
- // Heading for invoice
- $pdf->SetFont('Arial','B',14);
- $pdf->SetFillColor(255,255,255);
- $pdf->SetXY(10,10);
- $pdf->Cell(110,7,"Invoice for professional anaesthetic services","B","","",1);
- //Doctor's letterhead is printed here'
- $x=10;
- $y=20;
- //$pdf->Rect($x,$y,55,45);
- $pdf->SetFont('Arial','B',14);
- $pdf->SetXY($x,$y);
- $pdf->Cell(55,6,strtoupper("$doctortitle $doctorfirstname $doctorlastname"),"");
- $pdf->SetFont('Arial','',5);
- $pdf->SetXY($x+1,$y+4);
- //$pdf->Cell(55,4,"$doctorqualifications","");
- $adr=explode(chr(13), $practiceaddress);
- $pdf->SetFont('Arial','',12);
- $pdf->SetXY($x+1,$y+7);
- $pdf->Cell(85,4,"$adr[0]","");
- $pdf->SetXY($x,$y+11);
- $pdf->Cell(85,4,"$adr[1]","");
- $pdf->SetXY($x+1,$y+15);
- $pdf->Cell(85,4,"$practicecity $practicepostcode","");
- $pdf->SetFont('Arial','',8);
- $pdf->SetXY($x+1,$y+20);
- $pdf->Cell(85,4,"Ph. $practicephone","");
- if ($practicefax !=""){
- $pdf->SetXY($x+1,$y+23);
- $pdf->Cell(85,4,"Fax $practicefax","");
- }
- if ($practiceemail !=""){
- $pdf->SetXY($x+1,$y+26);
- $pdf->Cell(85,4,"Email $practiceemail","");
- }
- if ($practicewebpage !=""){
- $pdf->SetXY($x+1,$y+29);
- $pdf->Cell(85,4,"$practicewebpage","");
- }
- // Print :to:
- $x=10;
- $y=60;
- $pdf->SetFont('Arial',"BI",20);
- $pdf->SetXY($x,$y);
- $pdf->Cell(10,10,"To:");
- // Address for envelope window
- $x=35;
- $y=60;
- //$pdf->Rect(30,56,93,27);
- $pdf->SetFont('Arial','B',10);
- $pdf->SetXY($x,$y);
- $pdf->Cell(85,5,"$invoicepayertitle $invoicepayerfirstname $invoicepayerlastname","");
- $adr=explode(chr(13),$invoicepayeraddress);
- $pdf->SetFont('Arial','',10);
- $pdf->SetXY($x,$y+5);
- $pdf->Cell(85,5,"$adr[0]","");
- $pdf->SetXY($x,$y+10);
- $pdf->Cell(85,5,"$adr[1]","");
- $pdf->SetXY($x,$y+15);
- if ($invoicepayercountry != "Australia"){
- $country=strtoupper($invoicepayercountry);
- $ins="$invoicepayercity $country $invoicepayerpostcode";
- } else {
- $ins="$invoicepayercity $invoicepayerstate $invoicepayerpostcode";
- }
- $pdf->Cell(85,5,strtoupper("$ins"),"");
- // Procedure details box and content
- $x=125;
- $y=10;
- $pdf->Rect($x,$y,75,85);
- //Heading
- $pdf->SetXY($x,$y);
- $pdf->SetFont('Arial','B',12);
- $pdf->SetFillColor(124,124,124);
- $pdf->SetTextColor(255,255,255);
- $pdf->Cell(75,7,"Tax invoice No. $inum","LRTB",0,"C",1);
- //Invoice Number
- $pdf->setXY($x,$y+5);
- $pdf->SetFont('Arial','B',11);
- $pdf->SetTextColor(0,0,0);
- //$pdf->Cell(25,5,"Invoice Number","B");
- $pdf->setXY($x+20,$y+5);
- $pdf->SetFont('Arial','B',11);
- //$pdf->Cell(55,5,"$inum","B","","R");
- //Invoice Date
- $pdf->setXY($x,$y+9);
- $pdf->SetFont('Arial','B',8);
- $pdf->Cell(25,5,"Invoice date","");
- $dte=date("d F Y",$operationinvoicedate*60);
- $pdf->setXY($x+35,$y+9);
- $pdf->Cell(40,5,"$dte","","","R");
- //Provider number
- $pdf->setXY($x,$y+13);
- $pdf->SetFont('Arial','B',8);
- $pdf->Cell(25,5,"Provider number","");
- $pdf->setXY($x+35,$y+13);
- $pdf->Cell(40,5,"$dplinkprovider","","","R");
- //ABN
- $pdf->setXY($x,$y+17);
- $pdf->SetFont('Arial','B',8);
- $pdf->Cell(25,5,"ABN","B");
- $pdf->setXY($x+35,$y+17);
- $pdf->Cell(40,5,"$dplinkabn","","","R");
- //Patient Name
- $pdf->SetFillColor(255,255,255);
- $pdf->setXY($x,$y+21);
- $pdf->Cell(25,5,"Patient","L","","L",1);
- $pdf->setXY($x+25,$y+21);
- $pdf->Cell(50,5,"$patienttitle $patientfirstname $patientlastname","R","","R",1);
- //Patient DOB
- $pdf->setXY($x,$y+25);
- $pdf->Cell(25,5,"Date of birth","");
- $pdf->setXY($x+35,$y+25);
- $dob=date("d F Y",strtotime($patientbirthday));
- $pdf->Cell(40,5,"$dob","","","R");
- //Medicare number
- $pdf->SetFillColor(255,255,255);
- $pdf->setXY($x,$y+29);
- $pdf->Cell(25,5,"Medicare number","");
- $pdf->setXY($x+35,$y+29);
- $num=$patientmedicarenumber;
- $num=substr($num,0,10)."-".substr($num,10,1);
- $pdf->Cell(40,5,"$num","","","R");
- //Medicare expiry
- if ($patientmedicareexpirymonth !=0 && $patientmedicareexpiryyear !=0){
- $pdf->setXY($x,$y+33);
- $pdf->Cell(25,5,"Medicare expiry","");
- $pdf->setXY($x+35,$y+33);
- $num=$patientmedicarenumber;
- $pdf->Cell(40,5,"$patientmedicareexpirymonth / $patientmedicareexpiryyear","","","R");
- }
- // INSURER
- if ($patientinsurer != ""){
- $pdf->setXY($x,$y+37);
- $pdf->Cell(25,5,"Insurer","");
- $pdf->setXY($x+35,$y+37);
- $pdf->Cell(40,5,"$patientinsurer","","","R");
- }
- //Insurance Policy Number
- if ($patientinsurerpolicy != ""){
- $pdf->setXY($x,$y+41);
- $pdf->Cell(25,5,"Insurer policy number","");
- $pdf->setXY($x+35,$y+41);
- $pdf->Cell(40,5,"$patientinsurerpolicy","","","R");
- }
- //Procedure date
- $pdf->setXY($x,$y+45);
- $pdf->Cell(25,5,"Date of service","0");
- $pdf->setXY($x+35,$y+45);
- $dt=date("d F Y",$operationstart*60);
- $pdf->Cell(40,5,"$dt","","","R");
- //Surgeon
- $pdf->setXY($x,$y+53);
- $pdf->Cell(25,5,"Referring doctor","");
- $pdf->setXY($x+35,$y+53);
- $pdf->Cell(40,5,"$surgeon","","","R");
- //Surgeon Provider
- $pdf->setXY($x,$y+57);
- $pdf->Cell(25,5,"Referring doctor provider","");
- $pdf->setXY($x+35,$y+57);
- $pdf->Cell(40,5,"$surgeonprovider","","","R");
- //Referral date
- $pdf->setXY($x,$y+61);
- $pdf->Cell(25,5,"Referral date","0");
- $pdf->setXY($x+35,$y+61);
- $dt=date("d F Y",$operationstart*60);
- $pdf->Cell(40,5,"$dt","","","R");
- //Hospital
- $pdf->setXY($x,$y+65);
- $pdf->Cell(25,5,"Hospital","");
- $pdf->setXY($x+35,$y+65);
- $pdf->Cell(40,5,"$hospital","","","R");
- //Hospital Provider
- $pdf->setXY($x,$y+69);
- $pdf->Cell(25,5,"Hospital provider","");
- $pdf->setXY($x+35,$y+69);
- $pdf->Cell(40,5,"$hospitalprovider","","","R");
- // CREATE FYI Box
- $x=10;
- $y=190;
- $pdf->Rect($x,$y,95,20);
- $pdf->SetXY($x,$y);
- $pdf->SetFont('Arial','BU',8);
- $pdf->Cell(95,5,"For your information");
- // 1st line
- $pdf->SetXY($x,$y+5);
- if ($invoicetype == 4){
- $invoiceicopayment=sprintf("%01.2f",$invoiceicopayment);
- $mes1="An additional amount of $$invoiceicopayment was billed to your insurer.";
- $pdf->SetFont('Arial','',8);
- $pdf->Cell(95,5,$mes1);
- $pdf->SetXY($x,$y+10);
- $pdf->SetFont('Arial','B',6);
- $pdf->Cell(95,5,"This invoice is yours to pay. You cannot pass this on to Medicare or your insurer.");
- }
- if ($invoicetype == 3){
- $invoicepcopayment=sprintf("%01.2f",$invoicepcopayment);
- $pdf->SetFont('Arial','',8);
- $pdf->Cell(95,5,"This is the insurer portion of a KNOWN GAP invoice.");
- $pdf->SetXY($x,$y+10);
- $mes1="An additional amount of $$invoicepcopayment was billed to the patient.";
- $pdf->SetFont('Arial','',8);
- $pdf->Cell(95,5,$mes1);
- }
- // Create barcode and put it on page
- makebarcode ($inum);
- //$pdf->Image($barcodes."BC$inum.png",10,278,40,6,"");
- $pdf->Image($barcodes."BC$inum.png",160,272,40,5,"");
- //Make Bpay Box
- if ($dplinkbpayaccepted == 1){
- $x=10;
- $y=235;
- $pdf->Rect($x,$y,40,20);
- $pdf->Image($_SESSION['pathToRoot']."images\BPAY Portrait BW Logo.gif",$x-1,$y,12,20,"GIF");
- $pdf->SetFont('Arial','',9);
- $pdf->SetXY($x+8.5,$y+5);
- $pdf->Cell(29,0,"Biller Code: ".$dplinkbpaybillercode);
- $pdf->SetXY($x+8.5,$y+13);
- $pdf->Cell(29,0,"Ref: ".$inum);
- }
- // Make direct deposit box
- if ($dplinkbankdepositaccepted == 1){
- $x=52;
- $y=235;
- $pdf->Rect($x,$y,40,20);
- $pdf->SetFont('Arial','B',10);
- $pdf->SetXY($x+0,$y+0);
- $pdf->Cell(40,5,"Direct bank deposit");
- $pdf->SetFont('Arial','',7);
- $pdf->SetXY($x+0,$y+5);
- $pdf->Cell(40,3,"A/C name: $dplinkbankaccountname","");
- $pdf->SetXY($x+0,$y+8);
- $pdf->Cell(40,8,"BSB: $dplinkbankaccountbsb","");
- $pdf->SetXY($x+0,$y+13.5);
- $pdf->Cell(40,3,"A/C no. $dplinkbankaccountnumber","");
- $pdf->SetXY($x+0,$y+17);
- $rnum=$_SESSION['ddepositprefix'].$inum;
- $pdf->Cell(40,3,"Reference $rnum","");
- }
- // Make PayPal Box
- if ($dplinkpaypalaccepted == 1){
- $x=10;
- $y=213;
- $pdf->Rect($x,$y,40,20);
- $pdf->Image($_SESSION['pathToRoot']."images\paypallogo.gif",$x+1,$y+1,20,8,"GIF");
- $pdf->SetFont('Arial','',7);
- $pdf->SetXY($x+0,$y+10);
- $pdf->Cell(30,0,"Send your payment to:");
- $pdf->SetFont('Arial','',8);
- $pdf->SetXY($x+0,$y+14);
- $pdf->Cell(30,0,"$dplinkpaypalemail");
- $pdf->SetFont('Arial','',7);
- $pdf->SetXY($x+0,$y+18);
- $pdf->Cell(30,0,"Include this number: $inum");
- }
- //Make ONLINE payment box
- if ($dplinkwebpayaccepted == 1){
- $x=10;
- $y=257;
- $pdf->Image($_SESSION['pathToRoot']."images\padlock2.gif",$x+50,$y+2,28,16,"GIF");
- $pdf->Rect($x,$y,82,20);
- $pdf->SetFont('Arial','B',10);
- $pdf->SetXY($x,$y);
- $pdf->Cell(82,4,"Secure online payment");
- $pdf->SetXY($x,$y+4);
- $pdf->SetFont('Arial','',8);
- $pdf->Cell(82,4,"$practicewebpage");
- $pdf->SetXY($x,$y+8);
- $pdf->Cell(29,4,"Follow the \"Account Payments\" link and log on as below");
- $pdf->SetXY($x,$y+12);
- $pdf->Cell(29,4,"Login code");
- $pdf->SetXY($x+15,$y+12);
- $pdf->Cell(29,4,": $inum");
- $pdf->SetXY($x,$y+17.5);
- $pdf->Cell(29,0,"Password");
- $pdf->SetXY($x+15,$y+17.5);
- $pdf->Cell(29,0,": $invoicepassword");
- }
- // Make Phone payment
- if ($dplinkvisaaccepted == 1 || $dplinkmastercardaccepted == 1 || $dplinkamexaccepted == 1 || $dplinkdinersaccepted == 1){
- $x=52;
- $y=213;
- if ($dplinkvisaaccepted == 1){
- $pdf->Image($_SESSION['pathToRoot']."images\weslogo.gif",$x,$y,10,7,"GIF");
- }
- if ($dplinkmastercardaccepted == 1){
- $pdf->Image($_SESSION['pathToRoot']."images\mastercardlogo.gif",$x+10,$y,10,7,"GIF");
- }
- if ($dplinkamexaccepted == 1){
- $pdf->Image($_SESSION['pathToRoot']."images\amexlogo.gif",$x+20,$y,10,7,"GIF");
- }
- if ($dplinkdinersaccepted == 1){
- $pdf->Image($_SESSION['pathToRoot']."images\dinerslogo.gif",$x+30,$y,10,7,"GIF");
- }
- $pdf->Image($_SESSION['pathToRoot']."images\phone.gif",$x+8,$y+7,24,13,"GIF");
- $pdf->SetXY($x+0,$y+10);
- $pdf->SetFont('Arial','B',10);
- $pdf->Cell(40,0,"Payment by phone","",0,"L");
- $pdf->SetFont('Arial','B',9);
- $pdf->SetXY($x+0,$y+14);
- $pdf->Cell(30,0,"Call us on $practicephone");
- $pdf->SetFont('Arial','B',8);
- $pdf->SetXY($x+0,$y+18);
- $pdf->Cell(30,0,"Have your credit card handy");
- $pdf->Rect($x,$y,40,20);
- }
- // BOX for payment by mail
- $x=94;
- $y=213;
- $pdf->SetXY($x,$y);
- $pdf->SetFont('Arial','B',10);
- $pdf->Cell(106,5,"Payment in person, or by mail");
- $pdf->SetFont('Arial','',8);
- $pdf->SetXY($x,$y+5);
- $pdf->Cell(106,4,"Detach this section and deliver to the address above.");
- $pdf->SetXY($x,$y+9);
- $pdf->Cell(106,4,"Cheques payable to \"$dplinkchequespayableto\"");
- if ($dplinkvisaaccepted == 1 || $dplinkmastercardaccepted == 1 || $dplinkamexaccepted == 1 || $dplinkdinersaccepted == 1){
- $pdf->SetXY($x,$y+13);
- if ($dplinkvisaaccepted == 1){
- $cards="Visa, ";
- }
- if ($dplinkmastercardaccepted == 1){
- $cards.="Mastercard, ";
- }
- if ($dplinkamexaccepted == 1){
- $cards.="American Express, ";
- }
- if ($dplinkdinersaccepted == 1){
- $cards.="Diners Club, ";
- }
- $cards=substr($cards,0,strlen($cards)-2);
- $pdf->Cell(106,4,"Or pay with $cards as below.");
- $pdf->Rect($x+1,$y+21,4,4);
- $pdf->Rect($x+5,$y+21,4,4);
- $pdf->Rect($x+9,$y+21,4,4);
- $pdf->Rect($x+13,$y+21,4,4);
- $pdf->Line($x+17,$y+23,$x+18,$y+23);
- $pdf->Rect($x+18,$y+21,4,4);
- $pdf->Rect($x+22,$y+21,4,4);
- $pdf->Rect($x+26,$y+21,4,4);
- $pdf->Rect($x+30,$y+21,4,4);
- $pdf->Line($x+34,$y+23,$x+35,$y+23);
- $pdf->Rect($x+35,$y+21,4,4);
- $pdf->Rect($x+39,$y+21,4,4);
- $pdf->Rect($x+43,$y+21,4,4);
- $pdf->Rect($x+47,$y+21,4,4);
- $pdf->Line($x+51,$y+23,$x+52,$y+23);
- $pdf->Rect($x+52,$y+21,4,4);
- $pdf->Rect($x+56,$y+21,4,4);
- $pdf->Rect($x+60,$y+21,4,4);
- $pdf->Rect($x+64,$y+21,4,4);
- $pdf->Rect($x+72,$y+21,4,4);
- $pdf->Rect($x+76,$y+21,4,4);
- $pdf->Line($x+81,$y+24,$x+83,$y+22);
- $pdf->Rect($x+84,$y+21,4,4);
- $pdf->Rect($x+88,$y+21,4,4);
- $pdf->Rect($x+92,$y+21,4,4);
- $pdf->Rect($x+96,$y+21,4,4);
- for ($i=0;$i<25;$i+=1){
- $pdf->Rect($x+1+($i*4),$y+34,4,4);
- }
- $pdf->SetXY($x+25,$y+38);
- $pdf->Cell(55,4,"Cardholder Name");
- $pdf->SetXY($x+25,$y+25);
- $pdf->Cell(55,4,"Card Number");
- $pdf->SetXY($x+80,$y+25);
- $pdf->Cell(20,4,"Expiry");
- $pdf->Line($x+2,$y+54,$x+52,$y+54);
- $pdf->SetXY($x+10,$y+54);
- $pdf->Cell(30,4,"Cardholder signature");
- $pdf->SetXY($x+60,$y+50);
- $pdf->Cell(30,4,"$");
- $pdf->Line($x+60,$y+54,$x+80,$y+54);
- $pdf->SetXY($x+62,$y+54);
- $pdf->Cell(30,4,"Amount");
- $pdf->SetXY($x+45,$y+62);
- $pdf->Cell(0,0,"$inum");
- }
- $pdf->Rect($x,$y,106,64);
- // Print line items
- $pdf->SetTextColor(0,0,0);
- for ($i=1;$i<21;$i+=1){
- if ($inv["invoiceitemfee$i"] !=0 || $op["operationitemdesc$i"] !="" ){
- $pdf->SetFont('Arial','',8);
- if ($i % 2){
- $pdf->SetFillColor(255,255,255);
- } else {
- $pdf->SetFillColor(225,225,225);
- }
- $pdf->SetXY(10,106+($i*4));
- $itemnumber=$op["operationitem$i"];
- $pdf->Cell(15,4,$itemnumber,"",0,"L",1);
- $pdf->SetXY(25,106+($i*4));
- $desc=$op["operationitemdesc$i"];
- while ($pdf->GetStringWidth($desc)>158){
- $desc=substr($desc,0,(strlen($desc)-1));
- }
- $pdf->Cell(160,4,$desc,"",0,"L",1);
- $fee="";
- if ($inv["invoiceitemfee$i"] != 0){
- $fee=sprintf("%01.2f",$inv["invoiceitemfee$i"]);
- }
- $pdf->SetXY(184,106+($i*4));
- $dol="";
- if ($fee !=0){
- $dol="$";
- }
- $pdf->Cell(3,4,$dol,"",0,"L",1);
- $pdf->SetXY(187,106+($i*4));
- $pdf->Cell(13,4,"$fee","",0,"R",1);
- }
- }
- // Print cutting thingy line
- $x=10;
- $y=211.5;
- $pdf->SetXY($x,$y);
- $pdf->Cell(0,0,"---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
- // Print line item headings...
- $pdf->SetXY(10,105);
- $pdf->SetFont('Arial','B',8);
- $pdf->SetFillColor(124,124,124);
- $pdf->SetTextColor(255,255,255);
- $pdf->Cell(15,5,"Item No.","LRTB",0,"L",1);
- $pdf->SetXY(25,105);
- $pdf->Cell(159,5,"Description of service. Lengthy descriptions may be abbreviated.","LRTB",0,"C",1);
- $pdf->SetXY(184,105);
- $pdf->Cell(16,5,"Fee","LRTB",0,"C",1);
- // Print line item box and dividers
- $pdf->Rect(10,105,190,85);
- $pdf->Line(184,105,184,190);
- $pdf->Line(25,105,25,190);
- $dexp=date("F j, Y",$invoicediscountexpiry*60);
- // Print GST
- $pdf->SetXY(105,190);
- $pdf->SetFont('Arial','B',8);
- $pdf->SetFillColor(255,255,255);
- $pdf->SetTextColor(0,0,0);
- $pdf->Cell(79,5,"GST","LRTB",0,"R",1);
- $pdf->SetXY(184,190);
- $gst=sprintf("%01.2f",$invoicegst);
- $pdf->Cell(16,5,"$gst","LRTB",0,"R",1);
- // Print discount if paid before
- if ($invoicediscountamount !=0 ){
- $dpp="Discount for prompt payment";
- $disc=sprintf("%01.2f",$invoicediscountamount);
- }
- $pdf->SetXY(105,195);
- $pdf->Cell(79,5,"$dpp","LRTB",0,"R",1);
- $pdf->SetXY(184,195);
- $pdf->Cell(16,5,"$disc","LRTB",0,"R",1);
- // Payable after
- if ($invoicediscountamount !=0 ){
- $apam="Full amount payable after $dexp";
- $payafter=sprintf("%01.2f",$invoicetotal);
- }
- $pdf->SetXY(105,200);
- $pdf->Cell(79,5,"$apam","LRTB",0,"R",1);
- $pdf->SetXY(184,200);
- $pdf->Cell(16,5,"$payafter","LRTB",0,"R",1);
- // Payable before
- $pdf->SetXY(105,205);
- $pdf->SetFillColor(200,200,200);
- if ($invoicediscountamount !=0 ){
- $adn=" until $dexp";
- $pdf->Cell(79,5,"Discounted amount valid until $dexp","LRTB",0,"R",1);$pdf->SetXY(184,215);
- } else {
- $pdf->Cell(79,5,"Amount payable","LRTB",0,"R",1);$pdf->SetXY(184,215);
- }
- $pdf->SetXY(184,205);
- $paybefore=sprintf("%01.2f",$invoicetotalwithdiscount);
- $pdf->Cell(16,5,"$paybefore","LRTB",0,"R",1);
- if ($nme==""){
- $nme="Invoice-$inum.pdf";
- }
- $pdf->Output($pdfs.$nme,"F");
- return 1;
- }
- function password($num){
- $chars="aaaaqwertyuoplkhfdsazxcvbnmbbbbccccddddeeeeffffgggghhhhiiiikkkkmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz111122223333444455556666777788889999";
- return substr(str_shuffle($chars),0,$num);
- }
- function emailsubstitute($txt,$num){
- // Function to replace the ##doctorname## syle entries in an email with the proper text.
- // Requires the invoice number, so it can look up all the databases to find the proper text entries.
- // Possible substitutions are :
- // payer title payers title taken from invoice
- // payer firstname
- // payer lastname
- // amount owing
- // amount paid
- // discount expiry
- // extended discount
- // invoice total
- // invoice discounted total
- // invoice number
- // invoice password
- include $_SESSION['pathToRoot']."setup/settings.php";
- include $_SESSION['pathToRoot']."setup/arrays.php";
- $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect error.");
- // First get details of the invoice itself
- $query="SELECT * FROM invoice WHERE invoicecode=\"$num\"";
- $res = mysqli_query($con, $query) or die(mysqli_error());
- if (mysqli_num_rows($res) == 1){
- $r=mysqli_fetch_assoc($res);
- extract($r);
- // Get the invoice, now get the operation
- $query="SELECT * FROM operation WHERE operationcode=\"$invoiceoperationcode\"";
- $res = mysqli_query($con, $query) or die(mysqli_error());
- if (mysqli_num_rows($res) == 1){
- $r=mysqli_fetch_assoc($res);
- extract($r);
- // Got the operation. Now get the patient
- $query="SELECT * FROM patient WHERE patientcode=\"$operationpatientcode\"";
- $res = mysqli_query($con, $query) or die(mysqli_error());
- if (mysqli_num_rows($res) == 1){
- $r=mysqli_fetch_assoc($res);
- extract($r);
- // Gto the patient. Get the doctor
- $query="SELECT * FROM doctor WHERE doctorcode=\"$operationdoctorcode\"";
- $res = mysqli_query($con, $query) or die(mysqli_error());
- if (mysqli_num_rows($res) == 1){
- $r=mysqli_fetch_assoc($res);
- extract($r);
- // Got the doctor. Get the dplink.
- $query="SELECT * FROM dplink WHERE dplinkcode=\"$operationdplinkcode\"";
- $res = mysqli_query($con, $query) or die(mysqli_error());
- if (mysqli_num_rows($res) == 1){
- $r=mysqli_fetch_assoc($res);
- extract($r);
- // Got the DPlink. Get the practice
- $query="SELECT * FROM practice WHERE practicecode=\"$dplinkpractice\"";
- $res = mysqli_query($con, $query) or die(mysqli_error());
- if (mysqli_num_rows($res) == 1){
- $r=mysqli_fetch_assoc($res);
- extract($r);
- } else {
- $err.="Practice does not exist. ";
- }
- } else {
- $err.="DPlink does not exist. ";
- }
- } else {
- $err.="Doctor does not exist. ";
- }
- } else {
- $err.="Patient does not exist. ";
- }
- } else {
- $err.="Operation does not exist. ";
- }
- } else {
- $err.="Invoice does not exist. ";
- }
- $txt = str_ireplace(chr(13),"<br>",$txt);
- $txt = str_ireplace("##payer title##",$invoicepayertitle,$txt);
- $txt = str_ireplace("##payer firstname##",$invoicepayerfirstname,$txt);
- $txt = str_ireplace("##payer first name##",$invoicepayerfirstname,$txt);
- $txt = str_ireplace("##payer lastname##",$invoicepayerlastname,$txt);
- $txt = str_ireplace("##payer last name##",$invoicepayerlasttname,$txt);
- $txt = str_ireplace("##amount owing##",sprintf("%01.2f",$invoiceamountowing),$txt);
- $txt = str_ireplace("##amount paid##",sprintf("%01.2f",$invoiceamountpaid),$txt);
- $txt = str_ireplace("##discount expiry##",date("d F, Y",($invoicediscountexpiry*60)),$txt);
- $txt = str_ireplace("##extended discount##",date("d F, Y",($invoiceextendeddiscount*60)),$txt);
- $txt = str_ireplace("##invoice total##",$invoicetotal,$txt);
- $txt = str_ireplace("##invoice discounted total##",sprintf("%01.2f",$invoicetotalwithdiscount),$txt);
- $txt = str_ireplace("##invoice number##",$invoicecode,$txt);
- $txt = str_ireplace("##invoice password##",$invoicepassword,$txt);
- $txt = str_ireplace("##operation name##",$operationname,$txt);
- $txt = str_ireplace("##hospital name##",$operationhospitalname,$txt);
- $txt = str_ireplace("##surgeon name##",$operationsurgeonname,$txt);
- $txt = str_ireplace("##operation name##",$operationname,$txt);
- $txt = str_ireplace("##operation date##",date("d F, Y",($operationstart*60)),$txt);
- $txt = str_ireplace("##patient title##",$patienttitle,$txt);
- $txt = str_ireplace("##patient fist name##",$patientfirstname,$txt);
- $txt = str_ireplace("##patient last name##",$patientlastname,$txt);
- $txt = str_ireplace("##patient insurer##",$patientinsurer,$txt);
- $txt = str_ireplace("##patient medicare number##",$patientmedicarenumber,$txt);
- $txt = str_ireplace("##doctor title##",$doctortitle,$txt);
- $txt = str_ireplace("##doctor first name##",$doctorfirstname,$txt);
- $txt = str_ireplace("##doctor last name##",$doctorlastname,$txt);
- $txt = str_ireplace("##doctor provider##",$dplinkprovider,$txt);
- $txt = str_ireplace("##doctor provider number##",$dplinkprovider,$txt);
- $txt = str_ireplace("##practice web page##",$practicewebpage,$txt);
- $txt = str_ireplace("##practice webpage##",$practicewebpage,$txt);
- $txt = str_ireplace("##practice phone number##",$practicephone,$txt);
- $txt = str_ireplace("##practice fax number##",$practicefax,$txt);
- $txt = str_ireplace("##practice email##",$practiceemail,$txt);
- $txt = str_ireplace("##disclaimer##",$disclaimer,$txt);
- return $txt;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement