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.
11 require_once("../globals.php");
12 require_once("$srcdir/acl.inc");
13 require_once("$srcdir/options.inc.php");
14 require_once("$include_root/drugs/drugs.inc.php");
16 // Check authorization.
17 $thisauth = acl_check('admin', 'drugs');
19 die(xl('Not authorized'));
22 function addWarning($msg)
26 $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;
38 $form_days = sprintf('%d', (strtotime(date('Y-m-d')) - strtotime(date('Y-01-01'))) / (60 * 60 * 24) +
1);
42 $res = sqlStatement("SELECT d.*, SUM(di.on_hand) AS on_hand " .
44 "LEFT JOIN drug_inventory AS di ON di.drug_id = d.drug_id " .
45 "AND di.on_hand != 0 AND di.destroy_date IS NULL " .
46 "WHERE d.active = 1 " .
47 "GROUP BY d.name, d.drug_id ORDER BY d.name, d.drug_id");
52 <?php
html_header_show(); ?
>
54 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
55 <title
><?php
xl('Inventory List', 'e'); ?
></title
>
58 /* specifically include & exclude from printing */
60 #report_parameters {visibility: hidden; display: none;}
61 #report_parameters_daterange {visibility: visible; display: inline;}
62 #report_results {margin-top: 30px;}
64 /* specifically exclude some from the screen */
66 #report_parameters_daterange {visibility: hidden; display: none;}
69 body
{ font
-family
:sans
-serif
; font
-size
:10pt
; font
-weight
:normal
}
71 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
72 tr
.detail
{ font
-size
:10pt
; }
73 a
, a
:visited
, a
:hover
{ color
:#0000cc; }
75 table
.mymaintable
, table
.mymaintable td
, table
.mymaintable th
{
76 border
: 1px solid
#aaaaaa;
77 border
-collapse
: collapse
;
79 table
.mymaintable td
, table
.mymaintable th
{
80 padding
: 1pt
4pt
1pt
4pt
;
84 <script type
="text/javascript" src
="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
85 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-9-1/index.js"></script
>
86 <script type
="text/javascript" src
="../../library/js/report_helper.js?v=<?php echo $v_js_includes; ?>"></script
>
88 <script language
="JavaScript">
90 $
(document
).ready(function() {
91 oeFixedHeaderSetup(document
.getElementById('mymaintable'));
92 var win
= top
.printLogSetup ? top
: opener
.top
;
93 win
.printLogSetup(document
.getElementById('printbutton'));
96 function mysubmit(action
) {
97 var f
= document
.forms
[0];
98 f
.form_action
.value
= action
;
107 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0' class='body_top'>
111 <h2
><?php
echo htmlspecialchars(xl('Inventory List'))?
></h2
>
113 <form method
='post' action
='inventory_list.php' name
='theform'>
115 <div id
="report_parameters">
116 <!-- form_action is set to
"submit" at form submit time
-->
117 <input type
='hidden' name
='form_action' value
='' />
124 <?php
echo htmlspecialchars(xl('For the past')); ?
>
125 <input type
="input" name
="form_days" size
='3' value
="<?php echo $form_days; ?>" />
126 <?php
echo htmlspecialchars(xl('days')); ?
>
131 <td align
='left' valign
='middle'>
132 <table style
='border-left:1px solid; width:100%; height:100%'>
135 <a href
='#' class='css_button' onclick
='mysubmit("submit")' style
='margin-left:1em'>
136 <span
><?php
echo htmlspecialchars(xl('Submit'), ENT_NOQUOTES
); ?
></span
>
138 <?php
if ($form_action) { ?
>
139 <a href
='#' class='css_button' id
='printbutton' style
='margin-left:1em'>
140 <span
><?php
echo htmlspecialchars(xl('Print'), ENT_NOQUOTES
); ?
></span
>
151 <?php
if ($form_action) { // if submit ?>
153 <div id
="report_results">
154 <table width
='98%' id
='mymaintable' class='mymaintable'>
155 <thead style
='display:table-header-group'>
157 <th
><?php
xl('Name', 'e'); ?
></th
>
158 <th
><?php
xl('NDC', 'e'); ?
></th
>
159 <th
><?php
xl('Form', 'e'); ?
></th
>
160 <th align
='right'><?php
echo htmlspecialchars(xl('QOH')); ?
></th
>
161 <th align
='right'><?php
echo htmlspecialchars(xl('Reorder')); ?
></th
>
162 <th align
='right'><?php
echo htmlspecialchars(xl('Avg Monthly')); ?
></th
>
163 <th align
='right'><?php
echo htmlspecialchars(xl('Stock Months')); ?
></th
>
164 <th
><?php
echo htmlspecialchars(xl('Warnings')); ?
></th
>
170 while ($row = sqlFetchArray($res)) {
171 $on_hand = 0 +
$row['on_hand'];
172 $drug_id = 0 +
$row['drug_id'];
175 $srow = sqlQuery("SELECT " .
176 "SUM(quantity) AS sale_quantity " .
177 "FROM drug_sales WHERE " .
178 "drug_id = '$drug_id' AND " .
179 "sale_date > DATE_SUB(NOW(), INTERVAL $form_days DAY) " .
183 $bgcolor = "#" . (($encount & 1) ?
"ddddff" : "ffdddd");
185 $sale_quantity = $srow['sale_quantity'];
186 $months = $form_days / 30.5;
188 $monthly = ($months && $sale_quantity) ?
189 sprintf('%0.1f', $sale_quantity / $months) : ' ';
191 $stock_months = ' ';
192 if ($sale_quantity != 0) {
193 $stock_months = sprintf('%0.1f', $on_hand * $months / $sale_quantity);
194 if ($stock_months < 1.0) {
195 addWarning(htmlspecialchars(xl('QOH is less than monthly usage')));
199 // Check for reorder point reached.
200 if (!empty($row['reorder_point']) && $on_hand <= $row['reorder_point']) {
201 addWarning(htmlspecialchars(xl('Reorder point has been reached')));
204 // Compute the smallest quantity that might be taken from a lot based on the
205 // past 30 days of sales. If lot combining is allowed this is always 1.
207 if (!$row['allow_combining']) {
208 $sminrow = sqlQuery("SELECT " .
209 "MIN(quantity) AS min_sale " .
210 "FROM drug_sales WHERE " .
211 "drug_id = '$drug_id' AND " .
212 "sale_date > DATE_SUB(NOW(), INTERVAL $form_days DAY) " .
215 $min_sale = 0 +
$sminrow['min_sale'];
218 // Get all lots that we want to issue warnings about. These are lots
219 // expired, soon to expire, or with insufficient quantity for selling.
220 $ires = sqlStatement("SELECT * " .
221 "FROM drug_inventory WHERE " .
222 "drug_id = '$drug_id' AND " .
224 "destroy_date IS NULL AND ( " .
225 "on_hand < '$min_sale' OR " .
226 "expiration IS NOT NULL AND expiration < DATE_ADD(NOW(), INTERVAL 30 DAY) " .
227 ") ORDER BY lot_number");
229 // Generate warnings associated with individual lots.
230 while ($irow = sqlFetchArray($ires)) {
231 $lotno = $irow['lot_number'];
232 if ($irow['on_hand'] < $min_sale) {
233 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')));
240 } else if ($expdays <= 30) {
241 addWarning(htmlspecialchars(xl('Lot') . " '$lotno' " . xl('expires in') . " $expdays " . xl('days')));
246 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
247 echo " <td>" . htmlentities($row['name']) . "</td>\n";
248 echo " <td>" . htmlentities($row['ndc_number']) . "</td>\n";
250 generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'), $row['form']) .
252 echo " <td align='right'>" . $row['on_hand'] . "</td>\n";
253 echo " <td align='right'>" . $row['reorder_point'] . "</td>\n";
254 echo " <td align='right'>$monthly</td>\n";
255 echo " <td align='right'>$stock_months</td>\n";
256 echo " <td style='color:red'>$warnings</td>\n";
263 <?php
} // end if submit ?>