bug fixins (#1951)
[openemr.git] / interface / billing / new_payment.php
blob679a02d79e0fa8e562aaed1d90ffbd236e4947b8
1 <?php
2 /**
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/payment.inc.php");
40 use OpenEMR\Core\Header;
42 //===============================================================================
43 $screen='new_payment';
44 //===============================================================================
45 // Initialisations
46 $mode = isset($_POST['mode']) ? $_POST['mode'] : '';
47 $payment_id = isset($_REQUEST['payment_id']) ? $_REQUEST['payment_id'] + 0 : 0;
48 $request_payment_id = $payment_id ;
49 $hidden_patient_code = isset($_REQUEST['hidden_patient_code']) ? $_REQUEST['hidden_patient_code'] : '';
50 $default_search_patient = isset($_POST['default_search_patient']) ? $_POST['default_search_patient'] : '';
51 $hidden_type_code = formData('hidden_type_code', true);
52 //===============================================================================
53 //ar_session addition code
54 //===============================================================================
56 if ($mode == "new_payment" || $mode == "distribute") {
57 if (trim(formData('type_name'))=='insurance') {
58 $QueryPart="payer_id = '$hidden_type_code', patient_id = '0" ; // Closing Quote in idSqlStatement below
59 } elseif (trim(formData('type_name'))=='patient') {
60 $QueryPart="payer_id = '0', patient_id = '$hidden_type_code" ; // Closing Quote in idSqlStatement below
62 $user_id=$_SESSION['authUserID'];
63 $closed=0;
64 $modified_time = date('Y-m-d H:i:s');
65 $check_date=DateToYYYYMMDD(formData('check_date'));
66 $deposit_date=DateToYYYYMMDD(formData('deposit_date'));
67 $post_to_date=DateToYYYYMMDD(formData('post_to_date'));
68 if ($post_to_date=='') {
69 $post_to_date=date('Y-m-d');
71 if (formData('deposit_date')=='') {
72 $deposit_date=$post_to_date;
74 $payment_id = idSqlStatement("insert into ar_session set " .
75 $QueryPart .
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')) .
88 "'");
91 //===============================================================================
92 //ar_activity addition code
93 //===============================================================================
94 if ($mode == "PostPayments" || $mode == "FinishPayments") {
95 $user_id=$_SESSION['authUserID'];
96 $created_time = date('Y-m-d H:i:s');
97 for ($CountRow=1;; $CountRow++) {
98 if (isset($_POST["HiddenEncounter$CountRow"])) {
99 DistributionInsert($CountRow, $created_time, $user_id);
100 } else {
101 break;
104 if ($_REQUEST['global_amount']=='yes') {
105 sqlStatement("update ar_session set global_amount=".trim(formData("HidUnappliedAmount"))*1 ." where session_id ='$payment_id'");
107 if ($mode=="FinishPayments") {
108 header("Location: edit_payment.php?payment_id=$payment_id&ParentPage=new_payment");
109 die();
111 $mode = "search";
112 $_POST['mode'] = $mode;
115 //==============================================================================
116 //===============================================================================
117 $payment_id=$payment_id*1 > 0 ? $payment_id + 0 : $request_payment_id + 0;
118 //===============================================================================
120 //==============================================================================
121 //===============================================================================
123 <!DOCTYPE html>
124 <html>
125 <head>
126 <?php Header::setupHeader(['common', 'datetime-picker']);?>
129 <script language='JavaScript'>
130 var mypcc = '1';
131 </script><?php include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?>
132 </script><?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
133 <script language="javascript" type="text/javascript">
134 function CancelDistribute()
135 {//Used in the cancel button.Helpful while cancelling the distribution.
136 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Cancel Distribution for this Patient?'), ENT_QUOTES) ?>"))
138 document.getElementById('hidden_patient_code').value='';
139 document.getElementById('mode').value='search';
140 top.restoreSession();
141 document.forms[0].submit();
143 else
144 return false;
146 function PostPayments()
147 {//Used in saving the allocation
148 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
150 alert("<?php echo htmlspecialchars(xl('Fill the Row.'), ENT_QUOTES) ?>")
151 return false;
153 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
155 return false;
157 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
158 if(PostValue==1)
160 alert("<?php echo htmlspecialchars(xl('Cannot Post Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
161 return false;
163 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Post Payments?'), ENT_QUOTES) ?>"))
165 document.getElementById('mode').value='PostPayments';
166 top.restoreSession();
167 document.forms[0].submit();
169 else
170 return false;
172 function FinishPayments()
173 {//Used in finishig the allocation.Usually done when the amount gets reduced to zero.
174 //After this is pressed a confirmation screen comes,where you can edit if needed.
175 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
177 alert("<?php echo htmlspecialchars(xl('Fill the Row.'), ENT_QUOTES) ?>")
178 return false;
180 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
182 return false;
184 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
185 if(PostValue==1)
187 alert("<?php echo htmlspecialchars(xl('Cannot Post Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
188 return false;
190 if(PostValue==2)
192 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Post and Finish Payments?'), ENT_QUOTES) ?>"))
194 UnappliedAmount=document.getElementById('TdUnappliedAmount').innerHTML*1;
195 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) ?>"))
197 document.getElementById('mode').value='FinishPayments';
198 document.getElementById('global_amount').value='yes';
199 top.restoreSession();
200 document.forms[0].submit();
202 else
204 document.getElementById('mode').value='FinishPayments';
205 top.restoreSession();
206 document.forms[0].submit();
209 else
210 return false;
212 else
214 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Post and Finish Payments?'), ENT_QUOTES) ?>"))
216 document.getElementById('mode').value='FinishPayments';
217 top.restoreSession();
218 document.forms[0].submit();
220 else
221 return false;
225 function CompletlyBlank()
226 {//Checks whether any of the allocation row is filled.
227 for(RowCount=1;;RowCount++)
229 if(!document.getElementById('Payment'+RowCount))
230 break;
231 else
233 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)
237 else
238 return false;
241 return true;
243 function OnloadAction()
244 {//Displays message after saving to master table.
245 after_value=document.getElementById("after_value").value;
246 payment_id=document.getElementById('payment_id').value;
247 if(after_value=='distribute')
250 else if(after_value=='new_payment')
252 if(document.getElementById('TablePatientPortion'))
254 document.getElementById('TablePatientPortion').style.display='none';
256 if(confirm("<?php echo htmlspecialchars(xl('Successfully Saved.Would you like to Allocate?'), ENT_QUOTES) ?>"))
258 if(document.getElementById('TablePatientPortion'))
260 document.getElementById('TablePatientPortion').style.display='';
266 function ResetForm()
267 {//Resets form used in the 'Cancel Changes' button in the master screen.
268 document.forms[0].reset();
269 document.getElementById('TdUnappliedAmount').innerHTML='0.00';
270 document.getElementById('div_insurance_or_patient').innerHTML='&nbsp;';
271 CheckVisible('yes');//Payment Method is made 'Check Payment' and the Check box is made visible.
272 PayingEntityAction();//Paying Entity is made 'insurance' and Payment Category is 'Insurance Payment'
274 function FillUnappliedAmount()
275 {//Filling the amount
276 document.getElementById('TdUnappliedAmount').innerHTML=document.getElementById('payment_amount').value;
279 $(document).ready(function() {
280 $('.datepicker').datetimepicker({
281 <?php $datetimepicker_timepicker = false; ?>
282 <?php $datetimepicker_showseconds = false; ?>
283 <?php $datetimepicker_formatInput = true; ?>
284 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
285 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
288 </script>
289 <script language="javascript" type="text/javascript">
290 document.onclick=HideTheAjaxDivs;
291 </script>
292 <style>
293 .class1 {
294 width: 125px;
296 .class2 {
297 width: 250px;
299 .class3 {
300 width: 75px;
302 .class4 {
303 width: 100px;
305 .bottom {
306 border-bottom: 1px solid black;
308 .top {
309 border-top: 1px solid black;
311 .left {
312 border-left: 1px solid black;
314 .right {
315 border-right: 1px solid black;
317 #ajax_div_insurance {
318 position: absolute;
319 z-index: 10;
320 background-color: #FBFDD0;
321 border: 1px solid #ccc;
322 padding: 10px;
324 #ajax_div_patient {
325 position: absolute;
326 z-index: 10;
327 background-color: #FBFDD0;
328 border: 1px solid #ccc;
329 padding: 10px;
331 @media only screen and (max-width: 768px) {
332 [class*="col-"] {
333 width: 100%;
334 text-align: left!Important;
336 .navbar-toggle>span.icon-bar {
337 background-color: #68171A ! Important;
339 .navbar-default .navbar-toggle {
340 border-color: #4a4a4a;
342 .navbar-default .navbar-toggle:focus, .navbar-default .navbar-toggle:hover {
343 background-color: #f2f2f2 !Important;
344 font-weight: 900 !Important;
345 color: #000000 !Important;
347 .navbar-color {
348 background-color: #E5E5E5;
350 .icon-bar {
351 background-color: #68171A;
353 .navbar-header {
354 float: none;
356 .navbar-toggle {
357 display: block;
358 background-color: #f2f2f2;
360 .navbar-nav {
361 float: none!important;
363 .navbar-nav>li {
364 float: none;
366 .navbar-collapse.collapse.in {
367 z-index: 100;
368 background-color: #dfdfdf;
369 font-weight: 700;
370 color: #000000 !Important;
373 */ .navbar-default .navbar-nav>.active>a, .navbar-default .navbar-nav>.active>a:focus, .navbar-default .navbar-nav>.active>a:hover {
374 color: #000000 !Important;
375 background-color: /*#F5D6D8 !Important;
376 font-weight: 900 !Important;
378 .navbar-default .navbar-nav>li>a {
379 color: #000000 !Important;
380 font-weight: 700 !Important;
382 /*.btn-file {
383 position: relative;
384 overflow: hidden;
386 .btn-file input[type=file] {
387 position: absolute;
388 top: 0;
389 right: 0;
390 min-width: 100%;
391 min-height: 100%;
392 font-size: 100px;
393 text-align: right;
394 filter: alpha(opacity=0);
395 opacity: 0;
396 outline: none;
397 background: white;
398 cursor: inherit;
399 display: block;
402 nav.navbar.navbar-default.navbar-color {
403 background: #c1c1c1;
405 </style>
406 <?php
407 //to determine and set the form to open in the desired state - expanded or centered, any selection the user makes will
408 //become the user-specific default for that page. collectAndOrganizeExpandSetting() contains a single array as an
409 //argument, containing one or more elements, the name of the current file is the first element, if there are linked
410 // files they should be listed thereafter, please add _xpd suffix to the file name
411 $arr_files_php = array("new_payment_xpd", "search_payments_xpd", "era_payments_xpd");
412 $current_state = collectAndOrganizeExpandSetting($arr_files_php);
413 require_once("$srcdir/expand_contract_inc.php");
415 <title><?php echo xlt('New Payment'); ?></title>
416 </head>
417 <body class="body_top" onload="OnloadAction()">
418 <div class="<?php echo $container;?> expandable">
419 <div class="row">
420 <div class="col-sm-12">
421 <div class="page-header">
422 <h2>
423 <?php echo xlt('Payments'); ?> <i id="exp_cont_icon" class="fa <?php echo attr($expand_icon_class);?> oe-superscript-small expand_contract"
424 title="<?php echo attr($expand_title); ?>" aria-hidden="true"></i>
425 </h2>
426 </div>
427 </div>
428 </div>
429 <div class="row">
430 <div class="col-sm-12">
431 <nav class="navbar navbar-default navbar-color navbar-static-top" >
432 <div class="container-fluid">
433 <div class="navbar-header">
434 <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>
435 </div>
436 <div class="collapse navbar-collapse" id="myNavbar" >
437 <ul class="nav navbar-nav" >
438 <li class="active oe-bold-black">
439 <a href='new_payment.php' style="font-weight:700; color:#000000"><?php echo xlt('New Payment'); ?></a>
440 </li>
441 <li class="oe-bold-black" >
442 <a href='search_payments.php' style="font-weight:700; color:#000000"><?php echo xlt('Search Payment'); ?></a>
443 </li>
444 <li class="oe-bold-black">
445 <a href='era_payments.php' style="font-weight:700; color:#000000"><?php echo xlt('ERA Posting'); ?></a>
446 </li>
447 </ul>
448 </div>
449 </div>
450 </nav>
451 </div>
452 </div>
453 <div class="row">
454 <div class="col-sm-12">
455 <form action="new_payment.php" id="new_payment" method='post' name='new_payment' onsubmit="
456 <?php
457 if ($payment_id*1==0) {
458 echo 'top.restoreSession();return SavePayment();';
459 } else {
460 echo 'return false;';
461 }?>" style="display:inline">
462 <fieldset>
463 <?php
464 require_once("payment_master.inc.php"); //Check/cash details are entered here.
466 <br>
467 <?php
468 if ($payment_id*1>0) {
470 <?php
471 if ($PaymentType=='patient' && $default_search_patient != "default_search_patient") {
472 $default_search_patient = "default_search_patient";
473 $_POST['default_search_patient'] = $default_search_patient;
474 $hidden_patient_code=$TypeCode;
475 $_REQUEST['hidden_patient_code']=$hidden_patient_code;
476 $_REQUEST['RadioPaid']='Show_Paid';
478 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
480 <?php
481 if ($CountIndexBelow>0) {
483 <?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 ?>
484 <div class="form-group clearfix">
485 <div class="col-sm-12 text-left position-override">
486 <div class="btn-group btn-group-pinch" role="group">
487 <button class="btn btn-default btn-save" href="#" onclick="return PostPayments();"><?php echo xlt('Post Payments');?></button>
488 <button class="btn btn-default btn-save" href="#" onclick="return FinishPayments();"><?php echo xlt('Finish Payments');?></button>
489 <button class="btn btn-link btn-cancel btn-separate-left" href="#" onclick="CancelDistribute()"><?php echo xlt('Cancel');?></button>
490 </div>
491 </div>
492 </div>
493 <?php
494 }//if($CountIndexBelow>0)
496 <?php
499 </fieldset>
500 <input id="hidden_patient_code" name="hidden_patient_code" type="hidden" value="<?php echo htmlspecialchars($hidden_patient_code);?>"> <input id='mode' name='mode' type='hidden' value=''>
501 <input id='default_search_patient' name='default_search_patient' type='hidden' value='<?php echo $default_search_patient ?>'>
502 <input id='ajax_mode' name='ajax_mode' type='hidden' value=''>
503 <input id="after_value" name="after_value" type="hidden" value="<?php echo htmlspecialchars($mode);?>">
504 <input id="payment_id" name="payment_id" type="hidden" value="<?php echo htmlspecialchars($payment_id);?>"> <input id="hidden_type_code" name="hidden_type_code" type="hidden" value="<?php echo htmlspecialchars($hidden_type_code);?>">
505 <input id='global_amount' name='global_amount' type='hidden' value=''>
506 </form>
507 </div>
508 </div><!-- end of row div -->
509 <div class="clearfix">.</div>
510 </div><!-- end of container div -->
513 <script>
515 $(function() {
516 //https://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-bootstrap-3
517 // We can attach the `fileselect` event to all file inputs on the page
518 $(document).on('change', ':file', function() {
519 var input = $(this),
520 numFiles = input.get(0).files ? input.get(0).files.length :
522 label = input.val().replace(/\\/g, '/').replace(
523 /.*\//, '');
524 input.trigger('fileselect', [numFiles, label]);
526 // We can watch for our custom `fileselect` event like this
527 $(document).ready(function() {
528 $(':file').on('fileselect', function(event, numFiles,
529 label) {
530 var input = $(this).parents('.input-group')
531 .find(':text'),
532 log = numFiles > 1 ? numFiles +
533 ' files selected' : label;
534 if (input.length) {
535 input.val(log);
536 } else {
537 if (log) alert(log);
542 $(document).ready(function() {
543 $('select').removeClass('class1 text')
545 </script>
546 <script>
547 <?php
548 // jQuery script to change expanded/centered state dynamically
549 require_once("../expand_contract_js.php")
551 </script>
553 </body>
554 </html>