update message codes
[openemr.git] / interface / patient_file / pos_checkout.php
blob551afed966dd2afe35fd4d9afa6126f5956ca050
1 <?php
2 /**
3 * Checkout Module.
5 * This module supports a popup window to handle patient checkout
6 * as a point-of-sale transaction. Support for in-house drug sales
7 * is included.
9 * <pre>
10 * Important notes about system design:
11 * (1) Drug sales may or may not be associated with an encounter;
12 * they are if they are paid for concurrently with an encounter, or
13 * if they are "product" (non-prescription) sales via the Fee Sheet.
14 * (2) Drug sales without an encounter will have 20YYMMDD, possibly
15 * with a suffix, as the encounter-number portion of their invoice
16 * number.
17 * (3) Payments are saved as AR only, don't mess with the billing table.
18 * See library/classes/WSClaim.class.php for posting code.
19 * (4) On checkout, the billing and drug_sales table entries are marked
20 * as billed and so become unavailable for further billing.
21 * (5) Receipt printing must be a separate operation from payment,
22 * and repeatable.
24 * TBD:
25 * If this user has 'irnpool' set
26 * on display of checkout form
27 * show pending next invoice number
28 * on applying checkout
29 * save next invoice number to form_encounter
30 * compute new next invoice number
31 * on receipt display
32 * show invoice number
33 * </pre>
35 * Copyright (C) 2006-2010 Rod Roark <rod@sunsetsystems.com>
37 * LICENSE: This program is free software; you can redistribute it and/or
38 * modify it under the terms of the GNU General Public License
39 * as published by the Free Software Foundation; either version 2
40 * of the License, or (at your option) any later version.
41 * This program is distributed in the hope that it will be useful,
42 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 * GNU General Public License for more details.
45 * You should have received a copy of the GNU General Public License
46 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
48 * @package OpenEMR
49 * @author Rod Roark <rod@sunsetsystems.com>
50 * @author Brady Miller <brady@sparmy.com>
51 * @link http://www.open-emr.org
55 $fake_register_globals=false;
56 $sanitize_all_escapes=true;
58 require_once("../globals.php");
59 require_once("$srcdir/acl.inc");
60 require_once("$srcdir/patient.inc");
61 require_once("$srcdir/billing.inc");
62 require_once("$srcdir/sql-ledger.inc");
63 require_once("$srcdir/freeb/xmlrpc.inc");
64 require_once("$srcdir/freeb/xmlrpcs.inc");
65 require_once("$srcdir/formatting.inc.php");
66 require_once("$srcdir/formdata.inc.php");
67 require_once("../../custom/code_types.inc.php");
69 $currdecimals = $GLOBALS['currency_decimals'];
71 $INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2;
73 $details = empty($_GET['details']) ? 0 : 1;
75 $patient_id = empty($_GET['ptid']) ? $pid : 0 + $_GET['ptid'];
77 // Get the patient's name and chart number.
78 $patdata = getPatientData($patient_id, 'fname,mname,lname,pubpid,street,city,state,postal_code');
80 // Get the "next invoice reference number" from this user's pool.
82 function getInvoiceRefNumber() {
83 $trow = sqlQuery("SELECT lo.notes " .
84 "FROM users AS u, list_options AS lo " .
85 "WHERE u.username = ? AND " .
86 "lo.list_id = 'irnpool' AND lo.option_id = u.irnpool LIMIT 1", array($_SESSION['authUser']) );
87 return empty($trow['notes']) ? '' : $trow['notes'];
90 // Increment the "next invoice reference number" of this user's pool.
91 // This identifies the "digits" portion of that number and adds 1 to it.
92 // If it contains more than one string of digits, the last is used.
94 function updateInvoiceRefNumber() {
95 $irnumber = getInvoiceRefNumber();
96 // Here "?" specifies a minimal match, to get the most digits possible:
97 if (preg_match('/^(.*?)(\d+)(\D*)$/', $irnumber, $matches)) {
98 $newdigs = sprintf('%0' . strlen($matches[2]) . 'd', $matches[2] + 1);
99 $newnumber = $matches[1] . $newdigs . $matches[3];
100 sqlStatement("UPDATE users AS u, list_options AS lo " .
101 "SET lo.notes = ? WHERE " .
102 "u.username = ? AND " .
103 "lo.list_id = 'irnpool' AND lo.option_id = u.irnpool", array($newnumber,$_SESSION['authUser']) );
105 return $irnumber;
108 //////////////////////////////////////////////////////////////////////
109 // The following functions are inline here temporarily, and should be
110 // moved to an includable module for common use. In particular
111 // WSClaim.class.php should be rewritten to use them.
112 //////////////////////////////////////////////////////////////////////
114 // Initialize the array of invoice information for posting to the
115 // accounting system.
117 function invoice_initialize(& $invoice_info, $patient_id, $provider_id,
118 $payer_id = 0, $encounter = 0, $dosdate = '')
120 $db = $GLOBALS['adodb']['db'];
122 // Get foreign ID (customer) for patient.
123 $sql = "SELECT foreign_id from integration_mapping as im " .
124 "LEFT JOIN patient_data as pd on im.local_id=pd.id " .
125 "where pd.pid = ? and im.local_table='patient_data' and im.foreign_table='customer'";
126 $result = $db->Execute($sql, array($patient_id) );
127 if($result && !$result->EOF) {
128 $foreign_patient_id = $result->fields['foreign_id'];
130 else {
131 return "Patient '" . $patient_id . "' has not yet been posted to the accounting system.";
134 // Get foreign ID (salesman) for provider.
135 $sql = "SELECT foreign_id from integration_mapping WHERE " .
136 "local_id = ? AND local_table='users' and foreign_table='salesman'";
137 $result = $db->Execute($sql, array($provider_id) );
138 if($result && !$result->EOF) {
139 $foreign_provider_id = $result->fields['foreign_id'];
141 else {
142 return "Provider '" . $provider_id . "' has not yet been posted to the accounting system.";
145 // Get foreign ID (customer) for insurance payer.
146 if ($payer_id && ! $GLOBALS['insurance_companies_are_not_customers']) {
147 $sql = "SELECT foreign_id from integration_mapping WHERE " .
148 "local_id = ? AND local_table = 'insurance_companies' AND foreign_table='customer'";
149 $result = $db->Execute($sql, array($payer_id) );
150 if($result && !$result->EOF) {
151 $foreign_payer_id = $result->fields['foreign_id'];
153 else {
154 return "Payer '" . $payer_id . "' has not yet been posted to the accounting system.";
156 } else {
157 $foreign_payer_id = $payer_id;
160 // Create invoice notes for the new invoice that list the patient's
161 // insurance plans. This is so that when payments are posted, the user
162 // can easily see if a secondary claim needs to be submitted.
164 $insnotes = "";
165 $insno = 0;
166 foreach (array("primary", "secondary", "tertiary") as $instype) {
167 ++$insno;
168 $sql = "SELECT insurance_companies.name " .
169 "FROM insurance_data, insurance_companies WHERE " .
170 "insurance_data.pid = ? AND " .
171 "insurance_data.type = ? AND " .
172 "insurance_companies.id = insurance_data.provider " .
173 "ORDER BY insurance_data.date DESC LIMIT 1";
174 $result = $db->Execute($sql, array($patient_id,$instype) );
175 if ($result && !$result->EOF && $result->fields['name']) {
176 if ($insnotes) $insnotes .= "\n";
177 $insnotes .= "Ins$insno: " . $result->fields['name'];
180 $invoice_info['notes'] = $insnotes;
182 if (preg_match("/(\d\d\d\d)\D*(\d\d)\D*(\d\d)/", $dosdate, $matches)) {
183 $dosdate = $matches[2] . '-' . $matches[3] . '-' . $matches[1];
184 } else {
185 $dosdate = date("m-d-Y");
188 $invoice_info['salesman'] = $foreign_provider_id;
189 $invoice_info['customerid'] = $foreign_patient_id;
190 $invoice_info['payer_id'] = $foreign_payer_id;
191 $invoice_info['invoicenumber'] = $patient_id . "." . $encounter;
192 $invoice_info['dosdate'] = $dosdate;
193 $invoice_info['items'] = array();
194 $invoice_info['total'] = '0.00';
196 return '';
199 function invoice_add_line_item(& $invoice_info, $code_type, $code,
200 $code_text, $amount, $units=1)
202 $units = max(1, intval(trim($units)));
203 $amount = sprintf("%01.2f", $amount);
204 $price = $amount / $units;
205 $tmp = sprintf("%01.2f", $price);
206 if (abs($price - $tmp) < 0.000001) $price = $tmp;
207 $tii = array();
208 $tii['maincode'] = $code;
209 $tii['itemtext'] = "$code_type:$code";
210 if ($code_text) $tii['itemtext'] .= " $code_text";
211 $tii['qty'] = $units;
212 $tii['price'] = $price;
213 $tii['glaccountid'] = $GLOBALS['oer_config']['ws_accounting']['income_acct'];
214 $invoice_info['total'] = sprintf("%01.2f", $invoice_info['total'] + $amount);
215 $invoice_info['items'][] = $tii;
216 return '';
219 function invoice_post(& $invoice_info)
221 $function['ezybiz.add_invoice'] = array(new xmlrpcval($invoice_info, "struct"));
223 list($name, $var) = each($function);
224 $f = new xmlrpcmsg($name, $var);
226 $c = new xmlrpc_client($GLOBALS['oer_config']['ws_accounting']['url'],
227 $GLOBALS['oer_config']['ws_accounting']['server'],
228 $GLOBALS['oer_config']['ws_accounting']['port']);
230 $c->setCredentials($GLOBALS['oer_config']['ws_accounting']['username'],
231 $GLOBALS['oer_config']['ws_accounting']['password']);
233 $r = $c->send($f);
234 if (!$r) return "XMLRPC send failed";
236 // We are not doing anything with the return value yet... should we?
237 $tv = $r->value();
238 if (is_object($tv)) {
239 $value = $tv->getval();
241 else {
242 $value = null;
245 if ($r->faultCode()) {
246 return "Fault: Code: " . $r->faultCode() . " Reason '" . $r->faultString() . "'";
249 return '';
252 ///////////// End of SQL-Ledger invoice posting functions ////////////
254 // Output HTML for an invoice line item.
256 $prevsvcdate = '';
257 function receiptDetailLine($svcdate, $description, $amount, $quantity) {
258 global $prevsvcdate, $details;
259 if (!$details) return;
260 $amount = sprintf('%01.2f', $amount);
261 if (empty($quantity)) $quantity = 1;
262 $price = sprintf('%01.4f', $amount / $quantity);
263 $tmp = sprintf('%01.2f', $price);
264 if ($price == $tmp) $price = $tmp;
265 echo " <tr>\n";
266 echo " <td>" . ($svcdate == $prevsvcdate ? '&nbsp;' : text(oeFormatShortDate($svcdate))) . "</td>\n";
267 echo " <td>" . text($description) . "</td>\n";
268 echo " <td align='right'>" . text(oeFormatMoney($price)) . "</td>\n";
269 echo " <td align='right'>" . text($quantity) . "</td>\n";
270 echo " <td align='right'>" . text(oeFormatMoney($amount)) . "</td>\n";
271 echo " </tr>\n";
272 $prevsvcdate = $svcdate;
275 // Output HTML for an invoice payment.
277 function receiptPaymentLine($paydate, $amount, $description='') {
278 $amount = sprintf('%01.2f', 0 - $amount); // make it negative
279 echo " <tr>\n";
280 echo " <td>" . text(oeFormatShortDate($paydate)) . "</td>\n";
281 echo " <td>" . xlt('Payment') . " " . text($description) . "</td>\n";
282 echo " <td colspan='2'>&nbsp;</td>\n";
283 echo " <td align='right'>" . text(oeFormatMoney($amount)) . "</td>\n";
284 echo " </tr>\n";
287 // Generate a receipt from the last-billed invoice for this patient,
288 // or for the encounter specified as a GET parameter.
290 function generate_receipt($patient_id, $encounter=0) {
291 global $sl_err, $sl_cash_acc, $css_header, $details, $INTEGRATED_AR;
293 // Get details for what we guess is the primary facility.
294 $frow = sqlQuery("SELECT * FROM facility " .
295 "ORDER BY billing_location DESC, accepts_assignment DESC, id LIMIT 1");
297 $patdata = getPatientData($patient_id, 'fname,mname,lname,pubpid,street,city,state,postal_code,providerID');
299 // Get the most recent invoice data or that for the specified encounter.
301 // Adding a provider check so that their info can be displayed on receipts
302 if ($INTEGRATED_AR) {
303 if ($encounter) {
304 $ferow = sqlQuery("SELECT id, date, encounter, provider_id FROM form_encounter " .
305 "WHERE pid = ? AND encounter = ?", array($patient_id,$encounter) );
306 } else {
307 $ferow = sqlQuery("SELECT id, date, encounter, provider_id FROM form_encounter " .
308 "WHERE pid = ? " .
309 "ORDER BY id DESC LIMIT 1", array($patient_id) );
311 if (empty($ferow)) die(xlt("This patient has no activity."));
312 $trans_id = $ferow['id'];
313 $encounter = $ferow['encounter'];
314 $svcdate = substr($ferow['date'], 0, 10);
316 if ($GLOBALS['receipts_by_provider']){
317 if (isset($ferow['provider_id']) ) {
318 $encprovider = $ferow['provider_id'];
319 } else if (isset($patdata['providerID'])){
320 $encprovider = $patdata['providerID'];
321 } else { $encprovider = -1; }
324 if ($encprovider){
325 $providerrow = sqlQuery("SELECT fname, mname, lname, title, street, streetb, " .
326 "city, state, zip, phone, fax FROM users WHERE id = ?", array($encprovider) );
329 else {
330 SLConnect();
332 $arres = SLQuery("SELECT * FROM ar WHERE " .
333 "invnumber LIKE '$patient_id.%' " .
334 "ORDER BY id DESC LIMIT 1");
335 if ($sl_err) die(text($sl_err));
336 if (!SLRowCount($arres)) die(xlt("This patient has no activity."));
337 $arrow = SLGetRow($arres, 0);
339 $trans_id = $arrow['id'];
341 // Determine the date of service. An 8-digit encounter number is
342 // presumed to be a date of service imported during conversion or
343 // associated with prescriptions only. Otherwise look it up in the
344 // form_encounter table.
346 $svcdate = "";
347 list($trash, $encounter) = explode(".", $arrow['invnumber']);
348 if (strlen($encounter) >= 8) {
349 $svcdate = substr($encounter, 0, 4) . "-" . substr($encounter, 4, 2) .
350 "-" . substr($encounter, 6, 2);
352 else if ($encounter) {
353 $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " .
354 "encounter = ?", array($encounter) );
355 $svcdate = substr($tmp['date'], 0, 10);
357 } // end not $INTEGRATED_AR
359 // Get invoice reference number.
360 $encrow = sqlQuery("SELECT invoice_refno FROM form_encounter WHERE " .
361 "pid = ? AND encounter = ? LIMIT 1", array($patient_id,$encounter) );
362 $invoice_refno = $encrow['invoice_refno'];
364 <html>
365 <head>
366 <?php html_header_show(); ?>
367 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
368 <title><?php echo xlt('Receipt for Payment'); ?></title>
369 <script type="text/javascript" src="../../library/dialog.js"></script>
370 <script language="JavaScript">
372 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
374 // Process click on Print button.
375 function printme() {
376 var divstyle = document.getElementById('hideonprint').style;
377 divstyle.display = 'none';
378 window.print();
379 return false;
382 // Process click on Delete button.
383 function deleteme() {
384 dlgopen('deleter.php?billing=<?php echo attr("$patient_id.$encounter"); ?>', '_blank', 500, 450);
385 return false;
388 // Called by the deleteme.php window on a successful delete.
389 function imdeleted() {
390 window.close();
393 </script>
394 </head>
395 <body class="body_top">
396 <center>
397 <?php
398 if ( $GLOBALS['receipts_by_provider'] && !empty($providerrow) ) { printProviderHeader($providerrow); }
399 else { printFacilityHeader($frow); }
401 <?php
402 echo xlt("Receipt Generated") . ":" . text(date(' F j, Y'));
403 if ($invoice_refno) echo " " . xlt("Invoice Number") . ": " . text($invoice_refno) . " " . xlt("Service Date") . ": " . text($svcdate);
405 <br>&nbsp;
406 </b></p>
407 </center>
409 <?php echo text($patdata['fname']) . ' ' . text($patdata['mname']) . ' ' . text($patdata['lname']) ?>
410 <br><?php echo text($patdata['street']) ?>
411 <br><?php echo text($patdata['city']) . ', ' . text($patdata['state']) . ' ' . text($patdata['postal_code']) ?>
412 <br>&nbsp;
413 </p>
414 <center>
415 <table cellpadding='5'>
416 <tr>
417 <td><b><?php echo xlt('Date'); ?></b></td>
418 <td><b><?php echo xlt('Description'); ?></b></td>
419 <td align='right'><b><?php echo $details ? xlt('Price') : '&nbsp;'; ?></b></td>
420 <td align='right'><b><?php echo $details ? xlt('Qty' ) : '&nbsp;'; ?></b></td>
421 <td align='right'><b><?php echo xlt('Total'); ?></b></td>
422 </tr>
424 <?php
425 $charges = 0.00;
427 if ($INTEGRATED_AR) {
428 // Product sales
429 $inres = sqlStatement("SELECT s.sale_id, s.sale_date, s.fee, " .
430 "s.quantity, s.drug_id, d.name " .
431 "FROM drug_sales AS s LEFT JOIN drugs AS d ON d.drug_id = s.drug_id " .
432 // "WHERE s.pid = '$patient_id' AND s.encounter = '$encounter' AND s.fee != 0 " .
433 "WHERE s.pid = ? AND s.encounter = ? " .
434 "ORDER BY s.sale_id", array($patient_id,$encounter) );
435 while ($inrow = sqlFetchArray($inres)) {
436 $charges += sprintf('%01.2f', $inrow['fee']);
437 receiptDetailLine($inrow['sale_date'], $inrow['name'],
438 $inrow['fee'], $inrow['quantity']);
440 // Service and tax items
441 $inres = sqlStatement("SELECT * FROM billing WHERE " .
442 "pid = ? AND encounter = ? AND " .
443 // "code_type != 'COPAY' AND activity = 1 AND fee != 0 " .
444 "code_type != 'COPAY' AND activity = 1 " .
445 "ORDER BY id", array($patient_id,$encounter) );
446 while ($inrow = sqlFetchArray($inres)) {
447 $charges += sprintf('%01.2f', $inrow['fee']);
448 receiptDetailLine($svcdate, $inrow['code_text'],
449 $inrow['fee'], $inrow['units']);
451 // Adjustments.
452 $inres = sqlStatement("SELECT " .
453 "a.code_type, a.code, a.modifier, a.memo, a.payer_type, a.adj_amount, a.pay_amount, " .
454 "s.payer_id, s.reference, s.check_date, s.deposit_date " .
455 "FROM ar_activity AS a " .
456 "LEFT JOIN ar_session AS s ON s.session_id = a.session_id WHERE " .
457 "a.pid = ? AND a.encounter = ? AND " .
458 "a.adj_amount != 0 " .
459 "ORDER BY s.check_date, a.sequence_no", array($patient_id,$encounter) );
460 while ($inrow = sqlFetchArray($inres)) {
461 $charges -= sprintf('%01.2f', $inrow['adj_amount']);
462 $payer = empty($inrow['payer_type']) ? 'Pt' : ('Ins' . $inrow['payer_type']);
463 receiptDetailLine($svcdate, $payer . ' ' . $inrow['memo'],
464 0 - $inrow['adj_amount'], 1);
466 } // end $INTEGRATED_AR
467 else {
468 // Request all line items with money belonging to the invoice.
469 $inres = SLQuery("SELECT * FROM invoice WHERE " .
470 "trans_id = $trans_id AND sellprice != 0 ORDER BY id");
471 if ($sl_err) die($sl_err);
472 for ($irow = 0; $irow < SLRowCount($inres); ++$irow) {
473 $row = SLGetRow($inres, $irow);
474 $amount = sprintf('%01.2f', $row['sellprice'] * $row['qty']);
475 $charges += $amount;
476 $desc = preg_replace('/^.{1,6}:/', '', $row['description']);
477 receiptDetailLine($svcdate, $desc, $amount, $row['qty']);
479 } // end not $INTEGRATED_AR
482 <tr>
483 <td colspan='5'>&nbsp;</td>
484 </tr>
485 <tr>
486 <td><?php echo text(oeFormatShortDate($svcdispdate)); ?></td>
487 <td><b><?php echo xlt('Total Charges'); ?></b></td>
488 <td align='right'>&nbsp;</td>
489 <td align='right'>&nbsp;</td>
490 <td align='right'><?php echo text(oeFormatMoney($charges, true)) ?></td>
491 </tr>
492 <tr>
493 <td colspan='5'>&nbsp;</td>
494 </tr>
496 <?php
497 if ($INTEGRATED_AR) {
498 // Get co-pays.
499 $inres = sqlStatement("SELECT fee, code_text FROM billing WHERE " .
500 "pid = ? AND encounter = ? AND " .
501 "code_type = 'COPAY' AND activity = 1 AND fee != 0 " .
502 "ORDER BY id", array($patient_id,$encounter) );
503 while ($inrow = sqlFetchArray($inres)) {
504 $charges += sprintf('%01.2f', $inrow['fee']);
505 receiptPaymentLine($svcdate, 0 - $inrow['fee'], $inrow['code_text']);
507 // Get other payments.
508 $inres = sqlStatement("SELECT " .
509 "a.code_type, a.code, a.modifier, a.memo, a.payer_type, a.adj_amount, a.pay_amount, " .
510 "s.payer_id, s.reference, s.check_date, s.deposit_date " .
511 "FROM ar_activity AS a " .
512 "LEFT JOIN ar_session AS s ON s.session_id = a.session_id WHERE " .
513 "a.pid = ? AND a.encounter = ? AND " .
514 "a.pay_amount != 0 " .
515 "ORDER BY s.check_date, a.sequence_no", array($patient_id,$encounter) );
516 while ($inrow = sqlFetchArray($inres)) {
517 $payer = empty($inrow['payer_type']) ? 'Pt' : ('Ins' . $inrow['payer_type']);
518 $charges -= sprintf('%01.2f', $inrow['pay_amount']);
519 receiptPaymentLine($svcdate, $inrow['pay_amount'],
520 $payer . ' ' . $inrow['reference']);
522 } // end $INTEGRATED_AR
523 else {
524 $chart_id_cash = SLQueryValue("select id from chart where accno = '$sl_cash_acc'");
525 if ($sl_err) die($sl_err);
526 if (! $chart_id_cash) die("There is no COA entry for cash account '$sl_cash_acc'");
528 // Request all cash entries belonging to the invoice.
529 $atres = SLQuery("SELECT * FROM acc_trans WHERE " .
530 "trans_id = $trans_id AND chart_id = $chart_id_cash ORDER BY transdate");
531 if ($sl_err) die($sl_err);
533 for ($irow = 0; $irow < SLRowCount($atres); ++$irow) {
534 $row = SLGetRow($atres, $irow);
535 $amount = sprintf('%01.2f', $row['amount']); // negative
536 $charges += $amount;
537 $rowsource = $row['source'];
538 if (strtolower($rowsource) == 'co-pay') $rowsource = '';
539 receiptPaymentLine($row['transdate'], 0 - $amount, $rowsource);
541 } // end not $INTEGRATED_AR
543 <tr>
544 <td colspan='5'>&nbsp;</td>
545 </tr>
546 <tr>
547 <td>&nbsp;</td>
548 <td><b><?php echo xlt('Balance Due'); ?></b></td>
549 <td colspan='2'>&nbsp;</td>
550 <td align='right'><?php echo text(oeFormatMoney($charges, true)) ?></td>
551 </tr>
552 </table>
553 </center>
554 <div id='hideonprint'>
556 &nbsp;
557 <a href='#' onclick='return printme();'><?php echo xlt('Print'); ?></a>
558 <?php if (acl_check('acct','disc')) { ?>
559 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
560 <a href='#' onclick='return deleteme();'><?php echo xlt('Undo Checkout'); ?></a>
561 <?php } ?>
562 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
563 <?php if ($details) { ?>
564 <a href='pos_checkout.php?details=0&ptid=<?php echo attr($patient_id); ?>&enc=<?php echo attr($encounter); ?>' onclick='top.restoreSession()'><?php echo xlt('Hide Details'); ?></a>
565 <?php } else { ?>
566 <a href='pos_checkout.php?details=1&ptid=<?php echo attr($patient_id); ?>&enc=<?php echo attr($encounter); ?>' onclick='top.restoreSession()'><?php echo xlt('Show Details'); ?></a>
567 <?php } ?>
568 </p>
569 </div>
570 </body>
571 </html>
572 <?php
573 if (!$INTEGRATED_AR) SLClose();
574 } // end function generate_receipt()
576 // Function to output a line item for the input form.
578 $lino = 0;
579 function write_form_line($code_type, $code, $id, $date, $description,
580 $amount, $units, $taxrates) {
581 global $lino;
582 $amount = sprintf("%01.2f", $amount);
583 if (empty($units)) $units = 1;
584 $price = $amount / $units; // should be even cents, but ok here if not
585 if ($code_type == 'COPAY' && !$description) $description = xl('Payment');
586 echo " <tr>\n";
587 echo " <td>" . text(oeFormatShortDate($date));
588 echo "<input type='hidden' name='line[$lino][code_type]' value='" . attr($code_type) . "'>";
589 echo "<input type='hidden' name='line[$lino][code]' value='" . attr($code) . "'>";
590 echo "<input type='hidden' name='line[$lino][id]' value='" . attr($id) . "'>";
591 echo "<input type='hidden' name='line[$lino][description]' value='" . attr($description) . "'>";
592 echo "<input type='hidden' name='line[$lino][taxrates]' value='" . attr($taxrates) . "'>";
593 echo "<input type='hidden' name='line[$lino][price]' value='" . attr($price) . "'>";
594 echo "<input type='hidden' name='line[$lino][units]' value='" . attr($units) . "'>";
595 echo "</td>\n";
596 echo " <td>" . text($description) . "</td>";
597 echo " <td align='right'>" . text($units) . "</td>";
598 echo " <td align='right'><input type='text' name='line[$lino][amount]' " .
599 "value='" . attr($amount) . "' size='6' maxlength='8'";
600 // Modifying prices requires the acct/disc permission.
601 // if ($code_type == 'TAX' || ($code_type != 'COPAY' && !acl_check('acct','disc')))
602 echo " style='text-align:right;background-color:transparent' readonly";
603 // else echo " style='text-align:right' onkeyup='computeTotals()'";
604 echo "></td>\n";
605 echo " </tr>\n";
606 ++$lino;
609 // Create the taxes array. Key is tax id, value is
610 // (description, rate, accumulated total).
611 $taxes = array();
612 $pres = sqlStatement("SELECT option_id, title, option_value " .
613 "FROM list_options WHERE list_id = 'taxrate' ORDER BY seq");
614 while ($prow = sqlFetchArray($pres)) {
615 $taxes[$prow['option_id']] = array($prow['title'], $prow['option_value'], 0);
618 // Print receipt header for facility
619 function printFacilityHeader($frow){
620 echo "<p><b>" . text($frow['name']) .
621 "<br>" . text($frow['street']) .
622 "<br>" . text($frow['city']) . ', ' . text($frow['state']) . ' ' . text($frow['postal_code']) .
623 "<br>" . text($frow['phone']) .
624 "<br>&nbsp" .
625 "<br>";
628 // Pring receipt header for Provider
629 function printProviderHeader($pvdrow){
630 echo "<p><b>" . text($pvdrow['title']) . " " . text($pvdrow['fname']) . " " . text($pvdrow['mname']) . " " . text($pvdrow['lname']) . " " .
631 "<br>" . text($pvdrow['street']) .
632 "<br>" . text($pvdrow['city']) . ', ' . text($pvdrow['state']) . ' ' . text($pvdrow['postal_code']) .
633 "<br>" . text($pvdrow['phone']) .
634 "<br>&nbsp" .
635 "<br>";
638 // Mark the tax rates that are referenced in this invoice.
639 function markTaxes($taxrates) {
640 global $taxes;
641 $arates = explode(':', $taxrates);
642 if (empty($arates)) return;
643 foreach ($arates as $value) {
644 if (!empty($taxes[$value])) $taxes[$value][2] = '1';
648 $payment_methods = array(
649 'Cash',
650 'Check',
651 'MC',
652 'VISA',
653 'AMEX',
654 'DISC',
655 'Other');
657 $alertmsg = ''; // anything here pops up in an alert box
659 // If the Save button was clicked...
661 if ($_POST['form_save']) {
663 // On a save, do the following:
664 // Flag drug_sales and billing items as billed.
665 // Post the corresponding invoice with its payment(s) to sql-ledger
666 // and be careful to use a unique invoice number.
667 // Call the generate-receipt function.
668 // Exit.
670 $form_pid = $_POST['form_pid'];
671 $form_encounter = $_POST['form_encounter'];
673 // Get the posting date from the form as yyyy-mm-dd.
674 $dosdate = date("Y-m-d");
675 if (preg_match("/(\d\d\d\d)\D*(\d\d)\D*(\d\d)/", $_POST['form_date'], $matches)) {
676 $dosdate = $matches[1] . '-' . $matches[2] . '-' . $matches[3];
679 // If there is no associated encounter (i.e. this invoice has only
680 // prescriptions) then assign an encounter number of the service
681 // date, with an optional suffix to ensure that it's unique.
683 if (! $form_encounter) {
684 $form_encounter = substr($dosdate,0,4) . substr($dosdate,5,2) . substr($dosdate,8,2);
685 $tmp = '';
686 if ($INTEGRATED_AR) {
687 while (true) {
688 $ferow = sqlQuery("SELECT id FROM form_encounter WHERE " .
689 "pid = ? AND encounter = ?", array($form_pid, $form_encounter.$tmp) );
690 if (empty($ferow)) break;
691 $tmp = $tmp ? $tmp + 1 : 1;
694 else {
695 SLConnect();
696 while (SLQueryValue("select id from ar where " .
697 "invnumber = '$form_pid.$form_encounter$tmp'")) {
698 $tmp = $tmp ? $tmp + 1 : 1;
700 SLClose();
702 $form_encounter .= $tmp;
705 if ($INTEGRATED_AR) {
706 // Delete any TAX rows from billing because they will be recalculated.
707 sqlStatement("UPDATE billing SET activity = 0 WHERE " .
708 "pid = ? AND encounter = ? AND " .
709 "code_type = 'TAX'", array($form_pid,$form_encounter) );
711 else {
712 // Initialize an array of invoice information for posting.
713 $invoice_info = array();
714 $msg = invoice_initialize($invoice_info, $form_pid,
715 $_POST['form_provider'], $_POST['form_payer'], $form_encounter, $dosdate);
716 if ($msg) die($msg);
719 $form_amount = $_POST['form_amount'];
720 $lines = $_POST['line'];
722 for ($lino = 0; $lines[$lino]['code_type']; ++$lino) {
723 $line = $lines[$lino];
724 $code_type = $line['code_type'];
725 $id = $line['id'];
726 $amount = sprintf('%01.2f', trim($line['amount']));
728 if (!$INTEGRATED_AR) {
729 $msg = invoice_add_line_item($invoice_info, $code_type,
730 $line['code'], $line['description'], $amount, $line['units']);
731 if ($msg) die($msg);
734 if ($code_type == 'PROD') {
735 // Product sales. The fee and encounter ID may have changed.
736 $query = "update drug_sales SET fee = ?, " .
737 "encounter = ?, billed = 1 WHERE " .
738 "sale_id = ?";
739 sqlQuery($query, array($amount,$form_encounter,$id) );
741 else if ($code_type == 'TAX') {
742 // In the SL case taxes show up on the invoice as line items.
743 // Otherwise we gotta save them somewhere, and in the billing
744 // table with a code type of TAX seems easiest.
745 // They will have to be stripped back out when building this
746 // script's input form.
747 addBilling($form_encounter, 'TAX', 'TAX', 'Taxes', $form_pid, 0, 0,
748 '', '', $amount, '', '', 1);
750 else {
751 // Because there is no insurance here, there is no need for a claims
752 // table entry and so we do not call updateClaim(). Note we should not
753 // eliminate billed and bill_date from the billing table!
754 $query = "UPDATE billing SET fee = ?, billed = 1, " .
755 "bill_date = NOW() WHERE id = ?";
756 sqlQuery($query, array($amount,$id) );
760 // Post discount.
761 if ($_POST['form_discount']) {
762 if ($GLOBALS['discount_by_money']) {
763 $amount = sprintf('%01.2f', trim($_POST['form_discount']));
765 else {
766 $amount = sprintf('%01.2f', trim($_POST['form_discount']) * $form_amount / 100);
768 $memo = xl('Discount');
769 if ($INTEGRATED_AR) {
770 $time = date('Y-m-d H:i:s');
771 $query = "INSERT INTO ar_activity ( " .
772 "pid, encounter, code, modifier, payer_type, post_user, post_time, " .
773 "session_id, memo, adj_amount " .
774 ") VALUES ( " .
775 "?, " .
776 "?, " .
777 "'', " .
778 "'', " .
779 "'0', " .
780 "?, " .
781 "?, " .
782 "'0', " .
783 "?, " .
784 "? " .
785 ")";
786 sqlStatement($query, array($form_pid,$form_encounter,$_SESSION['authUserID'],$time,$memo,$amount) );
788 else {
789 $msg = invoice_add_line_item($invoice_info, 'DISCOUNT',
790 '', $memo, 0 - $amount);
791 if ($msg) die($msg);
795 // Post payment.
796 if ($_POST['form_amount']) {
797 $amount = sprintf('%01.2f', trim($_POST['form_amount']));
798 $form_source = trim($_POST['form_source']);
799 $paydesc = trim($_POST['form_method']);
800 if ($INTEGRATED_AR) {
801 //Fetching the existing code and modifier
802 $ResultSearchNew = sqlStatement("SELECT * FROM billing LEFT JOIN code_types ON billing.code_type=code_types.ct_key ".
803 "WHERE code_types.ct_fee=1 AND billing.activity!=0 AND billing.pid =? AND encounter=? ORDER BY billing.code,billing.modifier",
804 array($form_pid,$form_encounter));
805 if($RowSearch = sqlFetchArray($ResultSearchNew))
807 $Codetype=$RowSearch['code_type'];
808 $Code=$RowSearch['code'];
809 $Modifier=$RowSearch['modifier'];
810 }else{
811 $Codetype='';
812 $Code='';
813 $Modifier='';
815 $session_id=idSqlStatement("INSERT INTO ar_session (payer_id,user_id,reference,check_date,deposit_date,pay_total,".
816 " global_amount,payment_type,description,patient_id,payment_method,adjustment_code,post_to_date) ".
817 " VALUES ('0',?,?,now(),?,?,'','patient','COPAY',?,?,'patient_payment',now())",
818 array($_SESSION['authId'],$form_source,$dosdate,$amount,$form_pid,$paydesc));
819 $insrt_id=idSqlStatement("INSERT INTO ar_activity (pid,encounter,code_type,code,modifier,payer_type,post_time,post_user,session_id,pay_amount,account_code)".
820 " VALUES (?,?,?,?,?,0,?,?,?,?,'PCP')",
821 array($form_pid,$form_encounter,$Codetype,$Code,$Modifier,$dosdate,$_SESSION['authId'],$session_id,$amount));
823 else {
824 $msg = invoice_add_line_item($invoice_info, 'COPAY',
825 $paydesc, $form_source, 0 - $amount);
826 if ($msg) die($msg);
830 if (!$INTEGRATED_AR) {
831 $msg = invoice_post($invoice_info);
832 if ($msg) die($msg);
835 // If applicable, set the invoice reference number.
836 $invoice_refno = '';
837 if (isset($_POST['form_irnumber'])) {
838 $invoice_refno = trim($_POST['form_irnumber']);
840 else {
841 $invoice_refno = updateInvoiceRefNumber();
843 if ($invoice_refno) {
844 sqlStatement("UPDATE form_encounter " .
845 "SET invoice_refno = ? " .
846 "WHERE pid = ? AND encounter = ?", array($invoice_refno,$form_pid,$form_encounter) );
849 generate_receipt($form_pid, $form_encounter);
850 exit();
853 // If an encounter ID was given, then we must generate a receipt.
855 if (!empty($_GET['enc'])) {
856 generate_receipt($patient_id, $_GET['enc']);
857 exit();
860 // Get the unbilled billing table items for this patient.
861 $query = "SELECT id, date, code_type, code, modifier, code_text, " .
862 "provider_id, payer_id, units, fee, encounter " .
863 "FROM billing WHERE pid = ? AND activity = 1 AND " .
864 "billed = 0 AND code_type != 'TAX' " .
865 "ORDER BY encounter DESC, id ASC";
866 $bres = sqlStatement($query, array($patient_id) );
868 // Get the product sales for this patient.
869 $query = "SELECT s.sale_id, s.sale_date, s.prescription_id, s.fee, " .
870 "s.quantity, s.encounter, s.drug_id, d.name, r.provider_id " .
871 "FROM drug_sales AS s " .
872 "LEFT JOIN drugs AS d ON d.drug_id = s.drug_id " .
873 "LEFT OUTER JOIN prescriptions AS r ON r.id = s.prescription_id " .
874 "WHERE s.pid = ? AND s.billed = 0 " .
875 "ORDER BY s.encounter DESC, s.sale_id ASC";
876 $dres = sqlStatement($query, array($patient_id) );
878 // If there are none, just redisplay the last receipt and exit.
880 if (sqlNumRows($bres) == 0 && sqlNumRows($dres) == 0) {
881 generate_receipt($patient_id);
882 exit();
885 // Get the valid practitioners, including those not active.
886 $arr_users = array();
887 $ures = sqlStatement("SELECT id, username FROM users WHERE " .
888 "( authorized = 1 OR info LIKE '%provider%' ) AND username != ''");
889 while ($urow = sqlFetchArray($ures)) {
890 $arr_users[$urow['id']] = '1';
893 // Now write a data entry form:
894 // List unbilled billing items (cpt, hcpcs, copays) for the patient.
895 // List unbilled product sales for the patient.
896 // Present an editable dollar amount for each line item, a total
897 // which is also the default value of the input payment amount,
898 // and OK and Cancel buttons.
900 <html>
901 <head>
902 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
903 <title><?php echo xlt('Patient Checkout'); ?></title>
904 <style>
905 </style>
906 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
907 <script type="text/javascript" src="../../library/textformat.js"></script>
908 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
909 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
910 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
911 <script type="text/javascript" src="../../library/dialog.js"></script>
912 <script type="text/javascript" src="../../library/js/jquery-1.2.2.min.js"></script>
913 <script language="JavaScript">
914 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
916 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
918 // This clears the tax line items in preparation for recomputing taxes.
919 function clearTax(visible) {
920 var f = document.forms[0];
921 for (var lino = 0; true; ++lino) {
922 var pfx = 'line[' + lino + ']';
923 if (! f[pfx + '[code_type]']) break;
924 if (f[pfx + '[code_type]'].value != 'TAX') continue;
925 f[pfx + '[price]'].value = '0.00';
926 if (visible) f[pfx + '[amount]'].value = '0.00';
930 // For a given tax ID and amount, compute the tax on that amount and add it
931 // to the "price" (same as "amount") of the corresponding tax line item.
932 // Note the tax line items include their "taxrate" to make this easy.
933 function addTax(rateid, amount, visible) {
934 if (rateid.length == 0) return 0;
935 var f = document.forms[0];
936 for (var lino = 0; true; ++lino) {
937 var pfx = 'line[' + lino + ']';
938 if (! f[pfx + '[code_type]']) break;
939 if (f[pfx + '[code_type]'].value != 'TAX') continue;
940 if (f[pfx + '[code]'].value != rateid) continue;
941 var tax = amount * parseFloat(f[pfx + '[taxrates]'].value);
942 tax = parseFloat(tax.toFixed(<?php echo $currdecimals ?>));
943 var cumtax = parseFloat(f[pfx + '[price]'].value) + tax;
944 f[pfx + '[price]'].value = cumtax.toFixed(<?php echo $currdecimals ?>); // requires JS 1.5
945 if (visible) f[pfx + '[amount]'].value = cumtax.toFixed(<?php echo $currdecimals ?>); // requires JS 1.5
946 if (isNaN(tax)) alert('Tax rate not numeric at line ' + lino);
947 return tax;
949 return 0;
952 // This mess recomputes the invoice total and optionally applies a discount.
953 function computeDiscountedTotals(discount, visible) {
954 clearTax(visible);
955 var f = document.forms[0];
956 var total = 0.00;
957 for (var lino = 0; f['line[' + lino + '][code_type]']; ++lino) {
958 var code_type = f['line[' + lino + '][code_type]'].value;
959 // price is price per unit when the form was originally generated.
960 // By contrast, amount is the dynamically-generated discounted line total.
961 var price = parseFloat(f['line[' + lino + '][price]'].value);
962 if (isNaN(price)) alert('Price not numeric at line ' + lino);
963 if (code_type == 'COPAY' || code_type == 'TAX') {
964 // This works because the tax lines come last.
965 total += parseFloat(price.toFixed(<?php echo $currdecimals ?>));
966 continue;
968 var units = f['line[' + lino + '][units]'].value;
969 var amount = price * units;
970 amount = parseFloat(amount.toFixed(<?php echo $currdecimals ?>));
971 if (visible) f['line[' + lino + '][amount]'].value = amount.toFixed(<?php echo $currdecimals ?>);
972 total += amount;
973 var taxrates = f['line[' + lino + '][taxrates]'].value;
974 var taxids = taxrates.split(':');
975 for (var j = 0; j < taxids.length; ++j) {
976 addTax(taxids[j], amount, visible);
979 return total - discount;
982 // Recompute displayed amounts with any discount applied.
983 function computeTotals() {
984 var f = document.forms[0];
985 var discount = parseFloat(f.form_discount.value);
986 if (isNaN(discount)) discount = 0;
987 <?php if (!$GLOBALS['discount_by_money']) { ?>
988 // This site discounts by percentage, so convert it to a money amount.
989 if (discount > 100) discount = 100;
990 if (discount < 0 ) discount = 0;
991 discount = 0.01 * discount * computeDiscountedTotals(0, false);
992 <?php } ?>
993 var total = computeDiscountedTotals(discount, true);
994 f.form_amount.value = total.toFixed(<?php echo $currdecimals ?>);
995 return true;
998 </script>
999 </head>
1001 <body class="body_top">
1003 <form method='post' action='pos_checkout.php'>
1004 <input type='hidden' name='form_pid' value='<?php echo attr($patient_id) ?>' />
1006 <center>
1009 <table cellspacing='5'>
1010 <tr>
1011 <td colspan='3' align='center'>
1012 <b><?php echo xlt('Patient Checkout for '); ?><?php echo text($patdata['fname']) . " " .
1013 text($patdata['lname']) . " (" . text($patdata['pubpid']) . ")" ?></b>
1014 </td>
1015 </tr>
1016 <tr>
1017 <td><b><?php echo xlt('Date'); ?></b></td>
1018 <td><b><?php echo xlt('Description'); ?></b></td>
1019 <td align='right'><b><?php echo xlt('Qty'); ?></b></td>
1020 <td align='right'><b><?php echo xlt('Amount'); ?></b></td>
1021 </tr>
1022 <?php
1023 $inv_encounter = '';
1024 $inv_date = '';
1025 $inv_provider = 0;
1026 $inv_payer = 0;
1027 $gcac_related_visit = false;
1028 $gcac_service_provided = false;
1030 // Process billing table items.
1031 // Items that are not allowed to have a fee are skipped.
1033 while ($brow = sqlFetchArray($bres)) {
1034 // Skip all but the most recent encounter.
1035 if ($inv_encounter && $brow['encounter'] != $inv_encounter) continue;
1037 $thisdate = substr($brow['date'], 0, 10);
1038 $code_type = $brow['code_type'];
1040 // Collect tax rates, related code and provider ID.
1041 $taxrates = '';
1042 $related_code = '';
1043 $sqlBindArray = array();
1044 if (!empty($code_types[$code_type]['fee'])) {
1045 $query = "SELECT taxrates, related_code FROM codes WHERE code_type = ? " .
1046 " AND " .
1047 "code = ? AND ";
1048 array_push($sqlBindArray,$code_types[$code_type]['id'],$brow['code']);
1049 if ($brow['modifier']) {
1050 $query .= "modifier = ?";
1051 array_push($sqlBindArray,$brow['modifier']);
1052 } else {
1053 $query .= "(modifier IS NULL OR modifier = '')";
1055 $query .= " LIMIT 1";
1056 $tmp = sqlQuery($query,$sqlBindArray);
1057 $taxrates = $tmp['taxrates'];
1058 $related_code = $tmp['related_code'];
1059 markTaxes($taxrates);
1062 write_form_line($code_type, $brow['code'], $brow['id'], $thisdate,
1063 $brow['code_text'], $brow['fee'], $brow['units'],
1064 $taxrates);
1065 if (!$inv_encounter) $inv_encounter = $brow['encounter'];
1066 $inv_payer = $brow['payer_id'];
1067 if (!$inv_date || $inv_date < $thisdate) $inv_date = $thisdate;
1069 // Custom logic for IPPF to determine if a GCAC issue applies.
1070 if ($GLOBALS['ippf_specific'] && $related_code) {
1071 $relcodes = explode(';', $related_code);
1072 foreach ($relcodes as $codestring) {
1073 if ($codestring === '') continue;
1074 list($codetype, $code) = explode(':', $codestring);
1075 if ($codetype !== 'IPPF') continue;
1076 if (preg_match('/^25222/', $code)) {
1077 $gcac_related_visit = true;
1078 if (preg_match('/^25222[34]/', $code))
1079 $gcac_service_provided = true;
1085 // Process copays
1087 $totalCopay = getPatientCopay($patient_id,$encounter);
1088 if ($totalCopay < 0) {
1089 write_form_line("COPAY", "", "", "", "", $totalCopay, "", "");
1092 // Process drug sales / products.
1094 while ($drow = sqlFetchArray($dres)) {
1095 if ($inv_encounter && $drow['encounter'] && $drow['encounter'] != $inv_encounter) continue;
1097 $thisdate = $drow['sale_date'];
1098 if (!$inv_encounter) $inv_encounter = $drow['encounter'];
1100 if (!$inv_provider && !empty($arr_users[$drow['provider_id']]))
1101 $inv_provider = $drow['provider_id'] + 0;
1103 if (!$inv_date || $inv_date < $thisdate) $inv_date = $thisdate;
1105 // Accumulate taxes for this product.
1106 $tmp = sqlQuery("SELECT taxrates FROM drug_templates WHERE drug_id = ? " .
1107 " ORDER BY selector LIMIT 1", array($drow['drug_id']) );
1108 // accumTaxes($drow['fee'], $tmp['taxrates']);
1109 $taxrates = $tmp['taxrates'];
1110 markTaxes($taxrates);
1112 write_form_line('PROD', $drow['drug_id'], $drow['sale_id'],
1113 $thisdate, $drow['name'], $drow['fee'], $drow['quantity'], $taxrates);
1116 // Write a form line for each tax that has money, adding to $total.
1117 foreach ($taxes as $key => $value) {
1118 if ($value[2]) {
1119 write_form_line('TAX', $key, $key, date('Y-m-d'), $value[0], 0, 1, $value[1]);
1123 // Besides copays, do not collect any other information from ar_activity,
1124 // since this is for appt checkout.
1126 if ($inv_encounter) {
1127 $erow = sqlQuery("SELECT provider_id FROM form_encounter WHERE " .
1128 "pid = ? AND encounter = ? " .
1129 "ORDER BY id DESC LIMIT 1", array($patient_id,$inv_encounter) );
1130 $inv_provider = $erow['provider_id'] + 0;
1133 </table>
1136 <table border='0' cellspacing='4'>
1138 <tr>
1139 <td>
1140 <?php echo $GLOBALS['discount_by_money'] ? xlt('Discount Amount') : xlt('Discount Percentage'); ?>:
1141 </td>
1142 <td>
1143 <input type='text' name='form_discount' size='6' maxlength='8' value=''
1144 style='text-align:right' onkeyup='computeTotals()'>
1145 </td>
1146 </tr>
1148 <tr>
1149 <td>
1150 <?php echo xlt('Payment Method'); ?>:
1151 </td>
1152 <td>
1153 <select name='form_method'>
1154 <?php
1155 $query1112 = "SELECT * FROM list_options where list_id=? ORDER BY seq, title ";
1156 $bres1112 = sqlStatement($query1112,array('payment_method'));
1157 while ($brow1112 = sqlFetchArray($bres1112))
1159 if($brow1112['option_id']=='electronic' || $brow1112['option_id']=='bank_draft')
1160 continue;
1161 echo "<option value='".attr($brow1112['option_id'])."'>".text(xl_list_label($brow1112['title']))."</option>";
1164 </select>
1165 </td>
1166 </tr>
1168 <tr>
1169 <td>
1170 <?php echo xlt('Check/Reference Number'); ?>:
1171 </td>
1172 <td>
1173 <input type='text' name='form_source' size='10' value=''>
1174 </td>
1175 </tr>
1177 <tr>
1178 <td>
1179 <?php echo xlt('Amount Paid'); ?>:
1180 </td>
1181 <td>
1182 <input type='text' name='form_amount' size='10' value='0.00'>
1183 </td>
1184 </tr>
1186 <tr>
1187 <td>
1188 <?php echo xlt('Posting Date'); ?>:
1189 </td>
1190 <td>
1191 <input type='text' size='10' name='form_date' id='form_date'
1192 value='<?php echo attr($inv_date) ?>'
1193 title='yyyy-mm-dd date of service'
1194 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
1195 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1196 id='img_date' border='0' alt='[?]' style='cursor:pointer'
1197 title='<?php echo xla("Click here to choose a date"); ?>'>
1198 </td>
1199 </tr>
1201 <?php
1202 // If this user has a non-empty irnpool assigned, show the pending
1203 // invoice reference number.
1204 $irnumber = getInvoiceRefNumber();
1205 if (!empty($irnumber)) {
1207 <tr>
1208 <td>
1209 <?php echo xlt('Tentative Invoice Ref No'); ?>:
1210 </td>
1211 <td>
1212 <?php echo text($irnumber); ?>
1213 </td>
1214 </tr>
1215 <?php
1217 // Otherwise if there is an invoice reference number mask, ask for the refno.
1218 else if (!empty($GLOBALS['gbl_mask_invoice_number'])) {
1220 <tr>
1221 <td>
1222 <?php echo xlt('Invoice Reference Number'); ?>:
1223 </td>
1224 <td>
1225 <input type='text' name='form_irnumber' size='10' value=''
1226 onkeyup='maskkeyup(this,"<?php echo addslashes($GLOBALS['gbl_mask_invoice_number']); ?>")'
1227 onblur='maskblur(this,"<?php echo addslashes($GLOBALS['gbl_mask_invoice_number']); ?>")'
1229 </td>
1230 </tr>
1231 <?php
1235 <tr>
1236 <td colspan='2' align='center'>
1237 &nbsp;<br>
1238 <input type='submit' name='form_save' value='<?php echo xla('Save'); ?>' /> &nbsp;
1239 <?php if (empty($_GET['framed'])) { ?>
1240 <input type='button' value='<?php echo xla('Cancel'); ?>' onclick='window.close()' />
1241 <?php } ?>
1242 <input type='hidden' name='form_provider' value='<?php echo attr($inv_provider) ?>' />
1243 <input type='hidden' name='form_payer' value='<?php echo attr($inv_payer) ?>' />
1244 <input type='hidden' name='form_encounter' value='<?php echo attr($inv_encounter) ?>' />
1245 </td>
1246 </tr>
1248 </table>
1249 </center>
1251 </form>
1253 <script language='JavaScript'>
1254 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
1255 computeTotals();
1256 <?php
1257 // The following is removed, perhaps temporarily, because gcac reporting
1258 // no longer depends on gcac issues. -- Rod 2009-08-11
1259 /*********************************************************************
1260 // Custom code for IPPF. Try to make sure that a GCAC issue is linked to this
1261 // visit if it contains GCAC-related services.
1262 if ($gcac_related_visit) {
1263 $grow = sqlQuery("SELECT l.id, l.title, l.begdate, ie.pid " .
1264 "FROM lists AS l " .
1265 "LEFT JOIN issue_encounter AS ie ON ie.pid = l.pid AND " .
1266 "ie.encounter = '$inv_encounter' AND ie.list_id = l.id " .
1267 "WHERE l.pid = '$pid' AND " .
1268 "l.activity = 1 AND l.type = 'ippf_gcac' " .
1269 "ORDER BY ie.pid DESC, l.begdate DESC LIMIT 1");
1270 // Note that reverse-ordering by ie.pid is a trick for sorting
1271 // issues linked to the encounter (non-null values) first.
1272 if (empty($grow['pid'])) { // if there is no linked GCAC issue
1273 if (!empty($grow)) { // there is one that is not linked
1274 echo " if (confirm('" . xl('OK to link the GCAC issue dated') . " " .
1275 $grow['begdate'] . " " . xl('to this visit?') . "')) {\n";
1276 echo " $.getScript('link_issue_to_encounter.php?issue=" . $grow['id'] .
1277 "&thisenc=$inv_encounter');\n";
1278 echo " } else";
1280 echo " if (confirm('" . xl('Are you prepared to complete a new GCAC issue for this visit?') . "')) {\n";
1281 echo " dlgopen('summary/add_edit_issue.php?thisenc=$inv_encounter" .
1282 "&thistype=ippf_gcac', '_blank', 700, 600);\n";
1283 echo " } else {\n";
1284 echo " $.getScript('link_issue_to_encounter.php?thisenc=$inv_encounter');\n";
1285 echo " }\n";
1287 } // end if ($gcac_related_visit)
1288 *********************************************************************/
1290 if ($gcac_related_visit && !$gcac_service_provided) {
1291 // Skip this warning if the GCAC visit form is not allowed.
1292 $grow = sqlQuery("SELECT COUNT(*) AS count FROM list_options " .
1293 "WHERE list_id = 'lbfnames' AND option_id = 'LBFgcac'");
1294 if (!empty($grow['count'])) { // if gcac is used
1295 // Skip this warning if referral or abortion in TS.
1296 $grow = sqlQuery("SELECT COUNT(*) AS count FROM transactions " .
1297 "WHERE title = 'Referral' AND refer_date IS NOT NULL AND " .
1298 "refer_date = ? AND pid = ?", array($inv_date,$patient_id) );
1299 if (empty($grow['count'])) { // if there is no referral
1300 $grow = sqlQuery("SELECT COUNT(*) AS count FROM forms " .
1301 "WHERE pid = ? AND encounter = ? AND " .
1302 "deleted = 0 AND formdir = 'LBFgcac'", array($patient_id,$inv_encounter) );
1303 if (empty($grow['count'])) { // if there is no gcac form
1304 echo " alert('" . addslashes(xl('This visit will need a GCAC form, referral or procedure service.')) . "');\n";
1308 } // end if ($gcac_related_visit)
1310 </script>
1312 </body>
1313 </html>