Removes frames from login gui and condense login gui into a single file.
[openemr.git] / interface / reports / collections_report.php
blob232c312f3e9b567326b2a99c6e9b45e26f265a47
1 <?php
2 /*
3 * Collections report
5 * (TLH) Added payor,provider,fixed cvs download to included selected fields
6 * (TLH) Added ability to download selected invoices only or all for patient
8 * Copyright (C) 2015 Terry Hill <terry@lillysystems.com>
9 * Copyright (C) 2006-2016 Rod Roark <rod@sunsetsystems.com>
11 * LICENSE: This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
22 * @package OpenEMR
23 * @author Rod Roark <rod@sunsetsystems.com>
24 * @author Terry Hill <terry@lilysystems.com>
25 * @link http://www.open-emr.org
28 $fake_register_globals=false;
29 $sanitize_all_escapes=true;
31 require_once("../globals.php");
32 require_once("../../library/patient.inc");
33 require_once("../../library/invoice_summary.inc.php");
34 require_once("../../library/sl_eob.inc.php");
35 require_once("../../library/formatting.inc.php");
36 require_once "$srcdir/options.inc.php";
37 require_once "$srcdir/formdata.inc.php";
40 $alertmsg = '';
41 $bgcolor = "#aaaaaa";
42 $export_patient_count = 0;
43 $export_dollars = 0;
45 $today = date("Y-m-d");
47 $form_date = fixDate($_POST['form_date'], "");
48 $form_to_date = fixDate($_POST['form_to_date'], "");
49 $is_ins_summary = $_POST['form_category'] == 'Ins Summary';
50 $is_due_ins = ($_POST['form_category'] == 'Due Ins') || $is_ins_summary;
51 $is_due_pt = $_POST['form_category'] == 'Due Pt';
52 $is_all = $_POST['form_category'] == 'All';
53 $is_ageby_lad = strpos($_POST['form_ageby'], 'Last') !== false;
54 $form_facility = $_POST['form_facility'];
55 $form_provider = $_POST['form_provider'];
56 $form_payer_id = $_POST['form_payer_id'];
58 if ($_POST['form_refresh'] || $_POST['form_export'] || $_POST['form_csvexport']) {
59 if ($is_ins_summary) {
60 $form_cb_ssn = false;
61 $form_cb_dob = false;
62 $form_cb_pubpid = false;
63 $form_cb_adate = false;
64 $form_cb_policy = false;
65 $form_cb_phone = false;
66 $form_cb_city = false;
67 $form_cb_ins1 = false;
68 $form_cb_referrer = false;
69 $form_cb_idays = false;
70 $form_cb_err = false;
71 } else {
72 $form_cb_ssn = $_POST['form_cb_ssn'] ? true : false;
73 $form_cb_dob = $_POST['form_cb_dob'] ? true : false;
74 $form_cb_pubpid = $_POST['form_cb_pubpid'] ? true : false;
75 $form_cb_adate = $_POST['form_cb_adate'] ? true : false;
76 $form_cb_policy = $_POST['form_cb_policy'] ? true : false;
77 $form_cb_phone = $_POST['form_cb_phone'] ? true : false;
78 $form_cb_city = $_POST['form_cb_city'] ? true : false;
79 $form_cb_ins1 = $_POST['form_cb_ins1'] ? true : false;
80 $form_cb_referrer = $_POST['form_cb_referrer'] ? true : false;
81 $form_cb_idays = $_POST['form_cb_idays'] ? true : false;
82 $form_cb_err = $_POST['form_cb_err'] ? true : false;
84 } else {
85 $form_cb_ssn = true;
86 $form_cb_dob = false;
87 $form_cb_pubpid = false;
88 $form_cb_adate = false;
89 $form_cb_policy = false;
90 $form_cb_phone = true;
91 $form_cb_city = false;
92 $form_cb_ins1 = false;
93 $form_cb_referrer = false;
94 $form_cb_idays = false;
95 $form_cb_err = false;
97 $form_age_cols = (int) $_POST['form_age_cols'];
98 $form_age_inc = (int) $_POST['form_age_inc'];
99 if ($form_age_cols > 0 && $form_age_cols < 50) {
100 if ($form_age_inc <= 0) $form_age_inc = 30;
101 } else {
102 $form_age_cols = 0;
103 $form_age_inc = 0;
106 $initial_colspan = 1;
107 if ($is_due_ins ) ++$initial_colspan;
108 if ($form_cb_ssn ) ++$initial_colspan;
109 if ($form_cb_dob ) ++$initial_colspan;
110 if ($form_cb_pubpid ) ++$initial_colspan;
111 if ($form_cb_policy ) ++$initial_colspan;
112 if ($form_cb_phone ) ++$initial_colspan;
113 if ($form_cb_city ) ++$initial_colspan;
114 if ($form_cb_ins1 ) ++$initial_colspan;
115 if ($form_cb_referrer) ++$initial_colspan;
116 if ($form_provider ) ++$initial_colspan;
117 if ($form_payer_id ) ++$initial_colspan;
119 $final_colspan = $form_cb_adate ? 6 : 5;
121 $grand_total_charges = 0;
122 $grand_total_adjustments = 0;
123 $grand_total_paid = 0;
124 $grand_total_agedbal = array();
125 for ($c = 0; $c < $form_age_cols; ++$c) $grand_total_agedbal[$c] = 0;
128 function bucks($amount) {
129 if ($amount)
130 echo oeFormatMoney($amount); // was printf("%.2f", $amount);
133 function endPatient($ptrow) {
134 global $export_patient_count, $export_dollars, $bgcolor;
135 global $grand_total_charges, $grand_total_adjustments, $grand_total_paid;
136 global $grand_total_agedbal, $is_due_ins, $form_age_cols;
137 global $initial_colspan, $final_colspan, $form_cb_idays, $form_cb_err;
139 if (!$ptrow['pid']) return;
141 $pt_balance = $ptrow['amount'] - $ptrow['paid'];
143 if ($_POST['form_export']) {
144 // This is a fixed-length format used by Transworld Systems. Your
145 // needs will surely be different, so consider this just an example.
147 echo "1896H"; // client number goes here
148 echo "000"; // filler
149 echo sprintf("%-30s", substr($ptrow['ptname'], 0, 30));
150 echo sprintf("%-30s", " ");
151 echo sprintf("%-30s", substr($ptrow['address1'], 0, 30));
152 echo sprintf("%-15s", substr($ptrow['city'], 0, 15));
153 echo sprintf("%-2s", substr($ptrow['state'], 0, 2));
154 echo sprintf("%-5s", $ptrow['zipcode'] ? substr($ptrow['zipcode'], 0, 5) : '00000');
155 echo "1"; // service code
156 echo sprintf("%010.0f", $ptrow['pid']); // transmittal number = patient id
157 echo " "; // filler
158 echo sprintf("%-15s", substr($ptrow['ss'], 0, 15));
159 echo substr($ptrow['dos'], 5, 2) . substr($ptrow['dos'], 8, 2) . substr($ptrow['dos'], 2, 2);
160 echo sprintf("%08.0f", $pt_balance * 100);
161 echo sprintf("%-9s\n", " ");
163 if (!$_POST['form_without']) {
164 sqlStatement("UPDATE patient_data SET " .
165 "billing_note = CONCAT('IN COLLECTIONS " . date("Y-m-d") . "', billing_note) " .
166 "WHERE pid = ? ", array($ptrow['pid']));
168 $export_patient_count += 1;
169 $export_dollars += $pt_balance;
171 else if ($_POST['form_csvexport']) {
172 $export_patient_count += 1;
173 $export_dollars += $pt_balance;
175 else {
176 if ($ptrow['count'] > 1) {
177 echo " <tr bgcolor='$bgcolor'>\n";
178 /***************************************************************
179 echo " <td class='detail' colspan='$initial_colspan'>";
180 echo "&nbsp;</td>\n";
181 echo " <td class='detotal' colspan='$final_colspan'>&nbsp;Total Patient Balance:</td>\n";
182 ***************************************************************/
183 echo " <td class='detotal' colspan='" . ($initial_colspan + $final_colspan) .
184 "'>&nbsp;" . xlt('Total Patient Balance') . ":</td>\n";
185 /**************************************************************/
186 if ($form_age_cols) {
187 for ($c = 0; $c < $form_age_cols; ++$c) {
188 echo " <td class='detotal' align='right'>&nbsp;" .
189 oeFormatMoney($ptrow['agedbal'][$c]) . "&nbsp;</td>\n";
192 else {
193 echo " <td class='detotal' align='right'>&nbsp;" .
194 oeFormatMoney($pt_balance) . "&nbsp;</td>\n";
196 if ($form_cb_idays) echo " <td class='detail'>&nbsp;</td>\n";
197 echo " <td class='detail' colspan='2'>&nbsp;</td>\n";
198 if ($form_cb_err) echo " <td class='detail'>&nbsp;</td>\n";
199 echo " </tr>\n";
202 $grand_total_charges += $ptrow['charges'];
203 $grand_total_adjustments += $ptrow['adjustments'];
204 $grand_total_paid += $ptrow['paid'];
205 for ($c = 0; $c < $form_age_cols; ++$c) {
206 $grand_total_agedbal[$c] += $ptrow['agedbal'][$c];
210 function endInsurance($insrow) {
211 global $export_patient_count, $export_dollars, $bgcolor;
212 global $grand_total_charges, $grand_total_adjustments, $grand_total_paid;
213 global $grand_total_agedbal, $is_due_ins, $form_age_cols;
214 global $initial_colspan, $form_cb_idays, $form_cb_err;
215 if (!$insrow['pid']) return;
216 $ins_balance = $insrow['amount'] - $insrow['paid'];
217 if ($_POST['form_export'] || $_POST['form_csvexport']) {
218 // No exporting of insurance summaries.
219 $export_patient_count += 1;
220 $export_dollars += $ins_balance;
222 else {
223 echo " <tr bgcolor='$bgcolor'>\n";
224 echo " <td class='detail'>" . text($insrow['insname']) . "</td>\n";
225 echo " <td class='detotal' align='right'>&nbsp;" .
226 oeFormatMoney($insrow['charges']) . "&nbsp;</td>\n";
227 echo " <td class='detotal' align='right'>&nbsp;" .
228 oeFormatMoney($insrow['adjustments']) . "&nbsp;</td>\n";
229 echo " <td class='detotal' align='right'>&nbsp;" .
230 oeFormatMoney($insrow['paid']) . "&nbsp;</td>\n";
231 if ($form_age_cols) {
232 for ($c = 0; $c < $form_age_cols; ++$c) {
233 echo " <td class='detotal' align='right'>&nbsp;" .
234 oeFormatMoney($insrow['agedbal'][$c]) . "&nbsp;</td>\n";
237 else {
238 echo " <td class='detotal' align='right'>&nbsp;" .
239 oeFormatMoney($ins_balance) . "&nbsp;</td>\n";
241 echo " </tr>\n";
243 $grand_total_charges += $insrow['charges'];
244 $grand_total_adjustments += $insrow['adjustments'];
245 $grand_total_paid += $insrow['paid'];
246 for ($c = 0; $c < $form_age_cols; ++$c) {
247 $grand_total_agedbal[$c] += $insrow['agedbal'][$c];
251 function getInsName($payerid) {
252 $tmp = sqlQuery("SELECT name FROM insurance_companies WHERE id = ? ", array($payerid));
253 return $tmp['name'];
256 // In the case of CSV export only, a download will be forced.
257 if ($_POST['form_csvexport']) {
258 header("Pragma: public");
259 header("Expires: 0");
260 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
261 header("Content-Type: application/force-download");
262 header("Content-Disposition: attachment; filename=collections_report.csv");
263 header("Content-Description: File Transfer");
265 else {
267 <html>
268 <head>
269 <?php if (function_exists('html_header_show')) html_header_show(); ?>
270 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
271 <title><?php echo xlt('Collections Report')?></title>
272 <style type="text/css">
274 @media print {
275 #report_parameters {
276 visibility: hidden;
277 display: none;
279 #report_parameters_daterange {
280 visibility: visible;
281 display: inline;
283 #report_results {
284 margin-top: 30px;
288 /* specifically exclude some from the screen */
289 @media screen {
290 #report_parameters_daterange {
291 visibility: hidden;
292 display: none;
296 </style>
298 <script type="text/javascript" src="../../library/js/jquery-1.9.1.min.js"></script>
299 <script type="text/javascript" src="../../library/js/report_helper.js?v=<?php echo $v_js_includes; ?>"></script>
301 <script language="JavaScript">
303 $(document).ready(function() {
304 oeFixedHeaderSetup(document.getElementById('mymaintable'));
305 var win = top.printLogSetup ? top : opener.top;
306 win.printLogSetup(document.getElementById('printbutton'));
309 function checkAll(checked) {
310 var f = document.forms[0];
311 for (var i = 0; i < f.elements.length; ++i) {
312 var ename = f.elements[i].name;
313 if (ename.indexOf('form_cb[') == 0)
314 f.elements[i].checked = checked;
318 </script>
320 </head>
322 <body class="body_top">
324 <span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Collections'); ?></span>
326 <form method='post' action='collections_report.php' enctype='multipart/form-data' id='theform'>
328 <div id="report_parameters">
330 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
331 <input type='hidden' name='form_export' id='form_export' value=''/>
332 <input type='hidden' name='form_csvexport' id='form_csvexport' value=''/>
334 <table>
335 <tr>
336 <td width='610px'>
337 <div style='float:left'>
339 <table class='text'>
340 <tr>
341 <td class='label'>
342 <table>
343 <tr>
344 <td><?php echo xlt('Displayed Columns') ?>:</td>
345 </tr>
346 <tr>
347 <td>
348 <label><input type='checkbox' name='form_cb_ssn'<?php if ($form_cb_ssn) echo ' checked'; ?>>
349 <?php echo xlt('SSN') ?>&nbsp;</label>
350 </td>
351 <td>
352 <label><input type='checkbox' name='form_cb_dob'<?php if ($form_cb_dob) echo ' checked'; ?>>
353 <?php echo xlt('DOB') ?>&nbsp;</label>
354 </td>
355 <td>
356 <label><input type='checkbox' name='form_cb_pubpid'<?php if ($form_cb_pubpid) echo ' checked'; ?>>
357 <?php echo xlt('ID') ?>&nbsp;</label>
358 </td>
359 <td>
360 <label><input type='checkbox' name='form_cb_policy'<?php if ($form_cb_policy) echo ' checked'; ?>>
361 <?php echo xlt('Policy') ?>&nbsp;</label>
362 </td>
363 <td>
364 <label><input type='checkbox' name='form_cb_phone'<?php if ($form_cb_phone) echo ' checked'; ?>>
365 <?php echo xlt('Phone') ?>&nbsp;</label>
366 </td>
367 <td>
368 <label><input type='checkbox' name='form_cb_city'<?php if ($form_cb_city) echo ' checked'; ?>>
369 <?php echo xlt('City') ?>&nbsp;</label>
370 </td>
371 </tr>
372 <tr>
373 <td>
374 <label><input type='checkbox' name='form_cb_ins1'<?php if ($form_cb_ins1) echo ' checked'; ?>>
375 <?php echo xlt('Primary Ins') ?>&nbsp;</label>
376 </td>
377 <td>
378 <label><input type='checkbox' name='form_cb_referrer'<?php if ($form_cb_referrer) echo ' checked'; ?>>
379 <?php echo xlt('Referrer') ?>&nbsp;</label>
380 </td>
381 <td>
382 <label><input type='checkbox' name='form_cb_adate'<?php if ($form_cb_adate) echo ' checked'; ?>>
383 <?php echo xlt('Act Date') ?>&nbsp;</label>
384 </td>
385 <td>
386 <label><input type='checkbox' name='form_cb_idays'<?php if ($form_cb_idays) echo ' checked'; ?>>
387 <?php echo xlt('Inactive Days') ?>&nbsp;</label>
388 </td>
389 <td>
390 <label><input type='checkbox' name='form_cb_err'<?php if ($form_cb_err) echo ' checked'; ?>>
391 <?php echo xlt('Errors') ?></label>
392 </td>
393 </tr>
394 </table>
395 </td>
396 </tr>
397 </tr>
398 <td>
399 <table>
401 <tr>
402 <td class='label'>
403 <?php echo xlt('Service Date'); ?>:
404 </td>
405 <td>
406 <input type='text' name='form_date' id="form_date" size='10' value='<?php echo attr($form_date) ?>'
407 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
408 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
409 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
410 title='<?php echo xla('Click here to choose a date'); ?>'>
411 </td>
412 <td class='label'>
413 <?php echo xlt('To'); ?>:
414 </td>
415 <td>
416 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo attr($form_to_date) ?>'
417 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
418 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
419 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
420 title='<?php echo xla('Click here to choose a date'); ?>'>
421 </td>
422 <td>
423 <select name='form_category'>
424 <?php
425 foreach (array('Open' => xl('Open'),'Due Pt' => xl('Due Pt'),'Due Ins' => xl('Due Ins'),'Ins Summary' => xl('Ins Summary'),'Credits' => xl('Credits'),'All' => xl('All')) as $key => $value) {
426 echo " <option value='" . attr($key) . "'";
427 if ($_POST['form_category'] == $key) echo " selected";
428 echo ">" . text($value) . "</option>\n";
431 </select>
432 </td>
434 </tr>
437 <tr>
438 <td class='label'>
439 <?php echo xlt('Facility'); ?>:
440 </td>
441 <td>
442 <?php dropdown_facility($form_facility, 'form_facility', false); ?>
443 </td>
445 <td class='label'>
446 <?php echo xlt('Payor'); ?>:
447 </td>
448 <td>
449 <?php # added dropdown for payors (TLH)
450 $insurancei = getInsuranceProviders();
451 echo " <select name='form_payer_id'>\n";
452 echo " <option value='0'>-- " . xlt('All') . " --</option>\n";
453 foreach ($insurancei as $iid => $iname) {
454 echo "<option value='" . attr($iid) . "'";
455 if ($iid == $_POST['form_payer_id']) echo " selected";
456 echo ">" . text($iname) . "</option>\n";
457 if ($iid == $_POST['form_payer_id']) $ins_co_name = $iname;
459 echo " </select>\n";
461 </td>
462 </tr>
464 <tr>
465 <td class='label'>
466 <?php echo xlt('Age By') ?>:
467 </td>
468 <td>
469 <select name='form_ageby'>
470 <?php
471 foreach (array( 'Service Date'=>xl('Service Date'), 'Last Activity Date'=>xl('Last Activity Date')) as $key => $value) {
472 echo " <option value='" . attr($key) . "'";
473 if ($_POST['form_ageby'] == $value) echo " selected";
474 echo ">" . text($value) . "</option>\n";
477 </select>
478 </td>
480 <td class='label'>
481 <?php echo xlt('Provider') ?>:
482 </td>
483 <td>
484 <?php # Build a drop-down list of providers.
485 # Added (TLH)
487 $query = "SELECT id, lname, fname FROM users WHERE ".
488 "authorized = 1 ORDER BY lname, fname"; #(CHEMED) facility filter
490 $ures = sqlStatement($query);
492 echo " <select name='form_provider'>\n";
493 echo " <option value=''>-- " . xlt('All') . " --\n";
495 while ($urow = sqlFetchArray($ures)) {
496 $provid = $urow['id'];
497 echo " <option value='" . attr($provid) . "'";
498 if ($provid == $_POST['form_provider']) echo " selected";
499 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
500 if ($provid == $_POST['form_provider']) $provider_name = $urow['lname'] . ", " . $urow['fname'];
503 echo " </select>\n";
505 </td>
506 </tr>
507 </tr>
508 <td class='label'>
509 <?php echo xlt('Aging Columns') ?>:
510 </td>
511 <td>
512 <input type='text' name='form_age_cols' size='2' value='<?php echo attr($form_age_cols); ?>' />
513 </td>
514 <td class='label'>
515 <?php echo xlt('Days/Col') ?>:
516 </td>
517 <td>
518 <input type='text' name='form_age_inc' size='3' value='<?php echo attr($form_age_inc); ?>' />
519 </td>
520 </tr>
523 </table>
524 </td>
525 </tr>
526 </table>
528 </div>
530 </td>
531 <td align='left' valign='middle' height="100%">
532 <table style='border-left:1px solid; width:100%; height:100%' >
533 <tr>
534 <td>
535 <div style='margin-left:15px'>
536 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
537 <span>
538 <?php echo xlt('Submit'); ?>
539 </span>
540 </a>
542 <?php if ($_POST['form_refresh']) { ?>
543 <a href='#' class='css_button' onclick='window.print()'>
544 <span>
545 <?php echo xlt('Print'); ?>
546 </span>
547 </a>
548 <?php } ?>
549 </div>
550 </td>
551 </tr>
552 </table>
553 </td>
554 </tr>
555 </table>
556 </div>
559 <?php
561 } // end not form_csvexport
563 if ($_POST['form_refresh'] || $_POST['form_export'] || $_POST['form_csvexport']) {
564 $rows = array();
565 $where = "";
566 $sqlArray = array();
567 if ($_POST['form_export'] || $_POST['form_csvexport']) {
569 $where = "( 1 = 2";
570 foreach ($_POST['form_cb'] as $key => $value) {
571 list($key_newval['pid'], $key_newval['encounter']) = explode(".", $key);
572 $newkey = $key_newval['pid'];
573 $newencounter = $key_newval['encounter'];
574 # added this condition to handle the downloading of individual invoices (TLH)
575 if($_POST['form_individual'] ==1){
576 $where .= " OR f.encounter = ? ";
577 array_push($sqlArray, $newencounter);
579 else
581 $where .= " OR f.pid = ? ";
582 array_push($sqlArray, $newkey);
585 $where .= ' )';
587 if ($form_date) {
588 if ($where) $where .= " AND ";
589 if ($form_to_date) {
590 $where .= "f.date >= ? AND f.date <= ? ";
591 array_push($sqlArray, $form_date.' 00:00:00', $form_to_date.' 23:59:59');
593 else {
594 $where .= "f.date >= ? AND f.date <= ? ";
595 array_push($sqlArray, $form_date.' 00:00:00', $form_date.' 23:59:59');
598 if ($form_facility) {
599 if ($where) $where .= " AND ";
600 $where .= "f.facility_id = ? ";
601 array_push($sqlArray, $form_facility);
603 # added for filtering by provider (TLH)
604 if ($form_provider) {
605 if ($where) $where .= " AND ";
606 $where .= "f.provider_id = ? ";
607 array_push($sqlArray, $form_provider);
610 if (! $where) {
611 $where = "1 = 1";
613 # added provider from encounter to the query (TLH)
614 $query = "SELECT f.id, f.date, f.pid, CONCAT(w.lname, ', ', w.fname) AS provider_id, f.encounter, f.last_level_billed, " .
615 "f.last_level_closed, f.last_stmt_date, f.stmt_count, f.invoice_refno, " .
616 "p.fname, p.mname, p.lname, p.street, p.city, p.state, " .
617 "p.postal_code, p.phone_home, p.ss, p.billing_note, " .
618 "p.pubpid, p.DOB, CONCAT(u.lname, ', ', u.fname) AS referrer, " .
619 "( SELECT SUM(b.fee) FROM billing AS b WHERE " .
620 "b.pid = f.pid AND b.encounter = f.encounter AND " .
621 "b.activity = 1 AND b.code_type != 'COPAY' ) AS charges, " .
622 "( SELECT SUM(b.fee) FROM billing AS b WHERE " .
623 "b.pid = f.pid AND b.encounter = f.encounter AND " .
624 "b.activity = 1 AND b.code_type = 'COPAY' ) AS copays, " .
625 "( SELECT SUM(s.fee) FROM drug_sales AS s WHERE " .
626 "s.pid = f.pid AND s.encounter = f.encounter ) AS sales, " .
627 "( SELECT SUM(a.pay_amount) FROM ar_activity AS a WHERE " .
628 "a.pid = f.pid AND a.encounter = f.encounter ) AS payments, " .
629 "( SELECT SUM(a.adj_amount) FROM ar_activity AS a WHERE " .
630 "a.pid = f.pid AND a.encounter = f.encounter ) AS adjustments " .
631 "FROM form_encounter AS f " .
632 "JOIN patient_data AS p ON p.pid = f.pid " .
633 "LEFT OUTER JOIN users AS u ON u.id = p.ref_providerID " .
634 "LEFT OUTER JOIN users AS w ON w.id = f.provider_id " .
635 "WHERE $where " .
636 "ORDER BY f.pid, f.encounter";
638 $eres = sqlStatement($query, $sqlArray);
640 while ($erow = sqlFetchArray($eres)) {
641 $patient_id = $erow['pid'];
642 $encounter_id = $erow['encounter'];
643 $pt_balance = $erow['charges'] + $erow['sales'] + $erow['copays'] - $erow['payments'] - $erow['adjustments'];
644 $pt_balance = 0 + sprintf("%.2f", $pt_balance); // yes this seems to be necessary
645 $svcdate = substr($erow['date'], 0, 10);
647 if ($_POST['form_refresh'] && ! $is_all) {
648 if ($pt_balance == 0) continue;
650 if ($_POST['form_category'] == 'Credits') {
651 if ($pt_balance > 0) continue;
654 // If we have not yet billed the patient, then compute $duncount as a
655 // negative count of the number of insurance plans for which we have not
656 // yet closed out insurance. Here we also compute $insname as the name of
657 // the insurance plan from which we are awaiting payment, and its sequence
658 // number $insposition (1-3).
659 $last_level_closed = $erow['last_level_closed'];
660 $duncount = $erow['stmt_count'];
661 $payerids = array();
662 $insposition = 0;
663 $insname = '';
664 if (! $duncount) {
665 for ($i = 1; $i <= 3; ++$i) {
666 $tmp = arGetPayerID($patient_id, $svcdate, $i);
667 if (empty($tmp)) break;
668 $payerids[] = $tmp;
670 $duncount = $last_level_closed - count($payerids);
671 if ($duncount < 0) {
672 if (!empty($payerids[$last_level_closed])) {
673 $insname = getInsName($payerids[$last_level_closed]);
674 $insposition = $last_level_closed + 1;
679 // Skip invoices not in the desired "Due..." category.
681 if ($is_due_ins && $duncount >= 0) continue;
682 if ($is_due_pt && $duncount < 0) continue;
684 // echo "<!-- " . $erow['encounter'] . ': ' . $erow['charges'] . ' + ' . $erow['sales'] . ' + ' . $erow['copays'] . ' - ' . $erow['payments'] . ' - ' . $erow['adjustments'] . " -->\n"; // debugging
686 // An invoice is due from the patient if money is owed and we are
687 // not waiting for insurance to pay.
688 $isduept = ($duncount >= 0) ? " checked" : "";
690 $row = array();
692 $row['id'] = $erow['id'];
693 $row['invnumber'] = "$patient_id.$encounter_id";
694 $row['custid'] = $patient_id;
695 $row['name'] = $erow['fname'] . ' ' . $erow['lname'];
696 $row['address1'] = $erow['street'];
697 $row['city'] = $erow['city'];
698 $row['state'] = $erow['state'];
699 $row['zipcode'] = $erow['postal_code'];
700 $row['phone'] = $erow['phone_home'];
701 $row['duncount'] = $duncount;
702 $row['dos'] = $svcdate;
703 $row['ss'] = $erow['ss'];
704 $row['DOB'] = $erow['DOB'];
705 $row['pubpid'] = $erow['pubpid'];
706 $row['billnote'] = $erow['billing_note'];
707 $row['referrer'] = $erow['referrer'];
708 $row['provider'] = $erow['provider_id'];
709 $row['irnumber'] = $erow['invoice_refno'];
711 // Also get the primary insurance company name whenever there is one.
712 $row['ins1'] = '';
713 if ($insposition == 1) {
714 $row['ins1'] = $insname;
715 } else {
716 if (empty($payerids)) {
717 $tmp = arGetPayerID($patient_id, $svcdate, 1);
718 if (!empty($tmp)) $payerids[] = $tmp;
720 if (!empty($payerids)) {
721 $row['ins1'] = getInsName($payerids[0]);
725 // This computes the invoice's total original charges and adjustments,
726 // date of last activity, and determines if insurance has responded to
727 // all billing items.
728 $invlines = ar_get_invoice_summary($patient_id, $encounter_id, true);
730 // if ($encounter_id == 185) { // debugging
731 // echo "\n<!--\n";
732 // print_r($invlines);
733 // echo "\n-->\n";
734 // }
736 $row['charges'] = 0;
737 $row['adjustments'] = 0;
738 $row['paid'] = 0;
739 $ins_seems_done = true;
740 $ladate = $svcdate;
741 foreach ($invlines as $key => $value) {
742 $row['charges'] += $value['chg'] + $value['adj'];
743 $row['adjustments'] += 0 - $value['adj'];
744 $row['paid'] += $value['chg'] - $value['bal'];
745 foreach ($value['dtl'] as $dkey => $dvalue) {
746 $dtldate = trim(substr($dkey, 0, 10));
747 if ($dtldate && $dtldate > $ladate) $ladate = $dtldate;
749 $lckey = strtolower($key);
750 if ($lckey == 'co-pay' || $lckey == 'claim') continue;
751 if (count($value['dtl']) <= 1) $ins_seems_done = false;
754 // Simulating ar.amount in SQL-Ledger which is charges with adjustments:
755 $row['amount'] = $row['charges'] + $row['adjustments'];
757 $row['billing_errmsg'] = '';
758 if ($is_due_ins && $last_level_closed < 1 && $ins_seems_done)
759 $row['billing_errmsg'] = 'Ins1 seems done';
760 else if ($last_level_closed >= 1 && !$ins_seems_done)
761 $row['billing_errmsg'] = 'Ins1 seems not done';
763 $row['ladate'] = $ladate;
765 // Compute number of days since last activity.
766 $latime = mktime(0, 0, 0, substr($ladate, 5, 2),
767 substr($ladate, 8, 2), substr($ladate, 0, 4));
768 $row['inactive_days'] = floor((time() - $latime) / (60 * 60 * 24));
770 // Look up insurance policy number if we need it.
771 if ($form_cb_policy) {
772 $instype = ($insposition == 2) ? 'secondary' : (($insposition == 3) ? 'tertiary' : 'primary');
773 $insrow = sqlQuery("SELECT policy_number FROM insurance_data WHERE " .
774 "pid = ? AND type = ? AND date <= ? " .
775 "ORDER BY date DESC LIMIT 1", array($patient_id, $instype, $svcdate));
776 $row['policy'] = $insrow['policy_number'];
779 $ptname = $erow['lname'] . ", " . $erow['fname'];
780 if ($erow['mname']) $ptname .= " " . substr($erow['mname'], 0, 1);
782 if (!$is_due_ins ) $insname = '';
783 $rows[$insname . '|' . $ptname . '|' . $encounter_id] = $row;
784 } // end while
787 ksort($rows);
789 if ($_POST['form_export']) {
790 echo "<textarea rows='35' cols='100' readonly>";
792 else if ($_POST['form_csvexport']) {
793 # CSV headers added conditions if they are checked to display then export them (TLH)
794 if (true) {
795 echo '"' . xl('Insurance') . '",';
796 echo '"' . xl('Name') . '",';
797 if ($form_cb_ssn)
799 echo '"' . xl('SSN') . '",';
801 if ($form_cb_dob)
803 echo '"' . xl('DOB') . '",';
805 if ($form_cb_pubid)
807 echo '"' . xl('Pubid') . '",';
809 if ($form_cb_policy)
811 echo '"' . xl('Policy') . '",';
813 if ($form_cb_phone)
815 echo '"' . xl('Phone') . '",';
817 if ($form_cb_city)
819 echo '"' . xl('City') . '",';
821 echo '"' . xl('Invoice') . '",';
822 echo '"' . xl('DOS') . '",';
823 echo '"' . xl('Referrer') . '",';
824 echo '"' . xl('Provider') . '",';
825 echo '"' . xl('Charge') . '",';
826 echo '"' . xl('Adjust') . '",';
827 echo '"' . xl('Paid') . '",';
828 echo '"' . xl('Balance') . '",';
829 echo '"' . xl('IDays') . '",';
830 if ($form_cb_err)
832 echo '"' . xl('LADate') . '",';
833 echo '"' . xl('Error') . '"' . "\n";
835 else
837 echo '"' . xl('LADate') . '"' . "\n";
841 else {
844 <div id="report_results">
845 <table id='mymaintable'>
847 <thead>
848 <?php if ($is_due_ins) { ?>
849 <th>&nbsp;<?php echo xlt('Insurance')?></th>
850 <?php } ?>
851 <?php if (!$is_ins_summary) { ?>
852 <th>&nbsp;<?php echo xlt('Name')?></th>
853 <?php } ?>
854 <?php if ($form_cb_ssn) { ?>
855 <th>&nbsp;<?php echo xlt('SSN')?></th>
856 <?php } ?>
857 <?php if ($form_cb_dob) { ?>
858 <th>&nbsp;<?php echo xlt('DOB')?></th>
859 <?php } ?>
860 <?php if ($form_cb_pubpid) { ?>
861 <th>&nbsp;<?php echo xlt('ID')?></th>
862 <?php } ?>
863 <?php if ($form_cb_policy) { ?>
864 <th>&nbsp;<?php echo xlt('Policy')?></th>
865 <?php } ?>
866 <?php if ($form_cb_phone) { ?>
867 <th>&nbsp;<?php echo xlt('Phone')?></th>
868 <?php } ?>
869 <?php if ($form_cb_city) { ?>
870 <th>&nbsp;<?php echo xlt('City')?></th>
871 <?php } ?>
872 <?php if ($form_cb_ins1 || $form_payer_id) { ?>
873 <th>&nbsp;<?php echo xlt('Primary Ins')?></th>
874 <?php } ?>
875 <?php if ($form_provider) { ?>
876 <th>&nbsp;<?php echo xlt('Provider')?></th>
877 <?php } ?>
878 <?php if ($form_cb_referrer) { ?>
879 <th>&nbsp;<?php echo xlt('Referrer')?></th>
880 <?php } ?>
881 <?php if (!$is_ins_summary) { ?>
882 <th>&nbsp;<?php echo xlt('Invoice') ?></th>
883 <th>&nbsp;<?php echo xlt('Svc Date') ?></th>
884 <?php if ($form_cb_adate) { ?>
885 <th>&nbsp;<?php echo xlt('Act Date')?></th>
886 <?php } ?>
887 <?php } ?>
888 <th align="right"><?php echo xlt('Charge') ?>&nbsp;</th>
889 <th align="right"><?php echo xlt('Adjust') ?>&nbsp;</th>
890 <th align="right"><?php echo xlt('Paid') ?>&nbsp;</th>
891 <?php
892 // Generate aging headers if appropriate, else balance header.
893 if ($form_age_cols) {
894 for ($c = 0; $c < $form_age_cols;) {
895 echo " <th class='dehead' align='right'>";
896 echo $form_age_inc * $c;
897 if (++$c < $form_age_cols) {
898 echo "-" . ($form_age_inc * $c - 1);
899 } else {
900 echo "+";
902 echo "</th>\n";
905 else {
907 <th align="right"><?php echo xlt('Balance') ?>&nbsp;</th>
908 <?php
911 <?php if ($form_cb_idays) { ?>
912 <th align="right"><?php echo xlt('IDays')?>&nbsp;</th>
913 <?php } ?>
914 <?php if (!$is_ins_summary) { ?>
915 <th align="center"><?php echo xlt('Prv') ?></th>
916 <th align="center"><?php echo xlt('Sel') ?></th>
917 <?php } ?>
918 <?php if ($form_cb_err) { ?>
919 <th>&nbsp;<?php echo xlt('Error')?></th>
920 <?php } ?>
921 </thead>
923 <?php
924 } // end not export
926 $ptrow = array('insname' => '', 'pid' => 0);
927 $orow = -1;
929 foreach ($rows as $key => $row) {
930 list($insname, $ptname, $trash) = explode('|', $key);
931 list($pid, $encounter) = explode(".", $row['invnumber']);
932 if ($form_payer_id) {
933 if ($ins_co_name <> $row['ins1']) continue;
935 if ($is_ins_summary && $insname != $ptrow['insname']) {
936 endInsurance($ptrow);
937 $bgcolor = ((++$orow & 1) ? "#ffdddd" : "#ddddff");
938 $ptrow = array('insname' => $insname, 'ptname' => $ptname, 'pid' => $pid, 'count' => 1);
939 foreach ($row as $key => $value) $ptrow[$key] = $value;
940 $ptrow['agedbal'] = array();
942 else if (!$is_ins_summary && ($insname != $ptrow['insname'] || $pid != $ptrow['pid'])) {
943 // For the report, this will write the patient totals. For the
944 // collections export this writes everything for the patient:
945 endPatient($ptrow);
946 $bgcolor = ((++$orow & 1) ? "#ffdddd" : "#ddddff");
947 $ptrow = array('insname' => $insname, 'ptname' => $ptname, 'pid' => $pid, 'count' => 1);
948 foreach ($row as $key => $value) $ptrow[$key] = $value;
949 $ptrow['agedbal'] = array();
950 } else {
951 $ptrow['amount'] += $row['amount'];
952 $ptrow['paid'] += $row['paid'];
953 $ptrow['charges'] += $row['charges'];
954 $ptrow['adjustments'] += $row['adjustments'];
955 ++$ptrow['count'];
959 // Compute invoice balance and aging column number, and accumulate aging.
960 $balance = $row['charges'] + $row['adjustments'] - $row['paid'];
961 if ($form_age_cols) {
962 $agedate = $is_ageby_lad ? $row['ladate'] : $row['dos'];
963 $agetime = mktime(0, 0, 0, substr($agedate, 5, 2),
964 substr($agedate, 8, 2), substr($agedate, 0, 4));
965 $days = floor((time() - $agetime) / (60 * 60 * 24));
966 $agecolno = min($form_age_cols - 1, max(0, floor($days / $form_age_inc)));
967 $ptrow['agedbal'][$agecolno] += $balance;
970 if (!$is_ins_summary && !$_POST['form_export'] && !$_POST['form_csvexport']) {
971 $in_collections = stristr($row['billnote'], 'IN COLLECTIONS') !== false;
973 <tr bgcolor='<?php echo attr($bgcolor) ?>'>
974 <?php
975 if ($ptrow['count'] == 1) {
976 if ($is_due_ins) {
977 echo " <td class='detail'>&nbsp;" . attr($insname) ."</td>\n";
979 echo " <td class='detail'>&nbsp;" . attr($ptname) ."</td>\n";
980 if ($form_cb_ssn) {
981 echo " <td class='detail'>&nbsp;" . attr($row['ss']) . "</td>\n";
983 if ($form_cb_dob) {
984 echo " <td class='detail'>&nbsp;" . attr(oeFormatShortDate($row['DOB'])) . "</td>\n";
986 if ($form_cb_pubpid) {
987 echo " <td class='detail'>&nbsp;" . attr($row['pubpid']) . "</td>\n";
989 if ($form_cb_policy) {
990 echo " <td class='detail'>&nbsp;" . attr($row['policy']) . "</td>\n";
992 if ($form_cb_phone) {
993 echo " <td class='detail'>&nbsp;" . attr($row['phone']) . "</td>\n";
995 if ($form_cb_city) {
996 echo " <td class='detail'>&nbsp;" . attr($row['city']) . "</td>\n";
998 if ($form_cb_ins1 || $form_payer_id ) {
999 echo " <td class='detail'>&nbsp;" . attr($row['ins1']) . "</td>\n";
1001 if ($form_provider) {
1002 echo " <td class='detail'>&nbsp;" . attr($provider_name) . "</td>\n";
1004 if ($form_cb_referrer) {
1005 echo " <td class='detail'>&nbsp;" . attr($row['referrer']) . "</td>\n";
1007 } else {
1008 echo " <td class='detail' colspan='$initial_colspan'>";
1009 echo "&nbsp;</td>\n";
1012 <td class="detail">
1013 &nbsp;<a href="../billing/sl_eob_invoice.php?id=<?php echo attr($row['id']) ?>"
1014 target="_blank"><?php echo empty($row['irnumber']) ? $row['invnumber'] : $row['irnumber']; ?></a>
1015 </td>
1016 <td class="detail">
1017 &nbsp;<?php echo attr(oeFormatShortDate($row['dos'])); ?>
1018 </td>
1019 <?php if ($form_cb_adate) { ?>
1020 <td class='detail'>
1021 &nbsp;<?php echo attr(oeFormatShortDate($row['ladate'])); ?>
1022 </td>
1023 <?php } ?>
1024 <td class="detail" align="right">
1025 <?php attr(bucks($row['charges'])) ?>&nbsp;
1026 </td>
1027 <td class="detail" align="right">
1028 <?php attr(bucks($row['adjustments'])) ?>&nbsp;
1029 </td>
1030 <td class="detail" align="right">
1031 <?php attr(bucks($row['paid'])) ?>&nbsp;
1032 </td>
1033 <?php
1034 if ($form_age_cols) {
1035 for ($c = 0; $c < $form_age_cols; ++$c) {
1036 echo " <td class='detail' align='right'>";
1037 if ($c == $agecolno) {
1038 bucks($balance);
1040 echo "&nbsp;</td>\n";
1043 else {
1045 <td class="detail" align="right"><?php bucks($balance) ?>&nbsp;</td>
1046 <?php
1047 } // end else
1049 <?php
1050 if ($form_cb_idays) {
1051 echo " <td class='detail' align='right'>";
1052 echo attr($row['inactive_days']) . "&nbsp;</td>\n";
1055 <td class="detail" align="center">
1056 <?php echo $row['duncount'] ? $row['duncount'] : "&nbsp;" ?>
1057 </td>
1058 <td class="detail" align="center">
1059 <?php
1060 if ($in_collections) {
1061 echo " <b><font color='red'>IC</font></b>\n";
1062 } else {
1063 echo " <input type='checkbox' name='form_cb[" . attr($row['invnumber']) . "]' />\n";
1066 </td>
1067 <?php
1068 if ($form_cb_err) {
1069 echo " <td class='detail'>&nbsp;";
1070 echo text($row['billing_errmsg']) . "</td>\n";
1073 </tr>
1074 <?php
1075 } // end not export and not insurance summary
1077 else if ($_POST['form_csvexport']) {
1079 # The CSV detail line is written here added conditions for checked items (TLH).
1080 $balance = $row['charges'] + $row['adjustments'] - $row['paid'];
1081 if($balance >0) {
1082 // echo '"' . $insname . '",';
1083 echo '"' . $row['ins1'] . '",';
1084 echo '"' . $ptname . '",';
1085 if ($form_cb_ssn)
1087 echo '"' . $row['ss'] . '",';
1089 if ($form_cb_dob)
1091 echo '"' . oeFormatShortDate($row['DOB']) . '",';
1093 if ($form_cb_pubid)
1095 echo '"' . $row['pubpid'] . '",';
1097 if ($form_cb_policy)
1099 echo '"' . $row['policy'] . '",';
1101 if ($form_cb_phone)
1103 echo '"' . $row['phone'] . '",';
1105 if ($form_cb_city)
1107 echo '"' . $row['city'] . '",';
1109 echo '"' . (empty($row['irnumber']) ? $row['invnumber'] : $row['irnumber']) . '",';
1110 echo '"' . oeFormatShortDate($row['dos']) . '",';
1111 echo '"' . $row['referrer'] . '",';
1112 echo '"' . $row['provider'] . '",';
1113 echo '"' . oeFormatMoney($row['charges']) . '",';
1114 echo '"' . oeFormatMoney($row['adjustments']) . '",';
1115 echo '"' . oeFormatMoney($row['paid']) . '",';
1116 echo '"' . oeFormatMoney($balance) . '",';
1117 echo '"' . $row['inactive_days'] . '",';
1118 if ($form_cb_err)
1120 echo '"' . oeFormatShortDate($row['ladate']) . '",';
1121 echo '"' . $row['billing_errmsg'] . '"' . "\n";
1123 else
1125 echo '"' . oeFormatShortDate($row['ladate']) . '"' . "\n";
1128 } // end $form_csvexport
1130 } // end loop
1132 if ($is_ins_summary)
1133 endInsurance($ptrow);
1134 else
1135 endPatient($ptrow);
1137 if ($_POST['form_export']) {
1138 echo "</textarea>\n";
1139 $alertmsg .= "$export_patient_count patients with total of " .
1140 oeFormatMoney($export_dollars) . " have been exported ";
1141 if ($_POST['form_without']) {
1142 $alertmsg .= "but NOT flagged as in collections.";
1143 } else {
1144 $alertmsg .= "AND flagged as in collections.";
1147 else if ($_POST['form_csvexport']) {
1148 // echo "</textarea>\n";
1149 // $alertmsg .= "$export_patient_count patients representing $" .
1150 // sprintf("%.2f", $export_dollars) . " have been exported.";
1152 else {
1153 echo " <tr bgcolor='#ffffff'>\n";
1154 if ($is_ins_summary) {
1155 echo " <td class='dehead'>&nbsp;" . xlt('Report Totals') . ":</td>\n";
1156 } else {
1157 echo " <td class='detail' colspan='" . attr($initial_colspan) . "'>\n";
1158 echo " &nbsp;</td>\n";
1159 echo " <td class='dehead' colspan='" . attr($final_colspan - 3) .
1160 "'>&nbsp;" . xlt('Report Totals') . ":</td>\n";
1162 echo " <td class='dehead' align='right'>&nbsp;" .
1163 oeFormatMoney($grand_total_charges) . "&nbsp;</td>\n";
1164 echo " <td class='dehead' align='right'>&nbsp;" .
1165 oeFormatMoney($grand_total_adjustments) . "&nbsp;</td>\n";
1166 echo " <td class='dehead' align='right'>&nbsp;" .
1167 oeFormatMoney($grand_total_paid) . "&nbsp;</td>\n";
1168 if ($form_age_cols) {
1169 for ($c = 0; $c < $form_age_cols; ++$c) {
1170 echo " <td class='dehead' align='right'>" .
1171 oeFormatMoney($grand_total_agedbal[$c]) . "&nbsp;</td>\n";
1174 else {
1175 echo " <td class='dehead' align='right'>" .
1176 oeFormatMoney($grand_total_charges +
1177 $grand_total_adjustments - $grand_total_paid) . "&nbsp;</td>\n";
1179 if ($form_cb_idays) echo " <td class='detail'>&nbsp;</td>\n";
1180 if (!$is_ins_summary) echo " <td class='detail' colspan='2'>&nbsp;</td>\n";
1181 if ($form_cb_err) echo " <td class='detail'>&nbsp;</td>\n";
1182 echo " </tr>\n";
1183 echo "</table>\n";
1184 echo "</div>\n";
1186 } // end if form_refresh
1189 if (!$_POST['form_csvexport']) {
1190 if (!$_POST['form_export']) {
1193 <div style='float;margin-top:5px'>
1195 <a href='javascript:;' class='css_button' onclick='checkAll(true)'><span><?php echo xlt('Select All'); ?></span></a>
1196 <a href='javascript:;' class='css_button' onclick='checkAll(false)'><span><?php echo xlt('Clear All'); ?></span></a>
1197 <a href='javascript:;' class='css_button' onclick='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
1198 <span><?php echo xlt('Export Selected as CSV'); ?></span>
1199 </a>
1200 <a href='javascript:;' class='css_button' onclick='$("#form_export").attr("value","true"); $("#theform").submit();'>
1201 <span><?php echo xlt('Export Selected to Collections'); ?></span>
1202 </a>
1203 </div>
1205 <div style='float:left'>
1206 <label><input type='checkbox' name='form_individual' value='1' /> <?php echo xlt('Export Individual Invoices') ?>&nbsp;&nbsp;</label>
1207 </div>
1209 <div style='float:left'>
1210 <label><input type='checkbox' name='form_without' value='1' /> <?php echo xlt('Without Update') ?></label>
1211 </div>
1213 <?php
1214 } // end not export
1216 </form>
1217 </center>
1218 <script language="JavaScript">
1219 <?php
1220 if ($alertmsg) {
1221 echo "alert('" . addslashes($alertmsg) . "');\n";
1224 </script>
1225 </body>
1226 <!-- stuff for the popup calendar -->
1227 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
1228 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
1229 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
1230 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
1231 <script language="Javascript">
1232 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
1233 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
1234 </script>
1235 </html>
1236 <?php
1237 } // end not form_csvexport