ongoing internationalization of date widget
[openemr.git] / interface / reports / ippf_cyp_report.php
blobb78d0de12bf83b62b223d3237774ae5f164bd6a7
1 <?php
2 /**
3 * ippf_cyp_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) 2009-2010 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
14 require_once("../globals.php");
15 require_once("$srcdir/patient.inc");
16 require_once("$srcdir/acl.inc");
18 function formatcyp($amount)
20 if ($amount) {
21 return sprintf("%.2f", $amount);
24 return '';
27 function display_desc($desc)
29 if (preg_match('/^\S*?:(.+)$/', $desc, $matches)) {
30 $desc = $matches[1];
33 return $desc;
36 function thisLineItem($patient_id, $encounter_id, $description, $transdate, $qty, $cypfactor, $irnumber = '')
38 global $product, $productcyp, $producttotal, $productqty, $grandtotal, $grandqty;
40 $invnumber = empty($irnumber) ? "$patient_id.$encounter_id" : $irnumber;
41 $rowcyp = sprintf('%01.2f', $cypfactor);
42 $rowresult = sprintf('%01.2f', $rowcyp * $qty);
44 $rowproduct = $description;
45 if (! $rowproduct) {
46 $rowproduct = 'Unknown';
49 if ($product != $rowproduct) {
50 if ($product) {
51 // Print product total.
52 if ($_POST['form_csvexport']) {
53 if (! $_POST['form_details']) {
54 echo '"' . display_desc($product) . '",';
55 echo '"' . $productqty . '",';
56 echo '"' . formatcyp($productcyp) . '",';
57 echo '"' . formatcyp($producttotal) . '"' . "\n";
59 } else {
62 <tr bgcolor="#ddddff">
63 <td class="detail" colspan="<?php echo $_POST['form_details'] ? 3 : 1; ?>">
64 <?php
65 if ($_POST['form_details']) {
66 echo xl('Total for ');
68 echo display_desc($product) ?>
69 </td>
70 <td class="dehead" align="right">
71 <?php echo $productqty; ?>
72 </td>
73 <td class="dehead" align="right">
74 <?php echo formatcyp($productcyp); ?>
75 </td>
76 <td class="dehead" align="right">
77 <?php echo formatcyp($producttotal); ?>
78 </td>
79 </tr>
80 <?php
81 } // End not csv export
84 $producttotal = 0;
85 $productqty = 0;
86 $product = $rowproduct;
87 $productleft = $product;
88 $productcyp = $rowcyp;
91 if ($_POST['form_details']) {
92 if ($_POST['form_csvexport']) {
93 echo '"' . display_desc($product) . '",';
94 echo '"' . oeFormatShortDate(display_desc($transdate)) . '",';
95 echo '"' . display_desc($invnumber) . '",';
96 echo '"' . display_desc($qty) . '",';
97 echo '"' . formatcyp($rowcyp) . '",';
98 echo '"' . formatcyp($rowresult) . '"' . "\n";
99 } else {
102 <tr>
103 <td class="detail">
104 <?php echo display_desc($productleft);
105 $productleft = "&nbsp;"; ?>
106 </td>
107 <td class="dehead">
108 <?php echo oeFormatShortDate($transdate); ?>
109 </td>
110 <td class="detail">
111 <?php echo $invnumber; ?>
112 </td>
113 <td class="dehead" align="right">
114 <?php echo $qty; ?>
115 </td>
116 <td class="dehead" align="right">
117 <?php echo formatcyp($rowcyp); ?>
118 </td>
119 <td class="dehead" align="right">
120 <?php echo formatcyp($rowresult); ?>
121 </td>
122 </tr>
123 <?php
124 } // End not csv export
125 } // end details
126 $producttotal += $rowresult;
127 $grandtotal += $rowresult;
128 $productqty += $qty;
129 $grandqty += $qty;
130 } // end function
132 if (! acl_check('acct', 'rep')) {
133 die(xl("Unauthorized access."));
136 $form_from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
137 $form_to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
138 $form_facility = $_POST['form_facility'];
140 if ($_POST['form_csvexport']) {
141 header("Pragma: public");
142 header("Expires: 0");
143 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
144 header("Content-Type: application/force-download");
145 header("Content-Disposition: attachment; filename=ippf_cyp_report.csv");
146 header("Content-Description: File Transfer");
147 // CSV headers:
148 if ($_POST['form_details']) {
149 echo '"Item",';
150 echo '"Date",';
151 echo '"Invoice",';
152 echo '"Qty",';
153 echo '"CYP",';
154 echo '"Result"' . "\n";
155 } else {
156 echo '"Item",';
157 echo '"Qty",';
158 echo '"CYP",';
159 echo '"Result"' . "\n";
161 } else { // not export
163 <html>
164 <head>
165 <?php html_header_show();?>
167 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
168 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
170 <title><?php xl('CYP Report', 'e') ?></title>
172 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-9-1/index.js"></script>
173 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
175 <script language="JavaScript">
176 $(document).ready(function() {
177 var win = top.printLogSetup ? top : opener.top;
178 win.printLogSetup(document.getElementById('printbutton'));
180 $('.datepicker').datetimepicker({
181 <?php $datetimepicker_timepicker = false; ?>
182 <?php $datetimepicker_showseconds = false; ?>
183 <?php $datetimepicker_formatInput = false; ?>
184 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
185 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
188 </script>
190 </head>
192 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
193 <center>
195 <h2><?php xl('CYP Report', 'e')?></h2>
197 <form method='post' action='ippf_cyp_report.php'>
199 <table border='0' cellpadding='3'>
201 <tr>
202 <td>
203 <?php
204 // Build a drop-down list of facilities.
206 $query = "SELECT id, name FROM facility ORDER BY name";
207 $fres = sqlStatement($query);
208 echo " <select name='form_facility'>\n";
209 echo " <option value=''>-- All Facilities --\n";
210 while ($frow = sqlFetchArray($fres)) {
211 $facid = $frow['id'];
212 echo " <option value='$facid'";
213 if ($facid == $form_facility) {
214 echo " selected";
217 echo ">" . $frow['name'] . "\n";
220 echo " </select>\n";
222 &nbsp;<?xl('From:','e')?>
223 <input type='text' class='datepicker' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
224 title='yyyy-mm-dd'>
225 &nbsp;To:
226 <input type='text' class='datepicker' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
227 title='yyyy-mm-dd'>
228 &nbsp;
229 <input type='checkbox' name='form_details' value='1'<?php echo ($_POST['form_details']) ? " checked" : ""; ?>><?php xl('Details', 'e') ?>
230 &nbsp;
231 <input type='submit' name='form_refresh' value="<?php xl('Refresh', 'e') ?>">
232 &nbsp;
233 <input type='submit' name='form_csvexport' value="<?php xl('Export to CSV', 'e') ?>">
234 &nbsp;
235 <input type='button' value='<?php echo xla('Print'); ?>' id='printbutton' />
236 </td>
237 </tr>
239 <tr>
240 <td height="1">
241 </td>
242 </tr>
244 </table>
246 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
248 <tr bgcolor="#dddddd">
249 <td class="dehead">
250 <?php xl('Item', 'e') ?>
251 </td>
252 <?php if ($_POST['form_details']) { ?>
253 <td class="dehead">
254 <?php xl('Date', 'e') ?>
255 </td>
256 <td class="dehead">
257 <?php xl('Invoice', 'e') ?>
258 </td>
259 <?php } ?>
260 <td class="dehead" align="right">
261 <?php xl('Qty', 'e') ?>
262 </td>
263 <td class="dehead" align="right">
264 <?php xl('CYP', 'e') ?>
265 </td>
266 <td class="dehead" align="right">
267 <?php xl('Result', 'e') ?>
268 </td>
269 </tr>
270 <?php
271 } // end not export
273 // If generating a report.
275 if ($_POST['form_refresh'] || $_POST['form_csvexport']) {
276 $from_date = $form_from_date;
277 $to_date = $form_to_date;
279 $product = "";
280 $productleft = "";
281 $productcyp = 0;
282 $producttotal = 0; // total of results for product
283 $grandtotal = 0; // grand total of results
284 $productqty = 0;
285 $grandqty = 0;
287 $query = "SELECT b.pid, b.encounter, b.code_type, b.code, b.units, " .
288 "b.code_text, c.cyp_factor, fe.date, fe.facility_id, fe.invoice_refno " .
289 "FROM billing AS b " .
290 "JOIN codes AS c ON c.code_type = '12' AND c.code = b.code AND c.modifier = b.modifier AND c.cyp_factor > 0 " .
291 "JOIN form_encounter AS fe ON fe.pid = b.pid AND fe.encounter = b.encounter " .
292 "WHERE b.code_type = 'MA' AND b.activity = 1 AND " .
293 "fe.date >= '$from_date 00:00:00' AND fe.date <= '$to_date 23:59:59'";
294 // If a facility was specified.
295 if ($form_facility) {
296 $query .= " AND fe.facility_id = '$form_facility'";
299 $query .= " ORDER BY b.code, fe.date, fe.id";
301 $res = sqlStatement($query);
302 while ($row = sqlFetchArray($res)) {
303 thisLineItem(
304 $row['pid'],
305 $row['encounter'],
306 $row['code'] . ' ' . $row['code_text'],
307 substr($row['date'], 0, 10),
308 $row['units'],
309 $row['cyp_factor'],
310 $row['invoice_refno']
315 $query = "SELECT s.sale_date, s.quantity, s.pid, s.encounter, " .
316 "d.name, d.cyp_factor, fe.date, fe.facility_id, fe.invoice_refno " .
317 "FROM drug_sales AS s " .
318 "JOIN drugs AS d ON d.drug_id = s.drug_id AND d.cyp_factor > 0 " .
319 "JOIN form_encounter AS fe ON " .
320 "fe.pid = s.pid AND fe.encounter = s.encounter AND " .
321 "fe.date >= '$from_date 00:00:00' AND fe.date <= '$to_date 23:59:59' " .
322 "WHERE s.fee != 0";
323 // If a facility was specified.
324 if ($form_facility) {
325 $query .= " AND fe.facility_id = '$form_facility'";
328 $query .= " ORDER BY d.name, fe.date, fe.id";
330 $res = sqlStatement($query);
331 while ($row = sqlFetchArray($res)) {
332 thisLineItem(
333 $row['pid'],
334 $row['encounter'],
335 $row['name'],
336 substr($row['date'], 0, 10),
337 $row['quantity'],
338 $row['cyp_factor'],
339 $row['invoice_refno']
343 if ($_POST['form_csvexport']) {
344 if (! $_POST['form_details']) {
345 echo '"' . display_desc($product) . '",';
346 echo '"' . $productqty . '",';
347 echo '"' . formatcyp($productcyp) . '",';
348 echo '"' . formatcyp($producttotal) . '"' . "\n";
350 } else {
353 <tr bgcolor="#ddddff">
354 <td class="detail" colspan="<?php echo $_POST['form_details'] ? 3 : 1; ?>">
355 <?php
356 if ($_POST['form_details']) {
357 echo xl('Total for ');
359 echo display_desc($product) ?>
360 </td>
361 <td class="dehead" align="right">
362 <?php echo $productqty; ?>
363 </td>
364 <td class="dehead" align="right">
365 <?php echo formatcyp($productcyp); ?>
366 </td>
367 <td class="dehead" align="right">
368 <?php echo formatcyp($producttotal); ?>
369 </td>
370 </tr>
372 <tr bgcolor="#ffdddd">
373 <td class="detail" colspan="<?php echo $_POST['form_details'] ? 3 : 1; ?>">
374 <?php xl('Grand Total', 'e'); ?>
375 </td>
376 <td class="dehead" align="right">
377 <?php echo $grandqty; ?>
378 </td>
379 <td class="dehead" align="right">
380 &nbsp;
381 </td>
382 <td class="dehead" align="right">
383 <?php echo formatcyp($grandtotal); ?>
384 </td>
385 </tr>
387 <?php
388 } // End not csv export
389 } // end report generation
391 if (! $_POST['form_csvexport']) {
394 </table>
395 </form>
396 </center>
397 </body>
398 </html>
399 <?php
400 } // End not csv export