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