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 //This screen handles the cash/cheque entry and its distribution to various charges.
29 //===============================================================================
30 require_once("../globals.php");
31 require_once("$srcdir/invoice_summary.inc.php");
32 require_once("$srcdir/sl_eob.inc.php");
33 require_once("$srcdir/parse_era.inc.php");
34 require_once("../../library/acl.inc");
35 require_once("$srcdir/sql.inc");
36 require_once("$srcdir/auth.inc");
37 require_once("$srcdir/formdata.inc.php");
38 require_once("../../custom/code_types.inc.php");
39 require_once("$srcdir/patient.inc");
40 require_once("$srcdir/billrep.inc");
41 require_once(dirname(__FILE__
) . "/../../library/classes/OFX.class.php");
42 require_once(dirname(__FILE__
) . "/../../library/classes/X12Partner.class.php");
43 require_once("$srcdir/options.inc.php");
44 require_once("$srcdir/formatting.inc.php");
45 require_once("$srcdir/payment.inc.php");
46 //===============================================================================
47 $screen='new_payment';
48 //===============================================================================
49 //ar_session addition code
50 //===============================================================================
51 if (isset($_POST["mode"]))
53 if ($_POST["mode"] == "new_payment" ||
$_POST["mode"] == "distribute")
55 if(trim(formData('type_name' ))=='insurance')
57 $QueryPart="payer_id = '" . trim(formData('hidden_type_code' )) .
58 "', patient_id = '" . 0 ;
60 elseif(trim(formData('type_name' ))=='patient')
62 $QueryPart="payer_id = '" . 0 .
63 "', patient_id = '" . trim(formData('hidden_type_code' )) ;
65 $user_id=$_SESSION['authUserID'];
67 $modified_time = date('Y-m-d H:i:s');
68 $check_date=DateToYYYYMMDD(formData('check_date'));
69 $deposit_date=DateToYYYYMMDD(formData('deposit_date'));
70 $post_to_date=DateToYYYYMMDD(formData('post_to_date'));
72 $post_to_date=date('Y-m-d');
73 if(formData('deposit_date')=='')
74 $deposit_date=$post_to_date;
75 $payment_id = idSqlStatement("insert into ar_session set " .
77 "', user_id = '" . trim($user_id ) .
78 "', closed = '" . trim($closed ) .
79 "', reference = '" . trim(formData('check_number' )) .
80 "', check_date = '" . trim($check_date ) .
81 "', deposit_date = '" . trim($deposit_date ) .
82 "', pay_total = '" . trim(formData('payment_amount')) .
83 "', modified_time = '" . trim($modified_time ) .
84 "', payment_type = '" . trim(formData('type_name' )) .
85 "', description = '" . trim(formData('description' )) .
86 "', adjustment_code = '" . trim(formData('adjustment_code' )) .
87 "', post_to_date = '" . trim($post_to_date ) .
88 "', payment_method = '" . trim(formData('payment_method' )) .
92 //===============================================================================
93 //ar_activity addition code
94 //===============================================================================
95 if (isset($_POST["mode"]))
97 if ($_POST["mode"] == "PostPayments" ||
$_POST["mode"] == "FinishPayments")
99 $hidden_patient_code=$_REQUEST['hidden_patient_code'];
100 $payment_id=$_REQUEST['payment_id'];
101 $user_id=$_SESSION['authUserID'];
102 $created_time = date('Y-m-d H:i:s');
103 for($CountRow=1;;$CountRow++
)
105 if (isset($_POST["HiddenEncounter$CountRow"]))
107 DistributionInsert($CountRow,$created_time,$user_id);
112 if($_REQUEST['global_amount']=='yes')
113 sqlStatement("update ar_session set global_amount=".trim(formData("HidUnappliedAmount" ))*1 ." where session_id ='$payment_id'");
114 if($_POST["mode"]=="FinishPayments")
116 header("Location: edit_payment.php?payment_id=$payment_id&ParentPage=new_payment");
119 $_POST["mode"] = "search";
122 //==============================================================================
123 //===============================================================================
124 $payment_id=$payment_id*1 > 0 ?
$payment_id : $_REQUEST['payment_id'];
125 //===============================================================================
126 $DateFormat=DateFormatRead();
127 //==============================================================================
128 //===============================================================================
132 <?php
if (function_exists('html_header_show')) html_header_show(); ?
>
134 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
135 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
136 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
137 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
138 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
139 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
140 <script language
='JavaScript'>
143 <?php
include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?
>
144 <script type
="text/JavaScript" src
="../../library/js/jquery121.js"></script
>
145 <?php
include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?
>
146 <script type
="text/javascript" src
="../../library/js/common.js"></script
>
147 <script LANGUAGE
="javascript" TYPE
="text/javascript">
148 function CancelDistribute()
149 {//Used in the cancel button.Helpful while cancelling the distribution.
150 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Cancel Distribution for this Patient?'), ENT_QUOTES) ?>"))
152 document
.getElementById('hidden_patient_code').value
='';
153 document
.getElementById('mode').value
='search';
154 top
.restoreSession();
155 document
.forms
[0].submit();
160 function PostPayments()
161 {//Used in saving the allocation
162 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
164 alert("<?php echo htmlspecialchars( xl('Fill the Row.'), ENT_QUOTES) ?>")
167 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
171 PostValue
=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
174 alert("<?php echo htmlspecialchars( xl('Cannot Post Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
177 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Post Payments?'), ENT_QUOTES) ?>"))
179 document
.getElementById('mode').value
='PostPayments';
180 top
.restoreSession();
181 document
.forms
[0].submit();
186 function FinishPayments()
187 {//Used in finishig the allocation.Usually done when the amount gets reduced to zero.
188 //After this is pressed a confirmation screen comes,where you can edit if needed.
189 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
191 alert("<?php echo htmlspecialchars( xl('Fill the Row.'), ENT_QUOTES) ?>")
194 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
198 PostValue
=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
201 alert("<?php echo htmlspecialchars( xl('Cannot Post Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
206 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Post and Finish Payments?'), ENT_QUOTES) ?>"))
208 UnappliedAmount
=document
.getElementById('TdUnappliedAmount').innerHTML
*1;
209 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) ?>"))
211 document
.getElementById('mode').value
='FinishPayments';
212 document
.getElementById('global_amount').value
='yes';
213 top
.restoreSession();
214 document
.forms
[0].submit();
218 document
.getElementById('mode').value
='FinishPayments';
219 top
.restoreSession();
220 document
.forms
[0].submit();
228 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Post and Finish Payments?'), ENT_QUOTES) ?>"))
230 document
.getElementById('mode').value
='FinishPayments';
231 top
.restoreSession();
232 document
.forms
[0].submit();
239 function CompletlyBlank()
240 {//Checks whether any of the allocation row is filled.
241 for(RowCount
=1;;RowCount++
)
243 if(!document
.getElementById('Payment'+RowCount
))
247 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)
257 function OnloadAction()
258 {//Displays message after saving to master table.
259 after_value
=document
.getElementById("after_value").value
;
260 payment_id
=document
.getElementById('payment_id').value
;
261 if(after_value
=='distribute')
264 else if(after_value
=='new_payment')
266 if(document
.getElementById('TablePatientPortion'))
268 document
.getElementById('TablePatientPortion').style
.display
='none';
270 if(confirm("<?php echo htmlspecialchars( xl('Successfully Saved.Would you like to Allocate?'), ENT_QUOTES) ?>"))
272 if(document
.getElementById('TablePatientPortion'))
274 document
.getElementById('TablePatientPortion').style
.display
='';
281 {//Resets form used in the 'Cancel Changes' button in the master screen.
282 document
.forms
[0].reset();
283 document
.getElementById('TdUnappliedAmount').innerHTML
='0.00';
284 document
.getElementById('div_insurance_or_patient').innerHTML
=' ';
285 CheckVisible('yes');//Payment Method is made 'Check Payment' and the Check box is made visible.
286 PayingEntityAction();//Paying Entity is made 'insurance' and Payment Category is 'Insurance Payment'
288 function FillUnappliedAmount()
289 {//Filling the amount
290 document
.getElementById('TdUnappliedAmount').innerHTML
=document
.getElementById('payment_amount').value
;
293 <script language
="javascript" type
="text/javascript">
294 document
.onclick
=HideTheAjaxDivs
;
297 .class1
{width
:125px
;}
298 .class2
{width
:250px
;}
299 .bottom
{border
-bottom
:1px solid black
;}
300 .top
{border
-top
:1px solid black
;}
301 .left
{border
-left
:1px solid black
;}
302 .right
{border
-right
:1px solid black
;}
303 #ajax_div_insurance {
306 background
-color
: #FBFDD0;
307 border
: 1px solid
#ccc;
313 background
-color
: #FBFDD0;
314 border
: 1px solid
#ccc;
318 <link rel
="stylesheet" href
="<?php echo $css_header; ?>" type
="text/css">
320 <body
class="body_top" onLoad
="OnloadAction()" >
321 <form name
='new_payment' method
='post' action
="new_payment.php" onsubmit
='
326 top.restoreSession();return SavePayment();
336 ' style
="display:inline" >
337 <table width
="100%" border
="0" cellspacing
="0" cellpadding
="0">
339 <td colspan
="3" align
="left"><b
><?php
echo htmlspecialchars( xl('Payments'), ENT_QUOTES
) ?
></b
></td
>
342 <td colspan
="3" align
="left" ></td
>
345 <td colspan
="3" align
="left">
347 <li
class='current'><a href
='new_payment.php'><?php
echo htmlspecialchars( xl('New Payment'), ENT_QUOTES
) ?
></a
></li
>
348 <li
><a href
='search_payments.php'><?php
echo htmlspecialchars( xl('Search Payment'), ENT_QUOTES
) ?
></a
></li
>
349 <li
><a href
='era_payments.php'><?php
echo htmlspecialchars( xl('ERA Posting'), ENT_QUOTES
) ?
></a
></li
>
353 <td colspan
="3" align
="left" >
355 require_once("payment_master.inc.php"); //Check/cash details are entered here.
364 <table width
="999" border
="0" cellspacing
="0" cellpadding
="10" bgcolor
="#DEDEDE"><tr
><td
>
365 <table width
="979" border
="0" cellspacing
="0" cellpadding
="0">
367 <td colspan
="13" align
="left" >
368 <!--Distribute section
-->
370 if($PaymentType=='patient' && $_POST["default_search_patient"] != "default_search_patient")
372 $_POST["default_search_patient"] = "default_search_patient";
373 $_REQUEST['hidden_patient_code']=$TypeCode;
374 $_REQUEST['RadioPaid']='Show_Paid';
376 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
381 <td colspan
="13" align
="left" >
383 if($CountIndexBelow>0)
386 <table border
="0" cellspacing
="0" cellpadding
="0" width
="267" align
="center" id
="AllocateButtons">
393 <td width
="100"><a href
="#" onClick
="javascript:return PostPayments();" class="css_button"><span
><?php
echo htmlspecialchars( xl('Post Payments'), ENT_QUOTES
);?
></span
></a
></td
>
394 <td width
="107"><a href
="#" onClick
="javascript:return FinishPayments();" class="css_button"><span
><?php
echo htmlspecialchars( xl('Finish Payments'), ENT_QUOTES
);?
></span
></a
></td
>
395 <td width
="60"><a href
="#" onClick
="CancelDistribute()" class="css_button"><span
><?php
echo htmlspecialchars( xl('Cancel'), ENT_QUOTES
);?
></span
></a
></td
>
399 }//if($CountIndexBelow>0)
407 <input type
="hidden" name
="hidden_patient_code" id
="hidden_patient_code" value
="<?php echo htmlspecialchars($hidden_patient_code);?>"/>
408 <input type
='hidden' name
='mode' id
='mode' value
='' />
409 <input type
='hidden' name
='default_search_patient' id
='default_search_patient' value
='<?php echo $_POST["default_search_patient"] ?>' />
410 <input type
='hidden' name
='ajax_mode' id
='ajax_mode' value
='' />
411 <input type
="hidden" name
="after_value" id
="after_value" value
="<?php echo htmlspecialchars($_POST["mode
"]);?>"/>
412 <input type
="hidden" name
="payment_id" id
="payment_id" value
="<?php echo htmlspecialchars($payment_id);?>"/>
413 <input type
="hidden" name
="hidden_type_code" id
="hidden_type_code" value
="<?php echo htmlspecialchars(formData('hidden_type_code'));?>"/>
414 <input type
='hidden' name
='global_amount' id
='global_amount' value
='' />