3 * This screen handles the cash/cheque entry and its distribution to various charges.
5 * Copyright (C) 2010 Z&H Consultancy Services Private Limited <sam@zhservices.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * A copy of the GNU General Public License is included along with this program:
20 * openemr/interface/login/GnuGPL.html
21 * For more information write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * Author: Eldho Chacko <eldho@zhservices.com>
25 * Paul Simon K <paul@zhservices.com>
28 require_once("../globals.php");
29 require_once("$srcdir/invoice_summary.inc.php");
30 require_once("$srcdir/sl_eob.inc.php");
31 require_once("$srcdir/parse_era.inc.php");
32 require_once("../../library/acl.inc");
33 require_once("$srcdir/auth.inc");
34 require_once("../../custom/code_types.inc.php");
35 require_once("$srcdir/patient.inc");
36 require_once("$srcdir/billrep.inc");
37 require_once("$srcdir/options.inc.php");
38 require_once("$srcdir/formatting.inc.php");
39 require_once("$srcdir/payment.inc.php");
40 //===============================================================================
41 $screen='new_payment';
42 //===============================================================================
44 $mode = isset($_POST['mode']) ?
$_POST['mode'] : '';
45 $payment_id = isset($_REQUEST['payment_id']) ?
$_REQUEST['payment_id'] : '';
46 $request_payment_id = $payment_id ;
47 $hidden_patient_code = isset($_REQUEST['hidden_patient_code']) ?
$_REQUEST['hidden_patient_code'] : '';
48 $default_search_patient = isset($_POST['default_search_patient']) ?
$_POST['default_search_patient'] : '';
49 $hidden_type_code = formData('hidden_type_code', true );
50 //===============================================================================
51 //ar_session addition code
52 //===============================================================================
54 if ($mode == "new_payment" ||
$mode == "distribute")
56 if(trim(formData('type_name' ))=='insurance')
58 $QueryPart="payer_id = '$hidden_type_code', patient_id = '0" ; // Closing Quote in idSqlStatement below
60 elseif(trim(formData('type_name' ))=='patient')
62 $QueryPart="payer_id = '0', patient_id = '$hidden_type_code" ; // Closing Quote in idSqlStatement below
64 $user_id=$_SESSION['authUserID'];
66 $modified_time = date('Y-m-d H:i:s');
67 $check_date=DateToYYYYMMDD(formData('check_date'));
68 $deposit_date=DateToYYYYMMDD(formData('deposit_date'));
69 $post_to_date=DateToYYYYMMDD(formData('post_to_date'));
71 $post_to_date=date('Y-m-d');
72 if(formData('deposit_date')=='')
73 $deposit_date=$post_to_date;
74 $payment_id = idSqlStatement("insert into ar_session set " .
76 "', user_id = '" . trim($user_id ) .
77 "', closed = '" . trim($closed ) .
78 "', reference = '" . trim(formData('check_number' )) .
79 "', check_date = '" . trim($check_date ) .
80 "', deposit_date = '" . trim($deposit_date ) .
81 "', pay_total = '" . trim(formData('payment_amount')) .
82 "', modified_time = '" . trim($modified_time ) .
83 "', payment_type = '" . trim(formData('type_name' )) .
84 "', description = '" . trim(formData('description' )) .
85 "', adjustment_code = '" . trim(formData('adjustment_code' )) .
86 "', post_to_date = '" . trim($post_to_date ) .
87 "', payment_method = '" . trim(formData('payment_method' )) .
91 //===============================================================================
92 //ar_activity addition code
93 //===============================================================================
94 if ($mode == "PostPayments" ||
$mode == "FinishPayments")
96 $user_id=$_SESSION['authUserID'];
97 $created_time = date('Y-m-d H:i:s');
98 for($CountRow=1;;$CountRow++
)
100 if (isset($_POST["HiddenEncounter$CountRow"]))
102 DistributionInsert($CountRow,$created_time,$user_id);
107 if($_REQUEST['global_amount']=='yes')
108 sqlStatement("update ar_session set global_amount=".trim(formData("HidUnappliedAmount" ))*1 ." where session_id ='$payment_id'");
109 if($mode=="FinishPayments")
111 header("Location: edit_payment.php?payment_id=$payment_id&ParentPage=new_payment");
115 $_POST['mode'] = $mode;
118 //==============================================================================
119 //===============================================================================
120 $payment_id=$payment_id*1 > 0 ?
$payment_id : $request_payment_id;
121 //===============================================================================
122 $DateFormat=DateFormatRead();
123 //==============================================================================
124 //===============================================================================
128 <?php
if (function_exists('html_header_show')) html_header_show(); ?
>
130 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
131 <script type
="text/javascript" src
="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
132 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
133 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
134 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
135 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
136 <script language
='JavaScript'>
139 <?php
include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?
>
140 <script type
="text/JavaScript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-1/index.js"></script
>
141 <?php
include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?
>
142 <script type
="text/javascript" src
="../../library/js/common.js"></script
>
143 <script LANGUAGE
="javascript" TYPE
="text/javascript">
144 function CancelDistribute()
145 {//Used in the cancel button.Helpful while cancelling the distribution.
146 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Cancel Distribution for this Patient?'), ENT_QUOTES) ?>"))
148 document
.getElementById('hidden_patient_code').value
='';
149 document
.getElementById('mode').value
='search';
150 top
.restoreSession();
151 document
.forms
[0].submit();
156 function PostPayments()
157 {//Used in saving the allocation
158 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
160 alert("<?php echo htmlspecialchars( xl('Fill the Row.'), ENT_QUOTES) ?>")
163 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
167 PostValue
=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
170 alert("<?php echo htmlspecialchars( xl('Cannot Post Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
173 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Post Payments?'), ENT_QUOTES) ?>"))
175 document
.getElementById('mode').value
='PostPayments';
176 top
.restoreSession();
177 document
.forms
[0].submit();
182 function FinishPayments()
183 {//Used in finishig the allocation.Usually done when the amount gets reduced to zero.
184 //After this is pressed a confirmation screen comes,where you can edit if needed.
185 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
187 alert("<?php echo htmlspecialchars( xl('Fill the Row.'), ENT_QUOTES) ?>")
190 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
194 PostValue
=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
197 alert("<?php echo htmlspecialchars( xl('Cannot Post Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
202 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Post and Finish Payments?'), ENT_QUOTES) ?>"))
204 UnappliedAmount
=document
.getElementById('TdUnappliedAmount').innerHTML
*1;
205 if(confirm("<?php echo htmlspecialchars( xl('Undistributed is'), ENT_QUOTES) ?>" +
' ' + UnappliedAmount +
'.' +
"<?php echo htmlspecialchars('\n');echo htmlspecialchars( xl('Would you like the balance amount to apply to Global Account?'), ENT_QUOTES) ?>"))
207 document
.getElementById('mode').value
='FinishPayments';
208 document
.getElementById('global_amount').value
='yes';
209 top
.restoreSession();
210 document
.forms
[0].submit();
214 document
.getElementById('mode').value
='FinishPayments';
215 top
.restoreSession();
216 document
.forms
[0].submit();
224 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Post and Finish Payments?'), ENT_QUOTES) ?>"))
226 document
.getElementById('mode').value
='FinishPayments';
227 top
.restoreSession();
228 document
.forms
[0].submit();
235 function CompletlyBlank()
236 {//Checks whether any of the allocation row is filled.
237 for(RowCount
=1;;RowCount++
)
239 if(!document
.getElementById('Payment'+RowCount
))
243 if(document
.getElementById('Allowed'+RowCount
).value
=='' && document
.getElementById('Payment'+RowCount
).value
=='' && document
.getElementById('AdjAmount'+RowCount
).value
=='' && document
.getElementById('Deductible'+RowCount
).value
=='' && document
.getElementById('Takeback'+RowCount
).value
=='' && document
.getElementById('FollowUp'+RowCount
).checked
==false)
253 function OnloadAction()
254 {//Displays message after saving to master table.
255 after_value
=document
.getElementById("after_value").value
;
256 payment_id
=document
.getElementById('payment_id').value
;
257 if(after_value
=='distribute')
260 else if(after_value
=='new_payment')
262 if(document
.getElementById('TablePatientPortion'))
264 document
.getElementById('TablePatientPortion').style
.display
='none';
266 if(confirm("<?php echo htmlspecialchars( xl('Successfully Saved.Would you like to Allocate?'), ENT_QUOTES) ?>"))
268 if(document
.getElementById('TablePatientPortion'))
270 document
.getElementById('TablePatientPortion').style
.display
='';
277 {//Resets form used in the 'Cancel Changes' button in the master screen.
278 document
.forms
[0].reset();
279 document
.getElementById('TdUnappliedAmount').innerHTML
='0.00';
280 document
.getElementById('div_insurance_or_patient').innerHTML
=' ';
281 CheckVisible('yes');//Payment Method is made 'Check Payment' and the Check box is made visible.
282 PayingEntityAction();//Paying Entity is made 'insurance' and Payment Category is 'Insurance Payment'
284 function FillUnappliedAmount()
285 {//Filling the amount
286 document
.getElementById('TdUnappliedAmount').innerHTML
=document
.getElementById('payment_amount').value
;
289 <script language
="javascript" type
="text/javascript">
290 document
.onclick
=HideTheAjaxDivs
;
293 .class1
{width
:125px
;}
294 .class2
{width
:250px
;}
295 .bottom
{border
-bottom
:1px solid black
;}
296 .top
{border
-top
:1px solid black
;}
297 .left
{border
-left
:1px solid black
;}
298 .right
{border
-right
:1px solid black
;}
299 #ajax_div_insurance {
302 background
-color
: #FBFDD0;
303 border
: 1px solid
#ccc;
309 background
-color
: #FBFDD0;
310 border
: 1px solid
#ccc;
314 <link rel
="stylesheet" href
="<?php echo $css_header; ?>" type
="text/css">
316 <body
class="body_top" onLoad
="OnloadAction()" >
317 <form name
='new_payment' method
='post' action
="new_payment.php" onsubmit
='
322 top.restoreSession();return SavePayment();
332 ' style
="display:inline" >
333 <table width
="100%" border
="0" cellspacing
="0" cellpadding
="0">
335 <td colspan
="3" align
="left"><b
><?php
echo htmlspecialchars( xl('Payments'), ENT_QUOTES
) ?
></b
></td
>
338 <td colspan
="3" align
="left" ></td
>
341 <td colspan
="3" align
="left">
343 <li
class='current'><a href
='new_payment.php'><?php
echo htmlspecialchars( xl('New Payment'), ENT_QUOTES
) ?
></a
></li
>
344 <li
><a href
='search_payments.php'><?php
echo htmlspecialchars( xl('Search Payment'), ENT_QUOTES
) ?
></a
></li
>
345 <li
><a href
='era_payments.php'><?php
echo htmlspecialchars( xl('ERA Posting'), ENT_QUOTES
) ?
></a
></li
>
349 <td colspan
="3" align
="left" >
351 require_once("payment_master.inc.php"); //Check/cash details are entered here.
360 <table width
="999" border
="0" cellspacing
="0" cellpadding
="10" bgcolor
="#DEDEDE"><tr
><td
>
361 <table width
="979" border
="0" cellspacing
="0" cellpadding
="0">
363 <td colspan
="13" align
="left" >
364 <!--Distribute section
-->
366 if($PaymentType=='patient' && $default_search_patient != "default_search_patient")
368 $default_search_patient = "default_search_patient";
369 $_POST['default_search_patient'] = $default_search_patient;
370 $hidden_patient_code=$TypeCode;
371 $_REQUEST['hidden_patient_code']=$hidden_patient_code;
372 $_REQUEST['RadioPaid']='Show_Paid';
374 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
379 <td colspan
="13" align
="left" >
381 if($CountIndexBelow>0)
384 <table border
="0" cellspacing
="0" cellpadding
="0" width
="267" align
="center" id
="AllocateButtons">
391 <td width
="100"><a href
="#" onClick
="javascript:return PostPayments();" class="css_button"><span
><?php
echo htmlspecialchars( xl('Post Payments'), ENT_QUOTES
);?
></span
></a
></td
>
392 <td width
="107"><a href
="#" onClick
="javascript:return FinishPayments();" class="css_button"><span
><?php
echo htmlspecialchars( xl('Finish Payments'), ENT_QUOTES
);?
></span
></a
></td
>
393 <td width
="60"><a href
="#" onClick
="CancelDistribute()" class="css_button"><span
><?php
echo htmlspecialchars( xl('Cancel'), ENT_QUOTES
);?
></span
></a
></td
>
397 }//if($CountIndexBelow>0)
405 <input type
="hidden" name
="hidden_patient_code" id
="hidden_patient_code" value
="<?php echo htmlspecialchars($hidden_patient_code);?>"/>
406 <input type
='hidden' name
='mode' id
='mode' value
='' />
407 <input type
='hidden' name
='default_search_patient' id
='default_search_patient' value
='<?php echo $default_search_patient ?>' />
408 <input type
='hidden' name
='ajax_mode' id
='ajax_mode' value
='' />
409 <input type
="hidden" name
="after_value" id
="after_value" value
="<?php echo htmlspecialchars($mode);?>"/>
410 <input type
="hidden" name
="payment_id" id
="payment_id" value
="<?php echo htmlspecialchars($payment_id);?>"/>
411 <input type
="hidden" name
="hidden_type_code" id
="hidden_type_code" value
="<?php echo htmlspecialchars($hidden_type_code);?>"/>
412 <input type
='hidden' name
='global_amount' id
='global_amount' value
='' />