2 // Copyright (C) 2008-2016 Rod Roark <rod@sunsetsystems.com>
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.
10 $sanitize_all_escapes=true;
13 //STOP FAKE REGISTER GLOBALS
14 $fake_register_globals=false;
17 require_once("../globals.php");
18 require_once("$srcdir/acl.inc");
19 require_once("$srcdir/options.inc.php");
20 require_once("$include_root/drugs/drugs.inc.php");
22 // Check authorization.
23 $thisauth = acl_check('admin', 'drugs');
24 if (!$thisauth) die(xl('Not authorized'));
26 function addWarning($msg) {
28 if ($warnings) $warnings .= '<br />';
32 // this is "" or "submit".
33 $form_action = $_POST['form_action'];
35 if (!empty($_POST['form_days'])) {
36 $form_days = $_POST['form_days'] +
0;
39 $form_days = sprintf('%d', (strtotime(date('Y-m-d')) - strtotime(date('Y-01-01'))) / (60 * 60 * 24) +
1);
43 $res = sqlStatement("SELECT d.*, SUM(di.on_hand) AS on_hand " .
45 "LEFT JOIN drug_inventory AS di ON di.drug_id = d.drug_id " .
46 "AND di.on_hand != 0 AND di.destroy_date IS NULL " .
47 "WHERE d.active = 1 " .
48 "GROUP BY d.name, d.drug_id ORDER BY d.name, d.drug_id");
53 <?php
html_header_show(); ?
>
55 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
56 <title
><?php
xl('Inventory List','e'); ?
></title
>
59 /* specifically include & exclude from printing */
61 #report_parameters {visibility: hidden; display: none;}
62 #report_parameters_daterange {visibility: visible; display: inline;}
63 #report_results {margin-top: 30px;}
65 /* specifically exclude some from the screen */
67 #report_parameters_daterange {visibility: hidden; display: none;}
70 body
{ font
-family
:sans
-serif
; font
-size
:10pt
; font
-weight
:normal
}
72 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
73 tr
.detail
{ font
-size
:10pt
; }
74 a
, a
:visited
, a
:hover
{ color
:#0000cc; }
76 table
.mymaintable
, table
.mymaintable td
, table
.mymaintable th
{
77 border
: 1px solid
#aaaaaa;
78 border
-collapse
: collapse
;
80 table
.mymaintable td
, table
.mymaintable th
{
81 padding
: 1pt
4pt
1pt
4pt
;
85 <script type
="text/javascript" src
="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
86 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-9-1/index.js"></script
>
87 <script type
="text/javascript" src
="../../library/js/report_helper.js?v=<?php echo $v_js_includes; ?>"></script
>
89 <script language
="JavaScript">
91 $
(document
).ready(function() {
92 oeFixedHeaderSetup(document
.getElementById('mymaintable'));
93 var win
= top
.printLogSetup ? top
: opener
.top
;
94 win
.printLogSetup(document
.getElementById('printbutton'));
97 function mysubmit(action
) {
98 var f
= document
.forms
[0];
99 f
.form_action
.value
= action
;
100 top
.restoreSession();
108 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0' class='body_top'>
112 <h2
><?php
echo htmlspecialchars(xl('Inventory List'))?
></h2
>
114 <form method
='post' action
='inventory_list.php' name
='theform'>
116 <div id
="report_parameters">
117 <!-- form_action is set to
"submit" at form submit time
-->
118 <input type
='hidden' name
='form_action' value
='' />
125 <?php
echo htmlspecialchars(xl('For the past')); ?
>
126 <input type
="input" name
="form_days" size
='3' value
="<?php echo $form_days; ?>" />
127 <?php
echo htmlspecialchars(xl('days')); ?
>
132 <td align
='left' valign
='middle'>
133 <table style
='border-left:1px solid; width:100%; height:100%'>
136 <a href
='#' class='css_button' onclick
='mysubmit("submit")' style
='margin-left:1em'>
137 <span
><?php
echo htmlspecialchars(xl('Submit'), ENT_NOQUOTES
); ?
></span
>
139 <?php
if ($form_action) { ?
>
140 <a href
='#' class='css_button' id
='printbutton' style
='margin-left:1em'>
141 <span
><?php
echo htmlspecialchars(xl('Print'), ENT_NOQUOTES
); ?
></span
>
152 <?php
if ($form_action) { // if submit ?>
154 <div id
="report_results">
155 <table width
='98%' id
='mymaintable' class='mymaintable'>
156 <thead style
='display:table-header-group'>
158 <th
><?php
xl('Name','e'); ?
></th
>
159 <th
><?php
xl('NDC','e'); ?
></th
>
160 <th
><?php
xl('Form','e'); ?
></th
>
161 <th align
='right'><?php
echo htmlspecialchars(xl('QOH')); ?
></th
>
162 <th align
='right'><?php
echo htmlspecialchars(xl('Reorder')); ?
></th
>
163 <th align
='right'><?php
echo htmlspecialchars(xl('Avg Monthly')); ?
></th
>
164 <th align
='right'><?php
echo htmlspecialchars(xl('Stock Months')); ?
></th
>
165 <th
><?php
echo htmlspecialchars(xl('Warnings')); ?
></th
>
171 while ($row = sqlFetchArray($res)) {
172 $on_hand = 0 +
$row['on_hand'];
173 $drug_id = 0 +
$row['drug_id'];
176 $srow = sqlQuery("SELECT " .
177 "SUM(quantity) AS sale_quantity " .
178 "FROM drug_sales WHERE " .
179 "drug_id = '$drug_id' AND " .
180 "sale_date > DATE_SUB(NOW(), INTERVAL $form_days DAY) " .
184 $bgcolor = "#" . (($encount & 1) ?
"ddddff" : "ffdddd");
186 $sale_quantity = $srow['sale_quantity'];
187 $months = $form_days / 30.5;
189 $monthly = ($months && $sale_quantity) ?
190 sprintf('%0.1f', $sale_quantity / $months) : ' ';
192 $stock_months = ' ';
193 if ($sale_quantity != 0) {
194 $stock_months = sprintf('%0.1f', $on_hand * $months / $sale_quantity);
195 if ($stock_months < 1.0) {
196 addWarning(htmlspecialchars(xl('QOH is less than monthly usage')));
200 // Check for reorder point reached.
201 if (!empty($row['reorder_point']) && $on_hand <= $row['reorder_point']) {
202 addWarning(htmlspecialchars(xl('Reorder point has been reached')));
205 // Compute the smallest quantity that might be taken from a lot based on the
206 // past 30 days of sales. If lot combining is allowed this is always 1.
208 if (!$row['allow_combining']) {
209 $sminrow = sqlQuery("SELECT " .
210 "MIN(quantity) AS min_sale " .
211 "FROM drug_sales WHERE " .
212 "drug_id = '$drug_id' AND " .
213 "sale_date > DATE_SUB(NOW(), INTERVAL $form_days DAY) " .
216 $min_sale = 0 +
$sminrow['min_sale'];
219 // Get all lots that we want to issue warnings about. These are lots
220 // expired, soon to expire, or with insufficient quantity for selling.
221 $ires = sqlStatement("SELECT * " .
222 "FROM drug_inventory WHERE " .
223 "drug_id = '$drug_id' AND " .
225 "destroy_date IS NULL AND ( " .
226 "on_hand < '$min_sale' OR " .
227 "expiration IS NOT NULL AND expiration < DATE_ADD(NOW(), INTERVAL 30 DAY) " .
228 ") ORDER BY lot_number");
230 // Generate warnings associated with individual lots.
231 while ($irow = sqlFetchArray($ires)) {
232 $lotno = $irow['lot_number'];
233 if ($irow['on_hand'] < $min_sale) {
234 addWarning(htmlspecialchars(xl('Lot') . " '$lotno' " . xl('quantity seems unusable')));
236 if (!empty($irow['expiration'])) {
237 $expdays = (int) ((strtotime($irow['expiration']) - time()) / (60 * 60 * 24));
239 addWarning(htmlspecialchars(xl('Lot') . " '$lotno' " . xl('has expired')));
241 else if ($expdays <= 30) {
242 addWarning(htmlspecialchars(xl('Lot') . " '$lotno' " . xl('expires in') . " $expdays " . xl('days')));
247 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
248 echo " <td>" . htmlentities($row['name']) . "</td>\n";
249 echo " <td>" . htmlentities($row['ndc_number']) . "</td>\n";
251 generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'), $row['form']) .
253 echo " <td align='right'>" . $row['on_hand'] . "</td>\n";
254 echo " <td align='right'>" . $row['reorder_point'] . "</td>\n";
255 echo " <td align='right'>$monthly</td>\n";
256 echo " <td align='right'>$stock_months</td>\n";
257 echo " <td style='color:red'>$warnings</td>\n";
264 <?php
} // end if submit ?>