Added ability to click a column heading to sort on that column.
[openemr.git] / interface / drugs / drug_inventory.php
blob553218c609ed66ba8bd2aedfcee799ad95bf295f
1 <?php
2 // Copyright (C) 2006-2010 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("$srcdir/acl.inc");
11 require_once("drugs.inc.php");
12 require_once("$srcdir/options.inc.php");
13 require_once("$srcdir/formatting.inc.php");
15 // Check authorization.
16 $thisauth = acl_check('admin', 'drugs');
17 if (!$thisauth) die(xl('Not authorized'));
19 // For each sorting option, specify the ORDER BY argument.
21 $ORDERHASH = array(
22 'prod' => 'd.name, d.drug_id, di.expiration, di.lot_number',
23 'ndc' => 'd.ndc_number, d.name, d.drug_id, di.expiration, di.lot_number',
24 'form' => 'lof.title, d.name, d.drug_id, di.expiration, di.lot_number',
25 'lot' => 'di.lot_number, d.name, d.drug_id, di.expiration',
26 'wh' => 'lo.title, d.name, d.drug_id, di.expiration, di.lot_number',
27 'qoh' => 'di.on_hand, d.name, d.drug_id, di.expiration, di.lot_number',
28 'exp' => 'di.expiration, d.name, d.drug_id, di.lot_number',
31 // Get the order hash array value and key for this request.
32 $form_orderby = $ORDERHASH[$_REQUEST['form_orderby']] ? $_REQUEST['form_orderby'] : 'prod';
33 $orderby = $ORDERHASH[$form_orderby];
35 // get drugs
36 $res = sqlStatement("SELECT d.*, " .
37 "di.inventory_id, di.lot_number, di.expiration, di.manufacturer, " .
38 "di.on_hand, lo.title " .
39 "FROM drugs AS d " .
40 "LEFT JOIN drug_inventory AS di ON di.drug_id = d.drug_id " .
41 "AND di.destroy_date IS NULL " .
42 "LEFT JOIN list_options AS lo ON lo.list_id = 'warehouse' AND " .
43 "lo.option_id = di.warehouse_id " .
44 "LEFT JOIN list_options AS lof ON lof.list_id = 'drug_form' AND " .
45 "lof.option_id = d.form " .
46 "ORDER BY $orderby");
48 <html>
50 <head>
51 <?php html_header_show();?>
53 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
54 <title><?php xl('Drug Inventory','e'); ?></title>
56 <style>
57 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
58 tr.detail { font-size:10pt; }
59 a, a:visited, a:hover { color:#0000cc; }
60 </style>
62 <script type="text/javascript" src="../../library/dialog.js"></script>
64 <script language="JavaScript">
66 // callback from add_edit_drug.php or add_edit_drug_inventory.php:
67 function refreshme() {
68 location.reload();
71 // Process click on drug title.
72 function dodclick(id) {
73 dlgopen('add_edit_drug.php?drug=' + id, '_blank', 725, 475);
76 // Process click on drug QOO or lot.
77 function doiclick(id, lot) {
78 dlgopen('add_edit_lot.php?drug=' + id + '&lot=' + lot, '_blank', 600, 475);
81 // Process click on a column header for sorting.
82 function dosort(orderby) {
83 var f = document.forms[0];
84 f.form_orderby.value = orderby;
85 top.restoreSession();
86 f.submit();
87 return false;
90 </script>
92 </head>
94 <body class="body_top">
95 <form method='post' action='drug_inventory.php'>
97 <table width='100%' cellpadding='1' cellspacing='2'>
98 <tr class='head'>
99 <td title='<?php echo htmlspecialchars(xl('Click to edit'), ENT_QUOTES); ?>'>
100 <a href="#" onclick="return dosort('prod')"
101 <?php if ($form_orderby == "prod") echo " style=\"color:#00cc00\""; ?>>
102 <?php echo htmlspecialchars(xl('Name')); ?> </a>
103 </td>
104 <td>
105 <?php echo htmlspecialchars(xl('Act')); ?>
106 </td>
107 <td>
108 <a href="#" onclick="return dosort('ndc')"
109 <?php if ($form_orderby == "ndc") echo " style=\"color:#00cc00\""; ?>>
110 <?php echo htmlspecialchars(xl('NDC')); ?> </a>
111 </td>
112 <td>
113 <a href="#" onclick="return dosort('form')"
114 <?php if ($form_orderby == "form") echo " style=\"color:#00cc00\""; ?>>
115 <?php echo htmlspecialchars(xl('Form')); ?> </a>
116 </td>
117 <td>
118 <?php echo htmlspecialchars(xl('Size')); ?>
119 </td>
120 <td>
121 <?php echo htmlspecialchars(xl('Unit')); ?>
122 </td>
123 <td title='<?php echo htmlspecialchars(xl('Click to receive (add) new lot'), ENT_QUOTES); ?>'>
124 <?php echo htmlspecialchars(xl('New')); ?>
125 </td>
126 <td title='<?php echo htmlspecialchars(xl('Click to edit'), ENT_QUOTES); ?>'>
127 <a href="#" onclick="return dosort('lot')"
128 <?php if ($form_orderby == "lot") echo " style=\"color:#00cc00\""; ?>>
129 <?php echo htmlspecialchars(xl('Lot')); ?> </a>
130 </td>
131 <td>
132 <a href="#" onclick="return dosort('wh')"
133 <?php if ($form_orderby == "wh") echo " style=\"color:#00cc00\""; ?>>
134 <?php echo htmlspecialchars(xl('Warehouse')); ?> </a>
135 </td>
136 <td>
137 <a href="#" onclick="return dosort('qoh')"
138 <?php if ($form_orderby == "qoh") echo " style=\"color:#00cc00\""; ?>>
139 <?php echo htmlspecialchars(xl('QOH')); ?> </a>
140 </td>
141 <td>
142 <a href="#" onclick="return dosort('exp')"
143 <?php if ($form_orderby == "exp") echo " style=\"color:#00cc00\""; ?>>
144 <?php echo htmlspecialchars(xl('Expires')); ?> </a>
145 </td>
146 </tr>
147 <?php
148 $lastid = "";
149 $encount = 0;
150 while ($row = sqlFetchArray($res)) {
151 if ($lastid != $row['drug_id']) {
152 ++$encount;
153 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
154 $lastid = $row['drug_id'];
155 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
156 echo " <td onclick='dodclick($lastid)'>" .
157 "<a href='' onclick='return false'>" .
158 htmlentities($row['name']) . "</a></td>\n";
159 echo " <td>" . ($row['active'] ? xl('Yes') : xl('No')) . "</td>\n";
160 echo " <td>" . htmlentities($row['ndc_number']) . "</td>\n";
161 echo " <td>" .
162 generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'), $row['form']) .
163 "</td>\n";
164 echo " <td>" . $row['size'] . "</td>\n";
165 echo " <td>" .
166 generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'), $row['unit']) .
167 "</td>\n";
168 echo " <td onclick='doiclick($lastid,0)' title='" . xl('Add new lot and transaction') . "'>" .
169 "<a href='' onclick='return false'>" . xl('New') . "</a></td>\n";
170 } else {
171 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
172 echo " <td colspan='7'>&nbsp;</td>\n";
174 if (!empty($row['inventory_id'])) {
175 $lot_number = htmlentities($row['lot_number']);
176 echo " <td onclick='doiclick($lastid," . $row['inventory_id'] . ")'>" .
177 "<a href='' onclick='return false'>$lot_number</a></td>\n";
178 echo " <td>" . $row['title'] . "</td>\n";
179 echo " <td>" . $row['on_hand'] . "</td>\n";
180 echo " <td>" . oeFormatShortDate($row['expiration']) . "</td>\n";
181 } else {
182 echo " <td colspan='4'>&nbsp;</td>\n";
184 echo " </tr>\n";
185 } // end while
187 </table>
189 <center><p>
190 <input type='button' value='<?php echo htmlspecialchars(xl('Add Drug')); ?>' onclick='dodclick(0)' style='background-color:transparent' />
191 </p></center>
193 <input type="hidden" name="form_orderby" value="<?php echo $form_orderby ?>" />
195 </form>
196 </body>
197 </html>