Some more PHP Notice Fixes
[openemr.git] / interface / billing / new_payment.php
blob89cd8311e3aef4922787c7729f66438ac405f30f
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/sql.inc");
34 require_once("$srcdir/auth.inc");
35 require_once("$srcdir/formdata.inc.php");
36 require_once("../../custom/code_types.inc.php");
37 require_once("$srcdir/patient.inc");
38 require_once("$srcdir/billrep.inc");
39 require_once(dirname(__FILE__) . "/../../library/classes/OFX.class.php");
40 require_once(dirname(__FILE__) . "/../../library/classes/X12Partner.class.php");
41 require_once("$srcdir/options.inc.php");
42 require_once("$srcdir/formatting.inc.php");
43 require_once("$srcdir/payment.inc.php");
44 //===============================================================================
45 $screen='new_payment';
46 //===============================================================================
47 // Initialisations
48 $mode = isset($_POST['mode']) ? $_POST['mode'] : '';
49 $payment_id = isset($_REQUEST['payment_id']) ? $_REQUEST['payment_id'] : '';
50 $request_payment_id = $payment_id ;
51 $hidden_patient_code = isset($_REQUEST['hidden_patient_code']) ? $_REQUEST['hidden_patient_code'] : '';
52 $default_search_patient = isset($_POST['default_search_patient']) ? $_POST['default_search_patient'] : '';
53 $hidden_type_code = formData('hidden_type_code', true );
54 //===============================================================================
55 //ar_session addition code
56 //===============================================================================
58 if ($mode == "new_payment" || $mode == "distribute")
60 if(trim(formData('type_name' ))=='insurance')
62 $QueryPart="payer_id = '$hidden_type_code', patient_id = '0" ; // Closing Quote in idSqlStatement below
64 elseif(trim(formData('type_name' ))=='patient')
66 $QueryPart="payer_id = '0', patient_id = '$hidden_type_code" ; // Closing Quote in idSqlStatement below
68 $user_id=$_SESSION['authUserID'];
69 $closed=0;
70 $modified_time = date('Y-m-d H:i:s');
71 $check_date=DateToYYYYMMDD(formData('check_date'));
72 $deposit_date=DateToYYYYMMDD(formData('deposit_date'));
73 $post_to_date=DateToYYYYMMDD(formData('post_to_date'));
74 if($post_to_date=='')
75 $post_to_date=date('Y-m-d');
76 if(formData('deposit_date')=='')
77 $deposit_date=$post_to_date;
78 $payment_id = idSqlStatement("insert into ar_session set " .
79 $QueryPart .
80 "', user_id = '" . trim($user_id ) .
81 "', closed = '" . trim($closed ) .
82 "', reference = '" . trim(formData('check_number' )) .
83 "', check_date = '" . trim($check_date ) .
84 "', deposit_date = '" . trim($deposit_date ) .
85 "', pay_total = '" . trim(formData('payment_amount')) .
86 "', modified_time = '" . trim($modified_time ) .
87 "', payment_type = '" . trim(formData('type_name' )) .
88 "', description = '" . trim(formData('description' )) .
89 "', adjustment_code = '" . trim(formData('adjustment_code' )) .
90 "', post_to_date = '" . trim($post_to_date ) .
91 "', payment_method = '" . trim(formData('payment_method' )) .
92 "'");
95 //===============================================================================
96 //ar_activity addition code
97 //===============================================================================
98 if ($mode == "PostPayments" || $mode == "FinishPayments")
100 // $hidden_patient_code=$_REQUEST['hidden_patient_code'];
101 // $payment_id=$_REQUEST['payment_id'];
102 $user_id=$_SESSION['authUserID'];
103 $created_time = date('Y-m-d H:i:s');
104 for($CountRow=1;;$CountRow++)
106 if (isset($_POST["HiddenEncounter$CountRow"]))
108 DistributionInsert($CountRow,$created_time,$user_id);
110 else
111 break;
113 if($_REQUEST['global_amount']=='yes')
114 sqlStatement("update ar_session set global_amount=".trim(formData("HidUnappliedAmount" ))*1 ." where session_id ='$payment_id'");
115 if($mode=="FinishPayments")
117 header("Location: edit_payment.php?payment_id=$payment_id&ParentPage=new_payment");
118 die();
120 $mode = "search";
121 $_POST['mode'] = $mode;
124 //==============================================================================
125 //===============================================================================
126 $payment_id=$payment_id*1 > 0 ? $payment_id : $request_payment_id;
127 //===============================================================================
128 $DateFormat=DateFormatRead();
129 //==============================================================================
130 //===============================================================================
132 <html>
133 <head>
134 <?php if (function_exists('html_header_show')) html_header_show(); ?>
136 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
137 <script type="text/javascript" src="../../library/dialog.js"></script>
138 <script type="text/javascript" src="../../library/textformat.js"></script>
139 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
140 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
141 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
142 <script language='JavaScript'>
143 var mypcc = '1';
144 </script>
145 <?php include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?>
146 <script type="text/JavaScript" src="../../library/js/jquery121.js"></script>
147 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
148 <script type="text/javascript" src="../../library/js/common.js"></script>
149 <script LANGUAGE="javascript" TYPE="text/javascript">
150 function CancelDistribute()
151 {//Used in the cancel button.Helpful while cancelling the distribution.
152 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Cancel Distribution for this Patient?'), ENT_QUOTES) ?>"))
154 document.getElementById('hidden_patient_code').value='';
155 document.getElementById('mode').value='search';
156 top.restoreSession();
157 document.forms[0].submit();
159 else
160 return false;
162 function PostPayments()
163 {//Used in saving the allocation
164 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
166 alert("<?php echo htmlspecialchars( xl('Fill the Row.'), ENT_QUOTES) ?>")
167 return false;
169 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
171 return false;
173 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
174 if(PostValue==1)
176 alert("<?php echo htmlspecialchars( xl('Cannot Post Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
177 return false;
179 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Post Payments?'), ENT_QUOTES) ?>"))
181 document.getElementById('mode').value='PostPayments';
182 top.restoreSession();
183 document.forms[0].submit();
185 else
186 return false;
188 function FinishPayments()
189 {//Used in finishig the allocation.Usually done when the amount gets reduced to zero.
190 //After this is pressed a confirmation screen comes,where you can edit if needed.
191 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
193 alert("<?php echo htmlspecialchars( xl('Fill the Row.'), ENT_QUOTES) ?>")
194 return false;
196 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
198 return false;
200 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
201 if(PostValue==1)
203 alert("<?php echo htmlspecialchars( xl('Cannot Post Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
204 return false;
206 if(PostValue==2)
208 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Post and Finish Payments?'), ENT_QUOTES) ?>"))
210 UnappliedAmount=document.getElementById('TdUnappliedAmount').innerHTML*1;
211 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) ?>"))
213 document.getElementById('mode').value='FinishPayments';
214 document.getElementById('global_amount').value='yes';
215 top.restoreSession();
216 document.forms[0].submit();
218 else
220 document.getElementById('mode').value='FinishPayments';
221 top.restoreSession();
222 document.forms[0].submit();
225 else
226 return false;
228 else
230 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Post and Finish Payments?'), ENT_QUOTES) ?>"))
232 document.getElementById('mode').value='FinishPayments';
233 top.restoreSession();
234 document.forms[0].submit();
236 else
237 return false;
241 function CompletlyBlank()
242 {//Checks whether any of the allocation row is filled.
243 for(RowCount=1;;RowCount++)
245 if(!document.getElementById('Payment'+RowCount))
246 break;
247 else
249 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)
253 else
254 return false;
257 return true;
259 function OnloadAction()
260 {//Displays message after saving to master table.
261 after_value=document.getElementById("after_value").value;
262 payment_id=document.getElementById('payment_id').value;
263 if(after_value=='distribute')
266 else if(after_value=='new_payment')
268 if(document.getElementById('TablePatientPortion'))
270 document.getElementById('TablePatientPortion').style.display='none';
272 if(confirm("<?php echo htmlspecialchars( xl('Successfully Saved.Would you like to Allocate?'), ENT_QUOTES) ?>"))
274 if(document.getElementById('TablePatientPortion'))
276 document.getElementById('TablePatientPortion').style.display='';
282 function ResetForm()
283 {//Resets form used in the 'Cancel Changes' button in the master screen.
284 document.forms[0].reset();
285 document.getElementById('TdUnappliedAmount').innerHTML='0.00';
286 document.getElementById('div_insurance_or_patient').innerHTML='&nbsp;';
287 CheckVisible('yes');//Payment Method is made 'Check Payment' and the Check box is made visible.
288 PayingEntityAction();//Paying Entity is made 'insurance' and Payment Category is 'Insurance Payment'
290 function FillUnappliedAmount()
291 {//Filling the amount
292 document.getElementById('TdUnappliedAmount').innerHTML=document.getElementById('payment_amount').value;
294 </script>
295 <script language="javascript" type="text/javascript">
296 document.onclick=HideTheAjaxDivs;
297 </script>
298 <style>
299 .class1{width:125px;}
300 .class2{width:250px;}
301 .bottom{border-bottom:1px solid black;}
302 .top{border-top:1px solid black;}
303 .left{border-left:1px solid black;}
304 .right{border-right:1px solid black;}
305 #ajax_div_insurance {
306 position: absolute;
307 z-index:10;
308 background-color: #FBFDD0;
309 border: 1px solid #ccc;
310 padding: 10px;
312 #ajax_div_patient {
313 position: absolute;
314 z-index:10;
315 background-color: #FBFDD0;
316 border: 1px solid #ccc;
317 padding: 10px;
319 </style>
320 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
321 </head>
322 <body class="body_top" onLoad="OnloadAction()" >
323 <form name='new_payment' method='post' action="new_payment.php" onsubmit='
324 <?php
325 if($payment_id*1==0)
328 top.restoreSession();return SavePayment();
329 <?php
331 else
334 return false;
335 <?php
338 ' style="display:inline" >
339 <table width="100%" border="0" cellspacing="0" cellpadding="0">
340 <tr>
341 <td colspan="3" align="left"><b><?php echo htmlspecialchars( xl('Payments'), ENT_QUOTES) ?></b></td>
342 </tr>
343 <tr height="15">
344 <td colspan="3" align="left" ></td>
345 </tr>
346 <tr>
347 <td colspan="3" align="left">
348 <ul class="tabNav">
349 <li class='current'><a href='new_payment.php'><?php echo htmlspecialchars( xl('New Payment'), ENT_QUOTES) ?></a></li>
350 <li><a href='search_payments.php'><?php echo htmlspecialchars( xl('Search Payment'), ENT_QUOTES) ?></a></li>
351 <li><a href='era_payments.php'><?php echo htmlspecialchars( xl('ERA Posting'), ENT_QUOTES) ?></a></li>
352 </ul> </td>
353 </tr>
354 <tr>
355 <td colspan="3" align="left" >
356 <?php
357 require_once("payment_master.inc.php"); //Check/cash details are entered here.
359 </td>
360 </tr>
361 </table>
362 <?php
363 if($payment_id*1>0)
366 <table width="999" border="0" cellspacing="0" cellpadding="10" bgcolor="#DEDEDE"><tr><td>
367 <table width="979" border="0" cellspacing="0" cellpadding="0">
368 <tr>
369 <td colspan="13" align="left" >
370 <!--Distribute section-->
371 <?php
372 if($PaymentType=='patient' && $default_search_patient != "default_search_patient")
374 $default_search_patient = "default_search_patient";
375 $_POST['default_search_patient'] = $default_search_patient;
376 $hidden_patient_code=$TypeCode;
377 $_REQUEST['hidden_patient_code']=$hidden_patient_code;
378 $_REQUEST['RadioPaid']='Show_Paid';
380 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
382 </td>
383 </tr>
384 <tr>
385 <td colspan="13" align="left" >
386 <?php
387 if($CountIndexBelow>0)
390 <table border="0" cellspacing="0" cellpadding="0" width="267" align="center" id="AllocateButtons">
391 <tr height="5">
392 <td ></td>
393 <td ></td>
394 <td></td>
395 </tr>
396 <tr>
397 <td width="100"><a href="#" onClick="javascript:return PostPayments();" class="css_button"><span><?php echo htmlspecialchars( xl('Post Payments'), ENT_QUOTES);?></span></a></td>
398 <td width="107"><a href="#" onClick="javascript:return FinishPayments();" class="css_button"><span><?php echo htmlspecialchars( xl('Finish Payments'), ENT_QUOTES);?></span></a></td>
399 <td width="60"><a href="#" onClick="CancelDistribute()" class="css_button"><span><?php echo htmlspecialchars( xl('Cancel'), ENT_QUOTES);?></span></a></td>
400 </tr>
401 </table>
402 <?php
403 }//if($CountIndexBelow>0)
405 <?php
407 ?> </td>
408 </tr>
409 </table>
410 </td></tr></table>
411 <input type="hidden" name="hidden_patient_code" id="hidden_patient_code" value="<?php echo htmlspecialchars($hidden_patient_code);?>"/>
412 <input type='hidden' name='mode' id='mode' value='' />
413 <input type='hidden' name='default_search_patient' id='default_search_patient' value='<?php echo $default_search_patient ?>' />
414 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
415 <input type="hidden" name="after_value" id="after_value" value="<?php echo htmlspecialchars($mode);?>"/>
416 <input type="hidden" name="payment_id" id="payment_id" value="<?php echo htmlspecialchars($payment_id);?>"/>
417 <input type="hidden" name="hidden_type_code" id="hidden_type_code" value="<?php echo htmlspecialchars($hidden_type_code);?>"/>
418 <input type='hidden' name='global_amount' id='global_amount' value='' />
419 </form>
420 </body>
421 </html>