} SLClose(); } } row_delete("payments", "id = '" . $payrow['id'] . "'"); } } else { if ($billing) { if (!acl_check('acct', 'disc')) { die("Not authorized!"); } list($patient_id, $encounter_id) = explode(".", $billing); if ($GLOBALS['oer_config']['ws_accounting']['enabled'] === 2) { sqlStatement("DELETE FROM ar_activity WHERE " . "pid = '{$patient_id}' AND encounter = '{$encounter_id}'"); sqlStatement("DELETE ar_session FROM ar_session LEFT JOIN " . "ar_activity ON ar_session.session_id = ar_activity.session_id " . "WHERE ar_activity.session_id IS NULL"); row_modify("billing", "activity = 0", "pid = '{$patient_id}' AND " . "encounter = '{$encounter_id}' AND " . "code_type = 'COPAY' AND " . "activity = 1"); sqlStatement("UPDATE form_encounter SET last_level_billed = 0, " . "last_level_closed = 0, stmt_count = 0, last_stmt_date = NULL " . "WHERE pid = '{$patient_id}' AND encounter = '{$encounter_id}'"); } else { slInitialize(); $trans_id = SLQueryValue("SELECT id FROM ar WHERE ar.invnumber = '{$billing}' LIMIT 1"); if ($trans_id) { newEvent("delete", $_SESSION['authUser'], $_SESSION['authProvider'], 1, "Invoice {$billing} from SQL-Ledger"); SLQuery("DELETE FROM acc_trans WHERE trans_id = '{$trans_id}'"); if ($sl_err) { die($sl_err); } SLQuery("DELETE FROM invoice WHERE trans_id = '{$trans_id}'"); if ($sl_err) { die($sl_err); } SLQuery("DELETE FROM ar WHERE id = '{$trans_id}'");
} else { // Encounter is 0! Seems this happens for pre-payments. $tpmt = sprintf("%01.2f", $payrow['amount1'] + $payrow['amount2']); row_delete("ar_session", "patient_id = '" . add_escape_custom($patient_id) . "' AND " . "payer_id = 0 AND " . "reference = '" . add_escape_custom($payrow['source']) . "' AND " . "pay_total = '" . add_escape_custom($tpmt) . "' AND " . "(SELECT COUNT(*) FROM ar_activity where ar_activity.session_id = ar_session.session_id) = 0 " . "ORDER BY session_id DESC LIMIT 1"); } row_delete("payments", "id = '" . add_escape_custom($payrow['id']) . "'"); } } else { if ($billing) { if (!acl_check('acct', 'disc')) { die("Not authorized!"); } list($patient_id, $encounter_id) = explode(".", $billing); sqlStatement("DELETE FROM ar_activity WHERE " . "pid = ? AND encounter = ? ", array($patient_id, $encounter_id)); sqlStatement("DELETE ar_session FROM ar_session LEFT JOIN " . "ar_activity ON ar_session.session_id = ar_activity.session_id " . "WHERE ar_activity.session_id IS NULL"); row_modify("billing", "activity = 0", "pid = '" . add_escape_custom($patient_id) . "' AND " . "encounter = '" . add_escape_custom($encounter_id) . "' AND " . "code_type = 'COPAY' AND " . "activity = 1"); sqlStatement("UPDATE form_encounter SET last_level_billed = 0, " . "last_level_closed = 0, stmt_count = 0, last_stmt_date = NULL " . "WHERE pid = ? AND encounter = ?", array($patient_id, $encounter_id)); sqlStatement("UPDATE drug_sales SET billed = 0 WHERE " . "pid = ? AND encounter = ?", array($patient_id, $encounter_id)); updateClaim(true, $patient_id, $encounter_id, -1, -1, 1, 0, ''); // clears for rebilling } else { if ($transaction) { if (!acl_check('admin', 'super')) { die("Not authorized!"); } row_delete("transactions", "id = '" . add_escape_custom($transaction) . "'"); } else { die("Nothing was recognized to delete!"); } } }