Interim autoloaded library/classes via composer classmap, take 4. (#422)
[openemr.git] / interface / billing / new_payment.php
blob96f75b9a3938de7657416d4102d8eca6c1c35ab6
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/formatting.inc.php");
39 require_once("$srcdir/payment.inc.php");
40 //===============================================================================
41 $screen='new_payment';
42 //===============================================================================
43 // Initialisations
44 $mode = isset($_POST['mode']) ? $_POST['mode'] : '';
45 $payment_id = isset($_REQUEST['payment_id']) ? $_REQUEST['payment_id'] : '';
46 $request_payment_id = $payment_id ;
47 $hidden_patient_code = isset($_REQUEST['hidden_patient_code']) ? $_REQUEST['hidden_patient_code'] : '';
48 $default_search_patient = isset($_POST['default_search_patient']) ? $_POST['default_search_patient'] : '';
49 $hidden_type_code = formData('hidden_type_code', true );
50 //===============================================================================
51 //ar_session addition code
52 //===============================================================================
54 if ($mode == "new_payment" || $mode == "distribute")
56 if(trim(formData('type_name' ))=='insurance')
58 $QueryPart="payer_id = '$hidden_type_code', patient_id = '0" ; // Closing Quote in idSqlStatement below
60 elseif(trim(formData('type_name' ))=='patient')
62 $QueryPart="payer_id = '0', patient_id = '$hidden_type_code" ; // Closing Quote in idSqlStatement below
64 $user_id=$_SESSION['authUserID'];
65 $closed=0;
66 $modified_time = date('Y-m-d H:i:s');
67 $check_date=DateToYYYYMMDD(formData('check_date'));
68 $deposit_date=DateToYYYYMMDD(formData('deposit_date'));
69 $post_to_date=DateToYYYYMMDD(formData('post_to_date'));
70 if($post_to_date=='')
71 $post_to_date=date('Y-m-d');
72 if(formData('deposit_date')=='')
73 $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")
96 $user_id=$_SESSION['authUserID'];
97 $created_time = date('Y-m-d H:i:s');
98 for($CountRow=1;;$CountRow++)
100 if (isset($_POST["HiddenEncounter$CountRow"]))
102 DistributionInsert($CountRow,$created_time,$user_id);
104 else
105 break;
107 if($_REQUEST['global_amount']=='yes')
108 sqlStatement("update ar_session set global_amount=".trim(formData("HidUnappliedAmount" ))*1 ." where session_id ='$payment_id'");
109 if($mode=="FinishPayments")
111 header("Location: edit_payment.php?payment_id=$payment_id&ParentPage=new_payment");
112 die();
114 $mode = "search";
115 $_POST['mode'] = $mode;
118 //==============================================================================
119 //===============================================================================
120 $payment_id=$payment_id*1 > 0 ? $payment_id : $request_payment_id;
121 //===============================================================================
122 $DateFormat=DateFormatRead();
123 //==============================================================================
124 //===============================================================================
126 <html>
127 <head>
128 <?php if (function_exists('html_header_show')) html_header_show(); ?>
130 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
131 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
132 <script type="text/javascript" src="../../library/textformat.js"></script>
133 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
134 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
135 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></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-2-1/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"></script>
143 <script LANGUAGE="javascript" TYPE="text/javascript">
144 function CancelDistribute()
145 {//Used in the cancel button.Helpful while cancelling the distribution.
146 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Cancel Distribution for this Patient?'), ENT_QUOTES) ?>"))
148 document.getElementById('hidden_patient_code').value='';
149 document.getElementById('mode').value='search';
150 top.restoreSession();
151 document.forms[0].submit();
153 else
154 return false;
156 function PostPayments()
157 {//Used in saving the allocation
158 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
160 alert("<?php echo htmlspecialchars( xl('Fill the Row.'), ENT_QUOTES) ?>")
161 return false;
163 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
165 return false;
167 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
168 if(PostValue==1)
170 alert("<?php echo htmlspecialchars( xl('Cannot Post Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
171 return false;
173 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Post Payments?'), ENT_QUOTES) ?>"))
175 document.getElementById('mode').value='PostPayments';
176 top.restoreSession();
177 document.forms[0].submit();
179 else
180 return false;
182 function FinishPayments()
183 {//Used in finishig the allocation.Usually done when the amount gets reduced to zero.
184 //After this is pressed a confirmation screen comes,where you can edit if needed.
185 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
187 alert("<?php echo htmlspecialchars( xl('Fill the Row.'), ENT_QUOTES) ?>")
188 return false;
190 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
192 return false;
194 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
195 if(PostValue==1)
197 alert("<?php echo htmlspecialchars( xl('Cannot Post Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
198 return false;
200 if(PostValue==2)
202 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Post and Finish Payments?'), ENT_QUOTES) ?>"))
204 UnappliedAmount=document.getElementById('TdUnappliedAmount').innerHTML*1;
205 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) ?>"))
207 document.getElementById('mode').value='FinishPayments';
208 document.getElementById('global_amount').value='yes';
209 top.restoreSession();
210 document.forms[0].submit();
212 else
214 document.getElementById('mode').value='FinishPayments';
215 top.restoreSession();
216 document.forms[0].submit();
219 else
220 return false;
222 else
224 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Post and Finish Payments?'), ENT_QUOTES) ?>"))
226 document.getElementById('mode').value='FinishPayments';
227 top.restoreSession();
228 document.forms[0].submit();
230 else
231 return false;
235 function CompletlyBlank()
236 {//Checks whether any of the allocation row is filled.
237 for(RowCount=1;;RowCount++)
239 if(!document.getElementById('Payment'+RowCount))
240 break;
241 else
243 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)
247 else
248 return false;
251 return true;
253 function OnloadAction()
254 {//Displays message after saving to master table.
255 after_value=document.getElementById("after_value").value;
256 payment_id=document.getElementById('payment_id').value;
257 if(after_value=='distribute')
260 else if(after_value=='new_payment')
262 if(document.getElementById('TablePatientPortion'))
264 document.getElementById('TablePatientPortion').style.display='none';
266 if(confirm("<?php echo htmlspecialchars( xl('Successfully Saved.Would you like to Allocate?'), ENT_QUOTES) ?>"))
268 if(document.getElementById('TablePatientPortion'))
270 document.getElementById('TablePatientPortion').style.display='';
276 function ResetForm()
277 {//Resets form used in the 'Cancel Changes' button in the master screen.
278 document.forms[0].reset();
279 document.getElementById('TdUnappliedAmount').innerHTML='0.00';
280 document.getElementById('div_insurance_or_patient').innerHTML='&nbsp;';
281 CheckVisible('yes');//Payment Method is made 'Check Payment' and the Check box is made visible.
282 PayingEntityAction();//Paying Entity is made 'insurance' and Payment Category is 'Insurance Payment'
284 function FillUnappliedAmount()
285 {//Filling the amount
286 document.getElementById('TdUnappliedAmount').innerHTML=document.getElementById('payment_amount').value;
288 </script>
289 <script language="javascript" type="text/javascript">
290 document.onclick=HideTheAjaxDivs;
291 </script>
292 <style>
293 .class1{width:125px;}
294 .class2{width:250px;}
295 .bottom{border-bottom:1px solid black;}
296 .top{border-top:1px solid black;}
297 .left{border-left:1px solid black;}
298 .right{border-right:1px solid black;}
299 #ajax_div_insurance {
300 position: absolute;
301 z-index:10;
302 background-color: #FBFDD0;
303 border: 1px solid #ccc;
304 padding: 10px;
306 #ajax_div_patient {
307 position: absolute;
308 z-index:10;
309 background-color: #FBFDD0;
310 border: 1px solid #ccc;
311 padding: 10px;
313 </style>
314 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
315 </head>
316 <body class="body_top" onLoad="OnloadAction()" >
317 <form name='new_payment' method='post' action="new_payment.php" onsubmit='
318 <?php
319 if($payment_id*1==0)
322 top.restoreSession();return SavePayment();
323 <?php
325 else
328 return false;
329 <?php
332 ' style="display:inline" >
333 <table width="100%" border="0" cellspacing="0" cellpadding="0">
334 <tr>
335 <td colspan="3" align="left"><b><?php echo htmlspecialchars( xl('Payments'), ENT_QUOTES) ?></b></td>
336 </tr>
337 <tr height="15">
338 <td colspan="3" align="left" ></td>
339 </tr>
340 <tr>
341 <td colspan="3" align="left">
342 <ul class="tabNav">
343 <li class='current'><a href='new_payment.php'><?php echo htmlspecialchars( xl('New Payment'), ENT_QUOTES) ?></a></li>
344 <li><a href='search_payments.php'><?php echo htmlspecialchars( xl('Search Payment'), ENT_QUOTES) ?></a></li>
345 <li><a href='era_payments.php'><?php echo htmlspecialchars( xl('ERA Posting'), ENT_QUOTES) ?></a></li>
346 </ul> </td>
347 </tr>
348 <tr>
349 <td colspan="3" align="left" >
350 <?php
351 require_once("payment_master.inc.php"); //Check/cash details are entered here.
353 </td>
354 </tr>
355 </table>
356 <?php
357 if($payment_id*1>0)
360 <table width="999" border="0" cellspacing="0" cellpadding="10" bgcolor="#DEDEDE"><tr><td>
361 <table width="979" border="0" cellspacing="0" cellpadding="0">
362 <tr>
363 <td colspan="13" align="left" >
364 <!--Distribute section-->
365 <?php
366 if($PaymentType=='patient' && $default_search_patient != "default_search_patient")
368 $default_search_patient = "default_search_patient";
369 $_POST['default_search_patient'] = $default_search_patient;
370 $hidden_patient_code=$TypeCode;
371 $_REQUEST['hidden_patient_code']=$hidden_patient_code;
372 $_REQUEST['RadioPaid']='Show_Paid';
374 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
376 </td>
377 </tr>
378 <tr>
379 <td colspan="13" align="left" >
380 <?php
381 if($CountIndexBelow>0)
384 <table border="0" cellspacing="0" cellpadding="0" width="267" align="center" id="AllocateButtons">
385 <tr height="5">
386 <td ></td>
387 <td ></td>
388 <td></td>
389 </tr>
390 <tr>
391 <td width="100"><a href="#" onClick="javascript:return PostPayments();" class="css_button"><span><?php echo htmlspecialchars( xl('Post Payments'), ENT_QUOTES);?></span></a></td>
392 <td width="107"><a href="#" onClick="javascript:return FinishPayments();" class="css_button"><span><?php echo htmlspecialchars( xl('Finish Payments'), ENT_QUOTES);?></span></a></td>
393 <td width="60"><a href="#" onClick="CancelDistribute()" class="css_button"><span><?php echo htmlspecialchars( xl('Cancel'), ENT_QUOTES);?></span></a></td>
394 </tr>
395 </table>
396 <?php
397 }//if($CountIndexBelow>0)
399 <?php
401 ?> </td>
402 </tr>
403 </table>
404 </td></tr></table>
405 <input type="hidden" name="hidden_patient_code" id="hidden_patient_code" value="<?php echo htmlspecialchars($hidden_patient_code);?>"/>
406 <input type='hidden' name='mode' id='mode' value='' />
407 <input type='hidden' name='default_search_patient' id='default_search_patient' value='<?php echo $default_search_patient ?>' />
408 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
409 <input type="hidden" name="after_value" id="after_value" value="<?php echo htmlspecialchars($mode);?>"/>
410 <input type="hidden" name="payment_id" id="payment_id" value="<?php echo htmlspecialchars($payment_id);?>"/>
411 <input type="hidden" name="hidden_type_code" id="hidden_type_code" value="<?php echo htmlspecialchars($hidden_type_code);?>"/>
412 <input type='hidden' name='global_amount' id='global_amount' value='' />
413 </form>
414 </body>
415 </html>