added invalid user/pass error message
[openemr.git] / library / billrep.inc
blob0aa7b86d3066c57e1906b2b9bda9ec2befb12a9e
1 <?php
2         require_once("{$GLOBALS['srcdir']}/sql.inc");
4         //date must be in nice format (e.g. 2002-07-11)
6         function getBillsBetween($date, $date2, $auth="%", $unbilled, $code_type,
7                 $cols = "id,date,pid,code_type,code,user,authorized,x12_partner_id")
8         {
9                 $billstring = "billing.billed = '0'";
10                 if ($unbilled == "0") {
11                         //3 is an error condition
12                         $billstring = "billing.billed = '0' or (billing.billed = '1' and billing.bill_process = '3')";
13                 }
14                 else {
15                         $billstring = "billing.billed = '1'";
16                 }
18                 // Selecting by the date in the billing table is wrong, because that is
19                 // just the data entry date; instead we want to go by the encounter date
20                 // which is the date in the form_encounter table.
21                 //
22                 $sql = "SELECT fe.date AS enc_date, fe.pid AS enc_pid, " .
23                         "fe.encounter AS enc_encounter, billing.* " .
24                         "FROM form_encounter AS fe " .
25                         "LEFT OUTER JOIN billing ON " .
26                         "billing.encounter = fe.encounter AND " .
27                         "billing.pid = fe.pid AND " .
28                         "billing.authorized like '$auth' AND " .
29                         "( $billstring ) AND " .
30                         "billing.code_type LIKE '$code_type' AND " .
31                         "billing.activity = 1 " .
32                         "WHERE " .
33                         "fe.date >= '$date' AND " .
34                         "fe.date <= '$date2 23:59:59' " .
35                         "ORDER BY fe.encounter, fe.pid, billing.code_type, billing.code ASC";
37                 $res = sqlStatement($sql);
39                 for($iter=0; $row=sqlFetchArray($res); $iter++)
40                 {
41                         $all[$iter] = $row;
42                 }
44                 return $all;
45         }
47         function getBillsListBetween($date, $date2, $auth="%", $unbilled, $code_type,
48                 $cols = "billing.id, form_encounter.date, billing.pid, billing.code_type, billing.code, billing.user")
49         {
50                 $billstring = "billed = '0'";
51                 if ($unbilled == "0") {
52                         //3 is an error condition
53                         $billstring = "billed = '0' or (billed = '1' and bill_process = '3')";
54                 }
55                 else {
56                         $billstring = "billed = '1'";
57                 }
59                 // See above comment in getBillsBetween().
60                 //
61                 $sql = "select $cols " .
62                         "from form_encounter, billing where " .
63                         "form_encounter.date >= '$date' and " .
64                         "form_encounter.date <= '$date2 23:59:59' and " .
65                         "billing.encounter = form_encounter.encounter and " .
66                         "billing.authorized like '$auth' and " .
67                         "($billstring) and " .
68                         "billing.code_type like '$code_type' and " .
69                         "billing.activity = 1 " .
70                         "order by billing.pid, billing.date ASC";
72                 $res = sqlStatement($sql);
73                 //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";
74                 $string = "( ";
75                 for($iter=0; $row=sqlFetchArray($res); $iter++)
76                 {
77                         $string .= $row{"id"}.",";
78                 }
79                 $string = substr($string,0,strlen($string)-1);
80                 $string .= ")";
81                 return $string;
82         }
84         function billCodesList($list,$skip = "()") {
85                 if ($list == "()")
86                         return;
88                 if ($skip == "()")
89                         sqlStatement("update billing set billed=1 where id in $list");
90                 else
91                         sqlStatement("update billing set billed=1 where id in $list and id not in $skip");
93                 return;
94         }