enable to upload docx templates (#1961)
[openemr.git] / interface / reports / services_by_category.php
blobcf327ef7333c82621116c3b4f53d207aeb54751a
1 <?php
2 /**
3 * Services by category report.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2008-2016 Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("../../custom/code_types.inc.php");
18 use OpenEMR\Core\Header;
20 // Format dollars for display.
22 function bucks($amount)
24 if (empty($amount)) {
25 return '';
28 return oeFormatMoney($amount);
31 <html>
32 <head>
33 <title><?php echo xlt('Services by Category'); ?></title>
35 <?php Header::setupHeader(['datetime-picker', 'report-helper']); ?>
37 <style type="text/css">
38 /* specifically include & exclude from printing */
39 @media print {
40 #report_parameters {
41 visibility: hidden;
42 display: none;
44 #report_parameters_daterange {
45 visibility: visible;
46 display: inline;
48 #report_results table {
49 margin-top: 0px;
53 /* specifically exclude some from the screen */
54 @media screen {
55 #report_parameters_daterange {
56 visibility: hidden;
57 display: none;
61 table.mymaintable, table.mymaintable td, table.mymaintable th {
62 border: 1px solid #aaaaaa;
63 border-collapse: collapse;
65 table.mymaintable td, table.mymaintable th {
66 padding: 1pt 4pt 1pt 4pt;
68 </style>
70 <script language="JavaScript">
72 $(document).ready(function() {
73 oeFixedHeaderSetup(document.getElementById('mymaintable'));
74 var win = top.printLogSetup ? top : opener.top;
75 win.printLogSetup(document.getElementById('printbutton'));
76 });
77 </script>
78 </head>
80 <body class="body_top">
82 <span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Services by Category'); ?></span>
84 <form method='post' action='services_by_category.php' name='theform' id='theform' onsubmit='return top.restoreSession()'>
86 <div id="report_parameters">
88 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
90 <table>
91 <tr>
92 <td width='280px'>
93 <div style='float:left'>
95 <table class='text'>
96 <tr>
97 <td>
98 <select name='filter' class='form-control'>
99 <option value='0'><?php echo xlt('All'); ?></option>
100 <?php
101 foreach ($code_types as $key => $value) {
102 echo "<option value='" . attr($value['id']) . "'";
103 if ($value['id'] == $filter) {
104 echo " selected";
107 echo ">" . text($key) . "</option>\n";
110 </select>
111 </td>
112 <td>
113 <div class="checkbox">
114 <label><input type='checkbox' name='include_uncat' value='1'<?php echo (!empty($_REQUEST['include_uncat'])) ? " checked" : ""; ?> />
115 <?php echo xlt('Include Uncategorized'); ?></label>
116 </div>
117 </td>
118 </tr>
119 </table>
121 </div>
123 </td>
124 <td align='left' valign='middle' height="100%">
125 <table style='border-left:1px solid; width:100%; height:100%' >
126 <tr>
127 <td>
128 <div class="text-center">
129 <div class="btn-group" role="group">
130 <a href='#' class='btn btn-default btn-save' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
131 <?php echo xlt('Submit'); ?>
132 </a>
133 <?php if ($_POST['form_refresh']) { ?>
134 <a href='#' class='btn btn-default btn-print' id='printbutton'>
135 <?php echo xlt('Print'); ?>
136 </a>
137 <?php } ?>
138 </div>
139 </div>
140 </td>
141 </tr>
142 </table>
143 </td>
144 </tr>
145 </table>
146 </div> <!-- end of parameters -->
148 <?php
149 if ($_POST['form_refresh']) {
152 <div id="report_results">
155 <table width='98%' id='mymaintable' class='mymaintable'>
156 <thead style='display:table-header-group'>
157 <tr bgcolor="#dddddd">
158 <th class='bold'><?php echo xlt('Category'); ?></th>
159 <th class='bold'><?php echo xlt('Type'); ?></th>
160 <th class='bold'><?php echo xlt('Code'); ?></th>
161 <th class='bold'><?php echo xlt('Mod'); ?></th>
162 <th class='bold'><?php echo xlt('Units'); ?></th>
163 <th class='bold'><?php echo xlt('Description'); ?></th>
164 <?php if (related_codes_are_used()) { ?>
165 <th class='bold'><?php echo xlt('Related'); ?></th>
166 <?php } ?>
167 <?php
168 $pres = sqlStatement("SELECT title FROM list_options " .
169 "WHERE list_id = 'pricelevel' AND activity = 1 ORDER BY seq");
170 while ($prow = sqlFetchArray($pres)) {
171 // Added 5-09 by BM - Translate label if applicable
172 echo " <th class='bold' align='right' nowrap>" . text(xl_list_label($prow['title'])) . "</th>\n";
175 </tr>
176 </thead>
177 <tbody>
178 <?php
180 $sqlBindArray = array();
181 $filter = sanitizeNumber($_REQUEST['filter']);
182 $where = "c.active = 1";
183 if ($filter) {
184 $where .= " AND c.code_type = ?";
185 array_push($sqlBindArray, $filter);
187 if (empty($_REQUEST['include_uncat'])) {
188 $where .= " AND c.superbill != '' AND c.superbill != '0'";
191 $res = sqlStatement("SELECT c.*, lo.title FROM codes AS c " .
192 "LEFT OUTER JOIN list_options AS lo ON lo.list_id = 'superbill' " .
193 "AND lo.option_id = c.superbill AND lo.activity = 1 " .
194 "WHERE $where ORDER BY lo.title, c.code_type, c.code, c.modifier", $sqlBindArray);
196 $last_category = '';
197 $irow = 0;
198 while ($row = sqlFetchArray($res)) {
199 $category = $row['title'] ? $row['title'] : xl('Uncategorized');
200 $disp_category = ' ';
201 if ($category !== $last_category) {
202 $last_category = $category;
203 $disp_category = $category;
204 ++$irow;
207 foreach ($code_types as $key => $value) {
208 if ($value['id'] == $row['code_type']) {
209 break;
213 $bgcolor = (($irow & 1) ? "#ffdddd" : "#ddddff");
214 echo " <tr bgcolor='$bgcolor'>\n";
215 // Added 5-09 by BM - Translate label if applicable
216 echo " <td class='text'>" . text(xl_list_label($disp_category)) . "</td>\n";
217 echo " <td class='text'>" . text($key) . "</td>\n";
218 echo " <td class='text'>" . text($row['code']) . "</td>\n";
219 echo " <td class='text'>" . text($row['modifier']) . "</td>\n";
220 echo " <td class='text'>" . text($row['units']) . "</td>\n";
221 echo " <td class='text'>" . text($row['code_text']) . "</td>\n";
223 if (related_codes_are_used()) {
224 // Show related codes.
225 echo " <td class='text'>";
226 $arel = explode(';', $row['related_code']);
227 foreach ($arel as $tmp) {
228 list($reltype, $relcode) = explode(':', $tmp);
229 $reltype = $code_types[$reltype]['id'];
230 $relrow = sqlQuery("SELECT code_text FROM codes WHERE " .
231 "code_type = ? AND code = ? LIMIT 1", array($reltype, $relcode));
232 echo text($relcode) . ' ' . text(trim($relrow['code_text'])) . '<br />';
235 echo "</td>\n";
238 $pres = sqlStatement("SELECT p.pr_price " .
239 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
240 "p.pr_id = ? AND p.pr_selector = '' " .
241 "AND p.pr_level = lo.option_id " .
242 "WHERE lo.list_id = 'pricelevel' AND lo.activity = 1 ORDER BY lo.seq", array($row['id']));
243 while ($prow = sqlFetchArray($pres)) {
244 echo " <td class='text' align='right'>" . text(bucks($prow['pr_price'])) . "</td>\n";
247 echo " </tr>\n";
250 </tbody>
251 </table>
253 <?php } // end of submit logic ?>
254 </div>
256 </body>
257 </html>