4 * Check/cash details are entered here.Used in New Payment and Edit Payment screen.
5 * Special list function
8 * @link http://www.open-emr.org
9 * @author Eldho Chacko <eldho@zhservices.com>
10 * @author Paul Simon K <paul@zhservices.com>
11 * @author Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2010 Z&H Consultancy Services Private Limited <sam@zhservices.com>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 function generate_list_payment_category($tag_name, $list_id, $currvalue, $title, $empty_name = ' ', $class = '', $onchange = '', $PaymentType = 'insurance', $screen = 'new_payment')
19 $s .= "<select name='" . attr($tag_name) . "' id='" . attr($tag_name) . "'";
21 $s .= " class='" . attr($class) . "'";
24 $s .= " onchange='" . $onchange . "'"; //Need to html escape $onchange prior to the generate_list_payment_category function call
26 $s .= " title='" . attr($title) . "'>";
28 $s .= "<option value=''>" . xlt($empty_name) . "</option>";
30 $lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
31 $got_selected = false;
32 while ($lrow = sqlFetchArray($lres)) {
33 $s .= "<option id='option_" . attr($lrow['option_id']) . "'" . " value='" . attr($lrow['option_id']) . "'";
34 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
(strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue) ||
($lrow['option_id'] == 'insurance_payment' && $screen == 'new_payment')) {
38 if (($PaymentType == 'insurance' ||
$screen == 'new_payment') && ($lrow['option_id'] == 'family_payment' ||
$lrow['option_id'] == 'patient_payment')) {
39 $s .= " style='background-color: var(--light)' ";
41 if ($PaymentType == 'patient' && $lrow['option_id'] == 'insurance_payment') {
42 $s .= " style='background-color: var(--light)' ";
44 $s .= ">" . text(xl_list_label($lrow['title'])) . "</option>\n";
46 if (!$got_selected && strlen($currvalue) > 0) {
47 $currescaped = text($currvalue);
48 $s .= "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
50 $fontTitle = xl('Please choose a valid selection from the list.');
51 $fontText = xl('Fix this');
52 $s .= " <font class='text-danger' title='" . attr($fontTitle) . "'>" . text($fontText) . "!</font>";
59 // ================================================================================================
69 $UndistributedAmount = 0;
70 if ($payment_id > 0) {
71 $rs = sqlStatement("select pay_total,global_amount from ar_session where session_id=?", array($payment_id));
72 $row = sqlFetchArray($rs);
73 $pay_total = $row['pay_total'];
74 $global_amount = $row['global_amount'];
76 "SELECT sum(pay_amount) sum_pay_amount FROM ar_activity WHERE session_id = ? AND deleted IS NULL",
79 $row = sqlFetchArray($rs);
80 $pay_amount = $row['sum_pay_amount'];
81 $UndistributedAmount = $pay_total - $pay_amount - $global_amount;
83 $res = sqlStatement("SELECT check_date ,reference ,insurance_companies.name,
84 payer_id,pay_total,payment_type,post_to_date,patient_id ,
85 adjustment_code,description,deposit_date,payment_method
86 FROM ar_session left join insurance_companies on ar_session.payer_id=insurance_companies.id where ar_session.session_id =?", array($payment_id));
87 $row = sqlFetchArray($res);
88 $InsuranceCompanyName = $row['name'];
89 $InsuranceCompanyId = $row['payer_id'];
90 $PatientId = $row['patient_id'];
91 $CheckNumber = $row['reference'];
92 $CheckDate = $row['check_date'] == '0000-00-00' ?
'' : $row['check_date'];
93 $PayTotal = $row['pay_total'];
94 $PostToDate = $row['post_to_date'] == '0000-00-00' ?
'' : $row['post_to_date'];
95 $PaymentMethod = $row['payment_method'];
96 $PaymentType = $row['payment_type'];
97 $AdjustmentCode = $row['adjustment_code'];
98 $DepositDate = $row['deposit_date'] == '0000-00-00' ?
'' : $row['deposit_date'];
99 $Description = $row['description'];
100 if ($row['payment_type'] == 'insurance' ||
$row['payer_id'] * 1 > 0) {
101 $res = sqlStatement("SELECT insurance_companies.name FROM insurance_companies
102 where insurance_companies.id =?", array($InsuranceCompanyId));
103 $row = sqlFetchArray($res);
104 $div_after_save = $row['name'] ??
'';
105 $TypeCode = $InsuranceCompanyId;
106 if ($PaymentType == '') {
107 $PaymentType = 'insurance';
109 } elseif ($row['payment_type'] == 'patient' ||
$row['patient_id'] * 1 > 0) {
110 $res = sqlStatement("SELECT fname,lname,mname FROM patient_data
111 where pid =?", array($PatientId));
112 $row = sqlFetchArray($res);
113 $fname = $row['fname'];
114 $lname = $row['lname'];
115 $mname = $row['mname'];
116 $div_after_save = $lname . ' ' . $fname . ' ' . $mname;
117 $TypeCode = $PatientId;
118 if ($PaymentType == '') {
119 $PaymentType = 'patient';
125 //================================================================================================
126 if (($screen == 'new_payment' && $payment_id * 1 == 0) ||
($screen == 'edit_payment' && $payment_id * 1 > 0)) {//New entry or edit in edit screen comes here.
129 if (isset($_REQUEST['ParentPage']) && $_REQUEST['ParentPage'] == 'new_payment') {//This case comes when the Finish Payments is pressed from the New Payment screen.
132 <?php
echo xlt('Confirm Payment'); ?
>
136 } elseif ($screen == 'new_payment') { ?
>
138 <?php
echo xlt('Batch Payment Entry'); ?
>
143 <?php
echo xlt('Edit Payment'); ?
>
149 <div
class="forms col-3">
150 <label
class="control-label" for="check_date"><?php
echo xlt('Date'); ?
>:</label
>
151 <input
class="form-control datepicker" id
='check_date' name
='check_date' type
='text' value
="<?php echo attr(oeFormatShortDate($CheckDate)); ?>" autocomplete
="off">
153 <div
class="forms col-3">
154 <label
class="control-label" for="post_to_date"><?php
echo xlt('Post To Date'); ?
>:</label
>
155 <input
class="form-control datepicker" id
='post_to_date' name
='post_to_date' type
='text' value
="<?php echo ($screen == 'new_payment') ? attr(oeFormatShortDate(date('Y-m-d'))) : attr(oeFormatShortDate($PostToDate)); ?>" autocomplete
="off">
157 <div
class="forms col-3">
158 <label
class="control-label" for="payment_method"><?php
echo xlt('Payment Method'); ?
>:</label
>
161 if ($PaymentMethod == '' && $screen == 'edit_payment') {
166 echo generate_select_list("payment_method", "payment_method", "$PaymentMethod", "Payment Method", "$blankValue", "", 'CheckVisible("yes")');
170 <div
class="forms col-3">
171 <label
class="control-label" for="check_number"><?php
echo xlt('Check Number'); ?
>:</label
>
173 if ($PaymentMethod == 'check_payment' ||
$PaymentMethod == 'bank_draft' ||
$CheckNumber != '' ||
$screen == 'new_payment') {
175 $CheckDivDisplay = ' display: none; ';
177 $CheckDisplay = ' display: none; ';
178 $CheckDivDisplay = '';
181 <input type
="text" name
="check_number" style
="<?php echo $CheckDisplay; ?>" autocomplete
="off" class="form-control" value
="<?php echo attr($CheckNumber); ?>" onKeyUp
="ConvertToUpperCase(this)" id
="check_number" class="form-control " />
182 <div id
="div_check_number" class="text border" style
="width:140px;<?php echo $CheckDivDisplay; ?>"> 
;</div
>
186 <div
class="forms col-3">
187 <label
class="control-label" for="payment_method"><?php
echo xlt('Payment Amount'); ?
>:</label
>
188 <input type
="text" name
="payment_amount" autocomplete
="off" id
="payment_amount" onchange
="ValidateNumeric(this);<?php echo $screen == 'new_payment' ? 'FillUnappliedAmount();' : 'FillAmount();'; ?>" value
="<?php echo ($screen == 'new_payment') ? attr('0.00') : attr($PayTotal); ?>" class="form-control text-right" />
190 <div
class="forms col-3">
191 <label
class="control-label" for="type_name"><?php
echo xlt('Paying Entity'); ?
>:</label
>
193 if ($PaymentType == '' && $screen == 'edit_payment') {
198 echo generate_select_list("type_name", "payment_type", "$PaymentType", "Paying Entity", "$blankValue", "form-control", 'PayingEntityAction()');
201 <div
class="forms col-3">
202 <label
class="control-label" for="adjustment_code"><?php
echo xlt('Payment Category'); ?
>:</label
>
204 if ($AdjustmentCode == '' && $screen == 'edit_payment') {
209 echo generate_list_payment_category(
211 "payment_adjustment_code",
216 'FilterSelection(this)',
224 <div
class="forms col-6">
225 <label
class="control-label" for="type_code"><?php
echo xlt('Payment From'); ?
>:</label
>
226 <input type
="hidden" id
="hidden_ajax_close_value" value
="<?php echo attr($div_after_save); ?>" />
227 <input name
='type_code' id
='type_code' type
="text" class="form-control" onKeyDown
="PreventIt(event)" value
="<?php echo attr($div_after_save); ?>" autocomplete
="off" />
228 <!-- onKeyUp
="ajaxFunction(event,'non','edit_payment.php');" -->
229 <div id
='ajax_div_insurance_section'>
230 <div id
='ajax_div_insurance_error'>
232 <div id
="ajax_div_insurance" style
="display: none;"></div
>
235 <div
class="forms col-3">
236 <label
class="control-label" for="div_insurance_or_patient"><?php
echo xlt('Payor ID'); ?
>:</label
>
237 <!--<input
class="form-control" type
="text" value
= '<?php //echo attr($TypeCode);?>' name
="div_insurance_or_patient" id
="div_insurance_or_patient" placeholder
="Payor ID…" />-->
238 <div name
="div_insurance_or_patient" id
="div_insurance_or_patient" class="form-control"><?php
echo text($TypeCode); ?
></div
>
242 <div
class="forms col-2">
243 <label
class="control-label" for="deposit_date"><?php
echo xlt('Deposit Date'); ?
>:</label
>
244 <input type
='text' class='form-control datepicker' name
='deposit_date' id
='deposit_date' onKeyDown
="PreventIt(event)" value
="<?php echo attr(oeFormatShortDate($DepositDate)); ?>" autocomplete
="off" />
246 <div
class="forms col-6">
247 <label
class="control-label" for="description"><?php
echo xlt('Description'); ?
>:</label
>
248 <input type
="text" name
="description" id
="description" onKeyDown
="PreventIt(event)" value
="<?php echo attr($Description); ?>" class="form-control" />
250 <div
class="forms col-2">
251 <label
class="control-label" for="GlobalReset"><?php
echo xlt('Distributed to Global'); ?
>:</label
>
252 <div
class="input-group">
253 <button
class="input-group-prepend btn btn-secondary btn-delete" onclick
="getElementById('GlobalReset').value='-0.00';this.classList.remove('btn-delete');event.target.classList.add('fa', 'fa-ban');">
255 <input id
="GlobalReset" name
="global_reset" class="form-control" value
="<?php echo (($global_amount ?? null) * 1 === 0) ? attr("0.00") : attr(number_format(($global_amount ?? null), 2, '.', ',')); ?>" readonly
/>
258 <div
class="forms col-2">
259 <label
class="control-label" for="TdUnappliedAmount"><?php
echo xlt('Undistributed'); ?
>:</label
>
260 <div id
="TdUnappliedAmount" class="form-control bg-danger text-light"><?php
echo ($UndistributedAmount * 1 == 0) ?
attr("0.00") : attr(number_format($UndistributedAmount, 2, '.', ',')); ?
></div
>
261 <input name
="HidUnappliedAmount" id
="HidUnappliedAmount" value
="<?php echo ($UndistributedAmount * 1 == 0) ? attr("0.00") : attr(number_format($UndistributedAmount, 2, '.', ',')); ?>" type
="hidden" />
262 <input name
="HidUnpostedAmount" id
="HidUnpostedAmount" value
="<?php echo attr($UndistributedAmount); ?>" type
="hidden" />
263 <input name
="HidCurrentPostedAmount" id
="HidCurrentPostedAmount" value
="" type
="hidden" />
266 <?php
if ($screen == 'new_payment') { ?
>
267 <div
class="form-group mt-3">
269 <div
class="col-sm-12 text-left position-override">
270 <div
class="btn-group" role
="group">
271 <button onClick
="return SavePayment();" class="btn btn-primary btn-save"><?php
echo xlt('Save Changes'); ?
></button
>
272 <button
class="btn btn-primary btn-save" onClick
="return OpenEOBEntry();"><?php
echo xlt('Allocate'); ?
></button
>
273 <button onclick
="ResetForm(); return false;" class="btn btn-secondary btn-cancel"><?php
echo xlt('Cancel Changes'); ?
></button
>
280 </fieldset
><!--end of fieldset in edit
-payment
.php
-->
282 }//if(($screen=='new_payment' && $payment_id*1==0) || ($screen=='edit_payment' && $payment_id*1>0))
285 if ($screen == 'new_payment' && $payment_id * 1 > 0) {//After saving from the New Payment screen,all values are showed as labels.The date picker images are also removed.
287 <div
class="col-12 h3">
288 <?php
echo xlt('Batch Payment Entry'); ?
>
291 <div
class="forms col-3">
292 <label
class="control-label" for="check_date"><?php
echo xlt('Date'); ?
>:</label
>
293 <input
class="form-control" id
='check_date' name
='check_date' type
='text' value
="<?php echo attr(oeFormatShortDate($CheckDate)); ?> " disabled
>
295 <div
class="forms col-3">
296 <label
class="control-label" for="post_to_date"><?php
echo xlt('Post To Date'); ?
>:</label
>
297 <input
class="form-control" id
='post_to_date' name
='post_to_date' type
='text' value
="<?php echo ($screen == 'new_payment') ? attr(oeFormatShortDate(date('Y-m-d'))) : attr(oeFormatShortDate($PostToDate)); ?>" disabled
>
299 <div
class="forms col-3">
300 <label
class="control-label" for="payment_method"><?php
echo xlt('Payment Method'); ?
>:</label
>
301 <input type
="text" class="form-control" name
="payment_method1" id
="payment_method" value
="<?php
302 $list = 'payment_method';
303 $option = $PaymentMethod;
304 echo getListItemTitle($list, $option); ?>" disabled
/>
305 <input type
="hidden" name
="payment_method" value
="<?php echo attr($PaymentMethod); ?>" />
307 <div
class="forms col-3">
308 <label
class="control-label" for="checknumber"><?php
echo xlt('Check Number'); ?
>:</label
>
309 <input type
="text" class="form-control" name
="check_number" id
="checknumber" value
="<?php echo attr($CheckNumber); ?>" disabled
/>
313 <div
class="forms col-3">
314 <label
class="control-label" for="payment_amount"><?php
echo xlt('Payment Amount'); ?
>:</label
>
315 <input type
="text" class="form-control" name
="payment_amount" id
="payment_amount" value
="<?php echo attr($PayTotal); ?>" disabled
/>
317 <div
class="forms col-3">
318 <label
class="control-label" for="type_name"><?php
echo xlt('Paying Entity'); ?
>:</label
>
319 <input type
="text" class="form-control" name
="type_name1" id
="type_name1" value
="<?php
320 $list = 'payment_type';
321 $option = $PaymentType;
322 echo getListItemTitle($list, $option); ?>" disabled
/>
323 <input type
="hidden" name
="type_name" id
="type_name" value
="<?php echo attr($PaymentType); ?>" />
325 <div
class="forms col-3">
326 <label
class="control-label" for="adjustment_code"><?php
echo xlt('Payment Category'); ?
>:</label
>
327 <input type
="text" class="form-control" name
="adjustment_code1" id
="adjustment_code1" value
="<?php
328 $list = 'payment_adjustment_code';
329 $option = $AdjustmentCode;
330 echo getListItemTitle($list, $option); ?>" disabled
/>
331 <input type
="hidden" name
="adjustment_code" value
="<?php echo attr($AdjustmentCode); ?>" />
335 <div
class="forms col-6">
336 <label
class="control-label" for="div_insurance_or_patient"><?php
echo xlt('Payment From'); ?
>:</label
>
337 <input name
='div_insurance_or_patient' id
='div_insurance_or_patient' type
="text" class="form-control" value
="<?php echo attr($div_after_save); ?>" disabled
/>
339 <div
class="forms col-3">
340 <label
class="control-label" for="type_code"><?php
echo xlt('Payor ID'); ?
>:</label
>
341 <input type
="text" name
="type_code" id
="type_code" class="form-control" value
="<?php echo attr($TypeCode); ?>" disabled
/>
344 <div
class="row oe-custom-line">
345 <div
class="forms col-2">
346 <label
class="control-label" for="deposit_date"><?php
echo xlt('Deposit Date'); ?
>:</label
>
347 <input type
="text" class='form-control' name
="deposit_date" id
="deposit_date" value
="<?php echo attr(oeFormatShortDate($DepositDate)); ?>" disabled
/>
349 <div
class="forms col-6">
350 <label
class="control-label" for="description"><?php
echo xlt('Description'); ?
>:</label
>
351 <input type
="text" name
="description" id
="description" value
="<?php echo attr($Description); ?>" class="form-control" disabled
/>
353 <div
class="forms col-2">
354 <label
class="control-label" for="GlobalResetView"><?php
echo xlt('Distributed to Global'); ?
>:</label
>
355 <input id
="GlobalResetView" name
="global_reset_view" class="form-control" value
="<?php echo ($global_amount * 1 == 0) ? attr("0.00") : attr(number_format($global_amount, 2, '.', ',')); ?>" disabled
/>
357 <div
class="forms col-2">
358 <label
class="control-label" for="TdUnappliedAmount"><?php
echo xlt('Undistributed'); ?
>:</label
>
359 <div id
="TdUnappliedAmount" class="form-control bg-danger text-light"><?php
echo ($UndistributedAmount * 1 == 0) ?
attr("0.00") : attr(number_format($UndistributedAmount, 2, '.', ',')); ?
></div
>
360 <input name
="HidUnappliedAmount" id
="HidUnappliedAmount" value
="<?php echo ($UndistributedAmount * 1 == 0) ? attr("0.00") : attr(number_format($UndistributedAmount, 2, '.', ',')); ?>" type
="hidden" />
361 <input name
="HidUnpostedAmount" id
="HidUnpostedAmount" value
="<?php echo attr($UndistributedAmount); ?>" type
="hidden" />
362 <input name
="HidCurrentPostedAmount" id
="HidCurrentPostedAmount" value
="" type
="hidden" />
365 </fieldset
><!--end of fieldset in new_payment
.php
-->
367 }//if($screen=='new_payment' && $payment_id*1>0)
368 //================================================================================================