prepare("SELECT * FROM insurance_companies WHERE id = ?"); $stmt->execute([$insurance_id]); $insurance = $stmt->fetch(); if (!$insurance) { throw new Exception("Insurance Company not found"); } // Fetch Linked Bills // Linking via patients table: bills -> patients -> insurance_company_id $query = " SELECT b.*, p.name as patient_name, p.policy_number, p.civil_id, d.name_en as doctor_name_en FROM bills b JOIN patients p ON b.patient_id = p.id LEFT JOIN visits v ON b.visit_id = v.id LEFT JOIN employees d ON v.doctor_id = d.id WHERE p.insurance_company_id = ? AND b.insurance_covered > 0 AND DATE(b.created_at) BETWEEN ? AND ? ORDER BY b.created_at DESC "; $stmt = $db->prepare($query); $stmt->execute([$insurance_id, $start_date, $end_date]); $bills = $stmt->fetchAll(); // Calculate Totals $total_claim = 0; foreach ($bills as $bill) { $total_claim += $bill['insurance_covered']; } // Fetch Company Settings (Logo, Address, etc.) $stmt = $db->query("SELECT * FROM settings WHERE id = 1"); $settings = $stmt->fetch(); $lang = $_SESSION['lang'] ?? 'en'; } catch (Exception $e) { die("Error: " . $e->getMessage()); } ?> Statement - <?php echo htmlspecialchars($insurance['name_en']); ?>


:
:

: -

:

'; ?>

#