3 * This screen handles the cash/cheque entry and its distribution to various charges.
5 * The functions of this class support the billing process like the script billing_process.php.
8 * @link http://www.open-emr.org
9 * @author Eldho Chacko <eldho@zhservices.com>
10 * @author Paul Simon K <paul@zhservices.com>
11 * @author Stephen Waite <stephen.waite@cmsvt.com>
12 * @author Brady Miller <brady.g.miller@gmail.com>
13 * @copyright Copyright (c) Z&H Consultancy Services Private Limited <sam@zhservices.com>
14 * @copyright Copyright (C) 2018 Stephen Waite <stephen.waite@cmsvt.com>
15 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
16 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
20 require_once("../globals.php");
21 require_once("$srcdir/invoice_summary.inc.php");
22 require_once("../../library/acl.inc");
23 require_once("$srcdir/auth.inc");
24 require_once("../../custom/code_types.inc.php");
25 require_once("$srcdir/patient.inc");
26 require_once("$srcdir/billrep.inc");
27 require_once("$srcdir/options.inc.php");
28 require_once("$srcdir/payment.inc.php");
30 use OpenEMR\Billing\ParseERA
;
31 use OpenEMR\Core\Header
;
32 use OpenEMR\OeUI\OemrUI
;
34 //===============================================================================
35 $screen='new_payment';
36 //===============================================================================
38 $mode = isset($_POST['mode']) ?
$_POST['mode'] : '';
39 $payment_id = isset($_REQUEST['payment_id']) ?
$_REQUEST['payment_id'] +
0 : 0;
40 $request_payment_id = $payment_id ;
41 $hidden_patient_code = isset($_REQUEST['hidden_patient_code']) ?
$_REQUEST['hidden_patient_code'] : '';
42 $default_search_patient = isset($_POST['default_search_patient']) ?
$_POST['default_search_patient'] : '';
43 $hidden_type_code = isset($_REQUEST['hidden_type_code']) ?
$_REQUEST['hidden_type_code'] : '';
44 //===============================================================================
45 //ar_session addition code
46 //===============================================================================
48 if ($mode == "new_payment" ||
$mode == "distribute") {
49 if (trim($_POST['type_name'])=='insurance') {
50 $QueryPart="payer_id = '" . add_escape_custom($hidden_type_code) . "', patient_id = '0" ;
51 } elseif (trim($_POST['type_name'])=='patient') {
52 $QueryPart="payer_id = '0', patient_id = '" .add_escape_custom($hidden_type_code);
54 $user_id=$_SESSION['authUserID'];
56 $modified_time = date('Y-m-d H:i:s');
57 $check_date=DateToYYYYMMDD(formData('check_date'));
58 $deposit_date=DateToYYYYMMDD(formData('deposit_date'));
59 $post_to_date=DateToYYYYMMDD(formData('post_to_date'));
60 if ($post_to_date=='') {
61 $post_to_date=date('Y-m-d');
63 if ($_POST['deposit_date']=='') {
64 $deposit_date=$post_to_date;
66 $payment_id = sqlInsert("insert into ar_session set " .
68 "', user_id = '" . trim(add_escape_custom($user_id)) .
69 "', closed = '" . trim(add_escape_custom($closed)) .
70 "', reference = '" . trim(formData('check_number')) .
71 "', check_date = '" . trim(add_escape_custom($check_date)) .
72 "', deposit_date = '" . trim(add_escape_custom($deposit_date)) .
73 "', pay_total = '" . trim(formData('payment_amount')) .
74 "', modified_time = '" . trim(add_escape_custom($modified_time)) .
75 "', payment_type = '" . trim(formData('type_name')) .
76 "', description = '" . trim(formData('description')) .
77 "', adjustment_code = '" . trim(formData('adjustment_code')) .
78 "', post_to_date = '" . trim(add_escape_custom($post_to_date)) .
79 "', payment_method = '" . trim(formData('payment_method')) .
83 //===============================================================================
84 //ar_activity addition code
85 //===============================================================================
86 if ($mode == "PostPayments" ||
$mode == "FinishPayments") {
87 $user_id=$_SESSION['authUserID'];
88 $created_time = date('Y-m-d H:i:s');
89 for ($CountRow=1;; $CountRow++
) {
90 if (isset($_POST["HiddenEncounter$CountRow"])) {
91 DistributionInsert($CountRow, $created_time, $user_id);
96 if ($_REQUEST['global_amount']=='yes') {
97 sqlStatement("update ar_session set global_amount=? where session_id =?", [(isset($_POST["HidUnappliedAmount"]) ?
trim($_POST["HidUnappliedAmount"]) : ''), $payment_id]);
99 if ($mode=="FinishPayments") {
100 header("Location: edit_payment.php?payment_id=" . urlencode($payment_id) . "&ParentPage=new_payment");
104 $_POST['mode'] = $mode;
107 //==============================================================================
108 //===============================================================================
109 $payment_id=$payment_id*1 > 0 ?
$payment_id +
0 : $request_payment_id +
0;
110 //===============================================================================
112 //==============================================================================
113 //===============================================================================
118 <?php Header
::setupHeader(['common', 'datetime-picker']);?
>
121 <script language
='JavaScript'>
123 </script
><?php
include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?
>
124 </script
><?php
include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?
>
125 <script language
="javascript" type
="text/javascript">
126 function CancelDistribute()
127 {//Used in the cancel button.Helpful while cancelling the distribution.
128 if(confirm(<?php
echo xlj('Would you like to Cancel Distribution for this Patient?') ?
>))
130 document
.getElementById('hidden_patient_code').value
='';
131 document
.getElementById('mode').value
='search';
132 top
.restoreSession();
133 document
.forms
[0].submit();
138 function PostPayments()
139 {//Used in saving the allocation
140 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
142 alert(<?php
echo xlj('Fill the Row.'); ?
>);
145 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
149 PostValue
=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
152 alert(<?php
echo xlj('Cannot Post Payments.Undistributed is Negative.'); ?
>);
155 if(confirm(<?php
echo xlj('Would you like to Post Payments?'); ?
>))
157 document
.getElementById('mode').value
='PostPayments';
158 top
.restoreSession();
159 document
.forms
[0].submit();
164 function FinishPayments()
165 {//Used in finishig the allocation.Usually done when the amount gets reduced to zero.
166 //After this is pressed a confirmation screen comes,where you can edit if needed.
167 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
169 alert(<?php
echo xlj('Fill the Row.'); ?
>);
172 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
176 PostValue
=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
179 alert(<?php
echo xlj('Cannot Post Payments.Undistributed is Negative.'); ?
>);
184 if(confirm(<?php
echo xlj('Would you like to Post and Finish Payments?'); ?
>))
186 UnappliedAmount
=document
.getElementById('TdUnappliedAmount').innerHTML
*1;
187 if(confirm(<?php
echo xlj('Undistributed is'); ?
> +
' ' + UnappliedAmount +
'.' +
'\n' +
<?php
echo xlj('Would you like the balance amount to apply to Global Account?'); ?
>))
189 document
.getElementById('mode').value
='FinishPayments';
190 document
.getElementById('global_amount').value
='yes';
191 top
.restoreSession();
192 document
.forms
[0].submit();
196 document
.getElementById('mode').value
='FinishPayments';
197 top
.restoreSession();
198 document
.forms
[0].submit();
206 if(confirm(<?php
echo xlj('Would you like to Post and Finish Payments?'); ?
>))
208 document
.getElementById('mode').value
='FinishPayments';
209 top
.restoreSession();
210 document
.forms
[0].submit();
217 function CompletlyBlank()
218 {//Checks whether any of the allocation row is filled.
219 for(RowCount
=1;;RowCount++
)
221 if(!document
.getElementById('Payment'+RowCount
))
225 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)
235 function OnloadAction()
236 {//Displays message after saving to master table.
237 after_value
=document
.getElementById("after_value").value
;
238 payment_id
=document
.getElementById('payment_id').value
;
239 if(after_value
=='distribute')
242 else if(after_value
=='new_payment')
244 if(document
.getElementById('TablePatientPortion'))
246 document
.getElementById('TablePatientPortion').style
.display
='none';
248 if(confirm(<?php
echo xlj('Successfully Saved.Would you like to Allocate?'); ?
>))
250 if(document
.getElementById('TablePatientPortion'))
252 document
.getElementById('TablePatientPortion').style
.display
='';
259 {//Resets form used in the 'Cancel Changes' button in the master screen.
260 document
.forms
[0].reset();
261 document
.getElementById('TdUnappliedAmount').innerHTML
='0.00';
262 document
.getElementById('div_insurance_or_patient').innerHTML
=' ';
263 CheckVisible('yes');//Payment Method is made 'Check Payment' and the Check box is made visible.
264 PayingEntityAction();//Paying Entity is made 'insurance' and Payment Category is 'Insurance Payment'
266 function FillUnappliedAmount()
267 {//Filling the amount
268 document
.getElementById('TdUnappliedAmount').innerHTML
=document
.getElementById('payment_amount').value
;
272 $
('.datepicker').datetimepicker({
273 <?php
$datetimepicker_timepicker = false; ?
>
274 <?php
$datetimepicker_showseconds = false; ?
>
275 <?php
$datetimepicker_formatInput = true; ?
>
276 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
277 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
281 <script language
="javascript" type
="text/javascript">
282 document
.onclick
=HideTheAjaxDivs
;
298 border
-bottom
: 1px solid black
;
301 border
-top
: 1px solid black
;
304 border
-left
: 1px solid black
;
307 border
-right
: 1px solid black
;
309 #ajax_div_insurance {
312 background
-color
: #FBFDD0;
313 border
: 1px solid
#ccc;
319 background
-color
: #FBFDD0;
320 border
: 1px solid
#ccc;
323 @media only screen
and (max
-width
: 768px
) {
326 text
-align
: left
!Important
;
328 .navbar
-toggle
>span
.icon
-bar
{
329 background
-color
: #68171A ! Important;
331 .navbar
-default .navbar
-toggle
{
332 border
-color
: #4a4a4a;
334 .navbar
-default .navbar
-toggle
:focus
, .navbar
-default .navbar
-toggle
:hover
{
335 background
-color
: #f2f2f2 !Important;
336 font
-weight
: 900 !Important
;
337 color
: #000000 !Important;
340 background
-color
: #E5E5E5;
343 background
-color
: #68171A;
350 background
-color
: #f2f2f2;
353 float: none
!important
;
358 .navbar
-collapse
.collapse
.in
{
360 background
-color
: #dfdfdf;
362 color
: #000000 !Important;
365 */
.navbar
-default .navbar
-nav
>.active
>a
, .navbar
-default .navbar
-nav
>.active
>a
:focus
, .navbar
-default .navbar
-nav
>.active
>a
:hover
{
366 color
: #000000 !Important;
367 background
-color
: /*#F5D6D8 !Important;
368 font-weight: 900 !Important;
370 .navbar
-default .navbar
-nav
>li
>a
{
371 color
: #000000 !Important;
372 font
-weight
: 700 !Important
;
378 .btn-file input[type=file] {
386 filter: alpha(opacity=0);
394 nav
.navbar
.navbar
-default.navbar
-color
{
398 <title
><?php
echo xlt('New Payment'); ?
></title
>
400 $arrOeUiSettings = array(
401 'heading_title' => xl('Payments'),
402 'include_patient_name' => false,// use only in appropriate pages
403 'expandable' => true,
404 'expandable_files' => array("new_payment_xpd", "search_payments_xpd", "era_payments_xpd"),//all file names need suffix _xpd
405 'action' => "",//conceal, reveal, search, reset, link or back
406 'action_title' => "",
407 'action_href' => "",//only for actions - reset, link or back
408 'show_help_icon' => false,
409 'help_file_name' => ""
411 $oemr_ui = new OemrUI($arrOeUiSettings);
414 <body
class="body_top" onload
="OnloadAction()">
415 <div id
="container_div" class="<?php echo attr($oemr_ui->oeContainer()); ?>">
417 <div
class="col-sm-12">
418 <div
class="page-header">
419 <?php
echo $oemr_ui->pageHeading() . "\r\n"; ?
>
424 <div
class="col-sm-12">
425 <nav
class="navbar navbar-default navbar-color navbar-static-top" >
426 <div
class="container-fluid">
427 <div
class="navbar-header">
428 <button
class="navbar-toggle" data
-target
="#myNavbar" data
-toggle
="collapse" type
="button"><span
class="icon-bar"></span
> <span
class="icon-bar"></span
> <span
class="icon-bar"></span
></button
>
430 <div
class="collapse navbar-collapse" id
="myNavbar" >
431 <ul
class="nav navbar-nav" >
432 <li
class="active oe-bold-black">
433 <a href
='new_payment.php' style
="font-weight:700; color:#000000"><?php
echo xlt('New Payment'); ?
></a
>
435 <li
class="oe-bold-black" >
436 <a href
='search_payments.php' style
="font-weight:700; color:#000000"><?php
echo xlt('Search Payment'); ?
></a
>
438 <li
class="oe-bold-black">
439 <a href
='era_payments.php' style
="font-weight:700; color:#000000"><?php
echo xlt('ERA Posting'); ?
></a
>
448 <div
class="col-sm-12">
449 <form action
="new_payment.php" id
="new_payment" method
='post' name
='new_payment' onsubmit
="
451 if ($payment_id*1==0) {
452 echo 'top.restoreSession();return SavePayment();';
454 echo 'return false;';
455 }?>" style
="display:inline">
458 require_once("payment_master.inc.php"); //Check/cash details are entered here.
462 if ($payment_id*1>0) {
465 if ($PaymentType=='patient' && $default_search_patient != "default_search_patient") {
466 $default_search_patient = "default_search_patient";
467 $_POST['default_search_patient'] = $default_search_patient;
468 $hidden_patient_code=$TypeCode;
469 $_REQUEST['hidden_patient_code']=$hidden_patient_code;
470 $_REQUEST['RadioPaid']='Show_Paid';
472 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
475 if ($CountIndexBelow>0) {
477 <?php
//can change position of buttons by creating a class 'position-override' and adding rule text-align:center or right as the case may be in individual stylesheets ?>
478 <div
class="form-group clearfix">
479 <div
class="col-sm-12 text-left position-override">
480 <div
class="btn-group btn-group-pinch" role
="group">
481 <button
class="btn btn-default btn-save" href
="#" onclick
="return PostPayments();"><?php
echo xlt('Post Payments');?
></button
>
482 <button
class="btn btn-default btn-save" href
="#" onclick
="return FinishPayments();"><?php
echo xlt('Finish Payments');?
></button
>
483 <button
class="btn btn-link btn-cancel btn-separate-left" href
="#" onclick
="CancelDistribute()"><?php
echo xlt('Cancel');?
></button
>
488 }//if($CountIndexBelow>0)
494 <input id
="hidden_patient_code" name
="hidden_patient_code" type
="hidden" value
="<?php echo attr($hidden_patient_code);?>"> <input id
='mode' name
='mode' type
='hidden' value
=''>
495 <input id
='default_search_patient' name
='default_search_patient' type
='hidden' value
='<?php echo attr($default_search_patient); ?>'>
496 <input id
='ajax_mode' name
='ajax_mode' type
='hidden' value
=''>
497 <input id
="after_value" name
="after_value" type
="hidden" value
="<?php echo attr($mode);?>">
498 <input id
="payment_id" name
="payment_id" type
="hidden" value
="<?php echo attr($payment_id);?>"> <input id
="hidden_type_code" name
="hidden_type_code" type
="hidden" value
="<?php echo attr($hidden_type_code);?>">
499 <input id
='global_amount' name
='global_amount' type
='hidden' value
=''>
502 </div
><!-- end of row div
-->
503 <div
class="clearfix">.</div
>
504 </div
><!-- end of container div
-->
505 <?php
$oemr_ui->oeBelowContainerDiv();?
>
506 <script src
= '<?php echo $webroot;?>/library/js/oeUI/oeFileUploads.js'></script
>
509 $
('select').removeClass('class1 text')