acknowledgments update
[openemr.git] / interface / billing / new_payment.php
blob0849dc34e808b0058751edb8e743c40ae5f7d03c
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 $user_id=$_SESSION['authUserID'];
101 $created_time = date('Y-m-d H:i:s');
102 for($CountRow=1;;$CountRow++)
104 if (isset($_POST["HiddenEncounter$CountRow"]))
106 DistributionInsert($CountRow,$created_time,$user_id);
108 else
109 break;
111 if($_REQUEST['global_amount']=='yes')
112 sqlStatement("update ar_session set global_amount=".trim(formData("HidUnappliedAmount" ))*1 ." where session_id ='$payment_id'");
113 if($mode=="FinishPayments")
115 header("Location: edit_payment.php?payment_id=$payment_id&ParentPage=new_payment");
116 die();
118 $mode = "search";
119 $_POST['mode'] = $mode;
122 //==============================================================================
123 //===============================================================================
124 $payment_id=$payment_id*1 > 0 ? $payment_id : $request_payment_id;
125 //===============================================================================
126 $DateFormat=DateFormatRead();
127 //==============================================================================
128 //===============================================================================
130 <html>
131 <head>
132 <?php if (function_exists('html_header_show')) html_header_show(); ?>
134 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
135 <script type="text/javascript" src="../../library/dialog.js"></script>
136 <script type="text/javascript" src="../../library/textformat.js"></script>
137 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
138 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
139 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
140 <script language='JavaScript'>
141 var mypcc = '1';
142 </script>
143 <?php include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?>
144 <script type="text/JavaScript" src="../../library/js/jquery121.js"></script>
145 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
146 <script type="text/javascript" src="../../library/js/common.js"></script>
147 <script LANGUAGE="javascript" TYPE="text/javascript">
148 function CancelDistribute()
149 {//Used in the cancel button.Helpful while cancelling the distribution.
150 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Cancel Distribution for this Patient?'), ENT_QUOTES) ?>"))
152 document.getElementById('hidden_patient_code').value='';
153 document.getElementById('mode').value='search';
154 top.restoreSession();
155 document.forms[0].submit();
157 else
158 return false;
160 function PostPayments()
161 {//Used in saving the allocation
162 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
164 alert("<?php echo htmlspecialchars( xl('Fill the Row.'), ENT_QUOTES) ?>")
165 return false;
167 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
169 return false;
171 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
172 if(PostValue==1)
174 alert("<?php echo htmlspecialchars( xl('Cannot Post Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
175 return false;
177 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Post Payments?'), ENT_QUOTES) ?>"))
179 document.getElementById('mode').value='PostPayments';
180 top.restoreSession();
181 document.forms[0].submit();
183 else
184 return false;
186 function FinishPayments()
187 {//Used in finishig the allocation.Usually done when the amount gets reduced to zero.
188 //After this is pressed a confirmation screen comes,where you can edit if needed.
189 if(CompletlyBlank())//Checks whether any of the allocation row is filled.
191 alert("<?php echo htmlspecialchars( xl('Fill the Row.'), ENT_QUOTES) ?>")
192 return false;
194 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
196 return false;
198 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
199 if(PostValue==1)
201 alert("<?php echo htmlspecialchars( xl('Cannot Post Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
202 return false;
204 if(PostValue==2)
206 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Post and Finish Payments?'), ENT_QUOTES) ?>"))
208 UnappliedAmount=document.getElementById('TdUnappliedAmount').innerHTML*1;
209 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) ?>"))
211 document.getElementById('mode').value='FinishPayments';
212 document.getElementById('global_amount').value='yes';
213 top.restoreSession();
214 document.forms[0].submit();
216 else
218 document.getElementById('mode').value='FinishPayments';
219 top.restoreSession();
220 document.forms[0].submit();
223 else
224 return false;
226 else
228 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Post and Finish Payments?'), ENT_QUOTES) ?>"))
230 document.getElementById('mode').value='FinishPayments';
231 top.restoreSession();
232 document.forms[0].submit();
234 else
235 return false;
239 function CompletlyBlank()
240 {//Checks whether any of the allocation row is filled.
241 for(RowCount=1;;RowCount++)
243 if(!document.getElementById('Payment'+RowCount))
244 break;
245 else
247 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)
251 else
252 return false;
255 return true;
257 function OnloadAction()
258 {//Displays message after saving to master table.
259 after_value=document.getElementById("after_value").value;
260 payment_id=document.getElementById('payment_id').value;
261 if(after_value=='distribute')
264 else if(after_value=='new_payment')
266 if(document.getElementById('TablePatientPortion'))
268 document.getElementById('TablePatientPortion').style.display='none';
270 if(confirm("<?php echo htmlspecialchars( xl('Successfully Saved.Would you like to Allocate?'), ENT_QUOTES) ?>"))
272 if(document.getElementById('TablePatientPortion'))
274 document.getElementById('TablePatientPortion').style.display='';
280 function ResetForm()
281 {//Resets form used in the 'Cancel Changes' button in the master screen.
282 document.forms[0].reset();
283 document.getElementById('TdUnappliedAmount').innerHTML='0.00';
284 document.getElementById('div_insurance_or_patient').innerHTML='&nbsp;';
285 CheckVisible('yes');//Payment Method is made 'Check Payment' and the Check box is made visible.
286 PayingEntityAction();//Paying Entity is made 'insurance' and Payment Category is 'Insurance Payment'
288 function FillUnappliedAmount()
289 {//Filling the amount
290 document.getElementById('TdUnappliedAmount').innerHTML=document.getElementById('payment_amount').value;
292 </script>
293 <script language="javascript" type="text/javascript">
294 document.onclick=HideTheAjaxDivs;
295 </script>
296 <style>
297 .class1{width:125px;}
298 .class2{width:250px;}
299 .bottom{border-bottom:1px solid black;}
300 .top{border-top:1px solid black;}
301 .left{border-left:1px solid black;}
302 .right{border-right:1px solid black;}
303 #ajax_div_insurance {
304 position: absolute;
305 z-index:10;
306 background-color: #FBFDD0;
307 border: 1px solid #ccc;
308 padding: 10px;
310 #ajax_div_patient {
311 position: absolute;
312 z-index:10;
313 background-color: #FBFDD0;
314 border: 1px solid #ccc;
315 padding: 10px;
317 </style>
318 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
319 </head>
320 <body class="body_top" onLoad="OnloadAction()" >
321 <form name='new_payment' method='post' action="new_payment.php" onsubmit='
322 <?php
323 if($payment_id*1==0)
326 top.restoreSession();return SavePayment();
327 <?php
329 else
332 return false;
333 <?php
336 ' style="display:inline" >
337 <table width="100%" border="0" cellspacing="0" cellpadding="0">
338 <tr>
339 <td colspan="3" align="left"><b><?php echo htmlspecialchars( xl('Payments'), ENT_QUOTES) ?></b></td>
340 </tr>
341 <tr height="15">
342 <td colspan="3" align="left" ></td>
343 </tr>
344 <tr>
345 <td colspan="3" align="left">
346 <ul class="tabNav">
347 <li class='current'><a href='new_payment.php'><?php echo htmlspecialchars( xl('New Payment'), ENT_QUOTES) ?></a></li>
348 <li><a href='search_payments.php'><?php echo htmlspecialchars( xl('Search Payment'), ENT_QUOTES) ?></a></li>
349 <li><a href='era_payments.php'><?php echo htmlspecialchars( xl('ERA Posting'), ENT_QUOTES) ?></a></li>
350 </ul> </td>
351 </tr>
352 <tr>
353 <td colspan="3" align="left" >
354 <?php
355 require_once("payment_master.inc.php"); //Check/cash details are entered here.
357 </td>
358 </tr>
359 </table>
360 <?php
361 if($payment_id*1>0)
364 <table width="999" border="0" cellspacing="0" cellpadding="10" bgcolor="#DEDEDE"><tr><td>
365 <table width="979" border="0" cellspacing="0" cellpadding="0">
366 <tr>
367 <td colspan="13" align="left" >
368 <!--Distribute section-->
369 <?php
370 if($PaymentType=='patient' && $default_search_patient != "default_search_patient")
372 $default_search_patient = "default_search_patient";
373 $_POST['default_search_patient'] = $default_search_patient;
374 $hidden_patient_code=$TypeCode;
375 $_REQUEST['hidden_patient_code']=$hidden_patient_code;
376 $_REQUEST['RadioPaid']='Show_Paid';
378 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
380 </td>
381 </tr>
382 <tr>
383 <td colspan="13" align="left" >
384 <?php
385 if($CountIndexBelow>0)
388 <table border="0" cellspacing="0" cellpadding="0" width="267" align="center" id="AllocateButtons">
389 <tr height="5">
390 <td ></td>
391 <td ></td>
392 <td></td>
393 </tr>
394 <tr>
395 <td width="100"><a href="#" onClick="javascript:return PostPayments();" class="css_button"><span><?php echo htmlspecialchars( xl('Post Payments'), ENT_QUOTES);?></span></a></td>
396 <td width="107"><a href="#" onClick="javascript:return FinishPayments();" class="css_button"><span><?php echo htmlspecialchars( xl('Finish Payments'), ENT_QUOTES);?></span></a></td>
397 <td width="60"><a href="#" onClick="CancelDistribute()" class="css_button"><span><?php echo htmlspecialchars( xl('Cancel'), ENT_QUOTES);?></span></a></td>
398 </tr>
399 </table>
400 <?php
401 }//if($CountIndexBelow>0)
403 <?php
405 ?> </td>
406 </tr>
407 </table>
408 </td></tr></table>
409 <input type="hidden" name="hidden_patient_code" id="hidden_patient_code" value="<?php echo htmlspecialchars($hidden_patient_code);?>"/>
410 <input type='hidden' name='mode' id='mode' value='' />
411 <input type='hidden' name='default_search_patient' id='default_search_patient' value='<?php echo $default_search_patient ?>' />
412 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
413 <input type="hidden" name="after_value" id="after_value" value="<?php echo htmlspecialchars($mode);?>"/>
414 <input type="hidden" name="payment_id" id="payment_id" value="<?php echo htmlspecialchars($payment_id);?>"/>
415 <input type="hidden" name="hidden_type_code" id="hidden_type_code" value="<?php echo htmlspecialchars($hidden_type_code);?>"/>
416 <input type='hidden' name='global_amount' id='global_amount' value='' />
417 </form>
418 </body>
419 </html>