fix: set default x12 partner for item in billing manager (#7502)
[openemr.git] / interface / reports / destroyed_drugs_report.php
blob846fb26eb3f148b8bfd3eb8b3b9d6f696f3c9157
1 <?php
3 /**
4 * This report lists destroyed drug lots within a specified date range.
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2006-2016 Rod Roark <rod@sunsetsystems.com>
11 * @copyright Copyright (c) 2017-2019 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("$srcdir/patient.inc.php");
17 require_once("../drugs/drugs.inc.php");
19 use OpenEMR\Common\Csrf\CsrfUtils;
20 use OpenEMR\Core\Header;
22 if (!empty($_POST)) {
23 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
24 CsrfUtils::csrfNotVerified();
28 $form_from_date = isset($_POST['form_from_date']) ? DateToYYYYMMDD($_POST['form_from_date']) : date('Y-01-01'); // From date filter
29 $form_to_date = isset($_POST['form_to_date']) ? DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d'); // To date filter
31 function processData($data)
33 $data['inventory_id'] = [$data['inventory_id']];
34 $data['lot_number'] = [$data['lot_number']];
35 $data['on_hand'] = [$data['on_hand']];
36 $data['destroy_date'] = [$data['destroy_date']];
37 $data['destroy_method'] = [$data['destroy_method']];
38 $data['destroy_witness'] = [$data['destroy_witness']];
39 $data['destroy_notes'] = [$data['destroy_notes']];
40 return $data;
42 function mergeData($d1, $d2)
44 $d1['inventory_id'] = array_merge($d1['inventory_id'], $d2['inventory_id']);
45 $d1['lot_number'] = array_merge($d1['lot_number'], $d2['lot_number']);
46 $d1['on_hand'] = array_merge($d1['on_hand'], $d2['on_hand']);
47 $d1['destroy_date'] = array_merge($d1['destroy_date'], $d2['destroy_date']);
48 $d1['destroy_method'] = array_merge($d1['destroy_method'], $d2['destroy_method']);
49 $d1['destroy_witness'] = array_merge($d1['destroy_witness'], $d2['destroy_witness']);
50 $d1['destroy_notes'] = array_merge($d1['destroy_notes'], $d2['destroy_notes']);
51 return $d1;
53 function mapToTable($row)
55 if ($row) {
56 echo "<tr>\n";
57 echo "<td> " . text($row["name"]) . " </td>\n";
58 echo "<td>" . text($row["ndc_number"]) . " </td>\n";
59 echo "<td>";
60 foreach ($row['inventory_id'] as $key => $value) {
61 echo "<div onclick='doclick(" . attr(addslashes($row['drug_id'])) . "," . attr(addslashes($row['inventory_id'][$key])) . ")'>" .
62 "<a href='' onclick='return false'>" . text($row['lot_number'][$key]) . "</a></div>";
64 echo "</td>\n<td>";
66 foreach ($row['on_hand'] as $value) {
67 $value = $value != null ? $value : "N/A";
68 echo "<div >" . text($value) . "</div>";
70 echo "</td>\n<td>";
72 foreach ($row['destroy_date'] as $value) {
73 $value = $value != null ? $value : "N/A";
74 echo "<div >" . text(oeFormatShortDate($value)) . "</div>";
76 echo "</td>\n<td>";
78 foreach ($row['destroy_method'] as $value) {
79 $value = $value != null ? $value : "N/A";
80 echo "<div >" . text($value) . "</div>";
82 echo "</td>\n<td>";
84 foreach ($row['destroy_witness'] as $value) {
85 $value = $value != null ? $value : "N/A";
86 echo "<div >" . text($value) . "</div>";
88 echo "</td>\n<td>";
90 foreach ($row['destroy_notes'] as $value) {
91 $value = $value != null ? $value : "N/A";
92 echo "<div >" . text($value) . "</div>";
94 echo "</td>\n</tr>\n";
98 <html>
99 <head>
100 <title><?php echo xlt('Destroyed Drugs'); ?></title>
102 <?php Header::setupHeader(['datetime-picker','datatables', 'datatables-dt', 'datatables-bs', 'report-helper']); ?>
104 <style>
105 /* TODO: Is the below code for links necessary? */
106 a, a:visited, a:hover {
107 color: var(--primary);
109 #mymaintable thead .sorting::before,
110 #mymaintable thead .sorting_asc::before,
111 #mymaintable thead .sorting_asc::after,
112 #mymaintable thead .sorting_desc::before,
113 #mymaintable thead .sorting_desc::after,
114 #mymaintable thead .sorting::after {
115 display: none;
118 .dataTables_wrapper .dataTables_paginate .paginate_button {
119 padding: 0 !important;
120 margin: 0 !important;
121 border: 0 !important;
124 .paginate_button:hover{
125 background: transparent !important;
127 </style>
129 <script>
131 // Process click on destroyed drug.
132 function doclick(id, lot) {
133 dlgopen('../drugs/destroy_lot.php?drug=' + encodeURIComponent(id) + '&lot=' + encodeURIComponent(lot), '_blank', 600, 475);
136 $(function () {
137 var win = top.printLogSetup ? top : opener.top;
138 win.printLogSetup(document.getElementById('printbutton'));
140 $('#mymaintable').DataTable({
141 stripeClasses:['stripe1','stripe2'],
142 orderClasses: false,
143 <?php // Bring in the translations ?>
144 <?php require($GLOBALS['srcdir'] . '/js/xl/datatables-net.js.php'); ?>
147 $('.datepicker').datetimepicker({
148 <?php $datetimepicker_timepicker = false; ?>
149 <?php $datetimepicker_showseconds = false; ?>
150 <?php $datetimepicker_formatInput = true; ?>
151 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
152 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
156 </script>
157 </head>
159 <body class="container-fluid text-center">
162 <h2><?php echo xlt('Destroyed Drugs'); ?></h2>
164 <form name='theform' method='post' action='destroyed_drugs_report.php' onsubmit='return top.restoreSession()'>
165 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
167 <div class="col-sm-12">
168 <span class="font-weight-bold"><?php echo xlt('From'); ?>:</span>
169 <input type='text' style="width: 200px" class='datepicker form-control d-inline' name='form_from_date' id='form_from_date'
170 size='10' value='<?php echo attr(oeFormatShortDate($form_from_date)); ?>'>
171 <span class="font-weight-bold"><?php echo xlt('To{{Range}}'); ?>:</span>
172 <input type='text' style="width: 200px" class='datepicker form-control d-inline' name='form_to_date' id='form_to_date'
173 size='10' value='<?php echo attr(oeFormatShortDate($form_to_date)); ?>'>
174 <input class="btn btn-primary" type='submit' name='form_refresh' value='<?php echo xla('Refresh'); ?>' />
175 <input class="btn btn-secondary" type='button' value='<?php echo xla('Print'); ?>' id='printbutton' />
176 </div>
178 <!-- TODO: Why didn't we use the BS4 table class here? !-->
179 <table id='mymaintable' class="display table-striped">
180 <thead>
181 <tr>
182 <th><?php echo xlt('Drug Name'); ?></th>
183 <th><?php echo xlt('NDC'); ?></th>
184 <th><?php echo xlt('Lot'); ?></th>
185 <th><?php echo xlt('Qty'); ?></th>
186 <th><?php echo xlt('Date Destroyed'); ?></th>
187 <th><?php echo xlt('Method'); ?></th>
188 <th><?php echo xlt('Witness'); ?></th>
189 <th><?php echo xlt('Notes'); ?></th>
190 </tr>
191 </thead>
192 <tbody>
193 <?php
194 if ($_POST['form_refresh']) {
195 $where = "i.destroy_date >= ? AND " .
196 "i.destroy_date <= ?";
198 $query = "SELECT i.inventory_id, i.lot_number, i.on_hand, i.drug_id, " .
199 "i.destroy_date, i.destroy_method, i.destroy_witness, i.destroy_notes, " .
200 "d.name, d.ndc_number " .
201 "FROM drug_inventory AS i " .
202 "LEFT OUTER JOIN drugs AS d ON d.drug_id = i.drug_id " .
203 "WHERE $where " .
204 "ORDER BY d.name, i.drug_id, i.destroy_date, i.lot_number";
206 $res = sqlStatement($query, array($form_from_date, $form_to_date));
207 $prevRow = '';
208 while ($row = sqlFetchArray($res)) {
209 $row = processData($row);
210 if ($prevRow == '') {
211 $prevRow = $row;
212 continue;
214 if ($prevRow['drug_id'] == $row['drug_id']) {
215 $row = mergeData($prevRow, $row);
216 } else {
217 mapToTable($prevRow);
219 $prevRow = $row;
221 mapToTable($prevRow);
225 </tbody>
226 </table>
227 </form>
229 </body>
230 </html>