internationalization bug fix - translate submit button
[openemr.git] / interface / reports / ippf_cyp_report.php
blobba1a6bbbfb785549e20b3ddc16218e44cfd30545
1 <?php
2 // Copyright (C) 2009 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("../../library/patient.inc");
11 require_once("../../library/acl.inc");
13 function formatcyp($amount) {
14 if ($amount) return sprintf("%.2f", $amount);
15 return '';
18 function display_desc($desc) {
19 if (preg_match('/^\S*?:(.+)$/', $desc, $matches)) {
20 $desc = $matches[1];
22 return $desc;
25 function thisLineItem($patient_id, $encounter_id, $description, $transdate, $qty, $cypfactor) {
26 global $product, $productcyp, $producttotal, $productqty, $grandtotal, $grandqty;
28 $invnumber = "$patient_id.$encounter_id";
29 $rowcyp = sprintf('%01.2f', $cypfactor);
30 $rowresult = sprintf('%01.2f', $rowcyp * $qty);
32 $rowproduct = $description;
33 if (! $rowproduct) $rowproduct = 'Unknown';
35 if ($product != $rowproduct) {
36 if ($product) {
37 // Print product total.
38 if ($_POST['form_csvexport']) {
39 if (! $_POST['form_details']) {
40 echo '"' . display_desc($product) . '",';
41 echo '"' . $productqty . '",';
42 echo '"' . formatcyp($productcyp) . '",';
43 echo '"' . formatcyp($producttotal) . '"' . "\n";
46 else {
49 <tr bgcolor="#ddddff">
50 <td class="detail" colspan="<?php echo $_POST['form_details'] ? 3 : 1; ?>">
51 <?php if ($_POST['form_details']) echo xl('Total for '); echo display_desc($product) ?>
52 </td>
53 <td class="dehead" align="right">
54 <?php echo $productqty; ?>
55 </td>
56 <td class="dehead" align="right">
57 <?php echo formatcyp($productcyp); ?>
58 </td>
59 <td class="dehead" align="right">
60 <?php echo formatcyp($producttotal); ?>
61 </td>
62 </tr>
63 <?php
64 } // End not csv export
66 $producttotal = 0;
67 $productqty = 0;
68 $product = $rowproduct;
69 $productleft = $product;
70 $productcyp = $rowcyp;
73 if ($_POST['form_details']) {
74 if ($_POST['form_csvexport']) {
75 echo '"' . display_desc($product ) . '",';
76 echo '"' . display_desc($transdate) . '",';
77 echo '"' . display_desc($invnumber) . '",';
78 echo '"' . display_desc($qty ) . '",';
79 echo '"' . formatcyp($rowcyp) . '",';
80 echo '"' . formatcyp($rowresult) . '"' . "\n";
82 else {
85 <tr>
86 <td class="detail">
87 <?php echo display_desc($productleft); $productleft = "&nbsp;"; ?>
88 </td>
89 <td class="dehead">
90 <?php echo $transdate; ?>
91 </td>
92 <td class="detail">
93 <?php echo $invnumber; ?>
94 </td>
95 <td class="dehead" align="right">
96 <?php echo $qty; ?>
97 </td>
98 <td class="dehead" align="right">
99 <?php echo formatcyp($rowcyp); ?>
100 </td>
101 <td class="dehead" align="right">
102 <?php echo formatcyp($rowresult); ?>
103 </td>
104 </tr>
106 } // End not csv export
107 } // end details
108 $producttotal += $rowresult;
109 $grandtotal += $rowresult;
110 $productqty += $qty;
111 $grandqty += $qty;
112 } // end function
114 if (! acl_check('acct', 'rep')) die(xl("Unauthorized access."));
116 $form_from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
117 $form_to_date = fixDate($_POST['form_to_date'] , date('Y-m-d'));
118 $form_facility = $_POST['form_facility'];
120 if ($_POST['form_csvexport']) {
121 header("Pragma: public");
122 header("Expires: 0");
123 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
124 header("Content-Type: application/force-download");
125 header("Content-Disposition: attachment; filename=ippf_cyp_report.csv");
126 header("Content-Description: File Transfer");
127 // CSV headers:
128 if ($_POST['form_details']) {
129 echo '"Item",';
130 echo '"Date",';
131 echo '"Invoice",';
132 echo '"Qty",';
133 echo '"CYP",';
134 echo '"Result"' . "\n";
136 else {
137 echo '"Item",';
138 echo '"Qty",';
139 echo '"CYP",';
140 echo '"Result"' . "\n";
143 else { // not export
145 <html>
146 <head>
147 <?php html_header_show();?>
148 <title><?php xl('CYP Report','e') ?></title>
149 </head>
151 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
152 <center>
154 <h2><?php xl('CYP Report','e')?></h2>
156 <form method='post' action='ippf_cyp_report.php'>
158 <table border='0' cellpadding='3'>
160 <tr>
161 <td>
162 <?php
163 // Build a drop-down list of facilities.
165 $query = "SELECT id, name FROM facility ORDER BY name";
166 $fres = sqlStatement($query);
167 echo " <select name='form_facility'>\n";
168 echo " <option value=''>-- All Facilities --\n";
169 while ($frow = sqlFetchArray($fres)) {
170 $facid = $frow['id'];
171 echo " <option value='$facid'";
172 if ($facid == $form_facility) echo " selected";
173 echo ">" . $frow['name'] . "\n";
175 echo " </select>\n";
177 &nbsp;<?xl('From:','e')?>
178 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
179 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
180 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
181 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
182 title='<?php xl('Click here to choose a date','e'); ?>'>
183 &nbsp;To:
184 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
185 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
186 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
187 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
188 title='<?php xl('Click here to choose a date','e'); ?>'>
189 &nbsp;
190 <input type='checkbox' name='form_details' value='1'<?php if ($_POST['form_details']) echo " checked"; ?>><?php xl('Details','e') ?>
191 &nbsp;
192 <input type='submit' name='form_refresh' value="<?php xl('Refresh','e') ?>">
193 &nbsp;
194 <input type='submit' name='form_csvexport' value="<?php xl('Export to CSV','e') ?>">
195 &nbsp;
196 <input type='button' value='<?php xl('Print','e'); ?>' onclick='window.print()' />
197 </td>
198 </tr>
200 <tr>
201 <td height="1">
202 </td>
203 </tr>
205 </table>
207 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
209 <tr bgcolor="#dddddd">
210 <td class="dehead">
211 <?xl('Item','e')?>
212 </td>
213 <?php if ($_POST['form_details']) { ?>
214 <td class="dehead">
215 <?xl('Date','e')?>
216 </td>
217 <td class="dehead">
218 <?xl('Invoice','e')?>
219 </td>
220 <?php } ?>
221 <td class="dehead" align="right">
222 <?xl('Qty','e')?>
223 </td>
224 <td class="dehead" align="right">
225 <?xl('CYP','e')?>
226 </td>
227 <td class="dehead" align="right">
228 <?xl('Result','e')?>
229 </td>
230 </tr>
231 <?php
232 } // end not export
234 // If generating a report.
236 if ($_POST['form_refresh'] || $_POST['form_csvexport']) {
237 $from_date = $form_from_date;
238 $to_date = $form_to_date;
240 $product = "";
241 $productleft = "";
242 $productcyp = 0;
243 $producttotal = 0; // total of results for product
244 $grandtotal = 0; // grand total of results
245 $productqty = 0;
246 $grandqty = 0;
248 $query = "SELECT b.pid, b.encounter, b.code_type, b.code, b.units, " .
249 "b.code_text, c.cyp_factor, fe.date, fe.facility_id " .
250 "FROM billing AS b " .
251 "JOIN codes AS c ON c.code_type = '12' AND c.code = b.code AND c.modifier = b.modifier AND c.cyp_factor > 0 " .
252 "JOIN form_encounter AS fe ON fe.pid = b.pid AND fe.encounter = b.encounter " .
253 "WHERE b.code_type = 'MA' AND b.activity = 1 AND " .
254 "fe.date >= '$from_date 00:00:00' AND fe.date <= '$to_date 23:59:59'";
255 // If a facility was specified.
256 if ($form_facility) {
257 $query .= " AND fe.facility_id = '$form_facility'";
259 $query .= " ORDER BY b.code, fe.date, fe.id";
261 $res = sqlStatement($query);
262 while ($row = sqlFetchArray($res)) {
263 thisLineItem($row['pid'], $row['encounter'],
264 $row['code'] . ' ' . $row['code_text'],
265 substr($row['date'], 0, 10), $row['units'], $row['cyp_factor']);
268 $query = "SELECT s.sale_date, s.quantity, s.pid, s.encounter, " .
269 "d.name, d.cyp_factor, fe.date, fe.facility_id " .
270 "FROM drug_sales AS s " .
271 "JOIN drugs AS d ON d.drug_id = s.drug_id AND d.cyp_factor > 0 " .
272 "JOIN form_encounter AS fe ON " .
273 "fe.pid = s.pid AND fe.encounter = s.encounter AND " .
274 "fe.date >= '$from_date 00:00:00' AND fe.date <= '$to_date 23:59:59' " .
275 "WHERE s.fee != 0";
276 // If a facility was specified.
277 if ($form_facility) {
278 $query .= " AND fe.facility_id = '$form_facility'";
280 $query .= " ORDER BY d.name, fe.date, fe.id";
282 $res = sqlStatement($query);
283 while ($row = sqlFetchArray($res)) {
284 thisLineItem($row['pid'], $row['encounter'], $row['name'],
285 substr($row['date'], 0, 10), $row['quantity'], $row['cyp_factor']);
288 if ($_POST['form_csvexport']) {
289 if (! $_POST['form_details']) {
290 echo '"' . display_desc($product) . '",';
291 echo '"' . $productqty . '",';
292 echo '"' . formatcyp($productcyp) . '",';
293 echo '"' . formatcyp($producttotal) . '"' . "\n";
296 else {
299 <tr bgcolor="#ddddff">
300 <td class="detail" colspan="<?php echo $_POST['form_details'] ? 3 : 1; ?>">
301 <?php if ($_POST['form_details']) echo xl('Total for '); echo display_desc($product) ?>
302 </td>
303 <td class="dehead" align="right">
304 <?php echo $productqty; ?>
305 </td>
306 <td class="dehead" align="right">
307 <?php echo formatcyp($productcyp); ?>
308 </td>
309 <td class="dehead" align="right">
310 <?php echo formatcyp($producttotal); ?>
311 </td>
312 </tr>
314 <tr bgcolor="#ffdddd">
315 <td class="detail" colspan="<?php echo $_POST['form_details'] ? 3 : 1; ?>">
316 <?php xl('Grand Total','e'); ?>
317 </td>
318 <td class="dehead" align="right">
319 <?php echo $grandqty; ?>
320 </td>
321 <td class="dehead" align="right">
322 &nbsp;
323 </td>
324 <td class="dehead" align="right">
325 <?php echo formatcyp($grandtotal); ?>
326 </td>
327 </tr>
330 } // End not csv export
331 } // end report generation
333 if (! $_POST['form_csvexport']) {
336 </table>
337 </form>
338 </center>
339 </body>
341 <!-- stuff for the popup calendar -->
342 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
343 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
344 <script type="text/javascript" src="../../library/dynarch_calendar_en.js"></script>
345 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
346 <script language="Javascript">
347 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
348 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
349 </script>
351 </html>
352 <?php
353 } // End not csv export