Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 66.13 KB | None | 0 0
  1. <?php
  2. // includes/functions/global.php
  3. // functions that are essential to any and all pages.
  4.  
  5. function checkcode($code, $surname, $firstname)
  6. {
  7.     // This function takes a licence code and compares it to a doctor name to see if it is valid
  8.     // Possible responses
  9.     // 1 - Improperly formatted code or doctor name
  10.     // 2 - Invalid code / doctor combination
  11.     // 3 - Valid code / doctor but has expired
  12.     // DATE RETURNED - Valid and not yet expired Gives date of expiry.
  13.     $doctor = strtolower($surname . $firstname);
  14.     $code = strtolower($code);
  15.     if (strlen($code) != 17 or strlen(doctor) == 0) {
  16.         $ret = 1;
  17.     }
  18.     if ($ret != 1) {
  19.         $rdte = substr($code, 3, 5) . substr($code, -6, 3);
  20.         $dte = strrev($rdte);
  21.         $hsh = md5($dte . $doctor . $_SESSION['seed']);
  22.         if (substr($code, 0, 3) != substr($hsh, 0, 3)) {
  23.             $ret = 2;
  24.         }
  25.         if (substr($code, -3, 3) != substr($hsh, -3, 3)) {
  26.             $ret = 2;
  27.         }
  28.         if (substr($code, 8, 3) != substr($hsh, 9, 3)) {
  29.             $ret = 2;
  30.         }
  31.     }
  32.     if ($ret != 1 and $ret != 2) {
  33.         $tod = date("Y") . date("m") . date("d");
  34.         if ($tod > $dte) {
  35.             $ret = 3;
  36.         }
  37.         if ($tod <= $dte) {
  38.             $ret = $dte;
  39.         }
  40.     }
  41.     return $ret;
  42. }
  43.  
  44. function checkdigit($num){
  45.     $tot=0;
  46. for ($i=strlen($num)-1;$i>-1;$i--){
  47.     $m=substr($num,$i,1);
  48.     if ($i % 2 != 0){
  49.         $m=$m*2;
  50.     }
  51.     if ($m > 9){
  52.         $m=$m-9;
  53.     }
  54.     $tot=$tot+$m;
  55. }
  56. $u=10-($tot % 10);
  57. if ($u==10){
  58.     $u=0;
  59. }
  60. return $u;
  61. }
  62.  
  63. function ccval($number){
  64.   $number=preg_replace('/\D/', '', $number);
  65.   $number_length=strlen($number);
  66.   $parity=$number_length % 2;
  67.   $total=0;
  68.   for ($i=0; $i<$number_length; $i++) {
  69.     $digit=$number[$i];
  70.     if ($i % 2 == $parity) {
  71.       $digit*=2;
  72.       if ($digit > 9) {
  73.         $digit-=9;
  74.       }
  75.     }
  76.     $total+=$digit;
  77.   }
  78.  return ($total % 10 == 0) ? TRUE : FALSE;
  79. }  
  80.  
  81.  
  82. function checkdigit2($str){
  83.     if (is_string($str)){
  84.             for ($i=0;$i<strlen($str); $i++){
  85.                 $out = $out . Ord(substr($str,$i,1));
  86.             }
  87.     }  else {
  88.             $out=$str;
  89.     }
  90.     if ((int)(strlen($out)/2)  == (int)((strlen($out)/2)+0.9))
  91.             $m=0;
  92.         else
  93.             $m=1;
  94.     for ($i=0;$i<strlen($out); $i++){
  95.             $m=($m==1)?2:1;
  96.             $v=$m*substr($out, $i, 1);
  97.             if ($v>9)
  98.                 $v=(substr($v, 0, 1)+substr($v, 1, 1));
  99.             $sum = $sum + $v;
  100.     }
  101.     $cd=(round($sum/10+0.49)*10) - $sum;
  102.     return $cd;
  103. }
  104.  
  105. function writelog($event){
  106.     // figure out the filename first
  107.     $logname = date("Ymd D, M j, Y") . ".log";
  108.     $log = fopen($_SESSION['loglocation'] . $logname, "a");
  109.     $stamp = date("Y:m:d H:i:s");
  110.     if (isset($_SESSION['username'])) {
  111.         $user = $_SESSION['username'];
  112.     } else {
  113.         $user = "No active user";
  114.     }
  115.     $user = str_pad(substr($user, 0, 15), 15, " ");
  116.     $ip = str_pad($_SERVER['REMOTE_ADDR'], 15, " ");
  117.     fwrite($log, $stamp . " " . $user . " " . $ip . " " . $event . PHP_EOL);
  118.     fclose($log);
  119. }
  120. function convertdate($dte)
  121. {
  122.     $month = array("", "January", "February", "March", "April", "May", "June",
  123.         "July", "August", "September", "October", "November", "December");
  124.     $yr = (int)substr($dte, 0, 4);
  125.     $mo = (int)substr($dte, 4, 2);
  126.     $dy = (int)substr($dte, 6, 2);
  127.     $m = $month[$mo];
  128.     return $m . " " . $dy . ", " . $yr;
  129. }
  130.  
  131. function newcode()
  132. {
  133.     $a = uniqid();
  134.     $b = "abcdefghijklmnopqrstuvwxyz123456789";
  135.     $c = $a . substr(str_shuffle($b), 0, 4);
  136.     return $c;
  137. }
  138.  
  139. function reducedate($inp)
  140. {
  141.     $a = substr($inp, 6, 4) . substr($inp, 3, 2) . substr($inp, 0, 2);
  142.     return $a;
  143. }
  144.  
  145. function makebarcode($cd){
  146.     $nm=$cd;
  147.     include $_SESSION['pathToRoot']."setup/settings.php";
  148.     // Function creates a barcode using input data $inp
  149.     // and saves it to the default images/barcode directory
  150.     // Filename is BC$cd.png
  151.     // barcode is 150 X 30 pixels, black and white.
  152.     // This is enough for 10 digits.
  153.     $codestring="";
  154.     $sum=104; // value of codeB start char
  155.     for ($j=0;$j<strlen($cd);$j++) {
  156.         $c=substr($cd,$j,1); // get a single chracter
  157.         $a=ord($c)-32;       // subtract 32 - printable charset starts at 32
  158.         if ($a<0||$a>102) {
  159.             // we have an unprintable character
  160.             $a=31;
  161.         }      
  162.         $c=chr($a+16);
  163.         $codestring.=$c;
  164.             // now the calc
  165.         $sum+=($a*($j+1));
  166.     }
  167.     // finished with string, calc checsum
  168.     $checksum=$sum % 103;
  169.     $checksum+=16;
  170.     $cd=chr(104+16) . $codestring . chr($checksum) . chr(106+16);
  171.     $im = @imagecreate(150, 30) or die("Cannot Initialize new GD image stream");
  172.     $background_color = imagecolorallocate($im, 255,255,255);
  173.     $black = imagecolorallocate($im, 0, 0, 0);
  174.     imagettftext($im, 25, 0, 0,28, $black, $fontpath."K128.TTF", $cd);
  175.     imagepng($im,$barcodes."BC$nm.png");
  176.     imagedestroy($im);
  177. }
  178.  
  179. function insurerlist($order)
  180. {
  181.     // This function creates an array that is a list of insurers and their codes.
  182.     // If "order" is "a" the list is sorted alphabetically.
  183.     // if "order" is "p" the list is sorted by insurer's popularity'
  184.     // in "order" is "all" then all insurers are included, not just active ones.
  185.     include $_SESSION['pathToRoot']."setup/settings.php";
  186.     $query = "SELECT * FROM insurer WHERE insurerstatus=1";
  187.     $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect error making insurer list.");
  188.     $result = mysqli_query($con, $query) or die("SQL Query Error getting list of insurers.");
  189.     $res = mysqli_num_rows($result);
  190.     unset($lst);
  191.     if ($res > 0) {
  192.         while ($row = mysqli_fetch_assoc($result)) {
  193.             extract($row);
  194.             $lst[$cnt] = array("insname" => $insurername, "inscode" => $insurercode);
  195.             $cnt += 1;
  196.         }
  197.     }
  198.     return $lst;
  199. }
  200.  
  201. function surgeonlist($doctor)
  202. {
  203.     // This function creates an array that is a list of surgeons and thier codes.
  204.     // The array contains ALL the active surgeons in the surgeon table.
  205.     // If $doctor is specified (as a code, not as a name) the list is sorted according to
  206.     // the popularity of that surgeon with that doctor.
  207.     // ie. examine the last 1000 accounts this doctor has issued and see which surgeon is listed.
  208.     // Rank the list according to the frequency of occurrence on this list.
  209.     // Otherwise they are sorted alphabetically by surname.
  210.     include "setup/settings.php";
  211.     $query = "SELECT * FROM surgeon WHERE surgeonstatus=1";
  212.     $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect error making surgeon list.");
  213.     $result = mysqli_query($con, $query) or die("SQL Query Error getting list of surgeons.");
  214.     $res = mysqli_num_rows($result);
  215.     unset($lst);
  216.     if ($res > 0) {
  217.         while ($row = mysqli_fetch_assoc($result)) {
  218.             extract($row);
  219.             $lst[] = array("sname" => $surgeontitle . " " . $surgeonfirstname . " " . $surgeonlastname,
  220.                 "scode" => $insurercode);
  221.         }
  222.     }
  223.     return $lst;
  224. }
  225.  
  226. function hospitallist($doctor)
  227. {
  228.     // This function creates an array that is a list of hospital and thier codes.
  229.     // The array contains ALL the active hospital in the hospitals table.
  230.     include "setup/settings.php";
  231.     $query = "SELECT * FROM hospital WHERE hospitalstatus=1";
  232.     $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect error making hospital list.");
  233.     $result = mysqli_query($con, $query) or die("SQL Query Error getting list of hospital.");
  234.     $res = mysqli_num_rows($result);
  235.     unset($lst);
  236.     if ($res > 0) {
  237.         while ($row = mysqli_fetch_assoc($result)) {
  238.             extract($row);
  239.             $lst[] = array("hname" => $hospitalname, "hcode" => $hospitalcode);
  240.         }
  241.     }
  242.     return $lst;
  243. }
  244.  
  245. function doctorlist($option) {
  246.     // This function creates an array that is a list of active doctors and thier codes.
  247.     // The array contains ALL the active doctors in the doctors table.
  248.     // IF $option is "exclude" then doctors that have no practices are excluded from the list.
  249.     include "setup/settings.php";
  250.     $query = "SELECT * FROM doctor WHERE doctorstatus=1";
  251.     $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect error making doctor list.");
  252.     $result = mysqli_query($con, $query) or die("SQL Query Error getting list of hospital.");
  253.     $res = mysqli_num_rows($result);
  254.     unset($lst);
  255.     if ($res > 0) {
  256.         while ($row = mysqli_fetch_assoc($result)) {
  257.             extract($row);
  258.             $query2 = "SELECT * FROM dplink WHERE dplinkdoctor=\"$doctorcode\" AND dplinkstatus=\"1\"";
  259.             $result2 = mysqli_query($con, $query2) or die("SQL Query Error getting list of hospital.");
  260.             if (mysqli_num_rows($result2) != 0 || $option != "exclude") {
  261.                 $lst[] = array("dname" => "$doctorfirstname $doctorlastname",
  262.                     "dcode" => $doctorcode);
  263.             }
  264.         }
  265.     }
  266.     return $lst;
  267. }
  268.  
  269. function workingschedule ($date, $ins, $stt){
  270.     // finds which schedule was in operation for an insurer, on a date, in a state
  271.     // date should be YYYYMMDD format
  272.     // insurer should be 17 digit code
  273.     // state can be a number 1-9 or abbreviation like SA, ACT, WA  
  274.     include $_SESSION['pathToRoot']."setup/settings.php";
  275.     include $_SESSION['pathToRoot']."setup/arrays.php";
  276.     $err=0;
  277.     if ($ins=="mbs"){
  278.         $ins="mbs00000000000000";
  279.     }
  280.     // check bounds conditions for state
  281.     if($stt==0){
  282.         $stt=$statebynumber[$stt];
  283.     }
  284.     if ($stt == 0 || $stt > 8){
  285.         $err=1;
  286.     }
  287.     $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect checking insurer.");
  288.     // check bounds conditions for insurer, ie does the insurer exist?
  289.     if ($ins != "mbs00000000000000"){
  290.         $query = "SELECT * FROM insurer WHERE insurercode=\"$ins\"";
  291.         $result = mysqli_query($con, $query) or die("SQL Query Error checking insurer.");
  292.         $res = mysqli_num_rows($result);
  293.         if ($res == 0){
  294.             $err=1;
  295.         }
  296.     }
  297.     // check bounds conditions for date - ie is it a valid date?
  298.     if (strlen($date) != 8 || $date < 20060000 || $date > 20350000){
  299.         $err=1;
  300.     }
  301.     $winner="none";
  302.     if (!$err){
  303.         // All inputs are valid, so start processing
  304.         $query="SHOW TABLES LIKE \"is$ins%\"";
  305.         $result = mysqli_query($con, $query) or die("SQL Query Error checking insurer.");
  306.         $res = mysqli_num_rows($result);
  307.         if ($res > 0){
  308.             // There is at least 1 table for this insurer
  309.             $diff=100000000;
  310.             while($row=mysqli_fetch_array($result)){
  311.                 if(substr($row[0],19,1) == $stt || substr($row[0],19,1) == 9){
  312.                     //we have a compatible state. What about the date?
  313.                     $dt=substr($row[0],20,8);
  314.                     $datediff=$date-$dt;
  315.                     if ($datediff >= 0){
  316.                         // only consider tables starting ON OR BEFORE the specified date
  317.                         if ($datediff < $diff){
  318.                             // Only consider tables bettering the current match
  319.                             // Then we have a new winner. Record it.
  320.                             $diff=$datediff; // The new record to beat
  321.                             $winner=$row[0]; // The new winning table
  322.                         }
  323.                     }
  324.                 }
  325.             }
  326.         }
  327.     } else {
  328.         $winner="error";
  329.     }
  330.     return $winner;
  331. }
  332.  
  333. function doctorschedule ($date, $doc){
  334.     // finds which schedule was in operation for an insurer, on a date, in a state
  335.     // date should be YYYYMMDD format
  336.     // insurer should be 17 digit code
  337.     // state can be a number 1-9 or abbreviation like SA, ACT, WA  
  338.     include $_SESSION['pathToRoot']."setup/settings.php";
  339.     include $_SESSION['pathToRoot']."setup/arrays.php";
  340.     $err=0;
  341.     $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect checking doctor.");
  342.     // check bounds conditions for doctor, ie does the doctor exist?
  343.     $query = "SELECT * FROM doctor WHERE doctorcode=\"$doc\"";
  344.     $result = mysqli_query($con, $query) or die("SQL Query Error checking doctor.");
  345.     $res = mysqli_num_rows($result);
  346.     if ($res == 0){
  347.         $err=1;
  348.     }
  349.     // check bounds conditions for date - ie is it a valid date?
  350.     if (strlen($date) != 8 || $date < 20060000 || $date > 20350000){
  351.         $err=1;
  352.     }
  353.     $winner="none";
  354.     if (!$err){
  355.         // All inputs are valid, so start processing
  356.         $query="SHOW TABLES LIKE \"ds$doc%\"";
  357.         $result = mysqli_query($con, $query) or die("SQL Query Error checking doctor.");
  358.         $res = mysqli_num_rows($result);
  359.         if ($res > 0){
  360.             // There is at least 1 table for this doctor
  361.             $diff=100000000;
  362.             while($row=mysqli_fetch_array($result)){
  363.                 $dt=substr($row[0],19,8);
  364.                 $datediff=$date-$dt;
  365.                 if ($datediff >= 0){
  366.                     // only consider tables starting ON OR BEFORE the specified date
  367.                     if ($datediff < $diff){
  368.                         // Only consider tables bettering the current match
  369.                         // Then we have a new winner. Record it.
  370.                         $diff=$datediff; // The new record to beat
  371.                         $winner=$row[0]; // The new winning table
  372.                     }
  373.                 }
  374.             }
  375.         }
  376.     } else {
  377.         $winner="error";
  378.     }
  379.     return $winner;
  380. }
  381.  
  382. function calculateinvoice($invDate, $procStart, $procEnd, $procDuration, $procState, $docCode, $dplCode, $insCode, $feePercent, $discPercent, $discDuration, $feeType, $dollarsPerUnit, $dollarsPerHour, $billTo, $gst, $itemNumber, $itemValue){
  383.     unset($btb);
  384.     // complex function takes multiple inputs and (if they are valid) returns an array with billing data.
  385.     // Validation of input....
  386.     // Validate invoice date
  387.     // $fe is the flag for FATAL ERROR
  388.     include $_SESSION['pathToRoot']."setup/settings.php";
  389.     include $_SESSION['pathToRoot']."setup/arrays.php";
  390.     include_once$_SESSION['pathToRoot']."includes/functions/global.php";   
  391.     $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect error calculating invoice.");
  392.     $fe="";
  393.     $er="";
  394.     $timeNow=strtotime("now");
  395.     // ASSESS INVOICE DATE
  396.     $invDate=strtotime($invDate);
  397.     if ($invDate-$timeNow > 63072000 || $invDate-$timeNow < -63072000){
  398.         $er=$er."a|";
  399.         $btb[71]=$btb[71]."Invalid invoice date.BUM";
  400.     }
  401.     // ASSESS START TIME
  402.     if (($procStart*60)-$timeNow > 63072000 || ($procStart*60)-$timeNow < -63072000){
  403.         $er=$er."b|";
  404.         $btb[71]=$btb[71]."Invalid procedure start date.BUM";
  405.     }  
  406.     // ASSESS END TIME
  407.     if ($procEnd-$timeNow > 63072000 || $procEnd-$timeNow < -63072000){
  408.         $er=$er."c|";
  409.     }
  410.     // ASSESS PROCEDURE DURATION
  411.     if ($procDuration == 0){       
  412.         $procDuration=($procEnd-$procStart)/60;
  413.     }
  414.     if ($procDuration < 0 || $procDuration > 1440){
  415.         $er=$er."d|";
  416.     }
  417.     // ASSESS PROCEDURE STATE..if state is set, use it. If not, check provider number. If not, use default state.
  418.     $st=$defaultstate;
  419.     $q1="SELECT dplinkpractice FROM dplink WHERE dplinkcode=\"$dplCode\"";
  420.     $r1 = mysqli_query($con, $q1) or die(mysqli_error());
  421.     if (mysqli_num_rows($r1) == 1){
  422.         $row=mysqli_fetch_array($r1);
  423.         $q2="SELECT practicestate FROM practice WHERE practicecode=\"$row[0]\"";
  424.         $r2 = mysqli_query($con, $q2) or die(mysqli_error());
  425.         if (mysqli_num_rows($r2) == 1){
  426.             $row=mysqli_fetch_array($r2);
  427.             if ($statebynumber[$row[0]] >0 && $statebynumber[$row[0]] < 9){
  428.                 $st=$row[0];
  429.             }
  430.         }
  431.     }
  432.     if ($statebynumber[$procState] > 0 && $statebynumber[$procState] < 9){
  433.         $st=$procState;
  434.     }
  435.     $procState=$st;
  436.     // ASSESS FEE PERCENT
  437.     if ($feePercent < 1){
  438.         $er=$er."e|";
  439.     }
  440.     // ASSESS Discount PERCENT
  441.     if ($discPercent <0 || $discPercent > 99){
  442.         $er=$er."f|";
  443.     }
  444.     // ASSESS DISCOUNT DURATION
  445.     if ($discDuration < 0 || $discDuration > 365){
  446.         $er=$er."g|";
  447.     }
  448.     // ASSESS DOLLARS PER UNIT
  449.     if ($dollarsPerUnit < .01){
  450.         $er=$er."h|";
  451.     }
  452.     // ASSESS DOLLARS PER HOUR
  453.     if ($dollarsPerHour < .01){
  454.         $er=$er."i";
  455.     }
  456.     // ASSESS BILLTO
  457.     if ($billTo != "patient" && $billTo != "insurer" && $billTo !="both"){
  458.         $er=$er."j|";
  459.         $fe=$fe."j|";
  460.     }
  461.     if ($billTo == "insurer"){
  462.         $discDuration=0;
  463.         $discPercent=0;
  464.     }
  465.     // ONLY DO ANY OF THIS IF THERE ARE NO FATAL ERRORS
  466.     if ($fe==""){
  467.         // OH Good...no fatal errors so far.
  468.         // Convert the procedure start date/time into a YYMMDD format. Call it $psd
  469.         $psd=date("Ymd",$procStart*60);
  470.         // Check if the feetype insurer has a table valid on the procedure date. If so, call it $insTable
  471.         if ($feeType !="doctor" && $feeType !="mbs" && $feeType !="dpu" && $feeType !="dph" && $feeType !="ama" && $feeType !="manual"){
  472.                     $res=workingschedule($psd,$feeType,$procState);
  473.         if ($res !="error" && $res !="none"){
  474.             $insTable=$res;
  475.         } else {
  476.             // Flag a fatal error
  477.             $btb[71]=$btb[71]."Selected insurer has no fee table for procedure date.BUM";      
  478.         }
  479.         }
  480.  
  481.         // Check if the patient's insurer does GAP-COVER. If so, $knowngap=1
  482.         $gapcover=0;
  483.         if ($insCode !=""){
  484.             $q1="SELECT insurerknowngap FROM insurer WHERE insurercode=\"$insCode\"";
  485.             $r1 = mysqli_query($con, $q1) or die(mysqli_error());
  486.             if (mysqli_num_rows($r1) == 1){
  487.                 $row1=mysqli_fetch_array($r1);
  488.                 $knowngap=$row1[0];
  489.             }
  490.         }
  491.         // check if the patient's insurer has a fee table on this date. If so, call it $patInsTable
  492.         if ($insCode !=""){
  493.             $res=workingschedule($psd,$insCode,$procState);
  494.             if ($res !="error" && $res !="none"){
  495.                 $patInsTable=$res;
  496.             } else {
  497.             // Flag a non fatal error
  498.                 $btb[72]=$btb[72]."Patients insurer has no fee table for procedure date.BUM";
  499.             }
  500.         }
  501.  
  502.            
  503.         // Find the Medicare table active on the procedure date. Call is $medicareTable
  504.         $res=workingschedule($psd,"mbs",$procState);
  505.         if ($res !="error" && $res !="none"){
  506.             $medicareTable=$res;
  507.         }
  508.         // Find the doctor's fee table on the procedure date. If found, call it $doctorTable
  509.         $res=doctorschedule($psd,$docCode);
  510.         if ($res !="error" && $res !="none"){
  511.             $doctorTable=$res;
  512.         }
  513.    
  514.     } else {
  515.         // CRAP  IF WE ARE HERE THEN THERE IS A FATAL ERROR.
  516.     }
  517.     // OK...lets start calculating the TOTAL fee for each item number.
  518.     switch($feeType){
  519.         case "manual":
  520.             // Not much to do here. The values don't change
  521.         break;
  522.         case "doctor":
  523.             // Need to look up values in doctor's billing schedule
  524.             if ($doctorTable != ""){
  525.                 // Good we have a doctors table of fees
  526.                 // First iteration populates all fees that actually have a value
  527.                 for ($i4=1;$i4<21;$i4+=1){
  528.                     if ($itemNumber[$i4] != ""){
  529.                         $q3="SELECT * from $doctorTable WHERE scheduleitemnumber=\"$itemNumber[$i4]\"";
  530.                         if ($itemNumber[$i4] !=0){
  531.                             $q3="SELECT * from $doctorTable WHERE scheduleitemnumber=$itemNumber[$i4]";
  532.                         }
  533.                         $r3 = mysqli_query($con, $q3) or die(mysqli_error());
  534.                         if (mysqli_num_rows($r3) == 1){
  535.                             $row3=mysqli_fetch_array($r3);
  536.                             $itemValue[$i4]=$row3[1]*$feePercent/100;
  537.                         }
  538.                     }
  539.                 }
  540.                 // Second iteration looks for derived fees and calculates those, based on the OTHER values
  541.                 for ($i4=1;$i4<21;$i4+=1){
  542.                     if ($itemNumber[$i4] == 25025){
  543.                         for($i5=1;$i5<21;$i5+=1){
  544.                             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){
  545.                                 $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
  546.                             }
  547.                         }
  548.                        
  549.                     }
  550.                     if ($itemNumber[$i4] == 25030 ){
  551.                         for($i5=1;$i5<21;$i5+=1){
  552.                             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)){
  553.                                 $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
  554.                             }
  555.                         }
  556.                     }
  557.                     if ($itemNumber[$i4] == 25050 ){
  558.                         for($i5=1;$i5<21;$i5+=1){
  559.                             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)){
  560.                                 $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
  561.                             }
  562.                         }
  563.                     }                  
  564.                 }
  565.             } else {
  566.                 // There is no doctors table of fees so flag a fatal error
  567.                 $btb[71]=$btb[71]."No doctors fee table for procedure date.BUM";
  568.             }
  569.         break;
  570.         case "dph":
  571.             if ($dollarsPerHour > 0){
  572.                 if ($procDuration > 0 && $procDuration <=1440){
  573.                     $itemValue[1]=$procDuration*$dollarsPerHour/60;
  574.                 } else {
  575.                     $btb[71]=$btb[71]."Invalid procedure duration.BUM";
  576.                 }
  577.             } else {
  578.                 $btb[71]=$btb[71]."Invalid value for dollars per hour.BUM";
  579.             }
  580.         break;
  581.         case "dpu":
  582.             if ($dollarsPerUnit > 0){
  583.                 for ($i1=1;$i1<21;$i1+=1){
  584.                     if ($itemNumber[$i1] != ""){
  585.                         $q1="SELECT itemunits FROM item WHERE itemitemnumber=\"$itemNumber[$i1]\"";
  586.                         if ($itemNumber[$i1] !=0){
  587.                             $q1="SELECT itemunits FROM item WHERE itemitemnumber=$itemNumber[$i1]";
  588.                         }
  589.                         $r1 = mysqli_query($con, $q1) or die(mysqli_error());
  590.                         if (mysqli_num_rows($r1) == 1){
  591.                             $row1=mysqli_fetch_array($r1);
  592.                             if ($row1[0] > 0){
  593.                                 $itemValue[$i1]=$dollarsPerUnit*$row1[0];
  594.                             }
  595.                         }
  596.                     }
  597.                 }
  598.                 for ($i4=1;$i4<21;$i4+=1){
  599.                     if ($itemNumber[$i4] == 25025){
  600.                         for($i5=1;$i5<21;$i5+=1){
  601.                             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){
  602.                                 $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
  603.                             }
  604.                         }
  605.                        
  606.                     }
  607.                     if ($itemNumber[$i4] == 25030 ){
  608.                         for($i5=1;$i5<21;$i5+=1){
  609.                             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)){
  610.                                 $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
  611.                             }
  612.                         }
  613.                     }
  614.                     if ($itemNumber[$i4] == 25050 ){
  615.                         for($i5=1;$i5<21;$i5+=1){
  616.                             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)){
  617.                                 $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
  618.                             }
  619.                         }
  620.                     }                  
  621.                 }
  622.             } else {
  623.                 $btb[71]=$btb[71]."Invalid dollar value per unit.BUM";
  624.             }
  625.         break;
  626.         case "mbs":
  627.             // Need to look up values in mbs billing schedule
  628.             if ($medicareTable != ""){
  629.                 // Good we have a mbs table of fees
  630.                 // Get the value of a unit from item 23010 call it $mbsUnitValue - in case we need it for item 25200 or 25205
  631.                 $q1="SELECT insurerschedulevalue FROM $medicareTable WHERE insurerscheduleitemnumber=23010";
  632.                 $r1 = mysqli_query($con, $q1) or die(mysqli_error());
  633.                 $row1=mysqli_fetch_array($r1);
  634.                 $mbsUnitValue=$row1[0];
  635.                 // First iteration populates all fees that actually have a value
  636.                 for ($i4=1;$i4<21;$i4+=1){
  637.                     if ($itemNumber[$i4] != ""){
  638.                         $q3="SELECT * FROM $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i4]\"";
  639.                         if ($itemNumber[$i4] !=0){
  640.                             $q3="SELECT * FROM $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i4]";
  641.                         }
  642.                         $r3 = mysqli_query($con, $q3) or die(mysqli_error());
  643.                         if (mysqli_num_rows($r3) == 1){
  644.                             $row3=mysqli_fetch_array($r3);
  645.                             $itemValue[$i4]=$row3[1]*$feePercent/100;
  646.                             if ($itemNumber[$i4]==25200 || $itemNumber[$i4]==25205){
  647.                                 $itemValue[$i4]=$mbsUnitValue*5*$feePercent/100;
  648.                             }
  649.                         }
  650.                     }
  651.                 }
  652.                 // Second iteration looks for derived fees and calculates those, based on the OTHER values
  653.                 for ($i4=1;$i4<21;$i4+=1){
  654.                     if ($itemNumber[$i4] == 25025){
  655.                         for($i5=1;$i5<21;$i5+=1){
  656.                             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){
  657.                                 $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
  658.                             }
  659.                         }
  660.                        
  661.                     }
  662.                     if ($itemNumber[$i4] == 25030 ){
  663.                         for($i5=1;$i5<21;$i5+=1){
  664.                             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)){
  665.                                 $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
  666.                             }
  667.                         }
  668.                     }
  669.                     if ($itemNumber[$i4] == 25050 ){
  670.                         for($i5=1;$i5<21;$i5+=1){
  671.                             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)){
  672.                                 $itemValue[$i4]=$itemValue[$i4]+($itemValue[$i5]*.5);
  673.                             }
  674.                         }
  675.                     }                  
  676.                 }
  677.             } else {
  678.                 // There is no medicare table of fees so flag a fatal error
  679.                 $btb[71]=$btb[71]."No medicare fee table for procedure date.BUM";
  680.             }      
  681.         break;
  682.         case "ama":
  683.        
  684.         break;
  685.         default:
  686.             if ($insTable !=""){
  687.                 // Calculate using insurer's table...
  688.                 // Get the mbs value of a unit from item 23010 call it $mbsUnitValue - in case we need it for item 25200 or 25205
  689.                 $q1="SELECT insurerschedulevalue FROM $medicareTable WHERE insurerscheduleitemnumber=23010";
  690.                 $r1 = mysqli_query($con, $q1) or die(mysqli_error());
  691.                 $row1=mysqli_fetch_array($r1);
  692.                 $mbsUnitValue=$row1[0];
  693.                 // Get the insurer's value of a unit from item 23010 call it $insUnitValue - in case we need it for item 25200 or 25205
  694.                 $q1="SELECT insurerschedulevalue FROM $insTable WHERE insurerscheduleitemnumber=23010";
  695.                 $r1 = mysqli_query($con, $q1) or die(mysqli_error());
  696.                 $row1=mysqli_fetch_array($r1);
  697.                 $insUnitValue=$row1[0];            
  698.                 // First iteration populates all fees that actually have a value
  699.                 for ($i4=1;$i4<21;$i4+=1){
  700.                     if ($itemNumber[$i4] != ""){
  701.                         $q3="SELECT * FROM $insTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i4]\"";
  702.                         if ($itemNumber[$i4] != 0){
  703.                             $q3="SELECT * FROM $insTable WHERE insurerscheduleitemnumber=$itemNumber[$i4]";
  704.                         }
  705.                         $r3 = mysqli_query($con, $q3) or die(mysqli_error());
  706.                         if (mysqli_num_rows($r3) == 1){
  707.                             $row3=mysqli_fetch_array($r3);
  708.                             $itemValue[$i4]=$row3[1]*$feePercent/100;
  709.                             if ($itemNumber[$i4]==25200 || $itemNumber[$i4]==25205){
  710.                                 // Correct the percentage...if less than 100, make it more.
  711.                                 if ($row3[2] !=0 && $row3[2] < 100){
  712.                                     $row3[2]=$row3[2]+100;
  713.                                 }
  714.                                 if ($row3[2] > 0){
  715.                                     // If there IS a percent, then it's a percent of MEDICARE...so do that'
  716.                                     $itemValue[$i4]=$mbsUnitValue*5*$feePercent/100*$row3[2]/100;
  717.                                 } else {
  718.                                     // If there IS NOT a percent, then it's a percent of the internal table fee.
  719.                                     $itemValue[$i4]=$insUnitValue*5*$feePercent/100;
  720.                                 }
  721.                             }
  722.                         }
  723.                     }
  724.                 }
  725.                 // SECOND ITERATION. LOOK FOR 25025, 25030 25050
  726.                 for ($i1=1;$i1<21;$i1+=1){
  727.                     if ($itemNumber[$i1] == 25025){
  728.                         // OK Get the percentage for item 25025
  729.                         $q1="SELECT insurerschedulepercent FROM $insTable WHERE insurerscheduleitemnumber=25025";
  730.                         $r1 = mysqli_query($con, $q1) or die(mysqli_error());
  731.                         $row1=mysqli_fetch_array($r1);
  732.                         // CORRECT THE PERCENTAGE IF LESS THAN 100 and CALL IT $row1[2]
  733.                         if ($row1[0] !=0 && $row1[0] < 100){
  734.                                     $row1[0]=$row1[0]+100;
  735.                         }
  736.                         for ($i2=1;$i2<21;$i2+=1){
  737.                             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)){
  738.                                 if ($row1[0] > 0){
  739.                                     // If there IS a percent, then it's a percent off MEDICARE...so do that'
  740.                                     // Look up the MEDICARE Value of this item....
  741.                                     $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i2]\"";
  742.                                     if ($itemNumber[$i2] !=0){
  743.                                         $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i2]";
  744.                                     }
  745.                                     $r2 = mysqli_query($con, $q2) or die(mysqli_error());
  746.                                     $row2=mysqli_fetch_array($r2);
  747.                                     $itemValue[$i1]=$itemValue[$i1]+$feePercent/100*$row1[0]/100*$row2[0]*.5;
  748.                                 } else {
  749.                                     // If there IS NOT a percent, then it's a percent of the internal table fee.
  750.                                     $itemValue[$i1]=$row1[0]/100*$feePercent/100*$itemValue[$i2]*.5;
  751.                                 }
  752.                             }
  753.                         }
  754.                     }
  755.                     if ($itemNumber[$i1] == 25030){
  756.                         // OK Get the percentage for item 25030
  757.                         $q1="SELECT insurerschedulepercent FROM $insTable WHERE insurerscheduleitemnumber=25030";
  758.                         $r1 = mysqli_query($con, $q1) or die(mysqli_error());
  759.                         $row1=mysqli_fetch_array($r1);
  760.                         // CORRECT THE PERCENTAGE IF LESS THAN 100 and CALL IT $row1[2]
  761.                         if ($row1[0] !=0 && $row1[0] < 100){
  762.                                     $row1[0]=$row1[0]+100;
  763.                         }
  764.                         for ($i2=1;$i2<21;$i2+=1){
  765.                             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)){
  766.                                 if ($row1[0] > 0){
  767.                                     // If there IS a percent, then it's a percent off MEDICARE...so do that'
  768.                                     // Look up the MEDICARE Value of this item....
  769.                                     $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i2]\"";
  770.                                     if ($itemNumber[$i2] !=0){
  771.                                         $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i2]";
  772.                                     }
  773.                                     $r2 = mysqli_query($con, $q2) or die(mysqli_error());
  774.                                     $row2=mysqli_fetch_array($r2);
  775.                                     $itemValue[$i1]=$itemValue[$i1]+$feePercent/100*$row1[0]/100*$row2[0]*.5;
  776.                                 } else {
  777.                                     // If there IS NOT a percent, then it's a percent of the internal table fee.
  778.                                     $itemValue[$i1]=$row1[0]/100*$feePercent/100*$itemValue[$i2]*.5;
  779.                                 }
  780.                             }
  781.                         }
  782.                     }
  783.                     if ($itemNumber[$i1] == 25050){
  784.                         // OK Get the percentage for item 25050
  785.                         $q1="SELECT insurerschedulepercent FROM $insTable WHERE insurerscheduleitemnumber=25050";
  786.                         $r1 = mysqli_query($con, $q1) or die(mysqli_error());
  787.                         $row1=mysqli_fetch_array($r1);
  788.                         // CORRECT THE PERCENTAGE IF LESS THAN 100 and CALL IT $row1[2]
  789.                         if ($row1[0] !=0 && $row1[0] < 100){
  790.                                     $row1[0]=$row1[0]+100;
  791.                         }
  792.                         for ($i2=1;$i2<21;$i2+=1){
  793.                             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)){
  794.                                 if ($row1[0] > 0){
  795.                                     // If there IS a percent, then it's a percent off MEDICARE...so do that'
  796.                                     // Look up the MEDICARE Value of this item....
  797.                                     $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i2]\"";
  798.                                     if ($itemNumber[$i2] !=0){
  799.                                         $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i2]";
  800.                                     }
  801.                                     $r2 = mysqli_query($con, $q2) or die(mysqli_error());
  802.                                     $row2=mysqli_fetch_array($r2);
  803.                                     $itemValue[$i1]=$itemValue[$i1]+$feePercent/100*$row1[0]/100*$row2[0]*.5;
  804.                                 } else {
  805.                                     // If there IS NOT a percent, then it's a percent of the internal table fee.
  806.                                     $itemValue[$i1]=$row1[0]/100*$feePercent/100*$itemValue[$i2]*.5;
  807.                                 }
  808.                             }
  809.                         }
  810.                     }
  811.                    
  812.                 }              
  813.             } else {
  814.                 // No insurer fee table. Cant do calcs
  815.             }
  816.        
  817.         break;
  818.     }
  819.    
  820.    
  821.     // Figure out expected Medicare Rebates...
  822.             // Need to look up values in mbs billing schedule
  823.             if ($medicareTable != ""){
  824.                 // Good we have a mbs table of fees
  825.                 // Get the value of a unit from item 23010 call it $mbsUnitValue - in case we need it for item 25200 or 25205
  826.                 $q1="SELECT insurerschedulevalue FROM $medicareTable WHERE insurerscheduleitemnumber=23010";
  827.                 $r1 = mysqli_query($con, $q1) or die(mysqli_error());
  828.                 $row1=mysqli_fetch_array($r1);
  829.                 $mbsUnitValue=$row1[0];
  830.                 // First iteration populates all fees that actually have a value
  831.                 for ($i4=1;$i4<21;$i4+=1){
  832.                     if ($itemNumber[$i4] != ""){
  833.                         $q3="SELECT * FROM $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i4]\"";
  834.                         if ($itemNumber[$i4] !=0){
  835.                             $q3="SELECT * FROM $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i4]";
  836.                         }
  837.                         $r3 = mysqli_query($con, $q3) or die(mysqli_error());
  838.                         if (mysqli_num_rows($r3) == 1){
  839.                             $row3=mysqli_fetch_array($r3);
  840.                             $btb[40+$i4]=$row3[1]*$mcRebatePercent/100;
  841.                             if ($itemNumber[$i4]==25200 || $itemNumber[$i4]==25205){
  842.                                 $btb[40+$i4]=$mbsUnitValue*5*$mcRebatePercent/100;
  843.                             }
  844.                         }
  845.                     }
  846.                 }
  847.                 // Second iteration looks for derived fees and calculates those, based on the OTHER values
  848.                 for ($i4=1;$i4<21;$i4+=1){
  849.                     if ($itemNumber[$i4] == 25025){
  850.                         for($i5=1;$i5<21;$i5+=1){
  851.                             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){
  852.                                 $btb[40+$i4]=$btb[40+$i4]+($btb[40+$i5]*.5);
  853.                             }
  854.                         }
  855.                        
  856.                     }
  857.                     if ($itemNumber[$i4] == 25030 ){
  858.                         for($i5=1;$i5<21;$i5+=1){
  859.                             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)){
  860.                                 $btb[40+$i4]=$btb[40+$i4]+($btb[40+$i5]*.5);
  861.                             }
  862.                         }
  863.                     }
  864.                     if ($itemNumber[$i4] == 25050 ){
  865.                         for($i5=1;$i5<21;$i5+=1){
  866.                             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)){
  867.                                 $btb[40+$i4]=$btb[40+$i4]+($btb[40+$i5]*.5);
  868.                             }
  869.                         }
  870.                     }                  
  871.                 }
  872.             } else {
  873.                 // There is no medicare table of fees so can't be done. Never mind. Dont flag an error.        
  874.             }      
  875.    
  876.    
  877. // Figure out expected insurer rebates....
  878.             if ($patInsTable !=""){
  879.                 // Calculate using insurer's table...
  880.                 // Get the mbs value of a unit from item 23010 call it $mbsUnitValue - in case we need it for item 25200 or 25205
  881.                 $q1="SELECT insurerschedulevalue FROM $medicareTable WHERE insurerscheduleitemnumber=23010";
  882.                 $r1 = mysqli_query($con, $q1) or die(mysqli_error());
  883.                 $row1=mysqli_fetch_array($r1);
  884.                 $mbsUnitValue=$row1[0];
  885.                 // Get the insurer's value of a unit from item 23010 call it $insUnitValue - in case we need it for item 25200 or 25205
  886.                 $q1="SELECT insurerschedulevalue FROM $patInsTable WHERE insurerscheduleitemnumber=23010";
  887.                 $r1 = mysqli_query($con, $q1) or die(mysqli_error());
  888.                 $row1=mysqli_fetch_array($r1);
  889.                 $insUnitValue=$row1[0];            
  890.                 // First iteration populates all fees that actually have a value
  891.                 for ($i4=1;$i4<21;$i4+=1){
  892.                     if ($itemNumber[$i4] != ""){
  893.                         $q3="SELECT * FROM $patInsTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i4]\"";
  894.                         if ($itemNumber[$i4] != 0){
  895.                             $q3="SELECT * FROM $patInsTable WHERE insurerscheduleitemnumber=$itemNumber[$i4]";
  896.                         }
  897.                         $r3 = mysqli_query($con, $q3) or die(mysqli_error());
  898.                         if (mysqli_num_rows($r3) == 1){
  899.                             $row3=mysqli_fetch_array($r3);
  900.                             $btb[80+$i4]=$row3[1];
  901.                             if ($itemNumber[$i4]==25200 || $itemNumber[$i4]==25205){
  902.                                 // Correct the percentage...if less than 100, make it more.
  903.                                 if ($row3[2] !=0 && $row3[2] < 100){
  904.                                     $row3[2]=$row3[2]+100;
  905.                                 }
  906.                                 if ($row3[2] > 0){
  907.                                     // If there IS a percent, then it's a percent of MEDICARE...so do that'
  908.                                     $btb[80+$i4]=$mbsUnitValue*5*$row3[2]/100;
  909.                                 } else {
  910.                                     // If there IS NOT a percent, then it's a percent of the internal table fee.
  911.                                     $btb[80+$i4]=$insUnitValue*5;
  912.                                 }
  913.                             }
  914.                         }
  915.                     }
  916.                 }
  917.                 // SECOND ITERATION. LOOK FOR 25025, 25030 25050
  918.                 for ($i1=1;$i1<21;$i1+=1){
  919.                     if ($itemNumber[$i1] == 25025){
  920.                         // OK Get the percentage for item 25025
  921.                         $q1="SELECT insurerschedulepercent FROM $patInsTable WHERE insurerscheduleitemnumber=25025";
  922.                         $r1 = mysqli_query($con, $q1) or die(mysqli_error());
  923.                         $row1=mysqli_fetch_array($r1);
  924.                         // CORRECT THE PERCENTAGE IF LESS THAN 100 and CALL IT $row1[2]
  925.                         if ($row1[0] !=0 && $row1[0] < 100){
  926.                                     $row1[0]=$row1[0]+100;
  927.                         }
  928.                         for ($i2=1;$i2<21;$i2+=1){
  929.                             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)){
  930.                                 if ($row1[0] > 0){
  931.                                     // If there IS a percent, then it's a percent off MEDICARE...so do that'
  932.                                     // Look up the MEDICARE Value of this item....
  933.                                     $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i2]\"";
  934.                                     if ($itemNumber[$i2] !=0){
  935.                                         $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i2]";
  936.                                     }
  937.                                     $r2 = mysqli_query($con, $q2) or die(mysqli_error());
  938.                                     $row2=mysqli_fetch_array($r2);
  939.                                     $btb[80+$i1]=$btb[80+$i1]+$row1[0]/100*$row2[0]*.5;
  940.                                 } else {
  941.                                     // If there IS NOT a percent, then it's a percent of the internal table fee.
  942.                                     $btb[80+$i1]=$row1[0]/100*$btb[80+$i2]*.5;
  943.                                 }
  944.                             }
  945.                         }
  946.                     }
  947.                     if ($itemNumber[$i1] == 25030){
  948.                         // OK Get the percentage for item 25030
  949.                         $q1="SELECT insurerschedulepercent FROM $patInsTable WHERE insurerscheduleitemnumber=25030";
  950.                         $r1 = mysqli_query($con, $q1) or die(mysqli_error());
  951.                         $row1=mysqli_fetch_array($r1);
  952.                         // CORRECT THE PERCENTAGE IF LESS THAN 100 and CALL IT $row1[2]
  953.                         if ($row1[0] !=0 && $row1[0] < 100){
  954.                                     $row1[0]=$row1[0]+100;
  955.                         }
  956.                         for ($i2=1;$i2<21;$i2+=1){
  957.                             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)){
  958.                                 if ($row1[0] > 0){
  959.                                     // If there IS a percent, then it's a percent off MEDICARE...so do that'
  960.                                     // Look up the MEDICARE Value of this item....
  961.                                     $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i2]\"";
  962.                                     if ($itemNumber[$i2] !=0){
  963.                                         $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i2]";
  964.                                     }
  965.                                     $r2 = mysqli_query($con, $q2) or die(mysqli_error());
  966.                                     $row2=mysqli_fetch_array($r2);
  967.                                     $btb[80+$i1]=$btb[80+$i1]+$row1[0]/100*$row2[0]*.5;
  968.                                 } else {
  969.                                     // If there IS NOT a percent, then it's a percent of the internal table fee.
  970.                                     $btb[80+$i1]=$row1[0]/100*$btb[80+$i2]*.5;
  971.                                 }
  972.                             }
  973.                         }
  974.                     }
  975.                     if ($itemNumber[$i1] == 25050){
  976.                         // OK Get the percentage for item 25050
  977.                         $q1="SELECT insurerschedulepercent FROM $patInsTable WHERE insurerscheduleitemnumber=25050";
  978.                         $r1 = mysqli_query($con, $q1) or die(mysqli_error());
  979.                         $row1=mysqli_fetch_array($r1);
  980.                         // CORRECT THE PERCENTAGE IF LESS THAN 100 and CALL IT $row1[2]
  981.                         if ($row1[0] !=0 && $row1[0] < 100){
  982.                                     $row1[0]=$row1[0]+100;
  983.                         }
  984.                         for ($i2=1;$i2<21;$i2+=1){
  985.                             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)){
  986.                                 if ($row1[0] > 0){
  987.                                     // If there IS a percent, then it's a percent off MEDICARE...so do that'
  988.                                     // Look up the MEDICARE Value of this item....
  989.                                     $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=\"$itemNumber[$i2]\"";
  990.                                     if ($itemNumber[$i2] !=0){
  991.                                         $q2="SELECT insurerschedulevalue from $medicareTable WHERE insurerscheduleitemnumber=$itemNumber[$i2]";
  992.                                     }
  993.                                     $r2 = mysqli_query($con, $q2) or die(mysqli_error());
  994.                                     $row2=mysqli_fetch_array($r2);
  995.                                     $btb[80+$i1]=$btb[80+$i1]+$row1[0]/100*$row2[0]*.5;
  996.                                 } else {
  997.                                     // If there IS NOT a percent, then it's a percent of the internal table fee.
  998.                                     $btb[80+$i1]=$row1[0]/100*$btb[80+$i2]*.5;
  999.                                 }
  1000.                             }
  1001.                         }
  1002.                     }
  1003.                    
  1004.                 }
  1005.             if ($knowngap==0){
  1006.                 for ($i2=1;$i2<21;$i2+=1){
  1007.                     if ($itemValue[$i2]>$btb[$i2+80]){
  1008.                         $tmp=$btb[$i2+40]/($mcRebatePercent/100);
  1009.                         $btb[80+$i2]=$tmp;
  1010.                     }
  1011.                 }
  1012.                
  1013.             }              
  1014.             } else {
  1015.                 // BAD LUCK...No insurer table....don't flag an error. Rebate is just zero
  1016.             }
  1017.        
  1018.     // Package all the results for returning
  1019.     // Add pretty zeros for item values.
  1020.     for($i2=1;$i2<21;$i2+=1){
  1021.         if ($itemValue[$i2]){
  1022.             $btb[$i2]=sprintf("%01.2f", $itemValue[$i2]);
  1023.             $invTotal=$invTotal+$itemValue[$i2];
  1024.         }
  1025.     }
  1026.     // Calculate the GST if applicable
  1027.     $btb[63]=0;
  1028.     if ($gst == "true" || $gst == 1){
  1029.         for($i2=1;$i2<21;$i2+=1){
  1030.             $btb[63]=$btb[63]+($itemValue[$i2]*$GSTPercent/100);
  1031.         }
  1032.     }
  1033.     // Calculate the discount if applicable
  1034.     if ($discPercent > 0){
  1035.         $btb[65]=($invTotal+$btb[63])*$discPercent/100;
  1036.     }
  1037.    
  1038.     if ($btb[71] !=""){
  1039.         $btb[71]=substr($btb[71],0,(strlen($btb[71])-3));
  1040.     }
  1041.     if ($btb[72] !=""){
  1042.         $btb[72]=substr($btb[72],0,(strlen($btb[72])-3));
  1043.     }
  1044.     return $btb;
  1045. }
  1046. //////////////////////////////////////////////////////////////////////////////////INVOICEPDF
  1047. function invoicepdf($inum,$pwd="",$nme=""){
  1048.     include $_SESSION['pathToRoot']."setup/settings.php";
  1049. //  include_once"includes/classes/fpdf/fpdf_protection.php";
  1050.     // function to create a PDF for invoice number $inum
  1051.     // Returns "error" the invoice number does not exist.
  1052.     // Otherwise returns "1" for success, and creates in invoice in the default
  1053.     // PDF folder, with the name "Invoice-XXXXXX.pdf" where XXXXXX is the invoice number
  1054.     $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect error.");
  1055.     $query="SELECT * FROM invoice WHERE invoicecode=\"$inum\"";
  1056.     $res = mysqli_query($con, $query) or die(mysqli_error());
  1057.     if (mysqli_num_rows($res) == 1){
  1058.             $inv=mysqli_fetch_assoc($res);
  1059.             extract($inv);
  1060.             $query="SELECT * FROM operation WHERE operationcode=\"$invoiceoperationcode\"";
  1061.             $res = mysqli_query($con, $query) or die(mysqli_error());
  1062.             if (mysqli_num_rows($res) == 1){
  1063.                 $op=mysqli_fetch_assoc($res);
  1064.                 extract($op);
  1065.                 $query="SELECT * FROM patient WHERE patientcode=\"$operationpatientcode\"";
  1066.                 $res = mysqli_query($con, $query) or die(mysqli_error());
  1067.                 if (mysqli_num_rows($res) == 1){
  1068.                     $pat=mysqli_fetch_assoc($res);
  1069.                     extract($pat);
  1070.                     $query="SELECT * FROM doctor WHERE doctorcode=\"$operationdoctorcode\"";
  1071.                     $res = mysqli_query($con, $query) or die(mysqli_error());
  1072.                     if (mysqli_num_rows($res) == 1){
  1073.                         $doc=mysqli_fetch_assoc($res);
  1074.                         extract($doc);
  1075.                         $query="SELECT * from dplink where dplinkcode=\"$operationdplinkcode\"";
  1076.                         $res = mysqli_query($con, $query) or die(mysqli_error());
  1077.                         if (mysqli_num_rows($res) == 1){
  1078.                             $dpl=mysqli_fetch_assoc($res);
  1079.                             extract($dpl);
  1080.                             $query="SELECT * FROM practice WHERE practicecode=\"$dplinkpractice\"";
  1081.                             $res = mysqli_query($con, $query) or die(mysqli_error());
  1082.                             if (mysqli_num_rows($res) == 1){
  1083.                                 $pra=mysqli_fetch_assoc($res);
  1084.                                 extract($pra);
  1085.                                 $surgeon=$operationsurgeonname;
  1086.                                 $query="SELECT * FROM surgeon WHERE surgeoncode=\"$operationsurgeoncode\"";
  1087.                                 $res = mysqli_query($con, $query) or die(mysqli_error());
  1088.                                 if (mysqli_num_rows($res) == 1){
  1089.                                     $sur=mysqli_fetch_assoc($res);
  1090.                                     extract($sur);
  1091.                                     $surgeon="$surgeonfirstname $surgeonlastname";
  1092.                                 }
  1093.                                 $hospital=$operationhospitalname;
  1094.                                 $query="SELECT * FROM hospital WHERE hospitalcode=\"$operationhospitalcode\"";
  1095.                                 $res = mysqli_query($con, $query) or die(mysqli_error());
  1096.                                 if (mysqli_num_rows($res) == 1){
  1097.                                     $hos=mysqli_fetch_assoc($res);
  1098.                                     extract($hos);
  1099.                                 }
  1100.                             } else {
  1101.                                 return "error - practice $dplinkpractice does not exist";
  1102.                             }
  1103.                         } else {
  1104.                             return "error - dplink $operationdplinkcode does not exist";
  1105.                         }
  1106.                     } else {
  1107.                         return "error - doctor $operationdoctorcode does not exist";
  1108.                     }
  1109.                 } else {
  1110.                     return "error - patient $operationpatientcode does not exist";
  1111.                 }
  1112.             } else {
  1113.                 return "error - operation $invoiceoperationcode does not exist";
  1114.             }
  1115.     } else {
  1116.         return "error - invoice $inum does not exist";
  1117.     }
  1118.     // Landing here means we have correctly extracted all the details we need...So create PDF
  1119. //$pdf=new FPDF();
  1120. $pdf=new FPDF_Protection();
  1121. $pdf->SetProtection(array('print','copy'),$pwd,$pwd);
  1122. $pdf->SetAuthor($_SESSION['pdfAccountAuthor']);
  1123. $pdf->SetCreator($_SESSION['pdfAccountCreator']);
  1124. $pdf->SetSubject($_SESSION['pdfAccountSubject']);
  1125. $pdf->SetTitle($_SESSION['pdfAccountTitle']);
  1126. $pdf->SetDisplayMode($_SESSION['pdfAccountDisplayMode']);
  1127. $pdf->AddPage();
  1128.  
  1129. // Folding Guide
  1130. $pdf->Line(10,99,201,99);
  1131.  
  1132. // Box for logo
  1133. $x=70;
  1134. $y=20;
  1135. //$pdf->Rect($x,$y,50,30);
  1136.  
  1137.  
  1138. // Heading for invoice
  1139. $pdf->SetFont('Arial','B',14);
  1140. $pdf->SetFillColor(255,255,255);
  1141. $pdf->SetXY(10,10);
  1142. $pdf->Cell(110,7,"Invoice for professional anaesthetic services","B","","",1);
  1143.  
  1144. //Doctor's letterhead is printed here'
  1145. $x=10;
  1146. $y=20;
  1147. //$pdf->Rect($x,$y,55,45);
  1148. $pdf->SetFont('Arial','B',14);
  1149. $pdf->SetXY($x,$y);
  1150. $pdf->Cell(55,6,strtoupper("$doctortitle $doctorfirstname $doctorlastname"),"");
  1151. $pdf->SetFont('Arial','',5);
  1152. $pdf->SetXY($x+1,$y+4);
  1153. //$pdf->Cell(55,4,"$doctorqualifications","");
  1154. $adr=explode(chr(13), $practiceaddress);
  1155. $pdf->SetFont('Arial','',12);
  1156. $pdf->SetXY($x+1,$y+7);
  1157. $pdf->Cell(85,4,"$adr[0]","");
  1158. $pdf->SetXY($x,$y+11);
  1159. $pdf->Cell(85,4,"$adr[1]","");
  1160. $pdf->SetXY($x+1,$y+15);
  1161. $pdf->Cell(85,4,"$practicecity $practicepostcode","");
  1162. $pdf->SetFont('Arial','',8);
  1163. $pdf->SetXY($x+1,$y+20);
  1164. $pdf->Cell(85,4,"Ph. $practicephone","");
  1165. if ($practicefax !=""){
  1166.     $pdf->SetXY($x+1,$y+23);
  1167.     $pdf->Cell(85,4,"Fax $practicefax","");
  1168. }
  1169. if ($practiceemail !=""){
  1170.     $pdf->SetXY($x+1,$y+26);
  1171.     $pdf->Cell(85,4,"Email $practiceemail","");
  1172. }
  1173. if ($practicewebpage !=""){
  1174.     $pdf->SetXY($x+1,$y+29);
  1175.     $pdf->Cell(85,4,"$practicewebpage","");
  1176. }
  1177.  
  1178. // Print :to:
  1179. $x=10;
  1180. $y=60;
  1181. $pdf->SetFont('Arial',"BI",20);
  1182. $pdf->SetXY($x,$y);
  1183. $pdf->Cell(10,10,"To:");
  1184.  
  1185.  
  1186. // Address for envelope window
  1187. $x=35;
  1188. $y=60;
  1189. //$pdf->Rect(30,56,93,27);
  1190. $pdf->SetFont('Arial','B',10);
  1191. $pdf->SetXY($x,$y);
  1192. $pdf->Cell(85,5,"$invoicepayertitle $invoicepayerfirstname $invoicepayerlastname","");
  1193. $adr=explode(chr(13),$invoicepayeraddress);
  1194. $pdf->SetFont('Arial','',10);
  1195. $pdf->SetXY($x,$y+5);
  1196. $pdf->Cell(85,5,"$adr[0]","");
  1197. $pdf->SetXY($x,$y+10);
  1198. $pdf->Cell(85,5,"$adr[1]","");
  1199. $pdf->SetXY($x,$y+15);
  1200. if ($invoicepayercountry != "Australia"){
  1201.     $country=strtoupper($invoicepayercountry);
  1202.     $ins="$invoicepayercity $country $invoicepayerpostcode";
  1203. } else {
  1204.     $ins="$invoicepayercity $invoicepayerstate $invoicepayerpostcode";
  1205. }
  1206. $pdf->Cell(85,5,strtoupper("$ins"),"");
  1207.  
  1208. // Procedure details box and content
  1209. $x=125;
  1210. $y=10;
  1211. $pdf->Rect($x,$y,75,85);
  1212.         //Heading
  1213. $pdf->SetXY($x,$y);
  1214. $pdf->SetFont('Arial','B',12);
  1215. $pdf->SetFillColor(124,124,124);
  1216. $pdf->SetTextColor(255,255,255);
  1217. $pdf->Cell(75,7,"Tax invoice No. $inum","LRTB",0,"C",1);
  1218.         //Invoice Number
  1219. $pdf->setXY($x,$y+5);
  1220. $pdf->SetFont('Arial','B',11);
  1221. $pdf->SetTextColor(0,0,0);
  1222. //$pdf->Cell(25,5,"Invoice Number","B");
  1223. $pdf->setXY($x+20,$y+5);
  1224. $pdf->SetFont('Arial','B',11);
  1225. //$pdf->Cell(55,5,"$inum","B","","R");
  1226.         //Invoice Date
  1227. $pdf->setXY($x,$y+9);
  1228. $pdf->SetFont('Arial','B',8);
  1229. $pdf->Cell(25,5,"Invoice date","");
  1230. $dte=date("d F Y",$operationinvoicedate*60);
  1231. $pdf->setXY($x+35,$y+9);
  1232. $pdf->Cell(40,5,"$dte","","","R");
  1233.         //Provider number
  1234. $pdf->setXY($x,$y+13);
  1235. $pdf->SetFont('Arial','B',8);
  1236. $pdf->Cell(25,5,"Provider number","");
  1237. $pdf->setXY($x+35,$y+13);
  1238. $pdf->Cell(40,5,"$dplinkprovider","","","R");
  1239.         //ABN
  1240. $pdf->setXY($x,$y+17);
  1241. $pdf->SetFont('Arial','B',8);
  1242. $pdf->Cell(25,5,"ABN","B");
  1243. $pdf->setXY($x+35,$y+17);
  1244. $pdf->Cell(40,5,"$dplinkabn","","","R");
  1245.  
  1246.         //Patient Name
  1247. $pdf->SetFillColor(255,255,255);       
  1248. $pdf->setXY($x,$y+21);
  1249. $pdf->Cell(25,5,"Patient","L","","L",1);
  1250. $pdf->setXY($x+25,$y+21);
  1251. $pdf->Cell(50,5,"$patienttitle $patientfirstname $patientlastname","R","","R",1);
  1252.         //Patient DOB
  1253. $pdf->setXY($x,$y+25);
  1254. $pdf->Cell(25,5,"Date of birth","");
  1255. $pdf->setXY($x+35,$y+25);
  1256. $dob=date("d F Y",strtotime($patientbirthday));
  1257. $pdf->Cell(40,5,"$dob","","","R");
  1258.  
  1259.         //Medicare number
  1260. $pdf->SetFillColor(255,255,255);       
  1261. $pdf->setXY($x,$y+29);
  1262. $pdf->Cell(25,5,"Medicare number","");
  1263. $pdf->setXY($x+35,$y+29);
  1264. $num=$patientmedicarenumber;
  1265. $num=substr($num,0,10)."-".substr($num,10,1);
  1266. $pdf->Cell(40,5,"$num","","","R");
  1267.         //Medicare expiry
  1268. if ($patientmedicareexpirymonth !=0 && $patientmedicareexpiryyear !=0){
  1269.     $pdf->setXY($x,$y+33);
  1270.     $pdf->Cell(25,5,"Medicare expiry","");
  1271.     $pdf->setXY($x+35,$y+33);
  1272.     $num=$patientmedicarenumber;
  1273.     $pdf->Cell(40,5,"$patientmedicareexpirymonth / $patientmedicareexpiryyear","","","R");
  1274. }
  1275.     // INSURER
  1276. if ($patientinsurer != ""){
  1277.     $pdf->setXY($x,$y+37);
  1278.     $pdf->Cell(25,5,"Insurer","");
  1279.     $pdf->setXY($x+35,$y+37);
  1280.     $pdf->Cell(40,5,"$patientinsurer","","","R");
  1281. }
  1282.  
  1283.         //Insurance Policy Number
  1284. if ($patientinsurerpolicy != ""){
  1285.     $pdf->setXY($x,$y+41);
  1286.     $pdf->Cell(25,5,"Insurer policy number","");
  1287.     $pdf->setXY($x+35,$y+41);
  1288.     $pdf->Cell(40,5,"$patientinsurerpolicy","","","R");
  1289. }
  1290.  
  1291.         //Procedure date
  1292. $pdf->setXY($x,$y+45);
  1293. $pdf->Cell(25,5,"Date of service","0");
  1294. $pdf->setXY($x+35,$y+45);
  1295. $dt=date("d F Y",$operationstart*60);
  1296. $pdf->Cell(40,5,"$dt","","","R");
  1297.         //Surgeon
  1298. $pdf->setXY($x,$y+53);
  1299. $pdf->Cell(25,5,"Referring doctor","");
  1300. $pdf->setXY($x+35,$y+53);
  1301. $pdf->Cell(40,5,"$surgeon","","","R");
  1302.         //Surgeon Provider
  1303. $pdf->setXY($x,$y+57);
  1304. $pdf->Cell(25,5,"Referring doctor provider","");
  1305. $pdf->setXY($x+35,$y+57);
  1306. $pdf->Cell(40,5,"$surgeonprovider","","","R");
  1307.         //Referral date
  1308. $pdf->setXY($x,$y+61);
  1309. $pdf->Cell(25,5,"Referral date","0");
  1310. $pdf->setXY($x+35,$y+61);
  1311. $dt=date("d F Y",$operationstart*60);
  1312. $pdf->Cell(40,5,"$dt","","","R");
  1313.  
  1314.         //Hospital
  1315. $pdf->setXY($x,$y+65);
  1316. $pdf->Cell(25,5,"Hospital","");
  1317. $pdf->setXY($x+35,$y+65);
  1318. $pdf->Cell(40,5,"$hospital","","","R");
  1319.         //Hospital Provider
  1320. $pdf->setXY($x,$y+69);
  1321. $pdf->Cell(25,5,"Hospital provider","");
  1322. $pdf->setXY($x+35,$y+69);
  1323. $pdf->Cell(40,5,"$hospitalprovider","","","R");
  1324.  
  1325. // CREATE FYI Box
  1326. $x=10;
  1327. $y=190;
  1328. $pdf->Rect($x,$y,95,20);
  1329. $pdf->SetXY($x,$y);
  1330. $pdf->SetFont('Arial','BU',8);
  1331. $pdf->Cell(95,5,"For your information");
  1332.     // 1st line
  1333. $pdf->SetXY($x,$y+5);
  1334. if ($invoicetype == 4){
  1335.     $invoiceicopayment=sprintf("%01.2f",$invoiceicopayment);
  1336.     $mes1="An additional amount of $$invoiceicopayment was billed to your insurer.";
  1337.     $pdf->SetFont('Arial','',8);
  1338.     $pdf->Cell(95,5,$mes1);
  1339.     $pdf->SetXY($x,$y+10);
  1340.     $pdf->SetFont('Arial','B',6);
  1341.     $pdf->Cell(95,5,"This invoice is yours to pay. You cannot pass this on to Medicare or your insurer."); 
  1342. }
  1343. if ($invoicetype == 3){
  1344.     $invoicepcopayment=sprintf("%01.2f",$invoicepcopayment);
  1345.     $pdf->SetFont('Arial','',8);
  1346.     $pdf->Cell(95,5,"This is the insurer portion of a KNOWN GAP invoice.");
  1347.     $pdf->SetXY($x,$y+10);
  1348.     $mes1="An additional amount of $$invoicepcopayment was billed to the patient.";
  1349.     $pdf->SetFont('Arial','',8);
  1350.     $pdf->Cell(95,5,$mes1);
  1351. }
  1352.  
  1353.  
  1354.  
  1355. // Create barcode and put it on page
  1356. makebarcode ($inum);
  1357. //$pdf->Image($barcodes."BC$inum.png",10,278,40,6,"");
  1358. $pdf->Image($barcodes."BC$inum.png",160,272,40,5,"");
  1359. //Make Bpay Box
  1360. if ($dplinkbpayaccepted == 1){
  1361.     $x=10;
  1362.     $y=235;
  1363.     $pdf->Rect($x,$y,40,20);
  1364.     $pdf->Image($_SESSION['pathToRoot']."images\BPAY Portrait BW Logo.gif",$x-1,$y,12,20,"GIF");
  1365.     $pdf->SetFont('Arial','',9);
  1366.     $pdf->SetXY($x+8.5,$y+5);
  1367.     $pdf->Cell(29,0,"Biller Code: ".$dplinkbpaybillercode);
  1368.     $pdf->SetXY($x+8.5,$y+13);
  1369.     $pdf->Cell(29,0,"Ref: ".$inum);
  1370. }
  1371.  
  1372. // Make direct deposit box
  1373. if ($dplinkbankdepositaccepted == 1){
  1374.     $x=52;
  1375.     $y=235;
  1376.     $pdf->Rect($x,$y,40,20);
  1377.     $pdf->SetFont('Arial','B',10);
  1378.     $pdf->SetXY($x+0,$y+0);
  1379.     $pdf->Cell(40,5,"Direct bank deposit");
  1380.     $pdf->SetFont('Arial','',7);
  1381.     $pdf->SetXY($x+0,$y+5);
  1382.     $pdf->Cell(40,3,"A/C name: $dplinkbankaccountname","");
  1383.     $pdf->SetXY($x+0,$y+8);
  1384.     $pdf->Cell(40,8,"BSB: $dplinkbankaccountbsb","");
  1385.     $pdf->SetXY($x+0,$y+13.5);
  1386.     $pdf->Cell(40,3,"A/C no. $dplinkbankaccountnumber","");
  1387.     $pdf->SetXY($x+0,$y+17);
  1388.     $rnum=$_SESSION['ddepositprefix'].$inum;
  1389.     $pdf->Cell(40,3,"Reference $rnum","");
  1390. }
  1391.  
  1392. // Make PayPal Box
  1393. if ($dplinkpaypalaccepted == 1){
  1394.     $x=10;
  1395.     $y=213;
  1396.     $pdf->Rect($x,$y,40,20);
  1397.     $pdf->Image($_SESSION['pathToRoot']."images\paypallogo.gif",$x+1,$y+1,20,8,"GIF");
  1398.     $pdf->SetFont('Arial','',7);
  1399.     $pdf->SetXY($x+0,$y+10);
  1400.     $pdf->Cell(30,0,"Send your payment to:");
  1401.     $pdf->SetFont('Arial','',8);
  1402.     $pdf->SetXY($x+0,$y+14);
  1403.     $pdf->Cell(30,0,"$dplinkpaypalemail");
  1404.     $pdf->SetFont('Arial','',7);
  1405.     $pdf->SetXY($x+0,$y+18);
  1406.     $pdf->Cell(30,0,"Include this number: $inum");
  1407. }
  1408.  
  1409. //Make ONLINE payment box
  1410. if ($dplinkwebpayaccepted == 1){
  1411.     $x=10;
  1412.     $y=257;
  1413.     $pdf->Image($_SESSION['pathToRoot']."images\padlock2.gif",$x+50,$y+2,28,16,"GIF");
  1414.     $pdf->Rect($x,$y,82,20);
  1415.     $pdf->SetFont('Arial','B',10);
  1416.     $pdf->SetXY($x,$y);
  1417.     $pdf->Cell(82,4,"Secure online payment");
  1418.     $pdf->SetXY($x,$y+4);
  1419.     $pdf->SetFont('Arial','',8);
  1420.     $pdf->Cell(82,4,"$practicewebpage");
  1421.     $pdf->SetXY($x,$y+8);
  1422.     $pdf->Cell(29,4,"Follow the \"Account Payments\" link and log on as below");
  1423.     $pdf->SetXY($x,$y+12);
  1424.     $pdf->Cell(29,4,"Login code");
  1425.     $pdf->SetXY($x+15,$y+12);
  1426.     $pdf->Cell(29,4,":  $inum");
  1427.     $pdf->SetXY($x,$y+17.5);
  1428.     $pdf->Cell(29,0,"Password");
  1429.     $pdf->SetXY($x+15,$y+17.5);
  1430.     $pdf->Cell(29,0,":  $invoicepassword");
  1431. }
  1432.  
  1433.  
  1434.  
  1435. // Make Phone payment
  1436. if ($dplinkvisaaccepted == 1 || $dplinkmastercardaccepted == 1 || $dplinkamexaccepted == 1 || $dplinkdinersaccepted == 1){
  1437.     $x=52;
  1438.     $y=213;
  1439.     if ($dplinkvisaaccepted == 1){
  1440.         $pdf->Image($_SESSION['pathToRoot']."images\weslogo.gif",$x,$y,10,7,"GIF");
  1441.     }
  1442.     if ($dplinkmastercardaccepted == 1){
  1443.         $pdf->Image($_SESSION['pathToRoot']."images\mastercardlogo.gif",$x+10,$y,10,7,"GIF");
  1444.     }
  1445.     if ($dplinkamexaccepted == 1){
  1446.         $pdf->Image($_SESSION['pathToRoot']."images\amexlogo.gif",$x+20,$y,10,7,"GIF");
  1447.     }  
  1448.     if ($dplinkdinersaccepted == 1){
  1449.         $pdf->Image($_SESSION['pathToRoot']."images\dinerslogo.gif",$x+30,$y,10,7,"GIF");
  1450.        
  1451.     }
  1452.     $pdf->Image($_SESSION['pathToRoot']."images\phone.gif",$x+8,$y+7,24,13,"GIF");     
  1453.     $pdf->SetXY($x+0,$y+10);
  1454.     $pdf->SetFont('Arial','B',10);
  1455.     $pdf->Cell(40,0,"Payment by phone","",0,"L");
  1456.     $pdf->SetFont('Arial','B',9);  
  1457.     $pdf->SetXY($x+0,$y+14);
  1458.     $pdf->Cell(30,0,"Call us on $practicephone");
  1459.     $pdf->SetFont('Arial','B',8);  
  1460.     $pdf->SetXY($x+0,$y+18);
  1461.     $pdf->Cell(30,0,"Have your credit card handy");
  1462.     $pdf->Rect($x,$y,40,20);   
  1463. }
  1464.  
  1465. // BOX for payment by mail
  1466. $x=94;
  1467. $y=213;
  1468. $pdf->SetXY($x,$y);
  1469. $pdf->SetFont('Arial','B',10);
  1470. $pdf->Cell(106,5,"Payment in person, or by mail");
  1471. $pdf->SetFont('Arial','',8);
  1472. $pdf->SetXY($x,$y+5);
  1473. $pdf->Cell(106,4,"Detach this section and deliver to the address above.");
  1474. $pdf->SetXY($x,$y+9);
  1475. $pdf->Cell(106,4,"Cheques payable to \"$dplinkchequespayableto\"");
  1476.  
  1477. if ($dplinkvisaaccepted == 1 || $dplinkmastercardaccepted == 1 || $dplinkamexaccepted == 1 || $dplinkdinersaccepted == 1){
  1478.     $pdf->SetXY($x,$y+13);
  1479.     if ($dplinkvisaaccepted == 1){
  1480.         $cards="Visa, ";
  1481.     }
  1482.     if ($dplinkmastercardaccepted == 1){
  1483.         $cards.="Mastercard, ";
  1484.     }
  1485.     if ($dplinkamexaccepted == 1){
  1486.         $cards.="American Express, ";
  1487.     }
  1488.     if ($dplinkdinersaccepted == 1){
  1489.         $cards.="Diners Club, ";
  1490.     }
  1491.     $cards=substr($cards,0,strlen($cards)-2);
  1492.     $pdf->Cell(106,4,"Or pay with $cards as below.");
  1493.     $pdf->Rect($x+1,$y+21,4,4);
  1494.     $pdf->Rect($x+5,$y+21,4,4);
  1495.     $pdf->Rect($x+9,$y+21,4,4);
  1496.     $pdf->Rect($x+13,$y+21,4,4);
  1497.     $pdf->Line($x+17,$y+23,$x+18,$y+23);
  1498.     $pdf->Rect($x+18,$y+21,4,4);
  1499.     $pdf->Rect($x+22,$y+21,4,4);   
  1500.     $pdf->Rect($x+26,$y+21,4,4);
  1501.     $pdf->Rect($x+30,$y+21,4,4);
  1502.     $pdf->Line($x+34,$y+23,$x+35,$y+23);   
  1503.     $pdf->Rect($x+35,$y+21,4,4);
  1504.     $pdf->Rect($x+39,$y+21,4,4);   
  1505.     $pdf->Rect($x+43,$y+21,4,4);
  1506.     $pdf->Rect($x+47,$y+21,4,4);
  1507.     $pdf->Line($x+51,$y+23,$x+52,$y+23);   
  1508.     $pdf->Rect($x+52,$y+21,4,4);
  1509.     $pdf->Rect($x+56,$y+21,4,4);   
  1510.     $pdf->Rect($x+60,$y+21,4,4);
  1511.     $pdf->Rect($x+64,$y+21,4,4);
  1512.    
  1513.     $pdf->Rect($x+72,$y+21,4,4);
  1514.     $pdf->Rect($x+76,$y+21,4,4);
  1515.     $pdf->Line($x+81,$y+24,$x+83,$y+22);
  1516.     $pdf->Rect($x+84,$y+21,4,4);
  1517.     $pdf->Rect($x+88,$y+21,4,4);   
  1518.     $pdf->Rect($x+92,$y+21,4,4);
  1519.     $pdf->Rect($x+96,$y+21,4,4);
  1520.    
  1521.     for ($i=0;$i<25;$i+=1){
  1522.         $pdf->Rect($x+1+($i*4),$y+34,4,4);
  1523.     }  
  1524.     $pdf->SetXY($x+25,$y+38);
  1525.     $pdf->Cell(55,4,"Cardholder Name");
  1526.    
  1527.     $pdf->SetXY($x+25,$y+25);
  1528.     $pdf->Cell(55,4,"Card Number");
  1529.     $pdf->SetXY($x+80,$y+25);  
  1530.     $pdf->Cell(20,4,"Expiry");
  1531.    
  1532.     $pdf->Line($x+2,$y+54,$x+52,$y+54);            
  1533.     $pdf->SetXY($x+10,$y+54);
  1534.     $pdf->Cell(30,4,"Cardholder signature");
  1535.    
  1536.     $pdf->SetXY($x+60,$y+50);
  1537.     $pdf->Cell(30,4,"$");  
  1538.     $pdf->Line($x+60,$y+54,$x+80,$y+54);               
  1539.     $pdf->SetXY($x+62,$y+54);
  1540.     $pdf->Cell(30,4,"Amount");
  1541.        
  1542.     $pdf->SetXY($x+45,$y+62);
  1543.     $pdf->Cell(0,0,"$inum");
  1544. }
  1545.  
  1546. $pdf->Rect($x,$y,106,64);
  1547.  
  1548.  
  1549.  
  1550. // Print line items
  1551. $pdf->SetTextColor(0,0,0);
  1552. for ($i=1;$i<21;$i+=1){
  1553.     if ($inv["invoiceitemfee$i"] !=0 || $op["operationitemdesc$i"] !="" ){
  1554.     $pdf->SetFont('Arial','',8);
  1555.     if ($i % 2){
  1556.         $pdf->SetFillColor(255,255,255);
  1557.     } else {
  1558.         $pdf->SetFillColor(225,225,225);
  1559.     }
  1560.     $pdf->SetXY(10,106+($i*4));
  1561.     $itemnumber=$op["operationitem$i"];
  1562.     $pdf->Cell(15,4,$itemnumber,"",0,"L",1);
  1563.     $pdf->SetXY(25,106+($i*4));
  1564.     $desc=$op["operationitemdesc$i"];
  1565.     while ($pdf->GetStringWidth($desc)>158){
  1566.         $desc=substr($desc,0,(strlen($desc)-1));
  1567.     }
  1568.     $pdf->Cell(160,4,$desc,"",0,"L",1);
  1569.     $fee="";
  1570.     if ($inv["invoiceitemfee$i"] != 0){
  1571.         $fee=sprintf("%01.2f",$inv["invoiceitemfee$i"]);
  1572.     }
  1573.     $pdf->SetXY(184,106+($i*4));
  1574.     $dol="";
  1575.     if ($fee !=0){
  1576.         $dol="$";
  1577.     }
  1578.     $pdf->Cell(3,4,$dol,"",0,"L",1);
  1579.     $pdf->SetXY(187,106+($i*4));
  1580.     $pdf->Cell(13,4,"$fee","",0,"R",1);
  1581. }
  1582. }
  1583.  
  1584. // Print cutting thingy line
  1585. $x=10;
  1586. $y=211.5;
  1587. $pdf->SetXY($x,$y);
  1588. $pdf->Cell(0,0,"---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
  1589.  
  1590.  
  1591. // Print line item headings...
  1592. $pdf->SetXY(10,105);
  1593. $pdf->SetFont('Arial','B',8);
  1594. $pdf->SetFillColor(124,124,124);
  1595. $pdf->SetTextColor(255,255,255);
  1596. $pdf->Cell(15,5,"Item No.","LRTB",0,"L",1);
  1597. $pdf->SetXY(25,105);
  1598. $pdf->Cell(159,5,"Description of service. Lengthy descriptions may be abbreviated.","LRTB",0,"C",1);
  1599. $pdf->SetXY(184,105);
  1600. $pdf->Cell(16,5,"Fee","LRTB",0,"C",1);
  1601.  
  1602. // Print line item box and dividers
  1603. $pdf->Rect(10,105,190,85);
  1604. $pdf->Line(184,105,184,190);
  1605. $pdf->Line(25,105,25,190);
  1606.  
  1607. $dexp=date("F j, Y",$invoicediscountexpiry*60);
  1608.  
  1609. // Print GST
  1610. $pdf->SetXY(105,190);
  1611. $pdf->SetFont('Arial','B',8);
  1612. $pdf->SetFillColor(255,255,255);
  1613. $pdf->SetTextColor(0,0,0);
  1614. $pdf->Cell(79,5,"GST","LRTB",0,"R",1);
  1615. $pdf->SetXY(184,190);
  1616. $gst=sprintf("%01.2f",$invoicegst);
  1617. $pdf->Cell(16,5,"$gst","LRTB",0,"R",1);
  1618.  
  1619. // Print discount if paid before
  1620. if ($invoicediscountamount !=0 ){
  1621.     $dpp="Discount for prompt payment";
  1622.     $disc=sprintf("%01.2f",$invoicediscountamount);
  1623. }
  1624. $pdf->SetXY(105,195);
  1625. $pdf->Cell(79,5,"$dpp","LRTB",0,"R",1);
  1626. $pdf->SetXY(184,195);
  1627. $pdf->Cell(16,5,"$disc","LRTB",0,"R",1);
  1628.  
  1629.  
  1630. // Payable after
  1631. if ($invoicediscountamount !=0 ){
  1632.     $apam="Full amount payable after $dexp";
  1633.     $payafter=sprintf("%01.2f",$invoicetotal);
  1634. }
  1635. $pdf->SetXY(105,200);
  1636. $pdf->Cell(79,5,"$apam","LRTB",0,"R",1);
  1637. $pdf->SetXY(184,200);
  1638. $pdf->Cell(16,5,"$payafter","LRTB",0,"R",1);
  1639.  
  1640.  
  1641. // Payable before
  1642. $pdf->SetXY(105,205);
  1643. $pdf->SetFillColor(200,200,200);
  1644. if ($invoicediscountamount !=0 ){
  1645.     $adn=" until $dexp";
  1646.     $pdf->Cell(79,5,"Discounted amount valid until $dexp","LRTB",0,"R",1);$pdf->SetXY(184,215);
  1647. } else {
  1648.     $pdf->Cell(79,5,"Amount payable","LRTB",0,"R",1);$pdf->SetXY(184,215);
  1649. }
  1650. $pdf->SetXY(184,205);
  1651. $paybefore=sprintf("%01.2f",$invoicetotalwithdiscount);
  1652. $pdf->Cell(16,5,"$paybefore","LRTB",0,"R",1);
  1653.  
  1654. if ($nme==""){
  1655.     $nme="Invoice-$inum.pdf";
  1656. }
  1657. $pdf->Output($pdfs.$nme,"F");
  1658. return 1;  
  1659. }
  1660.  
  1661. function password($num){
  1662.     $chars="aaaaqwertyuoplkhfdsazxcvbnmbbbbccccddddeeeeffffgggghhhhiiiikkkkmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz111122223333444455556666777788889999";
  1663.     return substr(str_shuffle($chars),0,$num);
  1664. }
  1665.  
  1666. function emailsubstitute($txt,$num){
  1667.     // Function to replace the ##doctorname## syle entries in an email with the proper text.
  1668.     // Requires the invoice number, so it can look up all the databases to find the proper text entries.
  1669.     // Possible substitutions are :
  1670.     // payer title          payers title taken from invoice
  1671.     // payer firstname
  1672.     // payer lastname
  1673.     // amount owing
  1674.     // amount paid
  1675.     // discount expiry
  1676.     // extended discount
  1677.     // invoice total
  1678.     // invoice discounted total
  1679.     // invoice number
  1680.     // invoice password
  1681.    
  1682.     include $_SESSION['pathToRoot']."setup/settings.php";
  1683.     include $_SESSION['pathToRoot']."setup/arrays.php";
  1684.     $con = mysqli_connect($sqlhost, $sqluser, $sqlpassword, $sqldbname) or die("SQL Connect error.");
  1685.     // First get details of the invoice itself
  1686.     $query="SELECT * FROM invoice WHERE invoicecode=\"$num\"";
  1687.     $res = mysqli_query($con, $query) or die(mysqli_error());
  1688.     if (mysqli_num_rows($res) == 1){
  1689.         $r=mysqli_fetch_assoc($res);
  1690.         extract($r);
  1691.         // Get the invoice, now get the operation
  1692.         $query="SELECT * FROM operation WHERE operationcode=\"$invoiceoperationcode\"";
  1693.         $res = mysqli_query($con, $query) or die(mysqli_error());
  1694.         if (mysqli_num_rows($res) == 1){
  1695.             $r=mysqli_fetch_assoc($res);
  1696.             extract($r);
  1697.             // Got the operation. Now get the patient
  1698.             $query="SELECT * FROM patient WHERE patientcode=\"$operationpatientcode\"";
  1699.             $res = mysqli_query($con, $query) or die(mysqli_error());
  1700.             if (mysqli_num_rows($res) == 1){
  1701.                 $r=mysqli_fetch_assoc($res);
  1702.                 extract($r);
  1703.                 // Gto the patient. Get the doctor
  1704.                 $query="SELECT * FROM doctor WHERE doctorcode=\"$operationdoctorcode\"";
  1705.                 $res = mysqli_query($con, $query) or die(mysqli_error());
  1706.                 if (mysqli_num_rows($res) == 1){
  1707.                     $r=mysqli_fetch_assoc($res);
  1708.                     extract($r);
  1709.                     // Got the doctor. Get the dplink.
  1710.                     $query="SELECT * FROM dplink WHERE dplinkcode=\"$operationdplinkcode\"";
  1711.                     $res = mysqli_query($con, $query) or die(mysqli_error());
  1712.                     if (mysqli_num_rows($res) == 1){
  1713.                         $r=mysqli_fetch_assoc($res);
  1714.                         extract($r);
  1715.                         // Got the DPlink. Get the practice
  1716.                         $query="SELECT * FROM practice WHERE practicecode=\"$dplinkpractice\"";
  1717.                         $res = mysqli_query($con, $query) or die(mysqli_error());
  1718.                         if (mysqli_num_rows($res) == 1){
  1719.                             $r=mysqli_fetch_assoc($res);
  1720.                             extract($r);
  1721.                         } else {
  1722.                             $err.="Practice does not exist. ";
  1723.                         }
  1724.                     } else {
  1725.                         $err.="DPlink does not exist. ";
  1726.                     }
  1727.                 } else {
  1728.                     $err.="Doctor does not exist. ";
  1729.                 }
  1730.             } else {
  1731.                 $err.="Patient does not exist. ";
  1732.             }
  1733.         } else {
  1734.             $err.="Operation does not exist. ";
  1735.         }      
  1736.     } else {
  1737.         $err.="Invoice does not exist. ";
  1738.     }
  1739.     $txt = str_ireplace(chr(13),"<br>",$txt);  
  1740.     $txt = str_ireplace("##payer title##",$invoicepayertitle,$txt);
  1741.     $txt = str_ireplace("##payer firstname##",$invoicepayerfirstname,$txt);
  1742.     $txt = str_ireplace("##payer first name##",$invoicepayerfirstname,$txt);
  1743.     $txt = str_ireplace("##payer lastname##",$invoicepayerlastname,$txt);  
  1744.     $txt = str_ireplace("##payer last name##",$invoicepayerlasttname,$txt);
  1745.     $txt = str_ireplace("##amount owing##",sprintf("%01.2f",$invoiceamountowing),$txt);
  1746.     $txt = str_ireplace("##amount paid##",sprintf("%01.2f",$invoiceamountpaid),$txt);
  1747.     $txt = str_ireplace("##discount expiry##",date("d F, Y",($invoicediscountexpiry*60)),$txt);
  1748.     $txt = str_ireplace("##extended discount##",date("d F, Y",($invoiceextendeddiscount*60)),$txt);
  1749.     $txt = str_ireplace("##invoice total##",$invoicetotal,$txt);
  1750.     $txt = str_ireplace("##invoice discounted total##",sprintf("%01.2f",$invoicetotalwithdiscount),$txt);
  1751.     $txt = str_ireplace("##invoice number##",$invoicecode,$txt);
  1752.     $txt = str_ireplace("##invoice password##",$invoicepassword,$txt); 
  1753.     $txt = str_ireplace("##operation name##",$operationname,$txt);
  1754.     $txt = str_ireplace("##hospital name##",$operationhospitalname,$txt);      
  1755.     $txt = str_ireplace("##surgeon name##",$operationsurgeonname,$txt);
  1756.     $txt = str_ireplace("##operation name##",$operationname,$txt);
  1757.     $txt = str_ireplace("##operation date##",date("d F, Y",($operationstart*60)),$txt);
  1758.     $txt = str_ireplace("##patient title##",$patienttitle,$txt);   
  1759.     $txt = str_ireplace("##patient fist name##",$patientfirstname,$txt);       
  1760.     $txt = str_ireplace("##patient last name##",$patientlastname,$txt);
  1761.     $txt = str_ireplace("##patient insurer##",$patientinsurer,$txt);   
  1762.     $txt = str_ireplace("##patient medicare number##",$patientmedicarenumber,$txt);
  1763.     $txt = str_ireplace("##doctor title##",$doctortitle,$txt);     
  1764.     $txt = str_ireplace("##doctor first name##",$doctorfirstname,$txt);    
  1765.     $txt = str_ireplace("##doctor last name##",$doctorlastname,$txt);
  1766.     $txt = str_ireplace("##doctor provider##",$dplinkprovider,$txt);   
  1767.     $txt = str_ireplace("##doctor provider number##",$dplinkprovider,$txt);
  1768.     $txt = str_ireplace("##practice web page##",$practicewebpage,$txt);
  1769.     $txt = str_ireplace("##practice webpage##",$practicewebpage,$txt); 
  1770.     $txt = str_ireplace("##practice phone number##",$practicephone,$txt);  
  1771.     $txt = str_ireplace("##practice fax number##",$practicefax,$txt);
  1772.     $txt = str_ireplace("##practice email##",$practiceemail,$txt);
  1773.     $txt = str_ireplace("##disclaimer##",$disclaimer,$txt);        
  1774. return $txt;
  1775.            
  1776. }
  1777.  
  1778. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement