More complete support for activity flag in list_options table. (#274)
[openemr.git] / interface / reports / services_by_category.php
blob10a534518794568c92f58981bd511a7113e58e92
1 <?php
2 // Copyright (C) 2008-2016 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../globals.php");
10 require_once("../../custom/code_types.inc.php");
11 require_once("$srcdir/sql.inc");
12 require_once("$srcdir/formatting.inc.php");
14 // Format dollars for display.
16 function bucks($amount) {
17 if (empty($amount)) return '';
18 return oeFormatMoney($amount);
21 $filter = $_REQUEST['filter'] + 0;
22 $where = "c.active = 1";
23 if ($filter) $where .= " AND c.code_type = '$filter'";
24 if (empty($_REQUEST['include_uncat']))
25 $where .= " AND c.superbill != '' AND c.superbill != '0'";
27 <html>
28 <head>
29 <?php html_header_show(); ?>
30 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
34 <style type="text/css">
36 /* specifically include & exclude from printing */
37 @media print {
38 #report_parameters {
39 visibility: hidden;
40 display: none;
42 #report_parameters_daterange {
43 visibility: visible;
44 display: inline;
46 #report_results table {
47 margin-top: 0px;
51 /* specifically exclude some from the screen */
52 @media screen {
53 #report_parameters_daterange {
54 visibility: hidden;
55 display: none;
59 table.mymaintable, table.mymaintable td, table.mymaintable th {
60 border: 1px solid #aaaaaa;
61 border-collapse: collapse;
63 table.mymaintable td, table.mymaintable th {
64 padding: 1pt 4pt 1pt 4pt;
66 </style>
67 <title><?php xl('Services by Category','e'); ?></title>
69 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
70 <script type="text/javascript" src="../../library/textformat.js"></script>
71 <script type="text/javascript" src="../../library/dialog.js"></script>
72 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-9-1/index.js"></script>
73 <script type="text/javascript" src="../../library/js/report_helper.js?v=<?php echo $v_js_includes; ?>"></script>
75 <script language="JavaScript">
77 $(document).ready(function() {
78 oeFixedHeaderSetup(document.getElementById('mymaintable'));
79 var win = top.printLogSetup ? top : opener.top;
80 win.printLogSetup(document.getElementById('printbutton'));
81 });
83 </script>
85 </head>
87 <body class="body_top">
89 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Services by Category','e'); ?></span>
91 <form method='post' action='services_by_category.php' name='theform' id='theform'>
93 <div id="report_parameters">
95 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
97 <table>
98 <tr>
99 <td width='280px'>
100 <div style='float:left'>
102 <table class='text'>
103 <tr>
104 <td>
105 <select name='filter'>
106 <option value='0'><?php xl('All','e'); ?></option>
107 <?php
108 foreach ($code_types as $key => $value) {
109 echo "<option value='" . $value['id'] . "'";
110 if ($value['id'] == $filter) echo " selected";
111 echo ">$key</option>\n";
114 </select>
115 </td>
116 <td>
117 <input type='checkbox' name='include_uncat' value='1'<?php if (!empty($_REQUEST['include_uncat'])) echo " checked"; ?> />
118 <?php xl('Include Uncategorized','e'); ?>
119 </td>
120 </tr>
121 </table>
123 </div>
125 </td>
126 <td align='left' valign='middle' height="100%">
127 <table style='border-left:1px solid; width:100%; height:100%' >
128 <tr>
129 <td>
130 <div style='margin-left:15px'>
131 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
132 <span>
133 <?php xl('Submit','e'); ?>
134 </span>
135 </a>
137 <?php if ($_POST['form_refresh']) { ?>
138 <a href='#' class='css_button' id='printbutton'>
139 <span>
140 <?php xl('Print','e'); ?>
141 </span>
142 </a>
143 <?php } ?>
144 </div>
145 </td>
146 </tr>
147 </table>
148 </td>
149 </tr>
150 </table>
151 </div> <!-- end of parameters -->
153 <?php
154 if ($_POST['form_refresh']) {
157 <div id="report_results">
160 <table width='98%' id='mymaintable' class='mymaintable'>
161 <thead style='display:table-header-group'>
162 <tr bgcolor="#dddddd">
163 <th class='bold'><?php xl('Category' ,'e'); ?></th>
164 <th class='bold'><?php xl('Type' ,'e'); ?></th>
165 <th class='bold'><?php xl('Code' ,'e'); ?></th>
166 <th class='bold'><?php xl('Mod' ,'e'); ?></th>
167 <th class='bold'><?php xl('Units' ,'e'); ?></th>
168 <th class='bold'><?php xl('Description','e'); ?></th>
169 <?php if (related_codes_are_used()) { ?>
170 <th class='bold'><?php xl('Related' ,'e'); ?></th>
171 <?php } ?>
172 <?php
173 $pres = sqlStatement("SELECT title FROM list_options " .
174 "WHERE list_id = 'pricelevel' AND activity = 1 ORDER BY seq");
175 while ($prow = sqlFetchArray($pres)) {
176 // Added 5-09 by BM - Translate label if applicable
177 echo " <th class='bold' align='right' nowrap>" . xl_list_label($prow['title']) . "</th>\n";
180 </tr>
181 </thead>
182 <tbody>
183 <?php
184 $res = sqlStatement("SELECT c.*, lo.title FROM codes AS c " .
185 "LEFT OUTER JOIN list_options AS lo ON lo.list_id = 'superbill' " .
186 "AND lo.option_id = c.superbill AND lo.activity = 1 " .
187 "WHERE $where ORDER BY lo.title, c.code_type, c.code, c.modifier");
189 $last_category = '';
190 $irow = 0;
191 while ($row = sqlFetchArray($res)) {
192 $category = $row['title'] ? $row['title'] : 'Uncategorized';
193 $disp_category = '&nbsp';
194 if ($category !== $last_category) {
195 $last_category = $category;
196 $disp_category = $category;
197 ++$irow;
199 foreach ($code_types as $key => $value) {
200 if ($value['id'] == $row['code_type']) {
201 break;
204 $bgcolor = (($irow & 1) ? "#ffdddd" : "#ddddff");
205 echo " <tr bgcolor='$bgcolor'>\n";
206 // Added 5-09 by BM - Translate label if applicable
207 echo " <td class='text'>" . xl_list_label($disp_category) . "</td>\n";
208 echo " <td class='text'>$key</td>\n";
209 echo " <td class='text'>" . $row['code'] . "</td>\n";
210 echo " <td class='text'>" . $row['modifier'] . "</td>\n";
211 echo " <td class='text'>" . $row['units'] . "</td>\n";
212 echo " <td class='text'>" . $row['code_text'] . "</td>\n";
214 if (related_codes_are_used()) {
215 // Show related codes.
216 echo " <td class='text'>";
217 $arel = explode(';', $row['related_code']);
218 foreach ($arel as $tmp) {
219 list($reltype, $relcode) = explode(':', $tmp);
220 $reltype = $code_types[$reltype]['id'];
221 $relrow = sqlQuery("SELECT code_text FROM codes WHERE " .
222 "code_type = '$reltype' AND code = '$relcode' LIMIT 1");
223 echo $relcode . ' ' . trim($relrow['code_text']) . '<br />';
225 echo "</td>\n";
228 $pres = sqlStatement("SELECT p.pr_price " .
229 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
230 "p.pr_id = '" . $row['id'] . "' AND p.pr_selector = '' " .
231 "AND p.pr_level = lo.option_id " .
232 "WHERE lo.list_id = 'pricelevel' AND lo.activity = 1 ORDER BY lo.seq");
233 while ($prow = sqlFetchArray($pres)) {
234 echo " <td class='text' align='right'>" . bucks($prow['pr_price']) . "</td>\n";
236 echo " </tr>\n";
239 </tbody>
240 </table>
242 <?php } // end of submit logic ?>
243 </div>
245 </body>
246 </html>