continued bug fixes (#1876)
[openemr.git] / interface / billing / era_payments.php
blobae40544fdf91019754f6500d22926bc0d8a3801b
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.
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Paul Simon K <paul@zhservices.com>
26 // +------------------------------------------------------------------------------+
27 //===============================================================================
28 //Electronic posting is handled here.
29 //===============================================================================
32 require_once("../globals.php");
33 require_once("$srcdir/patient.inc");
34 require_once("$srcdir/invoice_summary.inc.php");
35 require_once($GLOBALS['OE_SITE_DIR'] . "/statement.inc.php");
36 require_once("$srcdir/parse_era.inc.php");
37 require_once("$srcdir/sl_eob.inc.php");
39 use OpenEMR\Core\Header;
41 $hidden_type_code = isset($_POST['hidden_type_code']) ? $_POST['hidden_type_code'] : '';
42 $check_date = isset($_POST['check_date']) ? $_POST['check_date'] : '';
43 $post_to_date = isset($_POST['post_to_date']) ? $_POST['post_to_date'] : '';
44 $deposit_date = isset($_POST['deposit_date']) ? $_POST['deposit_date'] : '';
45 $type_code = isset($_POST['type_code']) ? $_POST['type_code'] : '';
47 //===============================================================================
48 // This is called back by parse_era() if we are processing X12 835's.
49 $alertmsg = '';
50 $where = '';
51 $eraname = '';
52 $eracount = 0;
53 $Processed=0;
54 function era_callback(&$out)
56 global $where, $eracount, $eraname;
57 ++$eracount;
58 $eraname = $out['gs_date'] . '_' . ltrim($out['isa_control_number'], '0') .
59 '_' . ltrim($out['payer_id'], '0');
60 list($pid, $encounter, $invnumber) = slInvoiceNumber($out);
61 if ($pid && $encounter) {
62 if ($where) {
63 $where .= ' OR ';
65 $where .= "( f.pid = '" . add_escape_custom($pid) . "' AND f.encounter = '" . add_escape_custom($encounter) . "' )";
68 //===============================================================================
69 // Handle X12 835 file upload.
70 if ($_FILES['form_erafile']['size']) {
71 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
72 die(xlt('Authentication Error'));
75 $tmp_name = $_FILES['form_erafile']['tmp_name'];
76 // Handle .zip extension if present. Probably won't work on Windows.
77 if (strtolower(substr($_FILES['form_erafile']['name'], -4)) == '.zip') {
78 rename($tmp_name, "$tmp_name.zip");
79 exec("unzip -p " . escapeshellarg($tmp_name.".zip") . " > " . escapeshellarg($tmp_name));
80 unlink("$tmp_name.zip");
82 $alertmsg .= parse_era($tmp_name, 'era_callback');
83 $erafullname = $GLOBALS['OE_SITE_DIR'] . "/era/$eraname.edi";
84 if (is_file($erafullname)) {
85 $alertmsg .= xl("Warning").': '. xl("Set").' '.$eraname.' '. xl("was already uploaded").' ';
86 if (is_file($GLOBALS['OE_SITE_DIR'] . "/era/$eraname.html")) {
87 $Processed=1;
88 $alertmsg .= xl("and processed.").' ';
89 } else {
90 $alertmsg .= xl("but not yet processed.").' ';
93 rename($tmp_name, $erafullname);
94 } // End 835 upload
95 //===============================================================================
97 //===============================================================================
99 <!DOCTYPE html>
100 <html>
101 <head>
102 <?php Header::setupHeader(['datetime-picker', 'common']);?>
103 <?php require_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
104 <script language="javascript" type="text/javascript">
105 function Validate()
107 if(document.getElementById('uploadedfile').value=='')
109 alert("<?php echo xls('Please Choose a file');?>");
110 return false;
112 if(document.getElementById('hidden_type_code').value=='')
114 alert("<?php echo xls('Select Insurance, by typing'); ?>");
115 document.getElementById('type_code').focus();
116 return false;
118 if(document.getElementById('hidden_type_code').value!=document.getElementById('div_insurance_or_patient').innerHTML)
120 alert("<?php echo xls('Take Insurance, from Drop Down'); ?>");
121 document.getElementById('type_code').focus();
122 return false;
124 top.restoreSession();
125 document.forms[0].submit();
127 function OnloadAction()
128 {//Displays message after upload action,and popups the details.
129 after_value=document.getElementById('after_value').value;
130 if(after_value!='')
132 alert(after_value);
134 <?php
135 if ($_FILES['form_erafile']['size']) {
137 var f = document.forms[0];
138 var debug = <?php echo attr($_REQUEST['form_without']*1); ?> ;
139 var paydate = f.check_date.value;
140 var post_to_date = f.post_to_date.value;
141 var deposit_date = f.deposit_date.value;
142 window.open('sl_eob_process.php?eraname=<?php echo attr(urlencode($eraname)); ?>&debug=' + debug + '&paydate=' + paydate + '&post_to_date=' + post_to_date + '&deposit_date=' + deposit_date + '&original=original' + '&InsId=<?php echo attr(urlencode($hidden_type_code)); ?>' + '&csrf_token_form=<?php echo attr(urlencode(collectCsrfToken())); ?>' , '_blank');
143 return false;
144 <?php
149 $(document).ready(function() {
150 $('.datepicker').datetimepicker({
151 <?php $datetimepicker_timepicker = false; ?>
152 <?php $datetimepicker_showseconds = false; ?>
153 <?php $datetimepicker_formatInput = true; ?>
154 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
155 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
158 </script>
159 <script language="javascript" type="text/javascript">
160 document.onclick=HideTheAjaxDivs;
161 </script>
162 <style>
163 #ajax_div_insurance {
164 position: absolute;
165 z-index:10;
166 background-color: #FBFDD0;
167 border: 1px solid #ccc;
168 padding: 10px;
170 .bottom{border-bottom:1px solid black;}
171 .top{border-top:1px solid black;}
172 .left{border-left:1px solid black;}
173 .right{border-right:1px solid black;}
174 @media only screen and (max-width: 768px) {
175 [class*="col-"] {
176 width: 100%;
177 text-align: left!Important;
179 .navbar-toggle>span.icon-bar {
180 background-color: #68171A ! Important;
182 .navbar-default .navbar-toggle {
183 border-color: #4a4a4a;
185 .navbar-default .navbar-toggle:focus, .navbar-default .navbar-toggle:hover {
186 background-color: #f2f2f2 !Important;
187 font-weight: 900 !Important;
188 color: #000000 !Important;
190 .navbar-color {
191 background-color: #E5E5E5;
193 .icon-bar {
194 background-color: #68171A;
196 .navbar-header {
197 float: none;
199 .navbar-toggle {
200 display: block;
201 background-color: #f2f2f2;
203 .navbar-nav {
204 float: none!important;
206 .navbar-nav>li {
207 float: none;
209 .navbar-collapse.collapse.in {
210 z-index: 100;
211 background-color: #dfdfdf;
212 font-weight: 700;
213 color: #000000 !Important;
218 @media only screen and (max-width: 700px) {
219 [class*="col-"] {
220 width: 100%;
221 text-align:left!Important;
223 #form_without{
224 margin-left:0px !Important;
228 .input-group .form-control{
229 margin-bottom: 3px;
230 margin-left:0px;
232 #form_without{
233 margin-left:5px !Important;
235 </style>
236 <title><?php echo xlt('ERA Posting'); ?></title>
237 </head>
238 <body class="body_top" onload="OnloadAction()">
239 <div class="container">
240 <div class="row">
241 <div class="page-header">
242 <h2><?php echo xlt('Payments'); ?></h2>
243 </div>
244 </div>
245 <div class="row" >
246 <nav class="navbar navbar-default navbar-color navbar-static-top" >
247 <div class="container-fluid">
248 <div class="navbar-header">
249 <button class="navbar-toggle" data-target="#myNavbar" data-toggle="collapse" type="button"><span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span></button>
250 </div>
251 <div class="collapse navbar-collapse" id="myNavbar" >
252 <ul class="nav navbar-nav" >
253 <li class="oe-bold-black">
254 <a href='new_payment.php' style="font-weight:700; color:#000000"><?php echo xlt('New Payment'); ?></a>
255 </li>
256 <li class="oe-bold-black" >
257 <a href='search_payments.php' style="font-weight:700; color:#000000"><?php echo xlt('Search Payment'); ?></a>
258 </li>
259 <li class="active">
260 <a href='era_payments.php' style="font-weight:700; color:#000000"><?php echo xlt('ERA Posting'); ?></a>
261 </li>
262 </ul>
263 </div>
264 </div>
265 </nav>
266 </div>
268 <div class = "row">
269 <form action='era_payments.php' enctype="multipart/form-data" method='post' style="display:inline">
270 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
271 <fieldset>
272 <div class="col-xs-12 oe-custom-line">
273 <div class="form-group col-xs9 oe-file-div">
274 <div class="input-group">
275 <label class="input-group-btn">
276 <span class="btn btn-default">
277 <?php echo xlt('Browse'); ?>&hellip;<input type="file" id="uploadedfile" name="form_erafile" style="display: none;" >
278 <input name="MAX_FILE_SIZE" type="hidden" value="5000000">
279 </span>
280 </label>
281 <input type="text" class="form-control" placeholder="<?php echo xla('Click Browse and select one Electronic Remittance Advice (ERA) file...'); ?>" readonly>
282 </div>
283 </div>
284 </div>
285 <div class="col-xs-12 oe-custom-line">
286 <div class="form-group col-xs-3">
287 <label class="control-label" for="check_date"><?php echo xlt('Date'); ?>:</label>
288 <input class="form-control datepicker" id='check_date' name='check_date' onkeydown="PreventIt(event)" type='text' value="<?php echo attr($check_date); ?>">
289 </div>
290 <div class="form-group col-xs-3">
291 <label class="control-label" for="post_to_date"><?php echo xlt('Post To Date'); ?>:</label>
292 <input class="form-control datepicker" id='post_to_date' name='post_to_date' onkeydown="PreventIt(event)" type='text' value="<?php echo attr($post_to_date); ?>">
293 </div>
294 <div class="form-group col-xs-3 clearfix">
295 <label class="control-label" for="form_without"><?php echo xlt('Select'); ?>:</label>
296 <label class="checkbox">
297 <input name='form_without' id='form_without' type='checkbox' value='1'> <span class="oe-ckbox-label"><?php echo xlt('Without Update'); ?></span>
298 </label>
299 </div>
300 <div class="form-group col-xs-3">
301 <label class="control-label" for="deposit_date"><?php echo xlt('Deposit Date'); ?>:</label>
302 <input class="form-control datepicker" id='deposit_date' name='deposit_date' onkeydown="PreventIt(event)" type='text' value="<?php echo attr($deposit_date); ?>">
303 </div>
304 </div>
305 <div class="col-xs-12 oe-custom-line">
306 <div class="form-group col-xs-6">
307 <label class="control-label" for="type_code"><?php echo xlt('Insurance'); ?>:</label>
308 <input id="hidden_ajax_close_value" type="hidden" value="<?php echo attr($type_code); ?>">
309 <input autocomplete="off" class="form-control" id='type_code' name='type_code' onkeydown="PreventIt(event)" type="text" value="<?php echo attr($type_code); ?>"><br>
310 <!--onKeyUp="ajaxFunction(event,'non','search_payments.php');"-->
311 <div id='ajax_div_insurance_section'>
312 <div id='ajax_div_insurance_error'></div>
313 <div id="ajax_div_insurance" style="display:none;"></div>
314 </div>
315 </div>
316 <div class="form-group col-xs-3">
317 <label class="control-label" for="div_insurance_or_patient"><?php echo xlt('Insurance ID'); ?>:</label>
318 <div class="form-control" id="div_insurance_or_patient" >
319 <?php echo text($hidden_type_code); ?>
320 </div>
321 <input id="description" name="description" type="hidden">
322 </div>
323 </div>
324 </fieldset>
325 <?php //can change position of buttons by creating a class 'position-override' and adding rule text-align:center or right as the case may be in individual stylesheets ?>
326 <div class="form-group clearfix">
327 <div class="col-sm-12 text-left position-override">
328 <div class="btn-group" role="group">
329 <a class="btn btn-default btn-save" href="#" onclick="javascript:return Validate();"><span><?php echo xlt('Process ERA File');?></span></a>
330 </div>
331 </div>
332 </div>
333 <input type="hidden" name="after_value" id="after_value" value="<?php echo attr($alertmsg); ?>"/>
334 <input type="hidden" name="hidden_type_code" id="hidden_type_code" value="<?php echo attr($hidden_type_code); ?>"/>
335 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
336 </form>
337 </div>
338 </div><!-- End of Container Div-->
339 <script>
340 $(function() {
341 //https://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-bootstrap-3
342 // We can attach the `fileselect` event to all file inputs on the page
343 $(document).on('change', ':file', function() {
344 var input = $(this),
345 numFiles = input.get(0).files ? input.get(0).files.length : 1,
346 label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
347 input.trigger('fileselect', [numFiles, label]);
350 // We can watch for our custom `fileselect` event like this
351 $(document).ready( function() {
352 $(':file').on('fileselect', function(event, numFiles, label) {
353 var input = $(this).parents('.input-group').find(':text'),
354 log = numFiles > 1 ? numFiles + ' files selected' : label;
356 if( input.length ) {
357 input.val(log);
359 else {
360 if( log ) alert(log);
366 </script>
367 </body>
368 </html>