Compact css tweak
[openemr.git] / interface / patient_file / front_payment.php
blobfbc79e0cc9dbcce9292fc78fd67eec516a6af899
1 <?php
2 /**
3 * Front payment gui.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2006-2016 Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once("../globals.php");
14 require_once("$srcdir/acl.inc");
15 require_once("$srcdir/patient.inc");
16 require_once("$srcdir/billing.inc");
17 require_once("$srcdir/payment.inc.php");
18 require_once("$srcdir/forms.inc");
19 require_once("$srcdir/sl_eob.inc.php");
20 require_once("$srcdir/invoice_summary.inc.php");
21 require_once("../../custom/code_types.inc.php");
22 require_once("$srcdir/options.inc.php");
23 require_once("$srcdir/encounter_events.inc.php");
25 use OpenEMR\Core\Header;
26 use OpenEMR\Services\FacilityService;
28 $pid = $_REQUEST['hidden_patient_code'] > 0 ? $_REQUEST['hidden_patient_code'] : $pid;
30 $facilityService = new FacilityService();
33 <!DOCTYPE html>
34 <html>
35 <head>
36 <?php Header::setupHeader(['opener']);?>
38 <?php
39 // Format dollars for display.
41 function bucks($amount)
43 if ($amount) {
44 $amount = oeFormatMoney($amount);
45 return $amount;
47 return '';
50 function rawbucks($amount)
52 if ($amount) {
53 $amount = sprintf("%.2f", $amount);
54 return $amount;
56 return '';
59 // Display a row of data for an encounter.
61 $var_index=0;
62 function echoLine($iname, $date, $charges, $ptpaid, $inspaid, $duept, $encounter = 0, $copay = 0, $patcopay = 0)
64 global $var_index;
65 $var_index++;
66 $balance = bucks($charges - $ptpaid - $inspaid);
67 $balance = (round($duept, 2) != 0) ? 0 : $balance;//if balance is due from patient, then insurance balance is displayed as zero
68 $encounter = $encounter ? $encounter : '';
69 echo " <tr id='tr_" . attr($var_index) . "' >\n";
70 echo " <td class='detail'>" . text(oeFormatShortDate($date)) . "</td>\n";
71 echo " <td class='detail' id='" . attr($date) . "' align='center'>" . attr($encounter) . "</td>\n";
72 echo " <td class='detail' align='center' id='td_charges_$var_index' >" . attr(bucks($charges)) . "</td>\n";
73 echo " <td class='detail' align='center' id='td_inspaid_$var_index' >" . attr(bucks($inspaid * -1)) . "</td>\n";
74 echo " <td class='detail' align='center' id='td_ptpaid_$var_index' >" . attr(bucks($ptpaid * -1)) . "</td>\n";
75 echo " <td class='detail' align='center' id='td_patient_copay_$var_index' >" . attr(bucks($patcopay)) . "</td>\n";
76 echo " <td class='detail' align='center' id='td_copay_$var_index' >" . attr(bucks($copay)) . "</td>\n";
77 echo " <td class='detail' align='center' id='balance_$var_index'>" . attr(bucks($balance)) . "</td>\n";
78 echo " <td class='detail' align='center' id='duept_$var_index'>" . attr(bucks(round($duept, 2) * 1)) . "</td>\n";
79 echo " <td class='detail' align='right'><input type='text' name='" . attr($iname) . "' id='paying_" . attr($var_index) . "' " .
80 " value='" . '' . "' onchange='coloring();calctotal()' autocomplete='off' " .
81 "onkeyup='calctotal()' style='width:50px'/></td>\n";
82 echo " </tr>\n";
85 // We use this to put dashes, colons, etc. back into a timestamp.
87 function decorateString($fmt, $str)
89 $res = '';
90 while ($fmt) {
91 $fc = substr($fmt, 0, 1);
92 $fmt = substr($fmt, 1);
93 if ($fc == '.') {
94 $res .= substr($str, 0, 1);
95 $str = substr($str, 1);
96 } else {
97 $res .= $fc;
101 return $res;
104 // Compute taxes from a tax rate string and a possibly taxable amount.
106 function calcTaxes($row, $amount)
108 $total = 0;
109 if (empty($row['taxrates'])) {
110 return $total;
113 $arates = explode(':', $row['taxrates']);
114 if (empty($arates)) {
115 return $total;
118 foreach ($arates as $value) {
119 if (empty($value)) {
120 continue;
123 $trow = sqlQuery("SELECT option_value FROM list_options WHERE " .
124 "list_id = 'taxrate' AND option_id = ? AND activity = 1 LIMIT 1", array($value));
125 if (empty($trow['option_value'])) {
126 echo "<!-- Missing tax rate '" . text($value) . "'! -->\n";
127 continue;
130 $tax = sprintf("%01.2f", $amount * $trow['option_value']);
131 // echo "<!-- Rate = '$value', amount = '$amount', tax = '$tax' -->\n";
132 $total += $tax;
135 return $total;
138 $now = time();
139 $today = date('Y-m-d', $now);
140 $timestamp = date('Y-m-d H:i:s', $now);
143 // $patdata = getPatientData($pid, 'fname,lname,pubpid');
145 $patdata = sqlQuery("SELECT " .
146 "p.fname, p.mname, p.lname, p.pubpid,p.pid, i.copay " .
147 "FROM patient_data AS p " .
148 "LEFT OUTER JOIN insurance_data AS i ON " .
149 "i.pid = p.pid AND i.type = 'primary' " .
150 "WHERE p.pid = ? ORDER BY i.date DESC LIMIT 1", array($pid));
152 $alertmsg = ''; // anything here pops up in an alert box
154 // If the Save button was clicked...
155 if ($_POST['form_save']) {
156 $form_pid = $_POST['form_pid'];
157 $form_method = trim($_POST['form_method']);
158 $form_source = trim($_POST['form_source']);
159 $patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
160 $NameNew = $patdata['fname'] . " " . $patdata['lname'] . " " . $patdata['mname'];
162 if ($_REQUEST['radio_type_of_payment'] == 'pre_payment') {
163 $payment_id = idSqlStatement(
164 "insert into ar_session set " .
165 "payer_id = ?" .
166 ", patient_id = ?" .
167 ", user_id = ?" .
168 ", closed = ?" .
169 ", reference = ?" .
170 ", check_date = now() , deposit_date = now() " .
171 ", pay_total = ?" .
172 ", payment_type = 'patient'" .
173 ", description = ?" .
174 ", adjustment_code = 'pre_payment'" .
175 ", post_to_date = now() " .
176 ", payment_method = ?",
177 array(0, $form_pid, $_SESSION['authUserID'], 0, $form_source, $_REQUEST['form_prepayment'], $NameNew, $form_method)
180 frontPayment($form_pid, 0, $form_method, $form_source, $_REQUEST['form_prepayment'], 0, $timestamp);//insertion to 'payments' table.
183 if ($_POST['form_upay'] && $_REQUEST['radio_type_of_payment'] != 'pre_payment') {
184 foreach ($_POST['form_upay'] as $enc => $payment) {
185 if ($amount = 0 + $payment) {
186 $zero_enc = $enc;
187 if ($_REQUEST['radio_type_of_payment'] == 'invoice_balance') {
188 if (!$enc) {
189 $enc = calendar_arrived($form_pid);
191 } else {
192 if (!$enc) {
193 $enc = calendar_arrived($form_pid);
197 //----------------------------------------------------------------------------------------------------
198 //Fetching the existing code and modifier
199 $ResultSearchNew = sqlStatement(
200 "SELECT * FROM billing LEFT JOIN code_types ON billing.code_type=code_types.ct_key ".
201 "WHERE code_types.ct_fee=1 AND billing.activity!=0 AND billing.pid =? AND encounter=? ORDER BY billing.code,billing.modifier",
202 array($form_pid, $enc)
204 if ($RowSearch = sqlFetchArray($ResultSearchNew)) {
205 $Codetype = $RowSearch['code_type'];
206 $Code = $RowSearch['code'];
207 $Modifier = $RowSearch['modifier'];
208 } else {
209 $Codetype = '';
210 $Code = '';
211 $Modifier = '';
214 //----------------------------------------------------------------------------------------------------
215 if ($_REQUEST['radio_type_of_payment'] == 'copay') {//copay saving to ar_session and ar_activity tables
216 $session_id = sqlInsert(
217 "INSERT INTO ar_session (payer_id,user_id,reference,check_date,deposit_date,pay_total," .
218 " global_amount,payment_type,description,patient_id,payment_method,adjustment_code,post_to_date) " .
219 " VALUES ('0',?,?,now(),now(),?,'','patient','COPAY',?,?,'patient_payment',now())",
220 array($_SESSION['authId'], $form_source, $amount, $form_pid, $form_method)
223 sqlBeginTrans();
224 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
225 $insrt_id=sqlInsert(
226 "INSERT INTO ar_activity (pid,encounter,sequence_no,code_type,code,modifier,payer_type,post_time,post_user,session_id,pay_amount,account_code)".
227 " VALUES (?,?,?,?,?,?,0,now(),?,?,?,'PCP')",
228 array($form_pid, $enc, $sequence_no['increment'], $Codetype, $Code, $Modifier, $_SESSION['authId'], $session_id, $amount)
230 sqlCommitTrans();
232 frontPayment($form_pid, $enc, $form_method, $form_source, $amount, 0, $timestamp);//insertion to 'payments' table.
235 if ($_REQUEST['radio_type_of_payment'] == 'invoice_balance' || $_REQUEST['radio_type_of_payment'] == 'cash') { //Payment by patient after insurance paid, cash patients similar to do not bill insurance in feesheet.
236 if ($_REQUEST['radio_type_of_payment'] == 'cash') {
237 sqlStatement(
238 "update form_encounter set last_level_closed=? where encounter=? and pid=? ",
239 array(4, $enc, $form_pid)
241 sqlStatement(
242 "update billing set billed=? where encounter=? and pid=?",
243 array(1, $enc, $form_pid)
247 $adjustment_code = 'patient_payment';
248 $payment_id = idSqlStatement(
249 "insert into ar_session set " .
250 "payer_id = ?" .
251 ", patient_id = ?" .
252 ", user_id = ?" .
253 ", closed = ?" .
254 ", reference = ?" .
255 ", check_date = now() , deposit_date = now() " .
256 ", pay_total = ?" .
257 ", payment_type = 'patient'" .
258 ", description = ?" .
259 ", adjustment_code = ?" .
260 ", post_to_date = now() " .
261 ", payment_method = ?",
262 array(0, $form_pid, $_SESSION['authUserID'], 0, $form_source, $amount, $NameNew, $adjustment_code, $form_method)
265 //--------------------------------------------------------------------------------------------------------------------
267 frontPayment($form_pid, $enc, $form_method, $form_source, 0, $amount, $timestamp);//insertion to 'payments' table.
269 //--------------------------------------------------------------------------------------------------------------------
271 $resMoneyGot = sqlStatement(
272 "SELECT sum(pay_amount) as PatientPay FROM ar_activity where pid =? and " .
273 "encounter =? and payer_type=0 and account_code='PCP'",
274 array($form_pid, $enc)
275 );//new fees screen copay gives account_code='PCP'
276 $rowMoneyGot = sqlFetchArray($resMoneyGot);
277 $Copay = $rowMoneyGot['PatientPay'];
279 //--------------------------------------------------------------------------------------------------------------------
281 //Looping the existing code and modifier
282 $ResultSearchNew = sqlStatement(
283 "SELECT * FROM billing LEFT JOIN code_types ON billing.code_type=code_types.ct_key WHERE code_types.ct_fee=1 " .
284 "AND billing.activity!=0 AND billing.pid =? AND encounter=? ORDER BY billing.code,billing.modifier",
285 array($form_pid, $enc)
287 while ($RowSearch = sqlFetchArray($ResultSearchNew)) {
288 $Codetype = $RowSearch['code_type'];
289 $Code = $RowSearch['code'];
290 $Modifier = $RowSearch['modifier'];
291 $Fee = $RowSearch['fee'];
293 $resMoneyGot = sqlStatement(
294 "SELECT sum(pay_amount) as MoneyGot FROM ar_activity where pid =? " .
295 "and code_type=? and code=? and modifier=? and encounter =? and !(payer_type=0 and account_code='PCP')",
296 array($form_pid, $Codetype, $Code, $Modifier, $enc)
298 //new fees screen copay gives account_code='PCP'
299 $rowMoneyGot = sqlFetchArray($resMoneyGot);
300 $MoneyGot = $rowMoneyGot['MoneyGot'];
302 $resMoneyAdjusted = sqlStatement(
303 "SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where " .
304 "pid =? and code_type=? and code=? and modifier=? and encounter =?",
305 array($form_pid, $Codetype, $Code, $Modifier, $enc)
307 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
308 $MoneyAdjusted = $rowMoneyAdjusted['MoneyAdjusted'];
310 $Remainder = $Fee - $Copay - $MoneyGot - $MoneyAdjusted;
311 $Copay = 0;
312 if (round($Remainder, 2) != 0 && $amount != 0) {
313 if ($amount - $Remainder >= 0) {
314 $insert_value = $Remainder;
315 $amount = $amount - $Remainder;
316 } else {
317 $insert_value = $amount;
318 $amount = 0;
321 sqlBeginTrans();
322 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
323 sqlStatement(
324 "insert into ar_activity set " .
325 "pid = ?" .
326 ", encounter = ?" .
327 ", sequence_no = ?" .
328 ", code_type = ?" .
329 ", code = ?" .
330 ", modifier = ?" .
331 ", payer_type = ?" .
332 ", post_time = now() " .
333 ", post_user = ?" .
334 ", session_id = ?" .
335 ", pay_amount = ?" .
336 ", adj_amount = ?" .
337 ", account_code = 'PP'",
338 array($form_pid, $enc, $sequence_no['increment'], $Codetype, $Code, $Modifier, 0, $_SESSION['authUserID'], $payment_id, $insert_value, 0)
340 sqlCommitTrans();
341 }//if
342 }//while
343 if ($amount!=0) {//if any excess is there.
344 sqlBeginTrans();
345 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
346 sqlStatement(
347 "insert into ar_activity set " .
348 "pid = ?" .
349 ", encounter = ?" .
350 ", sequence_no = ?" .
351 ", code_type = ?" .
352 ", code = ?" .
353 ", modifier = ?" .
354 ", payer_type = ?" .
355 ", post_time = now() " .
356 ", post_user = ?" .
357 ", session_id = ?" .
358 ", pay_amount = ?" .
359 ", adj_amount = ?" .
360 ", account_code = 'PP'",
361 array($form_pid, $enc, $sequence_no['increment'], $Codetype, $Code, $Modifier, 0, $_SESSION['authUserID'], $payment_id, $amount, 0)
363 sqlCommitTrans();
366 //--------------------------------------------------------------------------------------------------------------------
367 }//invoice_balance
368 }//if ($amount = 0 + $payment)
369 }//foreach
370 }//if ($_POST['form_upay'])
371 }//if ($_POST['form_save'])
373 if ($_POST['form_save'] || $_REQUEST['receipt']) {
374 if ($_REQUEST['receipt']) {
375 $form_pid = $_GET['patient'];
376 $timestamp = decorateString('....-..-.. ..:..:..', $_GET['time']);
379 // Get details for what we guess is the primary facility.
380 $frow = $facilityService->getPrimaryBusinessEntity(array("useLegacyImplementation" => true));
382 // Get the patient's name and chart number.
383 $patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
385 // Re-fetch payment info.
386 $payrow = sqlQuery("SELECT " .
387 "SUM(amount1) AS amount1, " .
388 "SUM(amount2) AS amount2, " .
389 "MAX(method) AS method, " .
390 "MAX(source) AS source, " .
391 "MAX(dtime) AS dtime, " .
392 // "MAX(user) AS user " .
393 "MAX(user) AS user, " .
394 "MAX(encounter) as encounter " .
395 "FROM payments WHERE " .
396 "pid = ? AND dtime = ?", array($form_pid, $timestamp));
398 // Create key for deleting, just in case.
399 $ref_id = ($_REQUEST['radio_type_of_payment'] == 'copay') ? $session_id : $payment_id;
400 $payment_key = $form_pid . '.' . preg_replace('/[^0-9]/', '', $timestamp) . '.' . $ref_id;
402 if ($_REQUEST['radio_type_of_payment'] != 'pre_payment') {
403 // get facility from encounter
404 $tmprow = sqlQuery("SELECT `facility_id` FROM `form_encounter` WHERE `encounter` = ?", array($payrow['encounter']));
405 $frow = $facilityService->getById($tmprow['facility_id']);
406 } else {
407 // if pre_payment, then no encounter yet, so get main office address
408 $frow = $facilityService->getPrimaryBillingLocation();
411 // Now proceed with printing the receipt.
414 <title><?php echo xlt('Receipt for Payment'); ?></title>
415 <?php Header::setupHeader(['jquery-ui']); ?>
416 <script language="JavaScript">
418 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
420 $(document).ready(function () {
421 var win = top.printLogSetup ? top : opener.top;
422 win.printLogSetup(document.getElementById('printbutton'));
425 function closeHow(e) {
426 if (top.tab_mode) {
427 top.activateTabByName('pat', true);
428 top.tabCloseByName(window.name);
429 } else {
430 if (opener) {
431 if (opener.name === "left_nav") {
432 dlgclose();
433 return;
436 window.history.back();
440 // This is action to take before printing and is called from restoreSession.php.
441 function printlog_before_print() {
442 let divstyle = document.getElementById('hideonprint').style;
443 divstyle.display = 'none';
444 // currently exit is not hidden by default in case receipt print is not needed
445 // and left here for future option to force users to print via global etc..
446 // can still print later via reports.
447 divstyle = document.getElementById('showonprint').style;
448 divstyle.display = '';
451 // Process click on Delete button.
452 function deleteme() {
453 dlgopen('deleter.php?payment=<?php echo attr($payment_key); ?>', '_blank', 500, 450);
454 return false;
457 // Called by the deleteme.php window on a successful delete.
458 function imdeleted() {
459 if (opener) {
460 dlgclose(); // we're in reports/leftnav and callback reloads.
461 } else {
462 window.history.back(); // this is us full screen.
466 // Called to switch to the specified encounter having the specified DOS.
467 // This also closes the popup window.
468 function toencounter(enc, datestr, topframe) {
469 topframe.restoreSession();
470 // Hard-coding of RBot for this purpose is awkward, but since this is a
471 // pop-up and our openemr is left_nav, we have no good clue as to whether
472 // the top frame is more appropriate.
473 if(!top.tab_mode) {
474 topframe.left_nav.forceDual();
475 topframe.left_nav.setEncounter(datestr, enc, '');
476 topframe.left_nav.loadFrame('enc2', 'RBot', 'patient_file/encounter/encounter_top.php?set_encounter=' + enc);
477 } else {
478 top.goToEncounter(enc);
480 if (opener) dlgclose();
482 </script>
483 </head>
484 <body bgcolor='#ffffff'>
485 <center>
487 <p><h2><?php echo xlt('Receipt for Payment'); ?></h2>
489 <p><?php echo text($frow['name']) ?>
490 <br><?php echo text($frow['street']) ?>
491 <br><?php echo text($frow['city'] . ', ' . $frow['state']) . ' ' .
492 text($frow['postal_code']) ?>
493 <br><?php echo text($frow['phone']) ?>
496 <table border='0' cellspacing='8'>
497 <tr>
498 <td><?php echo xlt('Date'); ?>:</td>
499 <td><?php echo text(oeFormatSDFT(strtotime($payrow['dtime']))) ?></td>
500 </tr>
501 <tr>
502 <td><?php echo xlt('Patient'); ?>:</td>
503 <td><?php echo text($patdata['fname']) . " " . text($patdata['mname']) . " " .
504 text($patdata['lname']) . " (" . text($patdata['pubpid']) . ")" ?></td>
505 </tr>
506 <tr>
507 <td><?php echo xlt('Paid Via'); ?>:</td>
508 <td><?php echo generate_display_field(array('data_type' => '1', 'list_id' => 'payment_method'), $payrow['method']); ?></td>
509 </tr>
510 <tr>
511 <td><?php echo xlt('Check/Ref Number'); ?>:</td>
512 <td><?php echo text($payrow['source']) ?></td>
513 </tr>
514 <tr>
515 <td><?php echo xlt('Amount for This Visit'); ?>:</td>
516 <td><?php echo text(oeFormatMoney($payrow['amount1'])) ?></td>
517 </tr>
518 <tr>
519 <td>
520 <?php
521 if ($_REQUEST['radio_type_of_payment']=='pre_payment') {
522 echo xlt('Pre-payment Amount');
523 } else {
524 echo xlt('Amount for Past Balance');
527 :</td>
528 <td><?php echo text(oeFormatMoney($payrow['amount2'])) ?></td>
529 </tr>
530 <tr>
531 <td><?php echo xlt('Received By'); ?>:</td>
532 <td><?php echo text($payrow['user']) ?></td>
533 </tr>
534 </table>
536 <div id='hideonprint'>
538 <input type='button' value='<?php echo xla('Print'); ?>' id='printbutton' />
540 <?php
541 $todaysenc = todaysEncounterIf($pid);
542 if ($todaysenc && $todaysenc != $encounter) {
543 echo "&nbsp;<input type='button' " .
544 "value='" . xla('Open Today`s Visit') . "' " .
545 "onclick='toencounter($todaysenc, \"$today\", (opener ? opener.top : top))' />\n";
549 <?php if (acl_check('admin', 'super')) { ?>
550 &nbsp;
551 <input type='button' value='<?php echo xla('Delete'); ?>' style='color:red' onclick='deleteme()' />
552 <?php } ?>
554 </div>
555 <div id='showonprint'>
556 <input type='button' value='<?php echo xla('Exit'); ?>' id='donebutton' onclick="closeHow(event)"/>
557 </div>
558 </center>
559 </body>
561 <?php
563 // End of receipt printing logic.
565 } else {
567 // Here we display the form for data entry.
570 <title><?php echo xlt('Record Payment'); ?></title>
572 <style type="text/css">
573 body { font-family:sans-serif; font-size:10pt; font-weight:normal }
574 .dehead { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
575 .detail { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
576 #ajax_div_patient {
577 position: absolute;
578 z-index:10;
579 background-color: #FBFDD0;
580 border: 1px solid #ccc;
581 padding: 10px;
583 </style>
584 <!--Removed standard dependencies 12/29/17 as not needed any longer since moved to a tab/frame not popup.-->
588 <!-- supporting javascript code -->
589 <script language='JavaScript'>
590 var mypcc = '1';
591 </script>
592 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
593 <script language="javascript" type="text/javascript">
594 document.onclick=HideTheAjaxDivs;
595 </script>
597 <script type="text/javascript" src="../../library/topdialog.js"></script>
599 <script language="JavaScript">
600 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
601 function closeHow(e) {
602 if (top.tab_mode) {
603 top.activateTabByName('pat', true);
604 top.tabCloseByName(window.name);
605 } else {
606 if (opener) {
607 if (opener.name === "left_nav") {
608 dlgclose();
609 return;
612 window.history.back();
615 function calctotal() {
616 var f = document.forms[0];
617 var total = 0;
618 for (var i = 0; i < f.elements.length; ++i) {
619 var elem = f.elements[i];
620 var ename = elem.name;
621 if (ename.indexOf('form_upay[') == 0 || ename.indexOf('form_bpay[') == 0) {
622 if (elem.value.length > 0) total += Number(elem.value);
625 f.form_paytotal.value = Number(total).toFixed(2);
626 return true;
629 function coloring() {
630 for (var i = 1; ; ++i) {
631 if (document.getElementById('paying_' + i)) {
632 paying = document.getElementById('paying_' + i).value * 1;
633 patient_balance = document.getElementById('duept_' + i).innerHTML * 1;
635 //balance=document.getElementById('balance_'+i).innerHTML*1;
636 if (patient_balance > 0 && paying > 0) {
637 if (paying > patient_balance) {
638 document.getElementById('paying_' + i).style.background = '#FF0000';
640 else if (paying < patient_balance) {
641 document.getElementById('paying_' + i).style.background = '#99CC00';
643 else if (paying == patient_balance) {
644 document.getElementById('paying_' + i).style.background = '#ffffff';
646 } else {
647 document.getElementById('paying_' + i).style.background = '#ffffff';
650 else {
651 break;
656 function CheckVisible(MakeBlank) { //Displays and hides the check number text box.
657 if (document.getElementById('form_method').options[document.getElementById(
658 'form_method').selectedIndex].value == 'check_payment' || document.getElementById(
659 'form_method').options[document.getElementById('form_method').selectedIndex]
660 .value == 'bank_draft') {
661 document.getElementById('check_number').disabled = false;
662 } else {
663 document.getElementById('check_number').disabled = true;
667 function validate() {
668 var f = document.forms[0];
669 ok = -1;
670 top.restoreSession();
671 issue = 'no';
672 // prevent an empty form submission
673 let flgempty = true;
674 for (let i = 0; i < f.elements.length; ++i) {
675 let ename = f.elements[i].name;
676 if (f.elements[i].value == 'pre_payment' && f.elements[i].checked === true) {
677 if (Number(f.elements.namedItem("form_prepayment").value) !== 0) {
678 flgempty = false;
680 break;
682 if (ename.indexOf('form_upay[') === 0 || ename.indexOf('form_bpay[') === 0) {
683 if (Number(f.elements[i].value) !== 0) flgempty = false;
686 if (flgempty) {
687 alert("<?php echo xls('A Payment is Required!. Please input a payment line item entry.') ?>");
688 return false;
690 // continue validation.
691 if (((document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value == 'check_payment' ||
692 document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value == 'bank_draft') &&
693 document.getElementById('check_number').value == '')) {
694 alert("<?php echo addslashes(xl('Please Fill the Check/Ref Number')) ?>");
695 document.getElementById('check_number').focus();
696 return false;
698 if (document.getElementById('radio_type_of_payment_self1').checked == false &&
699 document.getElementById('radio_type_of_payment1').checked == false &&
700 document.getElementById('radio_type_of_payment2').checked == false &&
701 document.getElementById('radio_type_of_payment4').checked == false) {
702 alert("<?php echo addslashes(xl('Please Select Type Of Payment.')) ?>");
703 return false;
705 if (document.getElementById('radio_type_of_payment_self1').checked == true ||
706 document.getElementById('radio_type_of_payment1').checked == true) {
707 for (var i = 0; i < f.elements.length; ++i) {
708 var elem = f.elements[i];
709 var ename = elem.name;
710 if (ename.indexOf('form_upay[0') == 0) //Today is this text box.
712 if (elem.value * 1 > 0) {//A warning message, if the amount is posted with out encounter.
713 if (confirm("<?php echo addslashes(xlt('If patient has appointment click OK to create encounter otherwise, cancel this and then create an encounter for today visit.')) ?>")) {
714 ok = 1;
715 } else {
716 elem.focus();
717 return false;
720 break;
725 if (document.getElementById('radio_type_of_payment1').checked == true){//CO-PAY
726 var total = 0;
727 for (var i = 0; i < f.elements.length; ++i) {
728 var elem = f.elements[i];
729 var ename = elem.name;
730 if (ename.indexOf('form_upay[0]') == 0) {//Today is this text box.
731 if (f.form_paytotal.value * 1 != elem.value * 1) {//Total CO-PAY is not posted against today
732 //A warning message, if the amount is posted against an old encounter.
733 if (confirm("<?php echo addslashes(xl('You are posting against an old encounter?')) ?>")) {
734 ok = 1;
735 } else {
736 elem.focus();
737 return false;
740 break;
743 }//Co Pay
744 else if (document.getElementById('radio_type_of_payment2').checked == true) {//Invoice Balance
745 for (var i = 0; i < f.elements.length; ++i) {
746 var elem = f.elements[i];
747 var ename = elem.name;
748 if (ename.indexOf('form_upay[0') == 0) {
749 if (elem.value * 1 > 0) {
750 alert("<?php echo addslashes(xl('Invoice Balance cannot be posted. No Encounter is created.')) ?>");
751 return false;
753 break;
757 if (ok == -1) {
758 if (confirm("<?php echo addslashes(xl('Would you like to save?')) ?>")) {
759 return true;
761 else {
762 return false;
767 function cursor_pointer() { //Point the cursor to the latest encounter(Today)
768 var f = document.forms[0];
769 var total = 0;
770 for (var i = 0; i < f.elements.length; ++i) {
771 var elem = f.elements[i];
772 var ename = elem.name;
773 if (ename.indexOf('form_upay[') == 0) {
774 elem.focus();
775 break;
779 //=====================================================
780 function make_it_hide_enc_pay() {
781 document.getElementById('td_head_insurance_payment').style.display = "none";
782 document.getElementById('td_head_patient_co_pay').style.display = "none";
783 document.getElementById('td_head_co_pay').style.display = "none";
784 document.getElementById('td_head_insurance_balance').style.display = "none";
785 for (var i = 1; ; ++i) {
786 var td_inspaid_elem = document.getElementById('td_inspaid_' + i)
787 var td_patient_copay_elem = document.getElementById('td_patient_copay_' + i)
788 var td_copay_elem = document.getElementById('td_copay_' + i)
789 var balance_elem = document.getElementById('balance_' + i)
790 if (td_inspaid_elem) {
791 td_inspaid_elem.style.display = "none";
792 td_patient_copay_elem.style.display = "none";
793 td_copay_elem.style.display = "none";
794 balance_elem.style.display = "none";
795 } else {
796 break;
799 document.getElementById('td_total_4').style.display = "none";
800 document.getElementById('td_total_7').style.display = "none";
801 document.getElementById('td_total_8').style.display = "none";
802 document.getElementById('td_total_6').style.display = "none";
803 document.getElementById('table_display').width = "420px";
805 //=====================================================
806 function make_visible() {
807 document.getElementById('td_head_rep_doc').style.display = "";
808 document.getElementById('td_head_description').style.display = "";
809 document.getElementById('td_head_total_charge').style.display = "none";
810 document.getElementById('td_head_insurance_payment').style.display = "none";
811 document.getElementById('td_head_patient_payment').style.display = "none";
812 document.getElementById('td_head_patient_co_pay').style.display = "none";
813 document.getElementById('td_head_co_pay').style.display = "none";
814 document.getElementById('td_head_insurance_balance').style.display = "none";
815 document.getElementById('td_head_patient_balance').style.display = "none";
816 for (var i = 1; ; ++i) {
817 var td_charges_elem = document.getElementById('td_charges_' + i)
818 var td_inspaid_elem = document.getElementById('td_inspaid_' + i)
819 var td_ptpaid_elem = document.getElementById('td_ptpaid_' + i)
820 var td_patient_copay_elem = document.getElementById('td_patient_copay_' + i)
822 var td_copay_elem = document.getElementById('td_copay_' + i)
823 var balance_elem = document.getElementById('balance_' + i)
824 var duept_elem = document.getElementById('duept_' + i)
825 if (td_charges_elem) {
826 td_charges_elem.style.display = "none";
827 td_inspaid_elem.style.display = "none";
828 td_ptpaid_elem.style.display = "none";
829 td_patient_copay_elem.style.display = "none";
830 td_copay_elem.style.display = "none";
831 balance_elem.style.display = "none";
832 duept_elem.style.display = "none";
833 } else {
834 break;
837 document.getElementById('td_total_7').style.display = "";
838 document.getElementById('td_total_8').style.display = "";
839 document.getElementById('td_total_1').style.display = "none";
840 document.getElementById('td_total_2').style.display = "none";
841 document.getElementById('td_total_3').style.display = "none";
842 document.getElementById('td_total_4').style.display = "none";
843 document.getElementById('td_total_5').style.display = "none";
844 document.getElementById('td_total_6').style.display = "none";
845 document.getElementById('table_display').width = "505px";
848 function make_it_hide() {
849 document.getElementById('td_head_rep_doc').style.display = "none";
850 document.getElementById('td_head_description').style.display = "none";
851 document.getElementById('td_head_total_charge').style.display = "";
852 document.getElementById('td_head_insurance_payment').style.display = "";
853 document.getElementById('td_head_patient_payment').style.display = "";
854 document.getElementById('td_head_patient_co_pay').style.display = "";
855 document.getElementById('td_head_co_pay').style.display = "";
856 document.getElementById('td_head_insurance_balance').style.display = "";
857 document.getElementById('td_head_patient_balance').style.display = "";
858 for (var i = 1; ; ++i) {
859 var td_charges_elem = document.getElementById('td_charges_' + i)
860 var td_inspaid_elem = document.getElementById('td_inspaid_' + i)
861 var td_ptpaid_elem = document.getElementById('td_ptpaid_' + i)
862 var td_patient_copay_elem = document.getElementById('td_patient_copay_' + i)
864 var td_copay_elem = document.getElementById('td_copay_' + i)
865 var balance_elem = document.getElementById('balance_' + i)
866 var duept_elem = document.getElementById('duept_' + i)
867 if (td_charges_elem) {
868 td_charges_elem.style.display = "";
869 td_inspaid_elem.style.display = "";
870 td_ptpaid_elem.style.display = "";
871 td_patient_copay_elem.style.display = "";
872 td_copay_elem.style.display = "";
873 balance_elem.style.display = "";
874 duept_elem.style.display = "";
875 } else {
876 break;
879 document.getElementById('td_total_1').style.display = "";
880 document.getElementById('td_total_2').style.display = "";
881 document.getElementById('td_total_3').style.display = "";
882 document.getElementById('td_total_4').style.display = "";
883 document.getElementById('td_total_5').style.display = "";
884 document.getElementById('td_total_6').style.display = "";
885 document.getElementById('td_total_7').style.display = "";
886 document.getElementById('td_total_8').style.display = "";
887 document.getElementById('table_display').width = "635px";
890 function make_visible_radio() {
891 document.getElementById('tr_radio1').style.display = "";
892 document.getElementById('tr_radio2').style.display = "none";
895 function make_hide_radio() {
896 document.getElementById('tr_radio1').style.display = "none";
897 document.getElementById('tr_radio2').style.display = "";
900 function make_visible_row() {
901 document.getElementById('table_display').style.display = "";
902 document.getElementById('table_display_prepayment').style.display = "none";
905 function make_hide_row() {
906 document.getElementById('table_display').style.display = "none";
907 document.getElementById('table_display_prepayment').style.display = "";
910 function make_self() {
911 make_visible_row();
912 make_it_hide();
913 make_it_hide_enc_pay();
914 document.getElementById('radio_type_of_payment_self1').checked = true;
915 cursor_pointer();
918 function make_insurance() {
919 make_visible_row();
920 make_it_hide();
921 cursor_pointer();
922 document.getElementById('radio_type_of_payment1').checked = true;
924 </script>
926 <style>
927 @media only screen and (max-width: 768px) {
928 [class*="col-"] {
929 width: 100%;
930 text-align: left!Important;
933 .table {
934 margin: auto;
935 width: 90% !important;
937 @media (min-width: 992px) {
938 .modal-lg {
939 width: 1000px !Important;
942 </style>
943 <title><?php echo xlt('Record Payment'); ?></title>
944 </head>
945 <body>
946 <div class="container"><!--begin container div for form-->
947 <div class="row">
948 <div class="page-header">
949 <h2><?php echo xlt('Accept Payment for'); ?><?php echo " " . text($patdata['fname']) . " " .
950 text($patdata['lname']) . " (" . text($patdata['pubpid']) . ")" ?></h2>
951 <?php $NameNew = $patdata['fname'] . " " . $patdata['lname'] . " " . $patdata['mname']; ?>
952 </div>
953 </div>
954 <div class= "row">
955 <form method='post' action='front_payment.php<?php echo ($payid) ? "?payid=".attr($payid) : ""; ?>' onsubmit='return validate();'>
956 <input name='form_pid' type='hidden' value='<?php echo attr($pid) ?>'>
957 <fieldset>
958 <legend><?php echo xlt('Payment'); ?></legend>
959 <div class="col-xs-12 oe-custom-line">
960 <div class="col-xs-3 col-lg-offset-3">
961 <label class="control-label" for="form_method"><?php echo xlt('Payment Method'); ?>:</label>
962 </div>
963 <div class="col-xs-3">
964 <select class="form-control" id="form_method" name="form_method" onchange='CheckVisible("yes")'>
965 <?php
966 $query1112 = "SELECT * FROM list_options where list_id=? ORDER BY seq, title ";
967 $bres1112 = sqlStatement($query1112, array('payment_method'));
968 while ($brow1112 = sqlFetchArray($bres1112)) {
969 if ($brow1112['option_id']=='electronic' || $brow1112['option_id']=='bank_draft') {
970 continue;
972 echo "<option value='".attr($brow1112['option_id'])."'>".attr(xl_list_label($brow1112['title']))."</option>";
975 </select>
976 </div>
977 </div>
978 <div class="col-xs-12 oe-custom-line">
979 <div class="col-xs-3 col-lg-offset-3">
980 <label class="control-label" for="check_number"><?php echo xlt('Check/Ref Number'); ?>:</label>
981 </div>
982 <div class="col-xs-3">
983 <div id="ajax_div_patient" style="display:none;"></div>
984 <input type='text' id="check_number" name='form_source' class= 'form-control' value='<?php echo attr($payrow['source']); ?>'>
985 </div>
986 </div>
987 <div class="col-xs-12 oe-custom-line">
988 <div class="col-xs-3 col-lg-offset-3">
989 <label class="control-label" for="form_discount"><?php echo xla('Patient Coverage'); ?>:</label>
990 </div>
991 <div class="col-xs-6">
992 <div style="padding-left:15px">
993 <label class="radio-inline">
994 <input id="radio_type_of_coverage1" name="radio_type_of_coverage" onclick="make_visible_radio();make_self();" type="radio" value="self"><?php echo xla('Self'); ?>
995 </label>
996 <label class="radio-inline">
997 <input checked="checked" id="radio_type_of_coverag2" name="radio_type_of_coverage" onclick="make_hide_radio();make_insurance();" type="radio" value="insurance"><?php echo xla('Insurance'); ?>
998 </label>
999 </div>
1000 </div>
1001 </div>
1002 <div class="col-xs-12 oe-custom-line">
1003 <div class="col-xs-3 col-lg-offset-3">
1004 <label class="control-label" for=""><?php echo xlt('Payment against'); ?>:</label>
1005 </div>
1006 <div class="col-xs-6">
1007 <div id="tr_radio1" style="padding-left:15px; display:none"><!-- For radio Insurance -->
1008 <label class="radio-inline">
1009 <input id="radio_type_of_payment_self1" name="radio_type_of_payment" onclick="make_visible_row();make_it_hide_enc_pay();cursor_pointer();" type="radio" value="cash"><?php echo xla('Encounter Payment'); ?>
1010 </label>
1011 </div>
1012 <div id="tr_radio2" style="padding-left:15px"><!-- For radio self -->
1013 <label class="radio-inline">
1014 <input checked="checked" id="radio_type_of_payment1" name="radio_type_of_payment" onclick="make_visible_row();cursor_pointer();" type="radio" value="copay"><?php echo xla('Co Pay'); ?>
1015 </label>
1016 <label class="radio-inline">
1017 <input id="radio_type_of_payment2" name="radio_type_of_payment" onclick="make_visible_row();" type="radio" value="invoice_balance"><?php echo xla('Invoice Balance'); ?><br>
1018 </label>
1019 <label class="radio-inline">
1020 <input id="radio_type_of_payment4" name="radio_type_of_payment" onclick="make_hide_row();" type="radio" value="pre_payment"><?php echo xla('Pre Pay'); ?>
1021 </label>
1022 </div>
1023 </div>
1024 </div>
1025 <div class="col-xs-12 oe-custom-line">
1026 <div id="table_display_prepayment" style="display:none">
1027 <div class="col-xs-3 col-lg-offset-3">
1028 <label class="control-label" for="form_prepayment"><?php echo xla('Pre Payment'); ?>:</label>
1029 </div>
1030 <div class="col-xs-3">
1031 <input name='form_prepayment' id='form_prepayment'class='form-control' type='text' value =''>
1032 </div>
1033 </div>
1034 </div>
1035 </fieldset>
1036 <fieldset>
1037 <legend><?php echo xla('Collect For'); ?></legend>
1038 <div class= "table-responsive">
1039 <table class = "table" id="table_display">
1040 <thead>
1041 <tr bgcolor="#CCCCCC" id="tr_head">
1042 <td class="dehead" width="70"><?php echo xla('DOS'); ?></td>
1043 <td class="dehead" width="65"><?php echo xla('Encounter'); ?></td>
1044 <td align="center" class="dehead" id="td_head_total_charge" width="80"><?php echo xla('Total Charge'); ?></td>
1045 <td align="center" class="dehead" id="td_head_rep_doc" style='display:none' width="70"><?php echo xla('Report/ Form'); ?></td>
1046 <td align="center" class="dehead" id="td_head_description" style='display:none' width="200"><?php echo xla('Description'); ?></td>
1047 <td align="center" class="dehead" id="td_head_insurance_payment" width="80"><?php echo xla('Insurance Payment'); ?></td>
1048 <td align="center" class="dehead" id="td_head_patient_payment" width="80"><?php echo xla('Patient Payment'); ?></td>
1049 <td align="center" class="dehead" id="td_head_patient_co_pay" width="55"><?php echo xla('Co Pay Paid'); ?></td>
1050 <td align="center" class="dehead" id="td_head_co_pay" width="55"><?php echo xla('Required Co Pay'); ?></td>
1051 <td align="center" class="dehead" id="td_head_insurance_balance" width="80"><?php echo xla('Insurance Balance'); ?></td>
1052 <td align="center" class="dehead" id="td_head_patient_balance" width="80"><?php echo xla('Patient Balance'); ?></td>
1053 <td align="center" class="dehead" width="50"><?php echo xla('Paying'); ?></td>
1054 </tr>
1055 </thead>
1056 <?php
1057 $encs = array();
1059 // Get the unbilled service charges and payments by encounter for this patient.
1061 $query = "SELECT fe.encounter, b.code_type, b.code, b.modifier, b.fee, " .
1062 "LEFT(fe.date, 10) AS encdate ,fe.last_level_closed " .
1063 "FROM form_encounter AS fe left join billing AS b on " .
1064 "b.pid = ? AND b.activity = 1 AND " .//AND b.billed = 0
1065 "b.code_type != 'TAX' AND b.fee != 0 " .
1066 "AND fe.pid = b.pid AND fe.encounter = b.encounter " .
1067 "where fe.pid = ? " .
1068 "ORDER BY b.encounter";
1069 $bres = sqlStatement($query, array($pid, $pid));
1071 while ($brow = sqlFetchArray($bres)) {
1072 $key = 0 - $brow['encounter'];
1073 if (empty($encs[$key])) {
1074 $encs[$key] = array(
1075 'encounter' => $brow['encounter'],
1076 'date' => $brow['encdate'],
1077 'last_level_closed' => $brow['last_level_closed'],
1078 'charges' => 0,
1079 'payments' => 0);
1082 if ($brow['code_type'] === 'COPAY') {
1083 //$encs[$key]['payments'] -= $brow['fee'];
1084 } else {
1085 $encs[$key]['charges'] += $brow['fee'];
1086 // Add taxes.
1087 $sql_array = array();
1088 $query = "SELECT taxrates FROM codes WHERE " .
1089 "code_type = ? AND " .
1090 "code = ? AND ";
1091 array_push($sql_array, $code_types[$brow['code_type']]['id'], $brow['code']);
1092 if ($brow['modifier']) {
1093 $query .= "modifier = ?";
1094 array_push($sql_array, $brow['modifier']);
1095 } else {
1096 $query .= "(modifier IS NULL OR modifier = '')";
1099 $query .= " LIMIT 1";
1100 $trow = sqlQuery($query, $sql_array);
1101 $encs[$key]['charges'] += calcTaxes($trow, $brow['fee']);
1105 // Do the same for unbilled product sales.
1107 $query = "SELECT fe.encounter, s.drug_id, s.fee, " .
1108 "LEFT(fe.date, 10) AS encdate,fe.last_level_closed " .
1109 "FROM form_encounter AS fe left join drug_sales AS s " .
1110 "on s.pid = ? AND s.fee != 0 " .//AND s.billed = 0
1111 "AND fe.pid = s.pid AND fe.encounter = s.encounter " .
1112 "where fe.pid = ? " .
1113 "ORDER BY s.encounter";
1115 $dres = sqlStatement($query, array($pid, $pid));
1117 while ($drow = sqlFetchArray($dres)) {
1118 $key = 0 - $drow['encounter'];
1119 if (empty($encs[$key])) {
1120 $encs[$key] = array(
1121 'encounter' => $drow['encounter'],
1122 'date' => $drow['encdate'],
1123 'last_level_closed' => $drow['last_level_closed'],
1124 'charges' => 0,
1125 'payments' => 0);
1128 $encs[$key]['charges'] += $drow['fee'];
1129 // Add taxes.
1130 $trow = sqlQuery("SELECT taxrates FROM drug_templates WHERE drug_id = ? " .
1131 "ORDER BY selector LIMIT 1", array($drow['drug_id']));
1132 $encs[$key]['charges'] += calcTaxes($trow, $drow['fee']);
1135 ksort($encs, SORT_NUMERIC);
1136 $gottoday = false;
1137 //Bringing on top the Today always
1138 foreach ($encs as $key => $value) {
1139 $dispdate = $value['date'];
1140 if (strcmp($dispdate, $today) == 0 && !$gottoday) {
1141 $gottoday = true;
1142 break;
1146 // If no billing was entered yet for today, then generate a line for
1147 // entering today's co-pay.
1149 if (!$gottoday) {
1150 echoLine("form_upay[0]", date("Y-m-d"), 0, 0, 0, 0 /*$duept*/);//No encounter yet defined.
1153 $gottoday = false;
1154 foreach ($encs as $key => $value) {
1155 $enc = $value['encounter'];
1156 $dispdate = $value['date'];
1157 if (strcmp($dispdate, $today) == 0 && !$gottoday) {
1158 $dispdate = date("Y-m-d");
1159 $gottoday = true;
1161 //------------------------------------------------------------------------------------
1162 $inscopay = getCopay($pid, $dispdate);
1163 $patcopay = getPatientCopay($pid, $enc);
1164 //Insurance Payment
1165 //-----------------
1166 $drow = sqlQuery(
1167 "SELECT SUM(pay_amount) AS payments, " .
1168 "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
1169 "pid = ? and encounter = ? and " .
1170 "payer_type != 0 and account_code!='PCP' ",
1171 array($pid, $enc)
1173 $dpayment = $drow['payments'];
1174 $dadjustment = $drow['adjustments'];
1175 //Patient Payment
1176 //---------------
1177 $drow = sqlQuery(
1178 "SELECT SUM(pay_amount) AS payments, " .
1179 "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
1180 "pid = ? and encounter = ? and " .
1181 "payer_type = 0 and account_code!='PCP' ",
1182 array($pid, $enc)
1184 $dpayment_pat = $drow['payments'];
1186 //------------------------------------------------------------------------------------
1187 //NumberOfInsurance
1188 $ResultNumberOfInsurance = sqlStatement("SELECT COUNT( DISTINCT TYPE ) NumberOfInsurance FROM insurance_data
1189 where pid = ? and provider>0 ", array($pid));
1190 $RowNumberOfInsurance = sqlFetchArray($ResultNumberOfInsurance);
1191 $NumberOfInsurance = $RowNumberOfInsurance['NumberOfInsurance'] * 1;
1192 //------------------------------------------------------------------------------------
1193 $duept = 0;
1194 if ((($NumberOfInsurance == 0 || $value['last_level_closed'] == 4 || $NumberOfInsurance == $value['last_level_closed']))) {//Patient balance
1195 $brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
1196 "pid = ? and encounter = ? AND activity = 1", array($pid, $enc));
1197 $srow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
1198 "pid = ? and encounter = ? ", array($pid, $enc));
1199 $drow = sqlQuery("SELECT SUM(pay_amount) AS payments, " .
1200 "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
1201 "pid = ? and encounter = ? ", array($pid, $enc));
1202 $duept = $brow['amount'] + $srow['amount'] - $drow['payments'] - $drow['adjustments'];
1205 echoLine(
1206 "form_upay[$enc]",
1207 $dispdate,
1208 $value['charges'],
1209 $dpayment_pat,
1210 ($dpayment + $dadjustment),
1211 $duept,
1212 $enc,
1213 $inscopay,
1214 $patcopay
1219 // Continue with display of the data entry form.
1222 <tr bgcolor="#CCCCCC">
1223 <td class="dehead" id='td_total_1'></td>
1224 <td class="dehead" id='td_total_2'></td>
1225 <td class="dehead" id='td_total_3'></td>
1226 <td class="dehead" id='td_total_4'></td>
1227 <td class="dehead" id='td_total_5'></td>
1228 <td class="dehead" id='td_total_6'></td>
1229 <td class="dehead" id='td_total_7'></td>
1230 <td class="dehead" id='td_total_8'></td>
1231 <td align="right" class="dehead"><?php echo xla('Total');?></td>
1232 <td align="right" class="dehead"><input name='form_paytotal' readonly style='color:#00aa00;width:50px' type='text' value=''></td>
1233 </tr>
1234 </table>
1235 </div>
1236 </fieldset>
1237 <div class="form-group">
1238 <div class="col-sm-12 text-left position-override">
1239 <div class="btn-group btn-group-pinch" role="group">
1240 <button type='submit' class="btn btn-default btn-save" name='form_save' value='<?php echo xlt('Generate Invoice');?>'><?php echo xla('Generate Invoice');?></button>
1241 <button type='button' class="btn btn-link btn-cancel btn-separate-left" value='<?php echo xla('Cancel'); ?>' onclick='closeHow(event)'><?php echo xla('Cancel'); ?></button>
1242 <input type="hidden" name="hidden_patient_code" id="hidden_patient_code" value="<?php echo attr($pid);?>"/>
1243 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
1244 <input type='hidden' name='mode' id='mode' value='' />
1245 </div>
1246 </div>
1247 </div>
1248 </form>
1249 </div>
1250 <script language="JavaScript">
1251 calctotal();
1252 </script>
1253 </center>
1254 <?php
1257 </div><!--end of container div of accept payment i.e the form-->
1258 </body>
1259 </html>