migrated dragdrop upload.php to library/ajax
[openemr.git] / library / payment_jav.inc.php
blobe3ae349cc66eaf90b3a65f312fe1a8c288575e88
1 <?php
2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2010 Z&H Consultancy Services Private Limited <sam@zhservices.com>
4 //
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 //
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Paul Simon K <paul@zhservices.com>
26 // +------------------------------------------------------------------------------+
27 //===============================================================================
28 //This section handles payment related javascript functios.Add, Search and Edit screen uses these functions.
29 //===============================================================================
31 <script type="text/javascript">
32 function CheckVisible(MakeBlank)
33 {//Displays and hides the check number text box.Add and edit page uses the same function.
34 //In edit its value should not be lost on just a change.It is controlled be the 'MakeBlank' argument.
35 if(document.getElementById('payment_method').options[document.getElementById('payment_method').selectedIndex].value=='check_payment' ||
36 document.getElementById('payment_method').options[document.getElementById('payment_method').selectedIndex].value=='bank_draft' )
38 document.getElementById('div_check_number').style.display='none';
39 document.getElementById('check_number').style.display='';
41 else
43 document.getElementById('div_check_number').style.display='';
44 if(MakeBlank=='yes')
45 {//In Add page clearing the field is done.
46 document.getElementById('check_number').value='';
48 document.getElementById('check_number').style.display='none';
51 function PayingEntityAction()
53 //Which ajax is to be active(patient,insurance), is decided by the 'Paying Entity' drop down, where this function is called.
54 //So on changing some initialization is need.Done below.
55 document.getElementById('type_code').value='';
56 document.getElementById('hidden_ajax_close_value').value='';
57 document.getElementById('hidden_type_code').value='';
58 document.getElementById('div_insurance_or_patient').innerHTML='&nbsp;';
59 document.getElementById('description').value='';
60 if(document.getElementById('ajax_div_insurance'))
62 $("#ajax_div_patient_error").empty();
63 $("#ajax_div_patient").empty();
64 $("#ajax_div_insurance_error").empty();
65 $("#ajax_div_insurance").empty();
66 $("#ajax_div_insurance").hide();
67 document.getElementById('payment_method').style.display='';
69 //As per the selected value, one value is selected in the 'Payment Category' drop down.
70 if(document.getElementById('type_name').options[document.getElementById('type_name').selectedIndex].value=='patient')
72 document.getElementById('adjustment_code').value='patient_payment';
74 else if(document.getElementById('type_name').options[document.getElementById('type_name').selectedIndex].value=='insurance')
76 document.getElementById('adjustment_code').value='insurance_payment';
78 //As per the selected value, certain values are not selectable in the 'Payment Category' drop down.They are greyed out.
79 var list=document.getElementById('type_name');
80 var newValue = (list.options[list.selectedIndex].value);
81 if (newValue=='patient') {
82 if(document.getElementById('option_insurance_payment'))
83 document.getElementById('option_insurance_payment').style.backgroundColor='#DEDEDE';
84 if(document.getElementById('option_family_payment'))
85 document.getElementById('option_family_payment').style.backgroundColor='#ffffff';
86 if(document.getElementById('option_patient_payment'))
87 document.getElementById('option_patient_payment').style.backgroundColor='#ffffff';
89 if (newValue=='insurance') {
90 if(document.getElementById('option_family_payment'))
91 document.getElementById('option_family_payment').style.backgroundColor='#DEDEDE';
92 if(document.getElementById('option_patient_payment'))
93 document.getElementById('option_patient_payment').style.backgroundColor='#DEDEDE';
94 if(document.getElementById('option_insurance_payment'))
95 document.getElementById('option_insurance_payment').style.backgroundColor='#ffffff';
98 function FilterSelection(listSelected) {
99 //function PayingEntityAction() greyed out certain values as per the selection in the 'Paying Entity' drop down.
100 //When the same are selected in the 'Payment Category' drop down, this function reverts back to the old value.
101 if(document.getElementById('type_name').options[document.getElementById('type_name').selectedIndex].value=='patient')
103 ValueToPut='patient_payment';
105 else if(document.getElementById('type_name').options[document.getElementById('type_name').selectedIndex].value=='insurance')
107 ValueToPut='insurance_payment';
110 var newValueSelected = (listSelected.options[listSelected.selectedIndex].value);
112 var list=document.getElementById('type_name');
113 var newValue = (list.options[list.selectedIndex].value);
114 if (newValue=='patient') {
115 if(newValueSelected=='insurance_payment')
116 listSelected.value=ValueToPut;//Putting values back
118 if (newValue=='insurance') {
119 if(newValueSelected=='family_payment')
120 listSelected.value=ValueToPut;
121 if(newValueSelected=='patient_payment')
122 listSelected.value=ValueToPut;//Putting values back
125 function RestoreValues(CountIndex)
126 {//old remainder is restored back
127 if(document.getElementById('Allowed'+CountIndex).value*1==0 && document.getElementById('Payment'+CountIndex).value*1==0 && document.getElementById('AdjAmount'+CountIndex).value*1==0 && document.getElementById('Takeback'+CountIndex).value*1==0)
129 document.getElementById('RemainderTd'+CountIndex).innerHTML=document.getElementById('HiddenRemainderTd'+CountIndex).value*1
132 function ActionFollowUp(CountIndex)
133 {//Activating or deactivating the FollowUpReason text box.
134 if(document.getElementById('FollowUp'+CountIndex).checked)
136 document.getElementById('FollowUpReason'+CountIndex).readOnly=false;
137 document.getElementById('FollowUpReason'+CountIndex).value='';
139 else
141 document.getElementById('FollowUpReason'+CountIndex).value='';
142 document.getElementById('FollowUpReason'+CountIndex).readOnly=true;
145 function ValidateDateGreaterThanNow(DateValue,DateFormat)
146 {//Validate whether the date is greater than now.The 3 formats of date is taken care of.
147 if(DateFormat=='%Y-%m-%d')
149 DateValueArray=DateValue.split('-');
150 DateValue=DateValueArray[1]+'/'+DateValueArray[2]+'/'+DateValueArray[0];
152 else if(DateFormat=='%m/%d/%Y')
155 else if(DateFormat=='%d/%m/%Y')
157 DateValueArray=DateValue.split('/');
158 DateValue=DateValueArray[1]+'/'+DateValueArray[0]+'/'+DateValueArray[2];
160 PassedDate = new Date(DateValue);
161 Now = new Date();
162 if(PassedDate > Now)
163 return false;
164 else
165 return true;
167 function DateCheckGreater(DateValue1,DateValue2,DateFormat)
168 {//Checks which date is greater.The 3 formats of date is taken care of.
169 if(DateFormat=='%Y-%m-%d')
171 DateValueArray=DateValue1.split('-');
172 DateValue1=DateValueArray[1]+'/'+DateValueArray[2]+'/'+DateValueArray[0];
173 DateValueArray=DateValue2.split('-');
174 DateValue2=DateValueArray[1]+'/'+DateValueArray[2]+'/'+DateValueArray[0];
176 else if(DateFormat=='%m/%d/%Y')
179 else if(DateFormat=='%d/%m/%Y')
181 DateValueArray=DateValue1.split('/');
182 DateValue1=DateValueArray[1]+'/'+DateValueArray[0]+'/'+DateValueArray[2];
183 DateValueArray=DateValue2.split('/');
184 DateValue2=DateValueArray[1]+'/'+DateValueArray[0]+'/'+DateValueArray[2];
186 PassedDateValue1 = new Date(DateValue1);
187 PassedDateValue2 = new Date(DateValue2);
188 if(PassedDateValue1 <= PassedDateValue2)
189 return true;
190 else
191 return false;
193 function ConvertToUpperCase(ObjectPassed)
194 {//Convert To Upper Case.Example:- onKeyUp="ConvertToUpperCase(this)".
195 ObjectPassed.value=ObjectPassed.value.toUpperCase();
197 //--------------------------------
198 function SearchOnceMore()
199 {//Used in the option buttons,listing the charges.
200 //'Non Paid', 'Show Primary Complete', 'Show All Transactions' uses this when a patient is selected through ajax.
201 if(document.getElementById('hidden_patient_code').value*1>0)
203 document.getElementById('mode').value='search';
204 top.restoreSession();
205 document.forms[0].submit();
207 else
209 alert("<?php echo htmlspecialchars( xl('Please Select a Patient.'), ENT_QUOTES) ?>")
212 function CheckUnappliedAmount()
213 {//The value retured from here decides whether Payments can be posted/modified or not.
214 UnappliedAmount=document.getElementById('TdUnappliedAmount').innerHTML*1;
215 if(UnappliedAmount<0)
217 return 1;
219 else if(UnappliedAmount>0)
221 return 2;
223 else
225 return 3;
228 function ValidateNumeric(TheObject)
229 {//Numeric validations, used while typing numbers.
230 if(TheObject.value!=TheObject.value*1)
232 alert("<?php echo htmlspecialchars( xl('Value Should be Numeric'), ENT_QUOTES) ?>");
233 TheObject.focus();
234 return false;
237 function SavePayment()
238 {//Used before saving.
239 if(FormValidations())//FormValidations contains the form checks
241 if(confirm("<?php echo htmlspecialchars( xl('Would you like to save?'), ENT_QUOTES) ?>"))
243 top.restoreSession();
244 document.getElementById('mode').value='new_payment';
245 document.forms[0].submit();
247 else
248 return false;
250 else
251 return false;
253 function OpenEOBEntry()
254 {//Used before allocating the recieved amount.
255 if(FormValidations())//FormValidations contains the form checks
257 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Allocate?'), ENT_QUOTES) ?>"))
259 top.restoreSession();
260 document.getElementById('mode').value='distribute';
261 document.forms[0].submit();
263 else
264 return false;
266 else
267 return false;
269 function ScreenAdjustment(PassedObject,CountIndex)
270 {//Called when there is change in the amount by typing.
271 //Readjusts the various values.Another function FillAmount() is also used.
272 //Ins1 case and allowed is filled means it is primary's first payment.
273 //It moves to secondary or patient balance.
274 //If primary again pays means ==>change Post For to Ins1 and do not enter any value in the allowed box.
275 Allowed=document.getElementById('Allowed'+CountIndex).value*1;
276 if(document.getElementById('Allowed'+CountIndex).id==PassedObject.id)
278 document.getElementById('Payment'+CountIndex).value=Allowed;
280 Payment=document.getElementById('Payment'+CountIndex).value*1;
281 ChargeAmount=document.getElementById('HiddenChargeAmount'+CountIndex).value*1;
282 Remainder=document.getElementById('HiddenRemainderTd'+CountIndex).value*1;
283 if(document.getElementById('Allowed'+CountIndex).id==PassedObject.id)
285 if(document.getElementById('HiddenIns'+CountIndex).value==1)
287 document.getElementById('AdjAmount'+CountIndex).value=Math.round((ChargeAmount-Allowed)*100)/100;
289 else
291 document.getElementById('AdjAmount'+CountIndex).value=Math.round((Remainder-Allowed)*100)/100;
294 AdjustmentAmount=document.getElementById('AdjAmount'+CountIndex).value*1;
295 CopayAmount=document.getElementById('HiddenCopayAmount'+CountIndex).value*1;
296 Takeback=document.getElementById('Takeback'+CountIndex).value*1;
297 if(document.getElementById('HiddenIns'+CountIndex).value==1 && Allowed!=0)
298 {//Means it is primary's first payment.
299 document.getElementById('RemainderTd'+CountIndex).innerHTML=Math.round((ChargeAmount-AdjustmentAmount-CopayAmount-Payment+Takeback)*100)/100;
301 else
302 {//All other case.
303 document.getElementById('RemainderTd'+CountIndex).innerHTML=Math.round((Remainder-AdjustmentAmount-Payment+Takeback)*100)/100;
305 FillAmount();
307 function FillAmount()
308 {//Called when there is change in the amount by typing.
309 //Readjusts the various values.
310 <?php
311 if($screen=='new_payment')
314 UnpostedAmt=document.getElementById('HidUnpostedAmount').value*1;
315 <?php
317 else
320 UnpostedAmt=document.getElementById('payment_amount').value*1;
321 <?php
325 TempTotal=0;
326 for(RowCount=1;;RowCount++)
328 if(!document.getElementById('Payment'+RowCount))
329 break;
330 else
332 Takeback=document.getElementById('Takeback'+RowCount).value*1;
333 TempTotal=Math.round((TempTotal+document.getElementById('Payment'+RowCount).value*1-Takeback)*100)/100;
336 document.getElementById('TdUnappliedAmount').innerHTML=Math.round((UnpostedAmt-TempTotal)*100)/100;
337 document.getElementById('HidUnappliedAmount').value=Math.round((UnpostedAmt-TempTotal)*100)/100;
338 document.getElementById('HidCurrentPostedAmount').value=TempTotal;
340 function ActionOnInsPat(CountIndex)
341 {//Called when there is onchange in the Ins/Pat drop down.
342 InsPatDropDownValue=document.getElementById('payment_ins'+CountIndex).options[document.getElementById('payment_ins'+CountIndex).selectedIndex].value;
343 document.getElementById('HiddenIns'+CountIndex).value=InsPatDropDownValue;
344 if(InsPatDropDownValue==1)
346 document.getElementById('trCharges'+CountIndex).bgColor='#ddddff';
348 else if(InsPatDropDownValue==2)
350 document.getElementById('trCharges'+CountIndex).bgColor='#ffdddd';
352 else if(InsPatDropDownValue==3)
354 document.getElementById('trCharges'+CountIndex).bgColor='#F2F1BC';
356 else if(InsPatDropDownValue==0)
358 document.getElementById('trCharges'+CountIndex).bgColor='#AAFFFF';
361 function CheckPayingEntityAndDistributionPostFor()
362 {//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
363 PayingEntity=document.getElementById('type_name').options?document.getElementById('type_name').options[document.getElementById('type_name').selectedIndex].value:document.getElementById('type_name').value;
364 CountIndexAbove=0;
365 for(RowCount=CountIndexAbove+1;;RowCount++)
367 if(!document.getElementById('Payment'+RowCount))
368 break;
369 else 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)
372 else
374 InsPatDropDownValue=document.getElementById('payment_ins'+RowCount).options[document.getElementById('payment_ins'+RowCount).selectedIndex].value;
375 if(PayingEntity=='patient' && InsPatDropDownValue>0)
377 alert("<?php echo htmlspecialchars( xl('Cannot Post for Insurance.The Paying Entity selected is Patient.'), ENT_QUOTES) ?>");
378 return false;
380 else if(PayingEntity=='insurance' && InsPatDropDownValue==0)
382 alert("<?php echo htmlspecialchars( xl('Cannot Post for Patient.The Paying Entity selected is Insurance.'), ENT_QUOTES) ?>");
383 return false;
387 return true;
389 function FormValidations()
390 {//Screen validations are done here.
391 if(document.getElementById('check_date').value=='')
393 alert("<?php echo htmlspecialchars( xl('Please Fill the Date'), ENT_QUOTES) ?>");
394 document.getElementById('check_date').focus();
395 return false;
397 else if(!ValidateDateGreaterThanNow(document.getElementById('check_date').value,'<?php echo DateFormatRead();?>'))
399 alert("<?php echo htmlspecialchars( xl('Date Cannot be greater than Today'), ENT_QUOTES) ?>");
400 document.getElementById('check_date').focus();
401 return false;
403 if(document.getElementById('post_to_date').value=='')
405 alert("<?php echo htmlspecialchars( xl('Please Fill the Post To Date'), ENT_QUOTES) ?>");
406 document.getElementById('post_to_date').focus();
407 return false;
409 else if(!ValidateDateGreaterThanNow(document.getElementById('post_to_date').value,'<?php echo DateFormatRead();?>'))
411 alert("<?php echo htmlspecialchars( xl('Post To Date Cannot be greater than Today'), ENT_QUOTES) ?>");
412 document.getElementById('post_to_date').focus();
413 return false;
415 else if(DateCheckGreater(document.getElementById('post_to_date').value,'<?php echo $GLOBALS['post_to_date_benchmark']=='' ? date('Y-m-d',time() - (10 * 24 * 60 * 60)) : htmlspecialchars(oeFormatShortDate($GLOBALS['post_to_date_benchmark']));?>',
416 '<?php echo DateFormatRead();?>'))
418 alert("<?php echo htmlspecialchars( xl('Post To Date Must be greater than the Financial Close Date.'), ENT_QUOTES) ?>");
419 document.getElementById('post_to_date').focus();
420 return false;
422 if(((document.getElementById('payment_method').options[document.getElementById('payment_method').selectedIndex].value=='check_payment' ||
423 document.getElementById('payment_method').options[document.getElementById('payment_method').selectedIndex].value=='bank_draft') &&
424 document.getElementById('check_number').value=='' ))
426 alert("<?php echo htmlspecialchars( xl('Please Fill the Check Number'), ENT_QUOTES) ?>");
427 document.getElementById('check_number').focus();
428 return false;
430 <?php
431 if($screen=='edit_payment')
434 if(document.getElementById('check_number').value!='' &&
435 document.getElementById('payment_method').options[document.getElementById('payment_method').selectedIndex].value=='')
437 alert("<?php echo htmlspecialchars( xl('Please Select the Payment Method'), ENT_QUOTES) ?>");
438 document.getElementById('payment_method').focus();
439 return false;
441 <?php
444 if(document.getElementById('payment_amount').value=='')
446 alert("<?php echo htmlspecialchars( xl('Please Fill the Payment Amount'), ENT_QUOTES) ?>");
447 document.getElementById('payment_amount').focus();
448 return false;
450 if(document.getElementById('payment_amount').value!=document.getElementById('payment_amount').value*1)
452 alert("<?php echo htmlspecialchars( xl('Payment Amount must be Numeric'), ENT_QUOTES) ?>");
453 document.getElementById('payment_amount').focus();
454 return false;
456 <?php
457 if($screen=='edit_payment')
460 if(document.getElementById('adjustment_code').options[document.getElementById('adjustment_code').selectedIndex].value=='')
462 alert("<?php echo htmlspecialchars( xl('Please Fill the Payment Category'), ENT_QUOTES) ?>");
463 document.getElementById('adjustment_code').focus();
464 return false;
466 <?php
469 if(document.getElementById('type_code').value=='')
471 alert("<?php echo htmlspecialchars( xl('Please Fill the Payment From'), ENT_QUOTES) ?>");
472 document.getElementById('type_code').focus();
473 return false;
475 if(document.getElementById('hidden_type_code').value!=document.getElementById('div_insurance_or_patient').innerHTML)
477 alert("<?php echo htmlspecialchars( xl('Take Payment From, from Drop Down'), ENT_QUOTES) ?>");
478 document.getElementById('type_code').focus();
479 return false;
481 if(document.getElementById('deposit_date').value=='')
484 else if(!ValidateDateGreaterThanNow(document.getElementById('deposit_date').value,'<?php echo DateFormatRead();?>'))
486 alert("<?php echo htmlspecialchars( xl('Deposit Date Cannot be greater than Today'), ENT_QUOTES) ?>");
487 document.getElementById('deposit_date').focus();
488 return false;
490 return true;
492 //========================================================================================
493 function UpdateTotalValues(start,count,Payment,PaymentTotal)
494 {//Used in totaling the columns.
495 var paymenttot=0;
496 if(count > 0)
498 for(i=start;i<start+count;i++)
500 if(document.getElementById(Payment+i))
502 paymenttot=paymenttot+document.getElementById(Payment+i).value*1;
505 document.getElementById(PaymentTotal).innerHTML=Math.round((paymenttot)*100)/100;
508 </script>