fix: bug fix (#6270)
[openemr.git] / interface / drugs / add_edit_drug.php
blobb867f6dedc7f3f6e9f69372de6adb8260aa19f82
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\Common\Twig\TwigContainer;
17 use OpenEMR\Core\Header;
19 $alertmsg = '';
20 $drug_id = $_REQUEST['drug'];
21 $info_msg = "";
22 $tmpl_line_no = 0;
24 if (!AclMain::aclCheckCore('admin', 'drugs')) {
25 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Edit/Add Drug")]);
26 exit;
29 // Write a line of data for one template to the form.
31 function writeTemplateLine($selector, $dosage, $period, $quantity, $refills, $prices, $taxrates, $pkgqty)
33 global $tmpl_line_no;
34 ++$tmpl_line_no;
36 echo " <tr>\n";
37 echo " <td class='tmplcell drugsonly'>";
38 echo "<input class='form-control' name='form_tmpl[" . attr($tmpl_line_no) . "][selector]' value='" . attr($selector) . "' size='8' maxlength='100'>";
39 echo "</td>\n";
40 echo " <td class='tmplcell drugsonly'>";
41 echo "<input class='form-control' name='form_tmpl[" . attr($tmpl_line_no) . "][dosage]' value='" . attr($dosage) . "' size='6' maxlength='10'>";
42 echo "</td>\n";
43 echo " <td class='tmplcell drugsonly'>";
44 generate_form_field(array(
45 'data_type' => 1,
46 'field_id' => 'tmpl[' . attr($tmpl_line_no) . '][period]',
47 'list_id' => 'drug_interval',
48 'empty_title' => 'SKIP'
49 ), $period);
50 echo "</td>\n";
51 echo " <td class='tmplcell drugsonly'>";
52 echo "<input class='form-control' name='form_tmpl[" . attr($tmpl_line_no) . "][quantity]' value='" . attr($quantity) . "' size='3' maxlength='7'>";
53 echo "</td>\n";
54 echo " <td class='tmplcell drugsonly'>";
55 echo "<input class='form-control' name='form_tmpl[" . attr($tmpl_line_no) . "][refills]' value='" . attr($refills) . "' size='3' maxlength='5'>";
56 echo "</td>\n";
58 /******************************************************************
59 echo " <td class='tmplcell drugsonly'>";
60 echo "<input type='text' class='form-control' name='form_tmpl[" . attr($tmpl_line_no) .
61 "][pkgqty]' value='" . attr($pkgqty) . "' size='3' maxlength='5'>";
62 echo "</td>\n";
63 ******************************************************************/
65 foreach ($prices as $pricelevel => $price) {
66 echo " <td class='tmplcell'>";
67 echo "<input class='form-control' name='form_tmpl[" . attr($tmpl_line_no) . "][price][" . attr($pricelevel) . "]' value='" . attr($price) . "' size='6' maxlength='12'>";
68 echo "</td>\n";
71 $pres = sqlStatement("SELECT option_id FROM list_options " .
72 "WHERE list_id = 'taxrate' AND activity = 1 ORDER BY seq");
73 while ($prow = sqlFetchArray($pres)) {
74 echo " <td class='tmplcell'>";
75 echo "<input type='checkbox' name='form_tmpl[" . attr($tmpl_line_no) . "][taxrate][" . attr($prow['option_id']) . "]' value='1'";
76 if (strpos(":$taxrates", $prow['option_id']) !== false) {
77 echo " checked";
80 echo " /></td>\n";
83 echo " </tr>\n";
86 <html>
87 <head>
88 <title><?php echo $drug_id ? xlt("Edit") : xlt("Add New");
89 echo ' ' . xlt('Drug'); ?></title>
91 <?php Header::setupHeader(["opener"]); ?>
93 <style>
95 <?php if ($GLOBALS['sell_non_drug_products'] == 2) { // "Products but no prescription drugs and no templates" ?>
96 .drugsonly { display:none; }
97 <?php } else { ?>
98 .drugsonly { }
99 <?php } ?>
101 <?php if (empty($GLOBALS['ippf_specific'])) { ?>
102 .ippfonly { display:none; }
103 <?php } else { ?>
104 .ippfonly { }
105 <?php } ?>
107 </style>
109 <script>
111 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
113 // This is for callback by the find-code popup.
114 // Appends to or erases the current list of related codes.
115 // The target element is set by the find-code popup
116 // (this allows use of this in multiple form elements on the same page)
117 function set_related_target(codetype, code, selector, codedesc, target_element, limit=0) {
118 var f = document.forms[0];
119 var s = f[target_element].value;
120 if (code) {
121 if (limit > 0) {
122 s = codetype + ':' + code;
124 else {
125 if (codetype != 'PROD') {
126 // Return an error message if a service code is already selected.
127 if (s.indexOf(codetype + ':') == 0 || s.indexOf(';' + codetype + ':') > 0) {
128 return <?php echo xlj('A code of this type is already selected. Erase the field first if you need to replace it.') ?>;
131 if (s.length > 0) {
132 s += ';';
134 s += codetype + ':' + code;
136 } else {
137 s = '';
139 f[target_element].value = s;
140 return '';
143 // This is for callback by the find-code popup.
144 // Returns the array of currently selected codes with each element in codetype:code format.
145 function get_related() {
146 return document.forms[0].form_related_code.value.split(';');
149 // This is for callback by the find-code popup.
150 // Deletes the specified codetype:code from the currently selected list.
151 function del_related(s) {
152 my_del_related(s, document.forms[0].form_related_code, false);
155 // This invokes the find-code popup.
156 function sel_related(getter = '') {
157 dlgopen('../patient_file/encounter/find_code_dynamic.php' + getter, '_blank', 900, 800);
160 // onclick handler for "allow inventory" checkbox.
161 function dispensable_changed() {
162 var f = document.forms[0];
163 var dis = !f.form_dispensable.checked;
164 f.form_allow_multiple.disabled = dis;
165 f.form_allow_combining.disabled = dis;
166 return true;
169 function validate(f) {
170 var saving = f.form_save.clicked ? true : false;
171 f.form_save.clicked = false;
172 if (saving) {
173 if (f.form_name.value.search(/[^\s]/) < 0) {
174 alert(<?php echo xlj('Product name is required'); ?>);
175 return false;
178 var deleting = f.form_delete.clicked ? true : false;
179 f.form_delete.clicked = false;
180 if (deleting) {
181 if (!confirm(<?php echo xlj('This will permanently delete all lots of this product. Related reports will be incomplete or incorrect. Are you sure?'); ?>)) {
182 return false;
185 top.restoreSession();
186 return true;
189 </script>
191 </head>
193 <body class="body_top">
194 <?php
195 // If we are saving, then save and close the window.
196 // First check for duplicates.
198 if (!empty($_POST['form_save'])) {
199 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
200 CsrfUtils::csrfNotVerified();
203 $drugName = trim($_POST['form_name']);
204 if ($drugName === '') {
205 $alertmsg = xl('Drug name is required');
206 } else {
207 $crow = sqlQuery(
208 "SELECT COUNT(*) AS count FROM drugs WHERE " .
209 "name = ? AND " .
210 "form = ? AND " .
211 "size = ? AND " .
212 "unit = ? AND " .
213 "route = ? AND " .
214 "drug_id != ?",
215 array(
216 trim($_POST['form_name']),
217 trim($_POST['form_form']),
218 trim($_POST['form_size']),
219 trim($_POST['form_unit']),
220 trim($_POST['form_route']),
221 $drug_id
224 if ($crow['count']) {
225 $alertmsg = xl('Cannot add this entry because it already exists!');
230 if ((!empty($_POST['form_save']) || !empty($_POST['form_delete'])) && !$alertmsg) {
231 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
232 CsrfUtils::csrfNotVerified();
235 $new_drug = false;
236 if ($drug_id) {
237 if ($_POST['form_save']) { // updating an existing drug
238 sqlStatement(
239 "UPDATE drugs SET " .
240 "name = ?, " .
241 "ndc_number = ?, " .
242 "drug_code = ?, " .
243 "on_order = ?, " .
244 "reorder_point = ?, " .
245 "max_level = ?, " .
246 "form = ?, " .
247 "size = ?, " .
248 "unit = ?, " .
249 "route = ?, " .
250 "cyp_factor = ?, " .
251 "related_code = ?, " .
252 "dispensable = ?, " .
253 "allow_multiple = ?, " .
254 "allow_combining = ?, " .
255 "active = ?, " .
256 "consumable = ? " .
257 "WHERE drug_id = ?",
258 array(
259 trim($_POST['form_name']),
260 trim($_POST['form_ndc_number']),
261 trim($_POST['form_drug_code']),
262 trim($_POST['form_on_order']),
263 trim($_POST['form_reorder_point']),
264 trim($_POST['form_max_level']),
265 trim($_POST['form_form']),
266 trim($_POST['form_size']),
267 trim($_POST['form_unit']),
268 trim($_POST['form_route']),
269 trim($_POST['form_cyp_factor']),
270 trim($_POST['form_related_code']),
271 (empty($_POST['form_dispensable' ]) ? 0 : 1),
272 (empty($_POST['form_allow_multiple' ]) ? 0 : 1),
273 (empty($_POST['form_allow_combining']) ? 0 : 1),
274 (empty($_POST['form_active']) ? 0 : 1),
275 (empty($_POST['form_consumable' ]) ? 0 : 1),
276 $drug_id
279 sqlStatement("DELETE FROM drug_templates WHERE drug_id = ?", array($drug_id));
280 } else { // deleting
281 if (AclMain::aclCheckCore('admin', 'super')) {
282 sqlStatement("DELETE FROM drug_inventory WHERE drug_id = ?", array($drug_id));
283 sqlStatement("DELETE FROM drug_templates WHERE drug_id = ?", array($drug_id));
284 sqlStatement("DELETE FROM drugs WHERE drug_id = ?", array($drug_id));
285 sqlStatement("DELETE FROM prices WHERE pr_id = ? AND pr_selector != ''", array($drug_id));
288 } elseif ($_POST['form_save']) { // saving a new drug
289 $new_drug = true;
290 $drug_id = sqlInsert(
291 "INSERT INTO drugs ( " .
292 "name, ndc_number, drug_code, on_order, reorder_point, max_level, form, " .
293 "size, unit, route, cyp_factor, related_code, " .
294 "dispensable, allow_multiple, allow_combining, active, consumable " .
295 ") VALUES ( " .
296 "?, " .
297 "?, " .
298 "?, " .
299 "?, " .
300 "?, " .
301 "?, " .
302 "?, " .
303 "?, " .
304 "?, " .
305 "?, " .
306 "?, " .
307 "?, " .
308 "?, " .
309 "?, " .
310 "?, " .
311 "?, " .
312 "?)",
313 array(
314 trim($_POST['form_name']),
315 trim($_POST['form_ndc_number']),
316 trim($_POST['form_drug_code']),
317 trim($_POST['form_on_order']),
318 trim($_POST['form_reorder_point']),
319 trim($_POST['form_max_level']),
320 trim($_POST['form_form']),
321 trim($_POST['form_size']),
322 trim($_POST['form_unit']),
323 trim($_POST['form_route']),
324 trim($_POST['form_cyp_factor']),
325 trim($_POST['form_related_code']),
326 (empty($_POST['form_dispensable' ]) ? 0 : 1),
327 (empty($_POST['form_allow_multiple' ]) ? 0 : 1),
328 (empty($_POST['form_allow_combining']) ? 0 : 1),
329 (empty($_POST['form_active' ]) ? 0 : 1),
330 (empty($_POST['form_consumable' ]) ? 0 : 1)
335 if ($_POST['form_save'] && $drug_id) {
336 $tmpl = $_POST['form_tmpl'];
337 // If using the simplified drug form, then force the one and only
338 // selector name to be the same as the product name.
339 if ($GLOBALS['sell_non_drug_products'] == 2) {
340 $tmpl["1"]['selector'] = $_POST['form_name'];
343 sqlStatement("DELETE FROM prices WHERE pr_id = ? AND pr_selector != ''", array($drug_id));
344 for ($lino = 1; isset($tmpl["$lino"]['selector']); ++$lino) {
345 $iter = $tmpl["$lino"];
346 $selector = trim($iter['selector']);
347 if ($selector) {
348 $taxrates = "";
349 if (!empty($iter['taxrate'])) {
350 foreach ($iter['taxrate'] as $key => $value) {
351 $taxrates .= "$key:";
355 sqlStatement(
356 "INSERT INTO drug_templates ( " .
357 "drug_id, selector, dosage, period, quantity, refills, taxrates, pkgqty " .
358 ") VALUES ( ?, ?, ?, ?, ?, ?, ?, ? )",
359 array(
360 $drug_id,
361 $selector,
362 trim($iter['dosage']),
363 trim($iter['period']),
364 trim($iter['quantity']),
365 trim($iter['refills']),
366 $taxrates,
367 // floatval(trim($iter['pkgqty']))
372 // Add prices for this drug ID and selector.
373 foreach ($iter['price'] as $key => $value) {
374 if ($value) {
375 $value = $value + 0;
376 sqlStatement(
377 "INSERT INTO prices ( " .
378 "pr_id, pr_selector, pr_level, pr_price ) VALUES ( " .
379 "?, ?, ?, ? )",
380 array($drug_id, $selector, $key, $value)
383 } // end foreach price
384 } // end if selector is present
385 } // end for each selector
386 // Save warehouse-specific mins and maxes for this drug.
387 sqlStatement("DELETE FROM product_warehouse WHERE pw_drug_id = ?", array($drug_id));
388 foreach ($_POST['form_wh_min'] as $whid => $whmin) {
389 $whmin = 0 + $whmin;
390 $whmax = 0 + $_POST['form_wh_max'][$whid];
391 if ($whmin != 0 || $whmax != 0) {
392 sqlStatement("INSERT INTO product_warehouse ( " .
393 "pw_drug_id, pw_warehouse, pw_min_level, pw_max_level ) VALUES ( " .
394 "?, ?, ?, ? )", array($drug_id, $whid, $whmin, $whmax));
397 } // end if saving a drug
399 // Close this window and redisplay the updated list of drugs.
401 echo "<script>\n";
402 if ($info_msg) {
403 echo " alert('" . addslashes($info_msg) . "');\n";
406 echo " if (opener.refreshme) opener.refreshme();\n";
407 if ($new_drug) {
408 echo " window.location.href='add_edit_lot.php?drug=" . attr_url($drug_id) . "&lot=0'\n";
409 } else {
410 echo " window.close();\n";
413 echo "</script></body></html>\n";
414 exit();
417 if ($drug_id) {
418 $row = sqlQuery("SELECT * FROM drugs WHERE drug_id = ?", array($drug_id));
419 $tres = sqlStatement("SELECT * FROM drug_templates WHERE " .
420 "drug_id = ? ORDER BY selector", array($drug_id));
421 } else {
422 $row = array(
423 'name' => '',
424 'active' => '1',
425 'dispensable' => '1',
426 'allow_multiple' => '1',
427 'allow_combining' => '',
428 'consumable' => '0',
429 'ndc_number' => '',
430 'on_order' => '0',
431 'reorder_point' => '0',
432 'max_level' => '0',
433 'form' => '',
434 'size' => '',
435 'unit' => '',
436 'route' => '',
437 'cyp_factor' => '',
438 'related_code' => '',
441 $title = $drug_id ? xl("Update Drug") : xl("Add Drug");
443 <h3 class="ml-1"><?php echo text($title);?></h3>
444 <form method='post' name='theform' action='add_edit_drug.php?drug=<?php echo attr_url($drug_id); ?>'
445 onsubmit='return validate(this);'>
446 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
448 <div class="form-group">
449 <label><?php echo xlt('Name'); ?>:</label>
450 <input class="form-control" size="40" name="form_name" maxlength="80" value='<?php echo attr($row['name']) ?>' />
451 </div>
453 <div class="form-group mt-3">
454 <label><?php echo xlt('Attributes'); ?>:</label>
455 <input type='checkbox' name='form_active' value='1'<?php
456 if ($row['active']) {
457 echo ' checked';
458 } ?> />
459 <?php echo xlt('Active{{Drug}}'); ?>
460 <input type='checkbox' name='form_consumable' value='1'<?php
461 if ($row['consumable']) {
462 echo ' checked';
463 } ?> />
464 <?php echo xlt('Consumable'); ?>
465 </div>
467 <div class="form-group mt-3">
468 <label><?php echo xlt('Allow'); ?>:</label>
469 <input type='checkbox' name='form_dispensable' value='1' onclick='dispensable_changed();'<?php
470 if ($row['dispensable']) {
471 echo ' checked';
472 } ?> />
473 <?php echo xlt('Inventory'); ?>
474 <input type='checkbox' name='form_allow_multiple' value='1'<?php
475 if ($row['allow_multiple']) {
476 echo ' checked';
477 } ?> />
478 <?php echo xlt('Multiple Lots'); ?>
479 <input type='checkbox' name='form_allow_combining' value='1'<?php
480 if ($row['allow_combining']) {
481 echo ' checked';
482 } ?> />
483 <?php echo xlt('Combining Lots'); ?>
484 </div>
486 <div class="form-group mt-3">
487 <label><?php echo xlt('NDC Number'); ?>:</label>
488 <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'])); ?>")' />
489 </div>
491 <div class="form-group mt-3">
492 <label><?php echo xlt('RXCUI Code'); ?>:</label>
493 <input class="form-control w-100" type="text" size="50" name="form_drug_code" value='<?php echo attr($row['drug_code']) ?>'
494 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 />
495 </div>
497 <div class="form-group mt-3">
498 <label><?php echo xlt('On Order'); ?>:</label>
499 <input class="form-control" size="5" name="form_on_order" maxlength="7" value='<?php echo attr($row['on_order']) ?>' />
500 </div>
502 <div class="form-group mt-3">
503 <label><?php echo xlt('Limits'); ?>:</label>
504 <table class="table table-borderless pl-5">
505 <tr>
506 <td class="align-top ">
507 <?php echo !empty($GLOBALS['gbl_min_max_months']) ? xlt('Months') : xlt('Units'); ?>
508 </td>
509 <td class="align-top"><?php echo xlt('Global'); ?></td>
510 <?php
511 // One column header per warehouse title.
512 $pwarr = array();
513 $pwres = sqlStatement(
514 "SELECT lo.option_id, lo.title, " .
515 "pw.pw_min_level, pw.pw_max_level " .
516 "FROM list_options AS lo " .
517 "LEFT JOIN product_warehouse AS pw ON " .
518 "pw.pw_drug_id = ? AND " .
519 "pw.pw_warehouse = lo.option_id WHERE " .
520 "lo.list_id = 'warehouse' AND lo.activity = 1 ORDER BY lo.seq, lo.title",
521 array($drug_id)
523 while ($pwrow = sqlFetchArray($pwres)) {
524 $pwarr[] = $pwrow;
525 echo " <td class='align-top'>" . text($pwrow['title']) . "</td>\n";
528 </tr>
529 <tr>
530 <td class="align-top"><?php echo xlt('Min'); ?>&nbsp;</td>
531 <td class="align-top">
532 <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" />
533 </td>
534 <?php
535 foreach ($pwarr as $pwrow) {
536 echo " <td class='align-top'>";
537 echo "<input class='form-control' name='form_wh_min[" .
538 attr($pwrow['option_id']) .
539 "]' value='" . attr(0 + $pwrow['pw_min_level']) . "' size='5' " .
540 "title='" . xla('Warehouse minimum, 0 if not applicable') . "' data-toggle='tooltip' data-placement='top' />";
541 echo "&nbsp;&nbsp;</td>\n";
544 </tr>
545 <tr>
546 <td class="align-top"><?php echo xlt('Max'); ?>&nbsp;</td>
547 <td>
548 <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" />
549 </td>
550 <?php
551 foreach ($pwarr as $pwrow) {
552 echo " <td class='align-top'>";
553 echo "<input class='form-control' name='form_wh_max[" .
554 attr($pwrow['option_id']) .
555 "]' value='" . attr(0 + $pwrow['pw_max_level']) . "' size='5' " .
556 "title='" . xla('Warehouse maximum, 0 if not applicable') . "' data-toggle='tooltip' data-placement='top' />";
557 echo "</td>\n";
560 </tr>
561 </table>
562 </div>
564 <div class="form-group mt-3 drugsonly">
565 <label><?php echo xlt('Form'); ?>:</label>
566 <?php
567 generate_form_field(array('data_type' => 1,'field_id' => 'form','list_id' => 'drug_form','empty_title' => 'SKIP'), $row['form']);
569 </div>
571 <div class="form-group mt-3 drugsonly">
572 <label><?php echo xlt('Size'); ?>:</label>
573 <input class="form-control" size="5" name="form_size" maxlength="7" value='<?php echo attr($row['size']) ?>' />
574 </div>
576 <div class="form-group mt-3 drugsonly" title='<?php echo xlt('Measurement Units'); ?>'>
577 <label><?php echo xlt('Units'); ?>:</label>
578 <?php
579 generate_form_field(array('data_type' => 1,'field_id' => 'unit','list_id' => 'drug_units','empty_title' => 'SKIP'), $row['unit']);
581 </div>
583 <div class="form-group mt-3 drugsonly">
584 <label><?php echo xlt('Route'); ?>:</label>
585 <?php
586 generate_form_field(array('data_type' => 1,'field_id' => 'route','list_id' => 'drug_route','empty_title' => 'SKIP'), $row['route']);
588 </div>
590 <div class="form-group mt-3 ippfonly" style='display:none'> <!-- Removed per CV 2017-03-29 -->
591 <label><?php echo xlt('CYP Factor'); ?>:</label>
592 <input class="form-control" size="10" name="form_cyp_factor" maxlength="20" value='<?php echo attr($row['cyp_factor']) ?>' />
593 </div>
595 <div class="form-group mt-3 drugsonly">
596 <label><?php echo xlt('Relate To'); ?>:</label>
597 <input class="form-control w-100" type="text" size="50" name="form_related_code" value='<?php echo attr($row['related_code']) ?>'
598 onclick='sel_related("?target_element=form_related_code")' title='<?php echo xla('Click to select related code'); ?>' data-toggle="tooltip" data-placement="top" readonly />
599 </div>
601 <div class="form-group mt-3">
602 <label>
603 <?php echo $GLOBALS['sell_non_drug_products'] == 2 ? xlt('Fees') : xlt('Templates'); ?>:
604 </label>
605 <table class='table table-borderless'>
606 <thead>
607 <tr>
608 <th class='drugsonly'><?php echo xlt('Name'); ?></th>
609 <th class='drugsonly'><?php echo xlt('Schedule'); ?></th>
610 <th class='drugsonly'><?php echo xlt('Interval'); ?></th>
611 <th class='drugsonly'><?php echo xlt('Basic Units'); ?></th>
612 <th class='drugsonly'><?php echo xlt('Refills'); ?></th>
613 <?php
614 // Show a heading for each price level. Also create an array of prices
615 // for new template lines.
616 $emptyPrices = array();
617 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
618 "WHERE list_id = 'pricelevel' AND activity = 1 ORDER BY seq");
619 while ($prow = sqlFetchArray($pres)) {
620 $emptyPrices[$prow['option_id']] = '';
621 echo " <th>" .
622 generate_display_field(array('data_type' => '1','list_id' => 'pricelevel'), $prow['option_id']) .
623 "</th>\n";
626 // Show a heading for each tax rate.
627 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
628 "WHERE list_id = 'taxrate' AND activity = 1 ORDER BY seq");
629 while ($prow = sqlFetchArray($pres)) {
630 echo " <th>" .
631 generate_display_field(array('data_type' => '1','list_id' => 'taxrate'), $prow['option_id']) .
632 "</th>\n";
635 </tr>
636 </thead>
637 <tbody>
638 <?php
639 $blank_lines = $GLOBALS['sell_non_drug_products'] == 2 ? 1 : 3;
640 if ($tres) {
641 while ($trow = sqlFetchArray($tres)) {
642 $blank_lines = $GLOBALS['sell_non_drug_products'] == 2 ? 0 : 1;
643 $selector = $trow['selector'];
644 // Get array of prices.
645 $prices = array();
646 $pres = sqlStatement(
647 "SELECT lo.option_id, p.pr_price " .
648 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
649 "p.pr_id = ? AND p.pr_selector = ? AND " .
650 "p.pr_level = lo.option_id " .
651 "WHERE lo.list_id = 'pricelevel' AND lo.activity = 1 ORDER BY lo.seq",
652 array($drug_id, $selector)
654 while ($prow = sqlFetchArray($pres)) {
655 $prices[$prow['option_id']] = $prow['pr_price'];
658 writeTemplateLine(
659 $selector,
660 $trow['dosage'],
661 $trow['period'],
662 $trow['quantity'],
663 $trow['refills'],
664 $prices,
665 $trow['taxrates'],
666 $trow['pkgqty']
671 for ($i = 0; $i < $blank_lines; ++$i) {
672 $selector = $GLOBALS['sell_non_drug_products'] == 2 ? $row['name'] : '';
673 writeTemplateLine($selector, '', '', '', '', $emptyPrices, '', '1');
676 </tbody>
677 </table>
678 </div>
680 <div class="btn-group">
681 <button type='submit' class="btn btn-primary btn-save" name='form_save'
682 value='<?php echo $drug_id ? xla('Update') : xla('Add') ; ?>'
683 onclick='return this.clicked = true;'
684 ><?php echo $drug_id ? xlt('Update') : xlt('Add') ; ?></button>
685 <?php if (AclMain::aclCheckCore('admin', 'super') && $drug_id) { ?>
686 <button class="btn btn-danger" type='submit' name='form_delete'
687 onclick='return this.clicked = true;' value='<?php echo xla('Delete'); ?>'
688 ><?php echo xlt('Delete'); ?></button>
689 <?php } ?>
690 <button type='button' class="btn btn-secondary btn-cancel" onclick='window.close()'><?php echo xlt('Cancel'); ?></button>
691 </div>
692 </form>
694 <script>
696 $(function () {
697 $('[data-toggle="tooltip"]').tooltip();
700 dispensable_changed();
702 <?php
703 if ($alertmsg) {
704 echo "alert('" . addslashes($alertmsg) . "');\n";
708 </script>
710 </body>
711 </html>