fixed bug in setting pid
[openemr.git] / library / billrep.inc
blob830064f98b1667e114f85912fd41334d4dabd861
1 <?php
2         require_once("{$GLOBALS['srcdir']}/sql.inc");
4 //date must be in nice format (e.g. 2002-07-11)
6 function getBillsBy($date, $qtype = "day", $auth="%", $cols = "date,pid,code_type,code,user,authorized")
7         {
8                 if ($qtype == "all") {
9                         $res = sqlStatement("select $cols from billing order by date ASC");
10                 }
11                 elseif ($qtype == "day") {
12                         $res = sqlStatement("select $cols from billing where date like '$date' order by date ASC");
13                 }
14                 elseif ($qtype == "month") {
15                         $m = substr($date,5,2);
16                         $y = substr($date,0,4);
17                         $res = sqlStatement("select $cols from billing where MONTH(date) = '$m' and YEAR(date) = '$y' ORDER by date ASC");
18                 }
19                 elseif ($qtype == "year") {
20                         $y = substr($date,0,4);
21                         $res = sqlStatement("select $cols from billing where YEAR(date) = '$y' ORDER by date ASC");
22                 }
24                 for($iter=0; $row=sqlFetchArray($res); $iter++)
25                 {
26                         $all[$iter] = $row;
27                 }
29                 return $all;
30         }
34 function getBillsBetween($date, $date2, $auth="%", $unbilled, $code_type, $cols = "id,date,pid,code_type,code,user,authorized,x12_partner_id")
35         {
36                 
37                 $billstring = "billed = '0'";
38                 if ($unbilled == "0") {
39                         //3 is an error condition
40                         $billstring = "billed = '0' or (billed = '1' and bill_process = '3')";
41                 }
42                 else {
43                                 $billstring = "billed = '1'";
44                 }
45                 $sql = "select * from billing where date >= '$date' and date <= '$date2 23:59:59' and authorized like '$auth' and ($billstring) and code_type like '$code_type' and activity = 1 order by encounter,pid,code_type,code ASC";
46                 
47                 $res = sqlStatement($sql);
48                 //print "select $cols from billing where date >= '$date' and date <= '$date2 23:59:59' and authorized like '$auth' and billed like '$unbilled' and code_type like '$code_type' order by pid,date ASC";
49                 
50                 for($iter=0; $row=sqlFetchArray($res); $iter++)
51                 {
52                         $all[$iter] = $row;
53                 }
54                 
55                 return $all;
56         }
59 function getBillsListBetween($date, $date2, $auth="%", $unbilled, $code_type, $cols = "id,date,pid,code_type,code,user")
60         {
61                 $billstring = "billed = '0'";
62                 if ($unbilled == "0") {
63                         //3 is an error condition
64                         $billstring = "billed = '0' or (billed = '1' and bill_process = '3')";
65                 }
66                 else {
67                                 $billstring = "billed = '1'";
68                 }
69                 $sql = "select $cols from billing where date >= '$date' and date <= '$date2 23:59:59' and authorized like '$auth' and ($billstring) and code_type like '$code_type' and activity = 1 order by pid,date ASC";
70                 
71                 $res = sqlStatement($sql);
72                 //print "select $cols from billing where date >= '$date' and date <= '$date2 23:59:59' and authorized like '$auth' and billed like '$unbilled' and code_type like '$code_type' order by pid,date ASC";
73                 $string = "( ";
74                 for($iter=0; $row=sqlFetchArray($res); $iter++)
75                 {
76                         $string .= $row{"id"}.",";
77                 }
78                 $string = substr($string,0,strlen($string)-1);
79                 $string .= ")";
80                 return $string;
81         }
84 function billCodesBetween($date, $date2, $auth="%", $code_type)
85         {
86                 sqlStatement("update billing set billed=1 where date >= '$date' and date <= '$date2 23:59:59' and authorized like '$auth' and code_type like '$code_type'");
87         }
88 function billCodesList($list,$skip = "()") {
89         if ($list == "()")
90                 return;
92         if ($skip == "()")
93                 sqlStatement("update billing set billed=1 where id in $list");
94         else
95                 sqlStatement("update billing set billed=1 where id in $list and id not in $skip");
97         return;
100 function getCodeTypes () {
101                 $res = sqlStatement("select distinct code_type from billing order by code_type");
103                 for($iter=0; $row=sqlFetchArray($res); $iter++)
104                 {
105                         $all[$iter] = $row;
106                 }
108                 return $all;