Feat openemr fix 7764 last updated (#7767)
[openemr.git] / interface / patient_file / encounter / cash_receipt.php
blob06e10bb3249f27ac7b69a5b840135d65992d6237
1 <?php
3 /**
4 * cash_receipt.php
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 // TODO: Code cleanup
15 require_once("../../globals.php");
16 require_once("$srcdir/forms.inc.php");
17 require_once("$srcdir/pnotes.inc.php");
18 require_once("$srcdir/patient.inc.php");
19 require_once("$srcdir/report.inc.php");
20 require_once("$srcdir/options.inc.php");
22 use OpenEMR\Billing\BillingUtilities;
23 use OpenEMR\Common\Csrf\CsrfUtils;
24 use OpenEMR\Core\Header;
26 if (!CsrfUtils::verifyCsrfToken($_GET["csrf_token_form"])) {
27 CsrfUtils::csrfNotVerified();
30 $N = 6;
31 $first_issue = 1;
33 <html>
34 <head>
35 <?php Header::setupHeader(); ?>
36 </head>
38 <body class="bg-white ml-1">
39 <p>
40 <?php
41 $titleres = getPatientData($pid, "fname,lname,providerID");
42 // $sql = "select * from facility where billing_location = 1";
43 $sql = "select f.* from facility f " .
44 "LEFT JOIN form_encounter fe on fe.facility_id = f.id " .
45 "where fe.encounter = ?";
46 $db = $GLOBALS['adodb']['db'];
47 $results = $db->Execute($sql, array($encounter));
48 $facility = array();
49 if (!$results->EOF) {
50 $facility = $results->fields;
53 $practice_logo = "../../../custom/practice_logo.gif";
54 if (file_exists($practice_logo)) {
55 echo "<img src='$practice_logo' align='left'>\n";
58 <h2><?php echo text($facility['name']); ?></h2>
59 <?php echo text($facility['street']); ?><br />
60 <?php echo text($facility['city']); ?>, <?php echo text($facility['state']); ?> <?php echo text($facility['postal_code']); ?><div class="clearfix"></div>
61 <?php echo text($facility['phone']); ?><br />
63 </p>
65 <a href="javascript:window.close();"><span class='title'><?php print text($titleres["fname"]) . " " . text($titleres["lname"]); ?></span></a><br /><br />
67 <table>
68 <tr><td><?php echo xlt('Generated on'); ?>:</td><td> <?php print text(oeFormatShortDate(date("Y-m-d")));?></td></tr>
69 <?php
70 if ($date_result = sqlQuery("select date from form_encounter where encounter=? and pid=?", array($encounter, $pid))) {
71 $encounter_date = date("D F jS", strtotime($date_result["date"]));
72 $raw_encounter_date = date("Y-m-d", strtotime($date_result["date"]));
75 <tr><td><?php echo xlt('Date Of Service'); ?>: </td><td> <?php print text(oeFormatShortDate($raw_encounter_date));?></td></tr>
76 </table>
77 <br /><br />
78 <?php
79 //$provider = getProviderName($titleres['providerID']);
81 //print "Provider: " . $provider . "<br />";
83 $inclookupres = sqlStatement("select distinct formdir from forms where pid=?", array($pid));
84 while ($result = sqlFetchArray($inclookupres)) {
85 include_once("{$GLOBALS['incdir']}/forms/" . $result["formdir"] . "/report.php");
88 $printed = false;
90 //borrowed from diagnosis.php
93 <table class="table-bordered" cellpadding="5">
94 <?php
95 if ($result = BillingUtilities::getBillingByEncounter($pid, $encounter, "*")) {
96 $billing_html = array();
97 $total = 0.0;
98 $copay = 0.0;
100 //test
101 // foreach ($result as $key => $val) {
102 // print "<h2>$key</h2>";
103 // foreach($val as $key2 => $val2) {
104 // print "<p> $key2 = $val2 </p>\n";
105 // }
106 // }
107 //end test
109 foreach ($result as $iter) {
110 $html = '';
111 if ($iter["code_type"] == "ICD9") {
112 $html .= "<tr><td>" . text($iter['code_type']) .
113 "</td><td>" . text($iter['code']) . "</td><td>"
114 . text($iter["code_text"]) . "</td></tr>\n";
115 $billing_html[$iter["code_type"]] .= $html;
116 $counter++;
117 } elseif ($iter["code_type"] == "COPAY") {
118 $html .= "<tr><td>" . xlt('Payment') . ":</td><td>" . xlt('Thank You') . "!</td><td>"
119 . text($iter["code_text"]) . "</td><td>"
120 . text(oeFormatMoney($iter["code"])) . "</td></tr>\n";
121 if ($iter["code"] > 0.00) {
122 $copay += $iter["code"];
123 $billing_html[$iter["code_type"]] .= $html;
125 } else {
126 $html .= "<tr><td>" . text($iter['code_type']) .
127 "</td><td>" . text($iter['code']) . "</td><td>"
128 . text($iter["code_text"]) . ' ' . text($iter['modifier'])
129 . "</td><td>" . text(oeFormatMoney($iter['fee'])) . "</td></tr>\n";
130 $billing_html[$iter["code_type"]] .= $html;
131 $total += $iter['fee'];
132 $js = explode(":", $iter['justify']);
133 $counter = 0;
134 foreach ($js as $j) {
135 if (!empty($j)) {
136 if ($counter == 0) {
137 $billing_html[$iter["code_type"]] .= " (<b>" . text($j) . "</b>)";
138 } else {
139 $billing_html[$iter["code_type"]] .= " (" . text($j) . ")";
142 $counter++;
147 $billing_html[$iter["code_type"]] .= "</span></td></tr>\n";
151 $billing_html["CPT4"] .= "<tr><td>" . xlt('total') . "</td><td></td><td></td><td>" . text(oeFormatMoney($total)) . "</td></tr>\n";
153 <tr><td><?php echo xlt('code type'); ?></td><td><?php echo xlt('code'); ?></td><td><?php echo xlt('description'); ?></td><td><?php echo xlt('fee'); ?></td></tr>
154 <?php
155 $key = "ICD9";
156 $val = $billing_html[$key];
157 print $val;
158 $key = "CPT4";
159 $val = $billing_html[$key];
160 print $val;
161 $key = "COPAY";
162 $val = $billing_html[$key];
163 print $val;
164 $balance = $total - $copay;
165 if ($balance != 0.00) {
166 print "<tr><td>" . xlt('balance') . "</td><td></td><td>" . xlt('Please pay this amount') . ":</td><td>" . text(oeFormatMoney($balance)) . "</td></tr>\n";
170 </tr></table>
171 <?php
172 //if ($balance != 0.00) {
173 // print "<p>Note: The balance recorded above only reflects the encounter described by this statement. It does not reflect the balance of the entire account. A negative number in the balance field indicates a credit due to overpayment</p>";
177 </body>
178 </html>