Highway to PSR2
[openemr.git] / interface / billing / new_payment.php
blobc7c21c65cd6adb74a76a742439895c548121d53a
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");
39 //===============================================================================
40 $screen='new_payment';
41 //===============================================================================
42 // Initialisations
43 $mode = isset($_POST['mode']) ? $_POST['mode'] : '';
44 $payment_id = isset($_REQUEST['payment_id']) ? $_REQUEST['payment_id'] : '';
45 $request_payment_id = $payment_id ;
46 $hidden_patient_code = isset($_REQUEST['hidden_patient_code']) ? $_REQUEST['hidden_patient_code'] : '';
47 $default_search_patient = isset($_POST['default_search_patient']) ? $_POST['default_search_patient'] : '';
48 $hidden_type_code = formData('hidden_type_code', true);
49 //===============================================================================
50 //ar_session addition code
51 //===============================================================================
53 if ($mode == "new_payment" || $mode == "distribute") {
54 if (trim(formData('type_name'))=='insurance') {
55 $QueryPart="payer_id = '$hidden_type_code', patient_id = '0" ; // Closing Quote in idSqlStatement below
56 } elseif (trim(formData('type_name'))=='patient') {
57 $QueryPart="payer_id = '0', patient_id = '$hidden_type_code" ; // Closing Quote in idSqlStatement below
60 $user_id=$_SESSION['authUserID'];
61 $closed=0;
62 $modified_time = date('Y-m-d H:i:s');
63 $check_date=DateToYYYYMMDD(formData('check_date'));
64 $deposit_date=DateToYYYYMMDD(formData('deposit_date'));
65 $post_to_date=DateToYYYYMMDD(formData('post_to_date'));
66 if ($post_to_date=='') {
67 $post_to_date=date('Y-m-d');
70 if (formData('deposit_date')=='') {
71 $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;
105 if ($_REQUEST['global_amount']=='yes') {
106 sqlStatement("update ar_session set global_amount=".trim(formData("HidUnappliedAmount"))*1 ." where session_id ='$payment_id'");
109 if ($mode=="FinishPayments") {
110 header("Location: edit_payment.php?payment_id=$payment_id&ParentPage=new_payment");
111 die();
114 $mode = "search";
115 $_POST['mode'] = $mode;
118 //==============================================================================
119 //===============================================================================
120 $payment_id=$payment_id*1 > 0 ? $payment_id : $request_payment_id;
121 //===============================================================================
123 //==============================================================================
124 //===============================================================================
126 <html>
127 <head>
128 <?php if (function_exists('html_header_show')) {
129 html_header_show();
130 } ?>
134 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
135 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
136 <script language='JavaScript'>
137 var mypcc = '1';
138 </script>
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-7-2/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?v=<?php echo $v_js_includes; ?>"></script>
143 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
145 <script LANGUAGE="javascript" TYPE="text/javascript">
146 function CancelDistribute()
147 {//Used in the cancel button.Helpful while cancelling the distribution.
148 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Cancel Distribution for this Patient?'), ENT_QUOTES) ?>"))
150 document.getElementById('hidden_patient_code').value='';
151 document.getElementById('mode').value='search';
152 top.restoreSession();
153 document.forms[0].submit();
155 else
156 return false;
158 function PostPayments()
159 {//Used in saving the allocation
160 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
162 alert("<?php echo htmlspecialchars(xl('Fill the Row.'), ENT_QUOTES) ?>")
163 return false;
165 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
167 return false;
169 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
170 if(PostValue==1)
172 alert("<?php echo htmlspecialchars(xl('Cannot Post Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
173 return false;
175 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Post Payments?'), ENT_QUOTES) ?>"))
177 document.getElementById('mode').value='PostPayments';
178 top.restoreSession();
179 document.forms[0].submit();
181 else
182 return false;
184 function FinishPayments()
185 {//Used in finishig the allocation.Usually done when the amount gets reduced to zero.
186 //After this is pressed a confirmation screen comes,where you can edit if needed.
187 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
189 alert("<?php echo htmlspecialchars(xl('Fill the Row.'), ENT_QUOTES) ?>")
190 return false;
192 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
194 return false;
196 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
197 if(PostValue==1)
199 alert("<?php echo htmlspecialchars(xl('Cannot Post Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
200 return false;
202 if(PostValue==2)
204 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Post and Finish Payments?'), ENT_QUOTES) ?>"))
206 UnappliedAmount=document.getElementById('TdUnappliedAmount').innerHTML*1;
207 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) ?>"))
209 document.getElementById('mode').value='FinishPayments';
210 document.getElementById('global_amount').value='yes';
211 top.restoreSession();
212 document.forms[0].submit();
214 else
216 document.getElementById('mode').value='FinishPayments';
217 top.restoreSession();
218 document.forms[0].submit();
221 else
222 return false;
224 else
226 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Post and Finish Payments?'), ENT_QUOTES) ?>"))
228 document.getElementById('mode').value='FinishPayments';
229 top.restoreSession();
230 document.forms[0].submit();
232 else
233 return false;
237 function CompletlyBlank()
238 {//Checks whether any of the allocation row is filled.
239 for(RowCount=1;;RowCount++)
241 if(!document.getElementById('Payment'+RowCount))
242 break;
243 else
245 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)
249 else
250 return false;
253 return true;
255 function OnloadAction()
256 {//Displays message after saving to master table.
257 after_value=document.getElementById("after_value").value;
258 payment_id=document.getElementById('payment_id').value;
259 if(after_value=='distribute')
262 else if(after_value=='new_payment')
264 if(document.getElementById('TablePatientPortion'))
266 document.getElementById('TablePatientPortion').style.display='none';
268 if(confirm("<?php echo htmlspecialchars(xl('Successfully Saved.Would you like to Allocate?'), ENT_QUOTES) ?>"))
270 if(document.getElementById('TablePatientPortion'))
272 document.getElementById('TablePatientPortion').style.display='';
278 function ResetForm()
279 {//Resets form used in the 'Cancel Changes' button in the master screen.
280 document.forms[0].reset();
281 document.getElementById('TdUnappliedAmount').innerHTML='0.00';
282 document.getElementById('div_insurance_or_patient').innerHTML='&nbsp;';
283 CheckVisible('yes');//Payment Method is made 'Check Payment' and the Check box is made visible.
284 PayingEntityAction();//Paying Entity is made 'insurance' and Payment Category is 'Insurance Payment'
286 function FillUnappliedAmount()
287 {//Filling the amount
288 document.getElementById('TdUnappliedAmount').innerHTML=document.getElementById('payment_amount').value;
291 $(document).ready(function() {
292 $('.datepicker').datetimepicker({
293 <?php $datetimepicker_timepicker = false; ?>
294 <?php $datetimepicker_showseconds = false; ?>
295 <?php $datetimepicker_formatInput = true; ?>
296 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
297 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
300 </script>
301 <script language="javascript" type="text/javascript">
302 document.onclick=HideTheAjaxDivs;
303 </script>
304 <style>
305 .class1{width:125px;}
306 .class2{width:250px;}
307 .bottom{border-bottom:1px solid black;}
308 .top{border-top:1px solid black;}
309 .left{border-left:1px solid black;}
310 .right{border-right:1px solid black;}
311 #ajax_div_insurance {
312 position: absolute;
313 z-index:10;
314 background-color: #FBFDD0;
315 border: 1px solid #ccc;
316 padding: 10px;
318 #ajax_div_patient {
319 position: absolute;
320 z-index:10;
321 background-color: #FBFDD0;
322 border: 1px solid #ccc;
323 padding: 10px;
325 </style>
326 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
327 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
329 </head>
330 <body class="body_top" onLoad="OnloadAction()" >
331 <form name='new_payment' method='post' action="new_payment.php" onsubmit='
332 <?php
333 if ($payment_id*1==0) {
335 top.restoreSession();return SavePayment();
336 <?php
337 } else {
339 return false;
340 <?php
343 ' style="display:inline" >
344 <table width="100%" border="0" cellspacing="0" cellpadding="0">
345 <tr>
346 <td colspan="3" align="left"><b><?php echo htmlspecialchars(xl('Payments'), ENT_QUOTES) ?></b></td>
347 </tr>
348 <tr height="15">
349 <td colspan="3" align="left" ></td>
350 </tr>
351 <tr>
352 <td colspan="3" align="left">
353 <ul class="tabNav">
354 <li class='current'><a href='new_payment.php'><?php echo htmlspecialchars(xl('New Payment'), ENT_QUOTES) ?></a></li>
355 <li><a href='search_payments.php'><?php echo htmlspecialchars(xl('Search Payment'), ENT_QUOTES) ?></a></li>
356 <li><a href='era_payments.php'><?php echo htmlspecialchars(xl('ERA Posting'), ENT_QUOTES) ?></a></li>
357 </ul> </td>
358 </tr>
359 <tr>
360 <td colspan="3" align="left" >
361 <?php
362 require_once("payment_master.inc.php"); //Check/cash details are entered here.
364 </td>
365 </tr>
366 </table>
367 <?php
368 if ($payment_id*1>0) {
370 <table width="999" border="0" cellspacing="0" cellpadding="10" bgcolor="#DEDEDE"><tr><td>
371 <table width="979" border="0" cellspacing="0" cellpadding="0">
372 <tr>
373 <td colspan="13" align="left" >
374 <!--Distribute section-->
375 <?php
376 if ($PaymentType=='patient' && $default_search_patient != "default_search_patient") {
377 $default_search_patient = "default_search_patient";
378 $_POST['default_search_patient'] = $default_search_patient;
379 $hidden_patient_code=$TypeCode;
380 $_REQUEST['hidden_patient_code']=$hidden_patient_code;
381 $_REQUEST['RadioPaid']='Show_Paid';
384 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
386 </td>
387 </tr>
388 <tr>
389 <td colspan="13" align="left" >
390 <?php
391 if ($CountIndexBelow>0) {
393 <table border="0" cellspacing="0" cellpadding="0" width="267" align="center" id="AllocateButtons">
394 <tr height="5">
395 <td ></td>
396 <td ></td>
397 <td></td>
398 </tr>
399 <tr>
400 <td width="100"><a href="#" onClick="javascript:return PostPayments();" class="css_button"><span><?php echo htmlspecialchars(xl('Post Payments'), ENT_QUOTES);?></span></a></td>
401 <td width="107"><a href="#" onClick="javascript:return FinishPayments();" class="css_button"><span><?php echo htmlspecialchars(xl('Finish Payments'), ENT_QUOTES);?></span></a></td>
402 <td width="60"><a href="#" onClick="CancelDistribute()" class="css_button"><span><?php echo htmlspecialchars(xl('Cancel'), ENT_QUOTES);?></span></a></td>
403 </tr>
404 </table>
405 <?php
406 }//if($CountIndexBelow>0)
408 <?php
410 ?> </td>
411 </tr>
412 </table>
413 </td></tr></table>
414 <input type="hidden" name="hidden_patient_code" id="hidden_patient_code" value="<?php echo htmlspecialchars($hidden_patient_code);?>"/>
415 <input type='hidden' name='mode' id='mode' value='' />
416 <input type='hidden' name='default_search_patient' id='default_search_patient' value='<?php echo $default_search_patient ?>' />
417 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
418 <input type="hidden" name="after_value" id="after_value" value="<?php echo htmlspecialchars($mode);?>"/>
419 <input type="hidden" name="payment_id" id="payment_id" value="<?php echo htmlspecialchars($payment_id);?>"/>
420 <input type="hidden" name="hidden_type_code" id="hidden_type_code" value="<?php echo htmlspecialchars($hidden_type_code);?>"/>
421 <input type='hidden' name='global_amount' id='global_amount' value='' />
422 </form>
423 </body>
424 </html>