Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / interface / billing / new_payment.php
blobbd5ae4602d14439870a21dbe79df79d6c6412a6e
1 <?php
2 /**
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.
7 * @package OpenEMR
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 //===============================================================================
37 // Initialisations
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'];
55 $closed=0;
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 " .
67 $QueryPart .
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')) .
80 "'");
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);
92 } else {
93 break;
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");
101 die();
103 $mode = "search";
104 $_POST['mode'] = $mode;
107 //==============================================================================
108 //===============================================================================
109 $payment_id=$payment_id*1 > 0 ? $payment_id + 0 : $request_payment_id + 0;
110 //===============================================================================
112 //==============================================================================
113 //===============================================================================
115 <!DOCTYPE html>
116 <html>
117 <head>
118 <?php Header::setupHeader(['common', 'datetime-picker']);?>
121 <script language='JavaScript'>
122 var mypcc = '1';
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();
135 else
136 return false;
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.'); ?>);
143 return false;
145 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
147 return false;
149 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
150 if(PostValue==1)
152 alert(<?php echo xlj('Cannot Post Payments.Undistributed is Negative.'); ?>);
153 return false;
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();
161 else
162 return false;
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.'); ?>);
170 return false;
172 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
174 return false;
176 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
177 if(PostValue==1)
179 alert(<?php echo xlj('Cannot Post Payments.Undistributed is Negative.'); ?>);
180 return false;
182 if(PostValue==2)
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();
194 else
196 document.getElementById('mode').value='FinishPayments';
197 top.restoreSession();
198 document.forms[0].submit();
201 else
202 return false;
204 else
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();
212 else
213 return false;
217 function CompletlyBlank()
218 {//Checks whether any of the allocation row is filled.
219 for(RowCount=1;;RowCount++)
221 if(!document.getElementById('Payment'+RowCount))
222 break;
223 else
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)
229 else
230 return false;
233 return true;
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='';
258 function ResetForm()
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='&nbsp;';
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;
271 $(function() {
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 ?>
280 </script>
281 <script language="javascript" type="text/javascript">
282 document.onclick=HideTheAjaxDivs;
283 </script>
284 <style>
285 .class1 {
286 width: 125px;
288 .class2 {
289 width: 250px;
291 .class3 {
292 width: 75px;
294 .class4 {
295 width: 100px;
297 .bottom {
298 border-bottom: 1px solid black;
300 .top {
301 border-top: 1px solid black;
303 .left {
304 border-left: 1px solid black;
306 .right {
307 border-right: 1px solid black;
309 #ajax_div_insurance {
310 position: absolute;
311 z-index: 10;
312 background-color: #FBFDD0;
313 border: 1px solid #ccc;
314 padding: 10px;
316 #ajax_div_patient {
317 position: absolute;
318 z-index: 10;
319 background-color: #FBFDD0;
320 border: 1px solid #ccc;
321 padding: 10px;
323 @media only screen and (max-width: 768px) {
324 [class*="col-"] {
325 width: 100%;
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;
339 .navbar-color {
340 background-color: #E5E5E5;
342 .icon-bar {
343 background-color: #68171A;
345 .navbar-header {
346 float: none;
348 .navbar-toggle {
349 display: block;
350 background-color: #f2f2f2;
352 .navbar-nav {
353 float: none!important;
355 .navbar-nav>li {
356 float: none;
358 .navbar-collapse.collapse.in {
359 z-index: 100;
360 background-color: #dfdfdf;
361 font-weight: 700;
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;
374 /*.btn-file {
375 position: relative;
376 overflow: hidden;
378 .btn-file input[type=file] {
379 position: absolute;
380 top: 0;
381 right: 0;
382 min-width: 100%;
383 min-height: 100%;
384 font-size: 100px;
385 text-align: right;
386 filter: alpha(opacity=0);
387 opacity: 0;
388 outline: none;
389 background: white;
390 cursor: inherit;
391 display: block;
394 nav.navbar.navbar-default.navbar-color {
395 background: #c1c1c1;
397 </style>
398 <title><?php echo xlt('New Payment'); ?></title>
399 <?php
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);
413 </head>
414 <body class="body_top" onload="OnloadAction()">
415 <div id="container_div" class="<?php echo attr($oemr_ui->oeContainer()); ?>">
416 <div class="row">
417 <div class="col-sm-12">
418 <div class="page-header">
419 <?php echo $oemr_ui->pageHeading() . "\r\n"; ?>
420 </div>
421 </div>
422 </div>
423 <div class="row">
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>
429 </div>
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>
434 </li>
435 <li class="oe-bold-black" >
436 <a href='search_payments.php' style="font-weight:700; color:#000000"><?php echo xlt('Search Payment'); ?></a>
437 </li>
438 <li class="oe-bold-black">
439 <a href='era_payments.php' style="font-weight:700; color:#000000"><?php echo xlt('ERA Posting'); ?></a>
440 </li>
441 </ul>
442 </div>
443 </div>
444 </nav>
445 </div>
446 </div>
447 <div class="row">
448 <div class="col-sm-12">
449 <form action="new_payment.php" id="new_payment" method='post' name='new_payment' onsubmit="
450 <?php
451 if ($payment_id*1==0) {
452 echo 'top.restoreSession();return SavePayment();';
453 } else {
454 echo 'return false;';
455 }?>" style="display:inline">
456 <fieldset>
457 <?php
458 require_once("payment_master.inc.php"); //Check/cash details are entered here.
460 <br>
461 <?php
462 if ($payment_id*1>0) {
464 <?php
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.
474 <?php
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>
484 </div>
485 </div>
486 </div>
487 <?php
488 }//if($CountIndexBelow>0)
490 <?php
493 </fieldset>
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=''>
500 </form>
501 </div>
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>
507 <script>
508 $(function() {
509 $('select').removeClass('class1 text')
511 </script>
512 </body>
513 </html>