Convert initial license block to something more like the documentation standard.
[openemr.git] / interface / billing / new_payment.php
blobfc3bedd6b8b887812ce44ad7fccb1e488f576655
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 //ar_session addition code
48 //===============================================================================
49 if (isset($_POST["mode"]))
51 if ($_POST["mode"] == "new_payment" || $_POST["mode"] == "distribute")
53 if(trim(formData('type_name' ))=='insurance')
55 $QueryPart="payer_id = '" . trim(formData('hidden_type_code' )) .
56 "', patient_id = '" . 0 ;
58 elseif(trim(formData('type_name' ))=='patient')
60 $QueryPart="payer_id = '" . 0 .
61 "', patient_id = '" . trim(formData('hidden_type_code' )) ;
63 $user_id=$_SESSION['authUserID'];
64 $closed=0;
65 $modified_time = date('Y-m-d H:i:s');
66 $check_date=DateToYYYYMMDD(formData('check_date'));
67 $deposit_date=DateToYYYYMMDD(formData('deposit_date'));
68 $post_to_date=DateToYYYYMMDD(formData('post_to_date'));
69 if($post_to_date=='')
70 $post_to_date=date('Y-m-d');
71 if(formData('deposit_date')=='')
72 $deposit_date=$post_to_date;
73 $payment_id = idSqlStatement("insert into ar_session set " .
74 $QueryPart .
75 "', user_id = '" . trim($user_id ) .
76 "', closed = '" . trim($closed ) .
77 "', reference = '" . trim(formData('check_number' )) .
78 "', check_date = '" . trim($check_date ) .
79 "', deposit_date = '" . trim($deposit_date ) .
80 "', pay_total = '" . trim(formData('payment_amount')) .
81 "', modified_time = '" . trim($modified_time ) .
82 "', payment_type = '" . trim(formData('type_name' )) .
83 "', description = '" . trim(formData('description' )) .
84 "', adjustment_code = '" . trim(formData('adjustment_code' )) .
85 "', post_to_date = '" . trim($post_to_date ) .
86 "', payment_method = '" . trim(formData('payment_method' )) .
87 "'");
90 //===============================================================================
91 //ar_activity addition code
92 //===============================================================================
93 if (isset($_POST["mode"]))
95 if ($_POST["mode"] == "PostPayments" || $_POST["mode"] == "FinishPayments")
97 $hidden_patient_code=$_REQUEST['hidden_patient_code'];
98 $payment_id=$_REQUEST['payment_id'];
99 $user_id=$_SESSION['authUserID'];
100 $created_time = date('Y-m-d H:i:s');
101 for($CountRow=1;;$CountRow++)
103 if (isset($_POST["HiddenEncounter$CountRow"]))
105 DistributionInsert($CountRow,$created_time,$user_id);
107 else
108 break;
110 if($_REQUEST['global_amount']=='yes')
111 sqlStatement("update ar_session set global_amount=".trim(formData("HidUnappliedAmount" ))*1 ." where session_id ='$payment_id'");
112 if($_POST["mode"]=="FinishPayments")
114 header("Location: edit_payment.php?payment_id=$payment_id&ParentPage=new_payment");
115 die();
117 $_POST["mode"] = "search";
120 //==============================================================================
121 //===============================================================================
122 $payment_id=$payment_id*1 > 0 ? $payment_id : $_REQUEST['payment_id'];
123 //===============================================================================
124 $DateFormat=DateFormatRead();
125 //==============================================================================
126 //===============================================================================
128 <html>
129 <head>
130 <?php if (function_exists('html_header_show')) html_header_show(); ?>
132 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
133 <script type="text/javascript" src="../../library/dialog.js"></script>
134 <script type="text/javascript" src="../../library/textformat.js"></script>
135 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
136 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
137 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
138 <script language='JavaScript'>
139 var mypcc = '1';
140 </script>
141 <?php include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?>
142 <script type="text/JavaScript" src="../../library/js/jquery121.js"></script>
143 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
144 <script type="text/javascript" src="../../library/js/common.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;
290 </script>
291 <script language="javascript" type="text/javascript">
292 document.onclick=HideTheAjaxDivs;
293 </script>
294 <style>
295 .class1{width:125px;}
296 .class2{width:250px;}
297 .bottom{border-bottom:1px solid black;}
298 .top{border-top:1px solid black;}
299 .left{border-left:1px solid black;}
300 .right{border-right:1px solid black;}
301 #ajax_div_insurance {
302 position: absolute;
303 z-index:10;
304 background-color: #FBFDD0;
305 border: 1px solid #ccc;
306 padding: 10px;
308 #ajax_div_patient {
309 position: absolute;
310 z-index:10;
311 background-color: #FBFDD0;
312 border: 1px solid #ccc;
313 padding: 10px;
315 </style>
316 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
317 </head>
318 <body class="body_top" onLoad="OnloadAction()" >
319 <form name='new_payment' method='post' action="new_payment.php" onsubmit='
320 <?php
321 if($payment_id*1==0)
324 top.restoreSession();return SavePayment();
325 <?php
327 else
330 return false;
331 <?php
334 ' style="display:inline" >
335 <table width="100%" border="0" cellspacing="0" cellpadding="0">
336 <tr>
337 <td colspan="3" align="left"><b><?php echo htmlspecialchars( xl('Payments'), ENT_QUOTES) ?></b></td>
338 </tr>
339 <tr height="15">
340 <td colspan="3" align="left" ></td>
341 </tr>
342 <tr>
343 <td colspan="3" align="left">
344 <ul class="tabNav">
345 <li class='current'><a href='new_payment.php'><?php echo htmlspecialchars( xl('New Payment'), ENT_QUOTES) ?></a></li>
346 <li><a href='search_payments.php'><?php echo htmlspecialchars( xl('Search Payment'), ENT_QUOTES) ?></a></li>
347 <li><a href='era_payments.php'><?php echo htmlspecialchars( xl('ERA Posting'), ENT_QUOTES) ?></a></li>
348 </ul> </td>
349 </tr>
350 <tr>
351 <td colspan="3" align="left" >
352 <?php
353 require_once("payment_master.inc.php"); //Check/cash details are entered here.
355 </td>
356 </tr>
357 </table>
358 <?php
359 if($payment_id*1>0)
362 <table width="999" border="0" cellspacing="0" cellpadding="10" bgcolor="#DEDEDE"><tr><td>
363 <table width="979" border="0" cellspacing="0" cellpadding="0">
364 <tr>
365 <td colspan="13" align="left" >
366 <!--Distribute section-->
367 <?php
368 if($PaymentType=='patient' && $_POST["default_search_patient"] != "default_search_patient")
370 $_POST["default_search_patient"] = "default_search_patient";
371 $_REQUEST['hidden_patient_code']=$TypeCode;
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 $_POST["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($_POST["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(formData('hidden_type_code'));?>"/>
412 <input type='hidden' name='global_amount' id='global_amount' value='' />
413 </form>
414 </body>
415 </html>