2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2010 Z&H Consultancy Services Private Limited <sam@zhservices.com>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Paul Simon K <paul@zhservices.com>
26 // +------------------------------------------------------------------------------+
27 //===============================================================================
28 //Check/cash details are entered here.Used in New Payment and Edit Payment screen.
29 //===============================================================================
30 //Special list function
31 function generate_list_payment_category(
39 $PaymentType = 'insurance',
40 $screen = 'new_payment'
44 $tag_name_esc = htmlspecialchars($tag_name, ENT_QUOTES
);
45 $s .= "<select name='$tag_name_esc' id='$tag_name_esc'";
47 $s .= " class='$class'";
51 $s .= " onchange='$onchange'";
54 $selectTitle = htmlspecialchars($title, ENT_QUOTES
);
55 $s .= " title='$selectTitle'>";
56 $selectEmptyName = htmlspecialchars(xl($empty_name), ENT_QUOTES
);
58 $s .= "<option value=''>" . $selectEmptyName . "</option>";
61 $lres = sqlStatement("SELECT * FROM list_options " .
62 "WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
63 $got_selected = false;
64 while ($lrow = sqlFetchArray($lres)) {
65 $optionValue = htmlspecialchars($lrow['option_id'], ENT_QUOTES
);
66 $s .= "<option id='option_" . $lrow['option_id'] . "'" . " value='$optionValue'";
67 if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
68 (strlen($currvalue) > 0 && $lrow['option_id'] == $currvalue) ||
69 ($lrow['option_id'] == 'insurance_payment' && $screen=='new_payment')) {
74 if (($PaymentType == 'insurance' ||
$screen=='new_payment') && ($lrow['option_id'] == 'family_payment' ||
$lrow['option_id'] == 'patient_payment')) {
75 $s .= " style='background-color:#DEDEDE' ";
78 if ($PaymentType == 'patient' && $lrow['option_id'] == 'insurance_payment') {
79 $s .= " style='background-color:#DEDEDE' ";
82 $optionLabel = htmlspecialchars(xl_list_label($lrow['title']), ENT_QUOTES
);
83 $s .= ">$optionLabel</option>\n";
86 if (!$got_selected && strlen($currvalue) > 0) {
87 $currescaped = htmlspecialchars($currvalue, ENT_QUOTES
);
88 $s .= "<option value='$currescaped' selected>* $currescaped *</option>";
90 $fontTitle = htmlspecialchars(xl('Please choose a valid selection from the list.'), ENT_QUOTES
);
91 $fontText = htmlspecialchars(xl('Fix this'), ENT_QUOTES
);
92 $s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
99 //================================================================================================
101 $rs= sqlStatement("select pay_total,global_amount from ar_session where session_id='$payment_id'");
102 $row=sqlFetchArray($rs);
103 $pay_total=$row['pay_total'];
104 $global_amount=$row['global_amount'];
105 $rs= sqlStatement("select sum(pay_amount) sum_pay_amount from ar_activity where session_id='$payment_id'");
106 $row=sqlFetchArray($rs);
107 $pay_amount=$row['sum_pay_amount'];
108 $UndistributedAmount=$pay_total-$pay_amount-$global_amount;
110 $res = sqlStatement("SELECT check_date ,reference ,insurance_companies.name,
111 payer_id,pay_total,payment_type,post_to_date,patient_id ,
112 adjustment_code,description,deposit_date,payment_method
113 FROM ar_session left join insurance_companies on ar_session.payer_id=insurance_companies.id where ar_session.session_id ='$payment_id'");
114 $row = sqlFetchArray($res);
115 $InsuranceCompanyName=$row['name'];
116 $InsuranceCompanyId=$row['payer_id'];
117 $PatientId=$row['patient_id'];
118 $CheckNumber=$row['reference'];
119 $CheckDate=$row['check_date']=='0000-00-00'?
'':$row['check_date'];
120 $PayTotal=$row['pay_total'];
121 $PostToDate=$row['post_to_date']=='0000-00-00'?
'':$row['post_to_date'];
122 $PaymentMethod=$row['payment_method'];
123 $PaymentType=$row['payment_type'];
124 $AdjustmentCode=$row['adjustment_code'];
125 $DepositDate=$row['deposit_date']=='0000-00-00'?
'':$row['deposit_date'];
126 $Description=$row['description'];
127 if ($row['payment_type']=='insurance' ||
$row['payer_id']*1 > 0) {
128 $res = sqlStatement("SELECT insurance_companies.name FROM insurance_companies
129 where insurance_companies.id ='$InsuranceCompanyId'");
130 $row = sqlFetchArray($res);
131 $div_after_save=$row['name'];
132 $TypeCode=$InsuranceCompanyId;
133 if ($PaymentType=='') {
134 $PaymentType='insurance';
136 } elseif ($row['payment_type']=='patient' ||
$row['patient_id']*1 > 0) {
137 $res = sqlStatement("SELECT fname,lname,mname FROM patient_data
138 where pid ='$PatientId'");
139 $row = sqlFetchArray($res);
140 $fname=$row['fname'];
141 $lname=$row['lname'];
142 $mname=$row['mname'];
143 $div_after_save=$lname.' '.$fname.' '.$mname;
144 $TypeCode=$PatientId;
145 if ($PaymentType=='') {
146 $PaymentType='patient';
152 //================================================================================================
153 if (($screen=='new_payment' && $payment_id*1==0) ||
($screen=='edit_payment' && $payment_id*1>0)) {//New entry or edit in edit screen comes here.
155 <table width
="1024" border
="0" cellspacing
="0" cellpadding
="10" bgcolor
="#DEDEDE"><tr
><td
>
156 <table width
="1004" border
="0" style
="border:1px solid black" cellspacing
="0" cellpadding
="0">
158 <td colspan
="14" align
="left" ></td
>
161 <td colspan
="14" align
="left"> 
;<font
class='title'>
163 if ($_REQUEST['ParentPage']=='new_payment') {//This case comes when the Finish Payments is pressed from the New Payment screen.
165 <?php
echo htmlspecialchars(xl('Confirm Payment'), ENT_QUOTES
) ?
>
167 } elseif ($screen=='new_payment') {
169 <?php
echo htmlspecialchars(xl('Batch Payment Entry'), ENT_QUOTES
) ?
>
173 <?php
echo htmlspecialchars(xl('Edit Payment'), ENT_QUOTES
) ?
>
180 <td align
="left" width
="5" ></td
>
181 <td align
="left" width
="110" ></td
>
182 <td align
="left" width
="128"></td
>
183 <td align
="left" width
="25"></td
>
184 <td align
="left" width
="5"></td
>
185 <td align
="left" width
="85"></td
>
186 <td align
="left" width
="128"></td
>
187 <td align
="left" width
="25"></td
>
188 <td align
="left" width
="5"></td
>
189 <td align
="left" width
="113"></td
>
190 <td align
="left" width
="125"></td
>
191 <td align
="left" width
="5"></td
>
192 <td align
="left" width
="93"></td
>
193 <td align
="left" width
="152"></td
>
196 <td align
="left" class='text'></td
>
197 <td align
="left" class='text'><?php
echo htmlspecialchars(xl('Date'), ENT_QUOTES
).':' ?
></td
>
198 <td align
="left" class="text" ><input type
='text' size
='9' class='datepicker' name
='check_date' id
='check_date' class="class1 text " value
="<?php echo htmlspecialchars(oeFormatShortDate($CheckDate));?>"/></td
>
201 <td align
="left" class='text'><?php
echo htmlspecialchars(xl('Post To Date'), ENT_QUOTES
).':' ?
></td
>
202 <td align
="left" class="text"><input type
='text' size
='9' class='datepicker' name
='post_to_date' id
='post_to_date' class="class1 text " value
="<?php echo $screen=='new_payment'?htmlspecialchars(oeFormatShortDate(date('Y-m-d'))):htmlspecialchars(oeFormatShortDate($PostToDate));?>" /></td
>
205 <td align
="left" class="text"><?php
echo htmlspecialchars(xl('Payment Method'), ENT_QUOTES
).':' ?
></td
>
208 if ($PaymentMethod=='' && $screen=='edit_payment') {
214 echo generate_select_list("payment_method", "payment_method", "$PaymentMethod", "Payment Method", "$blankValue", "class1 text", 'CheckVisible("yes")');
218 <td align
="left" class="text"><?php
echo htmlspecialchars(xl('Check Number'), ENT_QUOTES
).':' ?
></td
>
221 if ($PaymentMethod=='check_payment' ||
$PaymentMethod=='bank_draft' ||
$CheckNumber!='' ||
$screen=='new_payment') {
223 $CheckDivDisplay=' display:none; ';
225 $CheckDisplay=' display:none; ';
229 <input type
="text" name
="check_number" style
="width:140px;<?php echo $CheckDisplay;?>" autocomplete
="off" value
="<?php echo htmlspecialchars($CheckNumber);?>" onKeyUp
="ConvertToUpperCase(this)" id
="check_number" class="text " />
230 <div id
="div_check_number" class="text" style
="border:1px solid black; width:140px;<?php echo $CheckDivDisplay;?>"> 
;</div
>
234 <td colspan
="14" align
="left" ></td
>
237 <td align
="left" class="text"></td
>
238 <td align
="left" class="text"><?php
echo htmlspecialchars(xl('Payment Amount'), ENT_QUOTES
).':' ?
></td
>
239 <td align
="left"><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'?htmlspecialchars('0.00'):htmlspecialchars($PayTotal);?>" style
="text-align:right" class="class1 text " /></td
>
240 <td align
="left" ></td
>
241 <td align
="left" ></td
>
242 <td align
="left" class="text"><?php
echo htmlspecialchars(xl('Paying Entity'), ENT_QUOTES
).':' ?
></td
>
243 <td align
="left"><?php
244 if ($PaymentType=='' && $screen=='edit_payment') {
250 echo generate_select_list("type_name", "payment_type", "$PaymentType", "Paying Entity", "$blankValue", "class1 text", 'PayingEntityAction()');
253 <td align
="left" ></td
>
254 <td align
="left" ></td
>
255 <td align
="left" class="text"><?php
echo htmlspecialchars(xl('Payment Category'), ENT_QUOTES
).':' ?
></td
>
256 <td align
="left"><?php
257 if ($AdjustmentCode=='' && $screen=='edit_payment') {
261 echo generate_list_payment_category(
263 "payment_adjustment_code",
268 'FilterSelection(this)',
274 <td align
="left" ></td
>
275 <td align
="left" ></td
>
276 <td align
="left" ></td
>
279 <td colspan
="14" align
="left" ></td
>
282 <td align
="left" class="text"></td
>
283 <td align
="left" class="text"><?php
echo htmlspecialchars(xl('Payment From'), ENT_QUOTES
).':' ?
></td
>
284 <td align
="left" colspan
="5"><input type
="hidden" id
="hidden_ajax_close_value" value
="<?php echo htmlspecialchars($div_after_save);?>" /><input name
='type_code' id
='type_code' class="text " style
="width:369px" onKeyDown
="PreventIt(event)" value
="<?php echo htmlspecialchars($div_after_save);?>" autocomplete
="off" /><br
>
285 <!-- onKeyUp
="ajaxFunction(event,'non','edit_payment.php');" -->
286 <div id
='ajax_div_insurance_section'>
287 <div id
='ajax_div_insurance_error'>
289 <div id
="ajax_div_insurance" style
="display:none;"></div
>
293 <td align
="left" colspan
="5"><div name
="div_insurance_or_patient" id
="div_insurance_or_patient" class="text" style
="border:1px solid black; padding-left:5px; width:55px; height:17px;"><?php
echo htmlspecialchars($TypeCode);?
></div
></td
>
294 <td align
="left" ></td
>
295 <td align
="left" ></td
>
298 <td align
="left" class='text'></td
>
299 <td align
="left" class='text'><?php
echo htmlspecialchars(xl('Deposit Date'), ENT_QUOTES
).':' ?
></td
>
300 <td align
="left"><input type
='text' size
='9' class='datepicker' name
='deposit_date' id
='deposit_date' onKeyDown
="PreventIt(event)" class="class1 text " value
="<?php echo htmlspecialchars(oeFormatShortDate($DepositDate));?>" /> </td
>
303 <td align
="left" class="text"><?php
echo htmlspecialchars(xl('Description'), ENT_QUOTES
).':' ?
></td
>
304 <td colspan
="6" align
="left"><input type
="text" name
="description" id
="description" onKeyDown
="PreventIt(event)" value
="<?php echo htmlspecialchars($Description);?>" style
="width:396px" class="text " /></td
>
305 <td align
="left" class="text"><font style
="font-size:11px"><?php
echo htmlspecialchars(xl('UNDISTRIBUTED'), ENT_QUOTES
).':' ?
></font
><input name
="HidUnappliedAmount" id
="HidUnappliedAmount" value
="<?php echo ($UndistributedAmount*1==0)? htmlspecialchars("0.00") : htmlspecialchars(number_format($UndistributedAmount, 2, '.', ','));?>" type
="hidden"/><input name
="HidUnpostedAmount" id
="HidUnpostedAmount" value
="<?php echo htmlspecialchars($UndistributedAmount); ?>" type
="hidden"/><input name
="HidCurrentPostedAmount" id
="HidCurrentPostedAmount" value
="" type
="hidden"/></td
>
306 <td align
="left" class="text"><div id
="TdUnappliedAmount" class="text" style
="border:1px solid black; width:75px; background-color:#EC7676; padding-left:5px;"><?php
echo ($UndistributedAmount*1==0)?
htmlspecialchars("0.00") : htmlspecialchars(number_format($UndistributedAmount, 2, '.', ','));?
></div
></td
>
309 if ($screen=='new_payment') {
312 <td colspan
="14" align
="center" class="text" id
="TdContainingButtons">
313 <table border
="0" cellspacing
="0" cellpadding
="0" width
="280">
320 <td width
="100"><a href
="#" onClick
="javascript:return SavePayment();" class="css_button"><span
><?php
echo htmlspecialchars(xl('Save Changes'), ENT_QUOTES
);?
></span
></a
></td
>
321 <td width
="110"><a href
="#" onClick
="javascript:ResetForm()" class="css_button"><span
><?php
echo htmlspecialchars(xl('Cancel Changes'), ENT_QUOTES
);?
></span
></a
></td
>
322 <td width
="70"><a href
="#" class="css_button" onClick
="javascript:OpenEOBEntry();"><span
><?php
echo htmlspecialchars(xl('Allocate'), ENT_QUOTES
);?
></span
></a
></td
>
330 <td colspan
="14" align
="left" ></td
>
335 }//if(($screen=='new_payment' && $payment_id*1==0) || ($screen=='edit_payment' && $payment_id*1>0))
336 //================================================================================================
339 if ($screen=='new_payment' && $payment_id*1>0) {
340 //After saving from the New Payment screen,all values are showed as labels.The date picker images are also removed.
342 <table width
="1024" border
="0" cellspacing
="0" cellpadding
="10" bgcolor
="#DEDEDE"><tr
><td align
="left">
343 <table width
="1004" border
="0" style
="border:1px solid black" cellspacing
="0" cellpadding
="0">
345 <td colspan
="13" align
="left" ></td
>
348 <td colspan
="13" align
="left" >
350 <table width
="969" border
="0" cellspacing
="0" cellpadding
="0" align
="left">
352 <td colspan
="13" align
="left"> 
;<font
class='title'><?php
echo htmlspecialchars(xl('Batch Payment Entry'), ENT_QUOTES
) ?
></font
></td
>
355 <td align
="left" width
="5" ></td
>
356 <td align
="left" width
="106" ></td
>
357 <td align
="left" width
="128"></td
>
358 <td align
="left" width
="5"></td
>
359 <td align
="left" width
="84"></td
>
360 <td align
="left" width
="128"></td
>
361 <td align
="left" width
="5"></td
>
362 <td align
="left" width
="113"></td
>
363 <td align
="left" width
="135"></td
>
364 <td align
="left" width
="5"></td
>
365 <td align
="left" width
="92"></td
>
366 <td align
="left" width
="158"></td
>
367 <td align
="left" width
="5"></td
>
370 <td align
="left" class='text'></td
>
371 <td align
="left" class='text'><?php
echo htmlspecialchars(xl('Date'), ENT_QUOTES
).':' ?
></td
>
372 <td align
="left" class="text bottom left top right"> 
;<?php
echo htmlspecialchars(oeFormatShortDate($CheckDate));?
><input type
="hidden" name
="check_date" value
="<?php echo htmlspecialchars(oeFormatShortDate($CheckDate));?>"/></td
>
374 <td align
="left" class='text'><?php
echo htmlspecialchars(xl('Post To Date'), ENT_QUOTES
).':' ?
></td
>
375 <td align
="left" class="text bottom left top right"> 
;<?php
echo htmlspecialchars(oeFormatShortDate($PostToDate));?
><input type
="hidden" name
="post_to_date" value
="<?php echo htmlspecialchars(oeFormatShortDate($PostToDate));?>"/></td
>
377 <td align
="left" class="text"><?php
echo htmlspecialchars(xl('Payment Method'), ENT_QUOTES
).':' ?
></td
>
378 <td align
="left" class="text bottom left top right"> 
;<?php
379 $frow['data_type']=1;
380 $frow['list_id']='payment_method';
381 generate_print_field($frow, $PaymentMethod);
382 ?
><input type
="hidden" name
="payment_method" value
="<?php echo htmlspecialchars($PaymentMethod);?>"/></td
>
384 <td align
="left" class="text"><?php
echo htmlspecialchars(xl('Check Number'), ENT_QUOTES
).':' ?
></td
>
385 <td
class="text bottom left top right"> 
;<?php
echo htmlspecialchars($CheckNumber);?
><input type
="hidden" name
="check_number" value
="<?php echo htmlspecialchars($CheckNumber);?>"/></td
>
386 <td
class="text"></td
>
389 <td colspan
="13" align
="left" ></td
>
392 <td align
="left" class="text"></td
>
393 <td align
="left" class="text"><?php
echo htmlspecialchars(xl('Payment Amount'), ENT_QUOTES
).':' ?
></td
>
394 <td align
="left" class="text bottom left top right"> 
;<?php
echo htmlspecialchars($PayTotal);?
><input type
="hidden" name
="payment_amount" value
="<?php echo htmlspecialchars($PayTotal);?>"/></td
>
395 <td align
="left" ></td
>
396 <td align
="left" class="text"><?php
echo htmlspecialchars(xl('Paying Entity'), ENT_QUOTES
).':' ?
></td
>
397 <td align
="left" class="text bottom left top right"> 
;<?php
398 $frow['data_type']=1;
399 $frow['list_id']='payment_type';
400 generate_print_field($frow, $PaymentType);
401 ?
><input type
="hidden" name
="type_name" id
="type_name" value
="<?php echo htmlspecialchars($PaymentType);?>"/></td
>
402 <td align
="left" ></td
>
403 <td align
="left" class="text"><?php
echo htmlspecialchars(xl('Payment Category'), ENT_QUOTES
).':' ?
></td
>
404 <td align
="left" class="text bottom left top right"> 
;<?php
405 $frow['data_type']=1;
406 $frow['list_id']='payment_adjustment_code';
407 generate_print_field($frow, $AdjustmentCode);
408 ?
><input type
="hidden" name
="adjustment_code" value
="<?php echo htmlspecialchars($AdjustmentCode);?>"/></td
>
409 <td align
="left" ></td
>
410 <td align
="left" ></td
>
411 <td align
="left" ></td
>
412 <td align
="left" ></td
>
415 <td colspan
="13" align
="left" ></td
>
418 <td align
="left" class="text"></td
>
419 <td align
="left" class="text"><?php
echo htmlspecialchars(xl('Payment From'), ENT_QUOTES
).':' ?
></td
>
420 <td colspan
="4" align
="left" class="text bottom left top right"><div name
="div_insurance_or_patient" id
="div_insurance_or_patient" class="text" > 
;<?php
echo htmlspecialchars($div_after_save);?
> 
;</div
></td
>
421 <td align
="left"></td
>
422 <td align
="left" ><div name
="div_insurance_or_patient" id
="div_insurance_or_patient" class="text" style
="border:1px solid black; padding-left:5px; width:55px"><?php
echo htmlspecialchars($TypeCode);?
></div
><input type
="hidden" name
="type_code" value
="<?php echo htmlspecialchars($TypeCode);?>"/></td
>
423 <td align
="left" ></td
>
424 <td align
="left" ></td
>
425 <td align
="left" ></td
>
426 <td align
="left" ></td
>
427 <td align
="left" ></td
>
430 <td colspan
="13" align
="left" ></td
>
433 <td align
="left" class='text'></td
>
434 <td align
="left" class='text'><?php
echo htmlspecialchars(xl('Deposit Date'), ENT_QUOTES
).':' ?
></td
>
435 <td align
="left" class="text bottom left top right"> 
;<?php
echo htmlspecialchars(oeFormatShortDate($DepositDate));?
><input type
="hidden" name
="deposit_date" value
="<?php echo htmlspecialchars(oeFormatShortDate($DepositDate));?>"/> </td
>
437 <td align
="left" class="text"><?php
echo htmlspecialchars(xl('Description'), ENT_QUOTES
).':' ?
></td
>
438 <td colspan
="4" align
="left" class="text bottom left top right"> 
;<?php
echo htmlspecialchars($Description);?
><input type
="hidden" name
="description" value
="<?php echo htmlspecialchars($Description);?>"/></td
>
439 <td align
="left" class='text'></td
>
440 <td align
="left" class="text"><font style
="font-size:11px"><?php
echo htmlspecialchars(xl('UNDISTRIBUTED'), ENT_QUOTES
).':' ?
></font
><input name
="HidUnappliedAmount" id
="HidUnappliedAmount" value
="<?php echo ($UndistributedAmount*1==0)? htmlspecialchars("0.00") : htmlspecialchars(number_format($UndistributedAmount, 2, '.', ','));?>" type
="hidden"/><input name
="HidUnpostedAmount" id
="HidUnpostedAmount" value
="<?php echo htmlspecialchars($UndistributedAmount); ?>" type
="hidden"/>
441 <input name
="HidCurrentPostedAmount" id
="HidCurrentPostedAmount" value
="" type
="hidden"/></td
>
442 <td align
="left" ><div id
="TdUnappliedAmount" class="text" style
="border:1px solid black; background-color:#EC7676; width:75px; padding-left:5px;"><?php
echo ($UndistributedAmount*1==0)?
htmlspecialchars("0.00") : htmlspecialchars(number_format($UndistributedAmount, 2, '.', ','));?
></div
></td
>
443 <td align
="left" class="text"></td
>
446 <td colspan
="13" align
="left"></td
>
454 }//if($screen=='new_payment' && $payment_id*1>0)
455 //================================================================================================