Updated to document new features, particularly multibox buttons.
[openemr.git] / interface / patient_file / front_payment.php
blob26022b69b3f745f1861d64269f6bc13dadbd3308
1 <?php
2 // Copyright (C) 2006 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 include_once("../globals.php");
10 include_once("$srcdir/patient.inc");
12 <html>
13 <head>
14 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
15 <?php
16 $payment_methods = array(
17 xl('Cash'),
18 xl('Check'),
19 xl('MC'),
20 xl('VISA'),
21 xl('AMEX'),
22 xl('DISC'),
23 xl('Other'));
25 // $patdata = getPatientData($pid, 'fname,lname,pubpid');
27 $patdata = sqlQuery("SELECT " .
28 "p.fname, p.mname, p.lname, p.pubpid, i.copay " .
29 "FROM patient_data AS p " .
30 "LEFT OUTER JOIN insurance_data AS i ON " .
31 "i.pid = p.pid AND i.type = 'primary' " .
32 "WHERE p.pid = '$pid' ORDER BY i.date DESC LIMIT 1");
34 $alertmsg = ''; // anything here pops up in an alert box
36 // If the Save button was clicked...
37 if ($_POST['form_save']) {
38 $form_pid = $_POST['form_pid'];
39 $payid = $_REQUEST['payid'];
41 if ($payid) {
42 sqlStatement("UPDATE payments SET " .
43 "dtime = NOW(), " .
44 "user = '" . $_SESSION['authUser'] . "', " .
45 "method = '" . $_POST['form_method'] . "', " .
46 "source = '" . $_POST['form_source'] . "', " .
47 "amount1 = '" . $_POST['form_amount1'] . "', " .
48 "amount2 = '" . $_POST['form_amount2'] . "' " .
49 "WHERE id = '$payid'");
50 } else {
51 $payid = sqlInsert("INSERT INTO payments ( " .
52 "pid, dtime, user, method, source, amount1, amount2 " .
53 ") VALUES ( " .
54 "'$form_pid', " .
55 "NOW(), " .
56 "'" . $_SESSION['authUser'] . "', " .
57 "'" . $_POST['form_method'] . "', " .
58 "'" . $_POST['form_source'] . "', " .
59 "'" . $_POST['form_amount1'] . "', " .
60 "'" . $_POST['form_amount2'] . "' " .
61 ")");
66 <?php
67 if ($_POST['form_save'] || $_REQUEST['receipt']) {
69 // Get details for what we guess is the primary facility.
70 $frow = sqlQuery("SELECT * FROM facility " .
71 "ORDER BY billing_location DESC, accepts_assignment DESC, id LIMIT 1");
73 // Re-fetch info for this payment.
74 $payrow = sqlQuery("SELECT * FROM payments WHERE id = '$payid'");
76 // Get the patient's name and chart number.
77 $patdata = getPatientData($payrow['pid'], 'fname,mname,lname,pubpid');
79 // Now proceed with printing the receipt.
82 <title><? xl('Receipt for Payment','e'); ?></title>
83 <body bgcolor='#ffffff'>
84 <center>
86 <p><h2><? xl('Receipt for Payment','e'); ?></h2>
88 <p><?php echo htmlentities($frow['name']) ?>
89 <br><?php echo htmlentities($frow['street']) ?>
90 <br><?php echo htmlentities($frow['city'] . ', ' . $frow['state']) . ' ' .
91 $frow['postal_code'] ?>
92 <br><?php echo htmlentities($frow['phone']) ?>
94 <p>
95 <table border='0' cellspacing='8'>
96 <tr>
97 <td><? xl('Date','e'); ?>:</td>
98 <td><?php echo date('Y-m-d', strtotime($payrow['dtime'])) ?></td>
99 </tr>
100 <tr>
101 <td><? xl('Patient','e'); ?>:</td>
102 <td><?php echo $patdata['fname'] . " " . $patdata['mname'] . " " .
103 $patdata['lname'] . " (" . $patdata['pubpid'] . ")" ?></td>
104 </tr>
105 <tr>
106 <td><? xl('Paid Via','e'); ?>:</td>
107 <td><?php echo $payrow['method'] ?></td>
108 </tr>
109 <tr>
110 <td><? xl('Check/Ref Number','e'); ?>:</td>
111 <td><?php echo $payrow['source'] ?></td>
112 </tr>
113 <tr>
114 <td><? xl('Amount for This Visit','e'); ?>:</td>
115 <td><?php echo $payrow['amount1'] ?></td>
116 </tr>
117 <tr>
118 <td><? xl('Amount for Past Balance','e'); ?>:</td>
119 <td><?php echo $payrow['amount2'] ?></td>
120 </tr>
121 <tr>
122 <td><? xl('Received By','e'); ?>:</td>
123 <td><?php echo $payrow['user'] ?></td>
124 </tr>
125 </table>
127 </center>
129 <p>&nbsp;<br>
130 <a href='' class='link_submit' onclick='window.print();return false;'><? xl('Print','e'); ?></a>
132 </body>
134 <?php
135 } else {
137 // This is the case where we display the form for data entry.
139 $payrow = array('amount1' => $patdata['copay']);
140 if ($_REQUEST['payid']) {
141 $payrow = sqlQuery("SELECT * FROM payments WHERE id = '" .
142 $_REQUEST['payid'] . "'");
144 // Continue with display of the data entry form.
146 <title><? xl('Record Payment','e'); ?></title>
148 <style>
149 </style>
151 <script type="text/javascript" src="../../library/topdialog.js"></script>
152 <script type="text/javascript" src="../../library/dialog.js"></script>
154 <script language="JavaScript">
155 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
156 </script>
158 </head>
160 <body <?echo $top_bg_line;?> leftmargin='0' topmargin='0' marginwidth='0'
161 marginheight='0' onunload='imclosing()'>
163 <form method='post' action='front_payment.php<?php if ($payid) echo "?payid=$payid"; ?>'
164 onsubmit='return top.restoreSession()'>
165 <input type='hidden' name='form_pid' value='<?php echo $pid ?>' />
167 <center>
169 <table border='0' cellspacing='8'>
171 <tr>
172 <td colspan='2' align='center'>
173 &nbsp;<br>
174 <b><? xl('Accept Payment for ','e'); ?><?php echo $patdata['fname'] . " " .
175 $patdata['lname'] . " (" . $patdata['pubpid'] . ")" ?></b>
176 <br>&nbsp;
177 </td>
178 </tr>
180 <tr>
181 <td>
182 <? xl('Payment Method','e'); ?>:
183 </td>
184 <td>
185 <select name='form_method'>
187 foreach ($payment_methods as $value) {
188 echo " <option value='$value'";
189 if ($value == $payrow['method']) echo " selected";
190 echo ">$value</option>\n";
193 </select>
194 </td>
195 </tr>
197 <tr>
198 <td>
199 <? xl('Check/Reference Number','e'); ?>:
200 </td>
201 <td>
202 <input type='text' name='form_source' size='10' value='<?php echo $payrow['source'] ?>'>
203 </td>
204 </tr>
206 <tr>
207 <td>
208 <? xl('Amount for Todays Visit','e'); ?>:
209 </td>
210 <td>
211 <input type='text' name='form_amount1' size='10' value='<?php echo $payrow['amount1'] ?>'>
212 </td>
213 </tr>
215 <tr>
216 <td>
217 <? xl('Amount for Prior Balance','e'); ?>:
218 </td>
219 <td>
220 <input type='text' name='form_amount2' size='10' value='<?php echo $payrow['amount2'] ?>'>
221 </td>
222 </tr>
224 <tr>
225 <td colspan='2' align='center'>
226 &nbsp;<br>
227 <input type='submit' name='form_save' value='<?php xl('Save','e'); ?>' /> &nbsp;
228 <input type='button' value='<?php xl('Cancel','e'); ?>' onclick='window.close()' />
229 </td>
230 </tr>
232 </table>
233 </center>
235 </form>
237 </body>
239 <?php
242 </html>