Improvements mostly concerning inventory.
[openemr.git] / interface / drugs / add_edit_drug.php
blobe90a66449a540175c26eef1b9c559ec37a7049c0
1 <?php
3 // Copyright (C) 2006-2021 Rod Roark <rod@sunsetsystems.com>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 require_once("../globals.php");
11 require_once("drugs.inc.php");
12 require_once("$srcdir/options.inc.php");
14 use OpenEMR\Common\Acl\AclMain;
15 use OpenEMR\Common\Csrf\CsrfUtils;
16 use OpenEMR\Core\Header;
18 $alertmsg = '';
19 $drug_id = $_REQUEST['drug'];
20 $info_msg = "";
21 $tmpl_line_no = 0;
23 if (!AclMain::aclCheckCore('admin', 'drugs')) {
24 die(xlt('Not authorized'));
27 // Write a line of data for one template to the form.
29 function writeTemplateLine($selector, $dosage, $period, $quantity, $refills, $prices, $taxrates, $pkgqty)
31 global $tmpl_line_no;
32 ++$tmpl_line_no;
34 echo " <tr>\n";
35 echo " <td class='tmplcell drugsonly'>";
36 echo "<input class='form-control' name='form_tmpl[" . attr($tmpl_line_no) . "][selector]' value='" . attr($selector) . "' size='8' maxlength='100'>";
37 echo "</td>\n";
38 echo " <td class='tmplcell drugsonly'>";
39 echo "<input class='form-control' name='form_tmpl[" . attr($tmpl_line_no) . "][dosage]' value='" . attr($dosage) . "' size='6' maxlength='10'>";
40 echo "</td>\n";
41 echo " <td class='tmplcell drugsonly'>";
42 generate_form_field(array(
43 'data_type' => 1,
44 'field_id' => 'tmpl[' . attr($tmpl_line_no) . '][period]',
45 'list_id' => 'drug_interval',
46 'empty_title' => 'SKIP'
47 ), $period);
48 echo "</td>\n";
49 echo " <td class='tmplcell drugsonly'>";
50 echo "<input class='form-control' name='form_tmpl[" . attr($tmpl_line_no) . "][quantity]' value='" . attr($quantity) . "' size='3' maxlength='7'>";
51 echo "</td>\n";
52 echo " <td class='tmplcell drugsonly'>";
53 echo "<input class='form-control' name='form_tmpl[" . attr($tmpl_line_no) . "][refills]' value='" . attr($refills) . "' size='3' maxlength='5'>";
54 echo "</td>\n";
56 /******************************************************************
57 echo " <td class='tmplcell drugsonly'>";
58 echo "<input type='text' class='form-control' name='form_tmpl[" . attr($tmpl_line_no) .
59 "][pkgqty]' value='" . attr($pkgqty) . "' size='3' maxlength='5'>";
60 echo "</td>\n";
61 ******************************************************************/
63 foreach ($prices as $pricelevel => $price) {
64 echo " <td class='tmplcell'>";
65 echo "<input class='form-control' name='form_tmpl[" . attr($tmpl_line_no) . "][price][" . attr($pricelevel) . "]' value='" . attr($price) . "' size='6' maxlength='12'>";
66 echo "</td>\n";
69 $pres = sqlStatement("SELECT option_id FROM list_options " .
70 "WHERE list_id = 'taxrate' AND activity = 1 ORDER BY seq");
71 while ($prow = sqlFetchArray($pres)) {
72 echo " <td class='tmplcell'>";
73 echo "<input type='checkbox' name='form_tmpl[" . attr($tmpl_line_no) . "][taxrate][" . attr($prow['option_id']) . "]' value='1'";
74 if (strpos(":$taxrates", $prow['option_id']) !== false) {
75 echo " checked";
78 echo " /></td>\n";
81 echo " </tr>\n";
84 <html>
85 <head>
86 <title><?php echo $drug_id ? xlt("Edit") : xlt("Add New");
87 echo ' ' . xlt('Drug'); ?></title>
89 <?php Header::setupHeader(["opener"]); ?>
91 <style>
93 <?php if ($GLOBALS['sell_non_drug_products'] == 2) { // "Products but no prescription drugs and no templates" ?>
94 .drugsonly { display:none; }
95 <?php } else { ?>
96 .drugsonly { }
97 <?php } ?>
99 <?php if (empty($GLOBALS['ippf_specific'])) { ?>
100 .ippfonly { display:none; }
101 <?php } else { ?>
102 .ippfonly { }
103 <?php } ?>
105 </style>
107 <script>
109 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
111 // This is for callback by the find-code popup.
112 // Appends to or erases the current list of related codes.
113 // The target element is set by the find-code popup
114 // (this allows use of this in multiple form elements on the same page)
115 function set_related_target(codetype, code, selector, codedesc, target_element, limit=0) {
116 var f = document.forms[0];
117 var s = f[target_element].value;
118 if (code) {
119 if (limit > 0) {
120 s = codetype + ':' + code;
122 else {
123 if (codetype != 'PROD') {
124 // Return an error message if a service code is already selected.
125 if (s.indexOf(codetype + ':') == 0 || s.indexOf(';' + codetype + ':') > 0) {
126 return <?php echo xlj('A code of this type is already selected. Erase the field first if you need to replace it.') ?>;
129 if (s.length > 0) {
130 s += ';';
132 s += codetype + ':' + code;
134 } else {
135 s = '';
137 f[target_element].value = s;
138 return '';
141 // This is for callback by the find-code popup.
142 // Returns the array of currently selected codes with each element in codetype:code format.
143 function get_related() {
144 return document.forms[0].form_related_code.value.split(';');
147 // This is for callback by the find-code popup.
148 // Deletes the specified codetype:code from the currently selected list.
149 function del_related(s) {
150 my_del_related(s, document.forms[0].form_related_code, false);
153 // This invokes the find-code popup.
154 function sel_related(getter = '') {
155 dlgopen('../patient_file/encounter/find_code_dynamic.php' + getter, '_blank', 900, 800);
158 // onclick handler for "allow inventory" checkbox.
159 function dispensable_changed() {
160 var f = document.forms[0];
161 var dis = !f.form_dispensable.checked;
162 f.form_allow_multiple.disabled = dis;
163 f.form_allow_combining.disabled = dis;
164 return true;
167 function validate(f) {
168 var saving = f.form_save.clicked ? true : false;
169 f.form_save.clicked = false;
170 if (saving) {
171 if (f.form_name.value.search(/[^\s]/) < 0) {
172 alert(<?php echo xlj('Product name is required'); ?>);
173 return false;
176 var deleting = f.form_delete.clicked ? true : false;
177 f.form_delete.clicked = false;
178 if (deleting) {
179 if (!confirm(<?php echo xlj('This will permanently delete all lots of this product. Related reports will be incomplete or incorrect. Are you sure?'); ?>)) {
180 return false;
183 top.restoreSession();
184 return true;
187 </script>
189 </head>
191 <body class="body_top">
192 <?php
193 // If we are saving, then save and close the window.
194 // First check for duplicates.
196 if (!empty($_POST['form_save'])) {
197 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
198 CsrfUtils::csrfNotVerified();
201 $drugName = trim($_POST['form_name']);
202 if ($drugName === '') {
203 $alertmsg = xl('Drug name is required');
204 } else {
205 $crow = sqlQuery(
206 "SELECT COUNT(*) AS count FROM drugs WHERE " .
207 "name = ? AND " .
208 "form = ? AND " .
209 "size = ? AND " .
210 "unit = ? AND " .
211 "route = ? AND " .
212 "drug_id != ?",
213 array(
214 trim($_POST['form_name']),
215 trim($_POST['form_form']),
216 trim($_POST['form_size']),
217 trim($_POST['form_unit']),
218 trim($_POST['form_route']),
219 $drug_id
222 if ($crow['count']) {
223 $alertmsg = xl('Cannot add this entry because it already exists!');
228 if ((!empty($_POST['form_save']) || !empty($_POST['form_delete'])) && !$alertmsg) {
229 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
230 CsrfUtils::csrfNotVerified();
233 $new_drug = false;
234 if ($drug_id) {
235 if ($_POST['form_save']) { // updating an existing drug
236 sqlStatement(
237 "UPDATE drugs SET " .
238 "name = ?, " .
239 "ndc_number = ?, " .
240 "drug_code = ?, " .
241 "on_order = ?, " .
242 "reorder_point = ?, " .
243 "max_level = ?, " .
244 "form = ?, " .
245 "size = ?, " .
246 "unit = ?, " .
247 "route = ?, " .
248 "cyp_factor = ?, " .
249 "related_code = ?, " .
250 "dispensable = ?, " .
251 "allow_multiple = ?, " .
252 "allow_combining = ?, " .
253 "active = ?, " .
254 "consumable = ? " .
255 "WHERE drug_id = ?",
256 array(
257 trim($_POST['form_name']),
258 trim($_POST['form_ndc_number']),
259 trim($_POST['form_drug_code']),
260 trim($_POST['form_on_order']),
261 trim($_POST['form_reorder_point']),
262 trim($_POST['form_max_level']),
263 trim($_POST['form_form']),
264 trim($_POST['form_size']),
265 trim($_POST['form_unit']),
266 trim($_POST['form_route']),
267 trim($_POST['form_cyp_factor']),
268 trim($_POST['form_related_code']),
269 (empty($_POST['form_dispensable' ]) ? 0 : 1),
270 (empty($_POST['form_allow_multiple' ]) ? 0 : 1),
271 (empty($_POST['form_allow_combining']) ? 0 : 1),
272 (empty($_POST['form_active']) ? 0 : 1),
273 (empty($_POST['form_consumable' ]) ? 0 : 1),
274 $drug_id
277 sqlStatement("DELETE FROM drug_templates WHERE drug_id = ?", array($drug_id));
278 } else { // deleting
279 if (AclMain::aclCheckCore('admin', 'super')) {
280 sqlStatement("DELETE FROM drug_inventory WHERE drug_id = ?", array($drug_id));
281 sqlStatement("DELETE FROM drug_templates WHERE drug_id = ?", array($drug_id));
282 sqlStatement("DELETE FROM drugs WHERE drug_id = ?", array($drug_id));
283 sqlStatement("DELETE FROM prices WHERE pr_id = ? AND pr_selector != ''", array($drug_id));
286 } elseif ($_POST['form_save']) { // saving a new drug
287 $new_drug = true;
288 $drug_id = sqlInsert(
289 "INSERT INTO drugs ( " .
290 "name, ndc_number, drug_code, on_order, reorder_point, max_level, form, " .
291 "size, unit, route, cyp_factor, related_code, " .
292 "dispensable, allow_multiple, allow_combining, active, consumable " .
293 ") VALUES ( " .
294 "?, " .
295 "?, " .
296 "?, " .
297 "?, " .
298 "?, " .
299 "?, " .
300 "?, " .
301 "?, " .
302 "?, " .
303 "?, " .
304 "?, " .
305 "?, " .
306 "?, " .
307 "?, " .
308 "?, " .
309 "?, " .
310 "?)",
311 array(
312 trim($_POST['form_name']),
313 trim($_POST['form_ndc_number']),
314 trim($_POST['form_drug_code']),
315 trim($_POST['form_on_order']),
316 trim($_POST['form_reorder_point']),
317 trim($_POST['form_max_level']),
318 trim($_POST['form_form']),
319 trim($_POST['form_size']),
320 trim($_POST['form_unit']),
321 trim($_POST['form_route']),
322 trim($_POST['form_cyp_factor']),
323 trim($_POST['form_related_code']),
324 (empty($_POST['form_dispensable' ]) ? 0 : 1),
325 (empty($_POST['form_allow_multiple' ]) ? 0 : 1),
326 (empty($_POST['form_allow_combining']) ? 0 : 1),
327 (empty($_POST['form_active' ]) ? 0 : 1),
328 (empty($_POST['form_consumable' ]) ? 0 : 1)
333 if ($_POST['form_save'] && $drug_id) {
334 $tmpl = $_POST['form_tmpl'];
335 // If using the simplified drug form, then force the one and only
336 // selector name to be the same as the product name.
337 if ($GLOBALS['sell_non_drug_products'] == 2) {
338 $tmpl["1"]['selector'] = $_POST['form_name'];
341 sqlStatement("DELETE FROM prices WHERE pr_id = ? AND pr_selector != ''", array($drug_id));
342 for ($lino = 1; isset($tmpl["$lino"]['selector']); ++$lino) {
343 $iter = $tmpl["$lino"];
344 $selector = trim($iter['selector']);
345 if ($selector) {
346 $taxrates = "";
347 if (!empty($iter['taxrate'])) {
348 foreach ($iter['taxrate'] as $key => $value) {
349 $taxrates .= "$key:";
353 sqlStatement(
354 "INSERT INTO drug_templates ( " .
355 "drug_id, selector, dosage, period, quantity, refills, taxrates, pkgqty " .
356 ") VALUES ( ?, ?, ?, ?, ?, ?, ?, ? )",
357 array(
358 $drug_id,
359 $selector,
360 trim($iter['dosage']),
361 trim($iter['period']),
362 trim($iter['quantity']),
363 trim($iter['refills']),
364 $taxrates,
365 // floatval(trim($iter['pkgqty']))
370 // Add prices for this drug ID and selector.
371 foreach ($iter['price'] as $key => $value) {
372 if ($value) {
373 $value = $value + 0;
374 sqlStatement(
375 "INSERT INTO prices ( " .
376 "pr_id, pr_selector, pr_level, pr_price ) VALUES ( " .
377 "?, ?, ?, ? )",
378 array($drug_id, $selector, $key, $value)
381 } // end foreach price
382 } // end if selector is present
383 } // end for each selector
384 // Save warehouse-specific mins and maxes for this drug.
385 sqlStatement("DELETE FROM product_warehouse WHERE pw_drug_id = ?", array($drug_id));
386 foreach ($_POST['form_wh_min'] as $whid => $whmin) {
387 $whmin = 0 + $whmin;
388 $whmax = 0 + $_POST['form_wh_max'][$whid];
389 if ($whmin != 0 || $whmax != 0) {
390 sqlStatement("INSERT INTO product_warehouse ( " .
391 "pw_drug_id, pw_warehouse, pw_min_level, pw_max_level ) VALUES ( " .
392 "?, ?, ?, ? )", array($drug_id, $whid, $whmin, $whmax));
395 } // end if saving a drug
397 // Close this window and redisplay the updated list of drugs.
399 echo "<script>\n";
400 if ($info_msg) {
401 echo " alert('" . addslashes($info_msg) . "');\n";
404 echo " if (opener.refreshme) opener.refreshme();\n";
405 if ($new_drug) {
406 echo " window.location.href='add_edit_lot.php?drug=" . attr_url($drug_id) . "&lot=0'\n";
407 } else {
408 echo " window.close();\n";
411 echo "</script></body></html>\n";
412 exit();
415 if ($drug_id) {
416 $row = sqlQuery("SELECT * FROM drugs WHERE drug_id = ?", array($drug_id));
417 $tres = sqlStatement("SELECT * FROM drug_templates WHERE " .
418 "drug_id = ? ORDER BY selector", array($drug_id));
419 } else {
420 $row = array(
421 'name' => '',
422 'active' => '1',
423 'dispensable' => '1',
424 'allow_multiple' => '1',
425 'allow_combining' => '',
426 'consumable' => '0',
427 'ndc_number' => '',
428 'on_order' => '0',
429 'reorder_point' => '0',
430 'max_level' => '0',
431 'form' => '',
432 'size' => '',
433 'unit' => '',
434 'route' => '',
435 'cyp_factor' => '',
436 'related_code' => '',
439 $title = $drug_id ? xl("Update Drug") : xl("Add Drug");
441 <h3 class="ml-1"><?php echo text($title);?></h3>
442 <form method='post' name='theform' action='add_edit_drug.php?drug=<?php echo attr_url($drug_id); ?>'
443 onsubmit='return validate(this);'>
444 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
446 <div class="form-group">
447 <label class="font-weight-bold"><?php echo xlt('Name'); ?>:</label>
448 <input class="form-control" size="40" name="form_name" maxlength="80" value='<?php echo attr($row['name']) ?>' />
449 </div>
451 <div class="form-group mt-3">
452 <label class="font-weight-bold"><?php echo xlt('Attributes'); ?>:</label>
453 <input type='checkbox' name='form_active' value='1'<?php
454 if ($row['active']) {
455 echo ' checked';
456 } ?> />
457 <?php echo xlt('Active{{Drug}}'); ?>
458 <input type='checkbox' name='form_consumable' value='1'<?php
459 if ($row['consumable']) {
460 echo ' checked';
461 } ?> />
462 <?php echo xlt('Consumable'); ?>
463 </div>
465 <div class="form-group mt-3">
466 <label class="font-weight-bold"><?php echo xlt('Allow'); ?>:</label>
467 <input type='checkbox' name='form_dispensable' value='1' onclick='dispensable_changed();'<?php
468 if ($row['dispensable']) {
469 echo ' checked';
470 } ?> />
471 <?php echo xlt('Inventory'); ?>
472 <input type='checkbox' name='form_allow_multiple' value='1'<?php
473 if ($row['allow_multiple']) {
474 echo ' checked';
475 } ?> />
476 <?php echo xlt('Multiple Lots'); ?>
477 <input type='checkbox' name='form_allow_combining' value='1'<?php
478 if ($row['allow_combining']) {
479 echo ' checked';
480 } ?> />
481 <?php echo xlt('Combining Lots'); ?>
482 </div>
484 <div class="form-group mt-3">
485 <label class="font-weight-bold"><?php echo xlt('NDC Number'); ?>:</label>
486 <input class="form-control w-100" size="40" name="form_ndc_number" maxlength="20" value='<?php echo attr($row['ndc_number']) ?>' onkeyup='maskkeyup(this,"<?php echo attr(addslashes($GLOBALS['gbl_mask_product_id'])); ?>")' onblur='maskblur(this,"<?php echo attr(addslashes($GLOBALS['gbl_mask_product_id'])); ?>")' />
487 </div>
489 <div class="form-group mt-3">
490 <label class="font-weight-bold"><?php echo xlt('RXCUI Code'); ?>:</label>
491 <input class="form-control w-100" type="text" size="50" name="form_drug_code" value='<?php echo attr($row['drug_code']) ?>'
492 onclick='sel_related("?codetype=RXCUI&limit=1&target_element=form_drug_code")' title='<?php echo xla('Click to select RXCUI code'); ?>' data-toggle="tooltip" data-placement="top" readonly />
493 </div>
495 <div class="form-group mt-3">
496 <label class="font-weight-bold"><?php echo xlt('On Order'); ?>:</label>
497 <input class="form-control" size="5" name="form_on_order" maxlength="7" value='<?php echo attr($row['on_order']) ?>' />
498 </div>
500 <div class="form-group mt-3">
501 <label class="font-weight-bold"><?php echo xlt('Limits'); ?>:</label>
502 <table class="table table-borderless pl-5">
503 <tr>
504 <td class="align-top font-weight-bold">
505 <?php echo !empty($GLOBALS['gbl_min_max_months']) ? xlt('Months') : xlt('Units'); ?>
506 </td>
507 <td class="align-top"><?php echo xlt('Global'); ?></td>
508 <?php
509 // One column header per warehouse title.
510 $pwarr = array();
511 $pwres = sqlStatement(
512 "SELECT lo.option_id, lo.title, " .
513 "pw.pw_min_level, pw.pw_max_level " .
514 "FROM list_options AS lo " .
515 "LEFT JOIN product_warehouse AS pw ON " .
516 "pw.pw_drug_id = ? AND " .
517 "pw.pw_warehouse = lo.option_id WHERE " .
518 "lo.list_id = 'warehouse' AND lo.activity = 1 ORDER BY lo.seq, lo.title",
519 array($drug_id)
521 while ($pwrow = sqlFetchArray($pwres)) {
522 $pwarr[] = $pwrow;
523 echo " <td class='align-top'>" . text($pwrow['title']) . "</td>\n";
526 </tr>
527 <tr>
528 <td class="align-top"><?php echo xlt('Min'); ?>&nbsp;</td>
529 <td class="align-top">
530 <input class="form-control" size='5' name='form_reorder_point' maxlength='7' value='<?php echo attr($row['reorder_point']) ?>' title='<?php echo xla('Reorder point, 0 if not applicable'); ?>' data-toggle="tooltip" data-placement="top" />
531 </td>
532 <?php
533 foreach ($pwarr as $pwrow) {
534 echo " <td class='align-top'>";
535 echo "<input class='form-control' name='form_wh_min[" .
536 attr($pwrow['option_id']) .
537 "]' value='" . attr(0 + $pwrow['pw_min_level']) . "' size='5' " .
538 "title='" . xla('Warehouse minimum, 0 if not applicable') . "' data-toggle='tooltip' data-placement='top' />";
539 echo "&nbsp;&nbsp;</td>\n";
542 </tr>
543 <tr>
544 <td class="align-top"><?php echo xlt('Max'); ?>&nbsp;</td>
545 <td>
546 <input class='form-control' size='5' name='form_max_level' maxlength='7' value='<?php echo attr($row['max_level']) ?>' title='<?php echo xla('Maximum reasonable inventory, 0 if not applicable'); ?>' data-toggle="tooltip" data-placement="top" />
547 </td>
548 <?php
549 foreach ($pwarr as $pwrow) {
550 echo " <td class='align-top'>";
551 echo "<input class='form-control' name='form_wh_max[" .
552 attr($pwrow['option_id']) .
553 "]' value='" . attr(0 + $pwrow['pw_max_level']) . "' size='5' " .
554 "title='" . xla('Warehouse maximum, 0 if not applicable') . "' data-toggle='tooltip' data-placement='top' />";
555 echo "</td>\n";
558 </tr>
559 </table>
560 </div>
562 <div class="form-group mt-3 drugsonly">
563 <label class="font-weight-bold"><?php echo xlt('Form'); ?>:</label>
564 <?php
565 generate_form_field(array('data_type' => 1,'field_id' => 'form','list_id' => 'drug_form','empty_title' => 'SKIP'), $row['form']);
567 </div>
569 <div class="form-group mt-3 drugsonly">
570 <label class="font-weight-bold"><?php echo xlt('Size'); ?>:</label>
571 <input class="form-control" size="5" name="form_size" maxlength="7" value='<?php echo attr($row['size']) ?>' />
572 </div>
574 <div class="form-group mt-3 drugsonly" title='<?php echo xlt('Measurement Units'); ?>'>
575 <label class="font-weight-bold"><?php echo xlt('Units'); ?>:</label>
576 <?php
577 generate_form_field(array('data_type' => 1,'field_id' => 'unit','list_id' => 'drug_units','empty_title' => 'SKIP'), $row['unit']);
579 </div>
581 <div class="form-group mt-3 drugsonly">
582 <label class="font-weight-bold"><?php echo xlt('Route'); ?>:</label>
583 <?php
584 generate_form_field(array('data_type' => 1,'field_id' => 'route','list_id' => 'drug_route','empty_title' => 'SKIP'), $row['route']);
586 </div>
588 <div class="form-group mt-3 ippfonly" style='display:none'> <!-- Removed per CV 2017-03-29 -->
589 <label class="font-weight-bold"><?php echo xlt('CYP Factor'); ?>:</label>
590 <input class="form-control" size="10" name="form_cyp_factor" maxlength="20" value='<?php echo attr($row['cyp_factor']) ?>' />
591 </div>
593 <div class="form-group mt-3 drugsonly">
594 <label class="font-weight-bold"><?php echo xlt('Relate To'); ?>:</label>
595 <input class="form-control w-100" type="text" size="50" name="form_related_code" value='<?php echo attr($row['related_code']) ?>'
596 onclick='sel_related("?target_element=form_related_code")' title='<?php echo xla('Click to select related code'); ?>' data-toggle="tooltip" data-placement="top" readonly />
597 </div>
599 <div class="form-group mt-3">
600 <label class="font-weight-bold">
601 <?php echo $GLOBALS['sell_non_drug_products'] == 2 ? xlt('Fees') : xlt('Templates'); ?>:
602 </label>
603 <table class='table table-borderless'>
604 <tr>
605 <td class='drugsonly font-weight-bold'><?php echo xlt('Name'); ?></td>
606 <td class='drugsonly font-weight-bold'><?php echo xlt('Schedule'); ?></td>
607 <td class='drugsonly font-weight-bold'><?php echo xlt('Interval'); ?></td>
608 <td class='drugsonly font-weight-bold'><?php echo xlt('Basic Units'); ?></td>
609 <td class='drugsonly font-weight-bold'><?php echo xlt('Refills'); ?></td>
610 <?php
611 // Show a heading for each price level. Also create an array of prices
612 // for new template lines.
613 $emptyPrices = array();
614 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
615 "WHERE list_id = 'pricelevel' AND activity = 1 ORDER BY seq");
616 while ($prow = sqlFetchArray($pres)) {
617 $emptyPrices[$prow['option_id']] = '';
618 echo " <td class='font-weight-bold'>" .
619 generate_display_field(array('data_type' => '1','list_id' => 'pricelevel'), $prow['option_id']) .
620 "</td>\n";
623 // Show a heading for each tax rate.
624 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
625 "WHERE list_id = 'taxrate' AND activity = 1 ORDER BY seq");
626 while ($prow = sqlFetchArray($pres)) {
627 echo " <td class='font-weight-bold'>" .
628 generate_display_field(array('data_type' => '1','list_id' => 'taxrate'), $prow['option_id']) .
629 "</td>\n";
632 </tr>
633 <?php
634 $blank_lines = $GLOBALS['sell_non_drug_products'] == 2 ? 1 : 3;
635 if ($tres) {
636 while ($trow = sqlFetchArray($tres)) {
637 $blank_lines = $GLOBALS['sell_non_drug_products'] == 2 ? 0 : 1;
638 $selector = $trow['selector'];
639 // Get array of prices.
640 $prices = array();
641 $pres = sqlStatement(
642 "SELECT lo.option_id, p.pr_price " .
643 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
644 "p.pr_id = ? AND p.pr_selector = ? AND " .
645 "p.pr_level = lo.option_id " .
646 "WHERE lo.list_id = 'pricelevel' AND lo.activity = 1 ORDER BY lo.seq",
647 array($drug_id, $selector)
649 while ($prow = sqlFetchArray($pres)) {
650 $prices[$prow['option_id']] = $prow['pr_price'];
653 writeTemplateLine(
654 $selector,
655 $trow['dosage'],
656 $trow['period'],
657 $trow['quantity'],
658 $trow['refills'],
659 $prices,
660 $trow['taxrates'],
661 $trow['pkgqty']
666 for ($i = 0; $i < $blank_lines; ++$i) {
667 $selector = $GLOBALS['sell_non_drug_products'] == 2 ? $row['name'] : '';
668 writeTemplateLine($selector, '', '', '', '', $emptyPrices, '', '1');
671 </table>
672 </div>
674 <div class="btn-group">
675 <button type='submit' class="btn btn-primary btn-save" name='form_save'
676 value='<?php echo $drug_id ? xla('Update') : xla('Add') ; ?>'
677 onclick='return this.clicked = true;'
678 ><?php echo $drug_id ? xlt('Update') : xlt('Add') ; ?></button>
679 <?php if (AclMain::aclCheckCore('admin', 'super') && $drug_id) { ?>
680 <button class="btn btn-danger" type='submit' name='form_delete'
681 onclick='return this.clicked = true;' value='<?php echo xla('Delete'); ?>'
682 ><?php echo xlt('Delete'); ?></button>
683 <?php } ?>
684 <button type='button' class="btn btn-secondary btn-cancel" onclick='window.close()'><?php echo xlt('Cancel'); ?></button>
685 </div>
686 </form>
688 <script>
690 $(function () {
691 $('[data-toggle="tooltip"]').tooltip();
694 dispensable_changed();
696 <?php
697 if ($alertmsg) {
698 echo "alert('" . addslashes($alertmsg) . "');\n";
702 </script>
704 </body>
705 </html>