adding company details to sick leave

This commit is contained in:
Flatlogic Bot 2026-03-29 17:20:23 +00:00
parent b19e996e1e
commit 913366b874
10 changed files with 367 additions and 115 deletions

View File

@ -219,13 +219,14 @@ $site_favicon = !empty($site_settings['company_favicon']) ? $site_settings['comp
<?php endif; ?>
<?php if (has_permission('reports')): ?>
<a href="#reportsSubmenu" data-bs-toggle="collapse" class="sidebar-link <?php echo in_array($section, ['reports']) ? 'active' : ''; ?> d-flex justify-content-between align-items-center">
<a href="#reportsSubmenu" data-bs-toggle="collapse" class="sidebar-link <?php echo in_array($section, ['reports', 'sick_leave_report']) ? 'active' : ''; ?> d-flex justify-content-between align-items-center">
<span><i class="bi bi-bar-chart-line me-2"></i> <?php echo __('reports'); ?></span>
<i class="bi bi-chevron-down small"></i>
</a>
<div class="collapse <?php echo in_array($section, ['reports']) ? 'show' : ''; ?>" id="reportsSubmenu">
<div class="collapse <?php echo in_array($section, ['reports', 'sick_leave_report']) ? 'show' : ''; ?>" id="reportsSubmenu">
<div class="sidebar-submenu">
<a href="reports.php" class="sidebar-link py-2 <?php echo $section === 'reports' ? 'active' : ''; ?>"><i class="bi bi-graph-up me-2"></i> <?php echo __('general_statistics'); ?></a>
<a href="sick_leave_report.php" class="sidebar-link py-2 <?php echo $section === 'sick_leave_report' ? 'active' : ''; ?>"><i class="bi bi-file-medical me-2"></i> <?php echo __('sick_leave_report'); ?></a>
</div>
</div>
<?php endif; ?>

View File

@ -0,0 +1,257 @@
<?php
// Filters
$search_name = $_GET['search_name'] ?? '';
$search_phone = $_GET['search_phone'] ?? '';
$search_doctor = $_GET['search_doctor'] ?? '';
$start_date = $_GET['start_date'] ?? date('Y-m-01');
$end_date = $_GET['end_date'] ?? date('Y-m-t');
// Pagination
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int)$_GET['page'] : 1;
$limit = 10;
$offset = ($page - 1) * $limit;
// Base Query
$query = "
SELECT
v.id as visit_id,
v.sick_leave_start_date,
v.sick_leave_days,
p.id as patient_number,
p.name as patient_name,
p.phone as patient_phone,
e.name_$lang as doctor_name
FROM visits v
JOIN patients p ON v.patient_id = p.id
JOIN employees e ON v.doctor_id = e.id
WHERE v.sick_leave_days IS NOT NULL AND v.sick_leave_days > 0
";
$params = [];
// Apply Filters
if (!empty($search_name)) {
$query .= " AND p.name LIKE ?";
$params[] = "%$search_name%";
}
if (!empty($search_phone)) {
$query .= " AND p.phone LIKE ?";
$params[] = "%$search_phone%";
}
if (!empty($search_doctor)) {
$query .= " AND v.doctor_id = ?";
$params[] = $search_doctor;
}
if (!empty($start_date) && !empty($end_date)) {
$query .= " AND DATE(v.sick_leave_start_date) BETWEEN ? AND ?";
$params[] = $start_date;
$params[] = $end_date;
}
// Count total for pagination
$count_query = "SELECT COUNT(*) FROM (" . $query . ") as total_count";
$stmt = $db->prepare($count_query);
$stmt->execute($params);
$total_records = $stmt->fetchColumn();
$total_pages = ceil($total_records / $limit);
// Add sorting and pagination
$query .= " ORDER BY v.sick_leave_start_date DESC LIMIT $limit OFFSET $offset";
$stmt = $db->prepare($query);
$stmt->execute($params);
$sick_leaves = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch doctors for filter
$stmt = $db->query("SELECT e.id, e.name_$lang as name FROM employees e JOIN positions po ON e.position_id = po.id WHERE po.name_en = 'Doctor' ORDER BY e.name_$lang");
$doctors = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<div class="d-flex justify-content-between align-items-center mb-4">
<h3 class="fw-bold text-secondary"><?php echo __('sick_leave_report'); ?></h3>
<button onclick="window.print()" class="btn btn-outline-dark no-print">
<i class="bi bi-printer"></i> <?php echo __('print'); ?>
</button>
</div>
<!-- Filters -->
<div class="card border-0 shadow-sm mb-4 no-print">
<div class="card-body">
<form method="GET" class="row g-3 align-items-end">
<div class="col-md-3">
<label class="form-label text-muted small"><?php echo __('filter_by_patient_name'); ?></label>
<input type="text" name="search_name" class="form-control" value="<?php echo htmlspecialchars($search_name); ?>" placeholder="<?php echo __('patient'); ?>...">
</div>
<div class="col-md-2">
<label class="form-label text-muted small"><?php echo __('filter_by_telephone'); ?></label>
<input type="text" name="search_phone" class="form-control" value="<?php echo htmlspecialchars($search_phone); ?>" placeholder="<?php echo __('telephone'); ?>...">
</div>
<div class="col-md-2">
<label class="form-label text-muted small"><?php echo __('filter_by_doctor'); ?></label>
<select name="search_doctor" class="form-select">
<option value=""><?php echo __('all'); ?></option>
<?php foreach ($doctors as $doc): ?>
<option value="<?php echo $doc['id']; ?>" <?php echo $search_doctor == $doc['id'] ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($doc['name']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-3">
<label class="form-label text-muted small"><?php echo __('filter_by_date_range'); ?></label>
<div class="input-group">
<input type="date" name="start_date" class="form-control" value="<?php echo $start_date; ?>">
<span class="input-group-text border-0 bg-light">-</span>
<input type="date" name="end_date" class="form-control" value="<?php echo $end_date; ?>">
</div>
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-primary w-100">
<i class="bi bi-search"></i> <?php echo __('search'); ?>
</button>
</div>
</form>
</div>
</div>
<!-- Print Header -->
<div class="print-only d-none mb-4">
<h2 class="text-center"><?php echo __('sick_leave_report'); ?></h2>
<p class="text-center text-muted">
<?php echo __('report_period'); ?>: <?php echo $start_date; ?> <?php echo __('to'); ?> <?php echo $end_date; ?><br>
<?php echo __('generated_on'); ?>: <?php echo date('Y-m-d H:i'); ?>
</p>
</div>
<!-- Table -->
<div class="card border-0 shadow-sm">
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="table-light text-secondary">
<tr>
<th class="px-4 py-3"><?php echo __('patient_number'); ?></th>
<th class="py-3"><?php echo __('patient'); ?></th>
<th class="py-3 text-center"><?php echo __('date_issued'); ?></th>
<th class="py-3 text-center"><?php echo __('number_of_days'); ?></th>
<th class="px-4 py-3 text-end"><?php echo __('issued_by'); ?></th>
</tr>
</thead>
<tbody>
<?php if (empty($sick_leaves)): ?>
<tr>
<td colspan="5" class="text-center py-4 text-muted">
<i class="bi bi-inbox fs-2 d-block mb-2"></i>
<?php echo __('no_data_found'); ?>
</td>
</tr>
<?php else: ?>
<?php foreach ($sick_leaves as $leave): ?>
<tr>
<td class="px-4 fw-semibold text-primary">
#<?php echo str_pad($leave['patient_number'], 6, '0', STR_PAD_LEFT); ?>
</td>
<td>
<div class="fw-semibold text-dark"><?php echo htmlspecialchars($leave['patient_name']); ?></div>
<small class="text-muted"><i class="bi bi-telephone"></i> <?php echo htmlspecialchars($leave['patient_phone'] ?: '-'); ?></small>
</td>
<td class="text-center">
<span class="badge bg-light text-dark border">
<i class="bi bi-calendar-event me-1"></i>
<?php echo date('Y-m-d', strtotime($leave['sick_leave_start_date'])); ?>
</span>
</td>
<td class="text-center">
<span class="badge bg-info bg-opacity-10 text-info fw-bold fs-6 border border-info border-opacity-25">
<?php echo htmlspecialchars($leave['sick_leave_days']); ?> <?php echo __('days'); ?>
</span>
</td>
<td class="px-4 text-end">
<span class="text-dark"><i class="bi bi-person-badge text-muted me-1"></i> <?php echo htmlspecialchars($leave['doctor_name']); ?></span>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Pagination -->
<?php if ($total_pages > 1): ?>
<div class="d-flex justify-content-between align-items-center mt-4 no-print">
<span class="text-muted small">
<?php echo __('showing'); ?> <?php echo $offset + 1; ?> <?php echo __('to'); ?> <?php echo min($offset + $limit, $total_records); ?> <?php echo __('of'); ?> <?php echo $total_records; ?> <?php echo __('entries'); ?>
</span>
<nav aria-label="Page navigation">
<ul class="pagination pagination-sm mb-0">
<li class="page-item <?php echo $page <= 1 ? 'disabled' : ''; ?>">
<a class="page-link" href="?page=<?php echo $page - 1; ?>&search_name=<?php echo urlencode($search_name); ?>&search_phone=<?php echo urlencode($search_phone); ?>&search_doctor=<?php echo urlencode($search_doctor); ?>&start_date=<?php echo $start_date; ?>&end_date=<?php echo $end_date; ?>">
<?php echo __('previous'); ?>
</a>
</li>
<?php
// Simple pagination logic
$start_page = max(1, $page - 2);
$end_page = min($total_pages, $page + 2);
for ($i = $start_page; $i <= $end_page; $i++):
?>
<li class="page-item <?php echo $page == $i ? 'active' : ''; ?>">
<a class="page-link" href="?page=<?php echo $i; ?>&search_name=<?php echo urlencode($search_name); ?>&search_phone=<?php echo urlencode($search_phone); ?>&search_doctor=<?php echo urlencode($search_doctor); ?>&start_date=<?php echo $start_date; ?>&end_date=<?php echo $end_date; ?>">
<?php echo $i; ?>
</a>
</li>
<?php endfor; ?>
<li class="page-item <?php echo $page >= $total_pages ? 'disabled' : ''; ?>">
<a class="page-link" href="?page=<?php echo $page + 1; ?>&search_name=<?php echo urlencode($search_name); ?>&search_phone=<?php echo urlencode($search_phone); ?>&search_doctor=<?php echo urlencode($search_doctor); ?>&start_date=<?php echo $start_date; ?>&end_date=<?php echo $end_date; ?>">
<?php echo __('next'); ?>
</a>
</li>
</ul>
</nav>
</div>
<?php endif; ?>
<style>
@media print {
/* Hide Non-Printable Elements */
#sidebar, .navbar, .btn, form, footer, .no-print, .pagination, .d-flex.justify-content-between.mt-4 {
display: none !important;
}
/* Layout Adjustments for Print */
.main-content {
margin-left: 0 !important;
padding: 0 !important;
width: 100% !important;
}
body {
background: white !important;
font-size: 12pt;
}
.card {
border: none !important;
box-shadow: none !important;
}
.print-only {
display: block !important;
}
/* Table Styling for Print */
.table {
width: 100% !important;
border-collapse: collapse !important;
}
.table th, .table td {
border: 1px solid #ddd !important;
padding: 8px !important;
}
}
</style>

View File

@ -2,6 +2,15 @@
$translations = array (
'en' =>
array (
'sick_leave_report' => 'Patient Sick Leave',
'date_issued' => 'Date Issued',
'number_of_days' => 'Number of Days',
'issued_by' => 'Issued By',
'filter_by_patient_name' => 'Patient Name',
'filter_by_telephone' => 'Telephone',
'filter_by_doctor' => 'Select Doctor',
'filter_by_date_range' => 'Date Range',
'to' => 'To',
'generate' => 'Generate',
'no_data_found' => 'No Data Found',
@ -520,6 +529,15 @@ $translations = array (
),
'ar' =>
array (
'sick_leave_report' => 'إجازات المرضى',
'date_issued' => 'تاريخ الإصدار',
'number_of_days' => 'عدد الأيام',
'issued_by' => 'صدرت بواسطة',
'filter_by_patient_name' => 'اسم المريض',
'filter_by_telephone' => 'رقم الهاتف',
'filter_by_doctor' => 'اختر الطبيب',
'filter_by_date_range' => 'نطاق التاريخ',
'to' => 'إلى',
'generate' => 'توليد',
'no_data_found' => 'لا توجد بيانات',

View File

@ -1,72 +0,0 @@
import sys
with open('includes/actions.php', 'r', encoding='utf-8') as f:
content = f.read()
# First remove the previously injected block
if "} elseif ($_POST['action'] === 'import_patients') {" in content:
import re
# We will use string manipulation to remove the whole block.
# It starts with "} elseif ($_POST['action'] === 'import_patients') {"
# and ends right before "} elseif ($_POST['action'] === 'import_drugs_groups') {"
start_idx = content.find("} elseif ($_POST['action'] === 'import_patients') {")
end_idx = content.find("} elseif ($_POST['action'] === 'import_drugs_groups') {", start_idx + 1)
if start_idx != -1 and end_idx != -1:
content = content[:start_idx] + content[end_idx:]
inject_code = """ } elseif ($_POST['action'] === 'import_patients') {
if (isset($_FILES['file'])) {
try {
$rows = parse_import_file($_FILES['file']);
if ($rows) {
$db->beginTransaction();
$stmt = $db->prepare("INSERT INTO patients (name, dob, nationality, phone, city) VALUES (?, ?, ?, ?, ?)");
foreach ($rows as $row) {
$name = trim($row[0] ?? '');
if (empty($name)) continue;
$dob = trim($row[1] ?? '');
if (!empty($dob)) {
$parsed_date = strtotime(str_replace('/', '-', $dob));
if ($parsed_date) {
$dob = date('Y-m-d', $parsed_date);
} else {
$dob = null;
}
} else {
$dob = null;
}
$nationality = trim($row[2] ?? '');
$phone = trim($row[3] ?? '');
$city = trim($row[4] ?? '');
$stmt->execute([$name, $dob, $nationality, $phone, $city]);
}
$db->commit();
$_SESSION['flash_message'] = __('patients').' '.__('imported_successfully') ?? 'Import successful';
} else {
$_SESSION['flash_message'] = $_SESSION['import_error'] ?? 'Failed to parse file or empty.'; unset($_SESSION['import_error']);
}
} catch (Exception $e) {
if ($db->inTransaction()) {
$db->rollBack();
}
$_SESSION['flash_message'] = "Error importing data: " . $e->getMessage();
}
} else {
$_SESSION['flash_message'] = "No file selected.";
}
header('Location: ../patients.php');
exit;
"""
if "} elseif ($_POST['action'] === 'import_drugs_groups') {" in content:
content = content.replace("} elseif ($_POST['action'] === 'import_drugs_groups') {", inject_code + "} elseif ($_POST['action'] === 'import_drugs_groups') {")
with open('includes/actions.php', 'w', encoding='utf-8') as f:
f.write(content)
print("Injected successfully")
else:
print("Could not find the hook in actions.php")

View File

@ -1,26 +0,0 @@
import re
with open("includes/layout/footer.php", "r") as f:
content = f.read()
new_body = """<div class="mb-3">
<label class="form-label"><?php echo __("select_file"); ?></label>
<input type="file" name="file" class="form-control" accept=".csv,.xls,.xlsx" required>
<div class="form-text mt-2 text-muted">
<i class="bi bi-info-circle me-1"></i> <?php echo __("excel_format_info"); ?>
</div>
</div>
<div class="mt-3 text-center">
<a href="download_patient_template.php" class="btn btn-outline-success btn-sm">
<i class="bi bi-download me-1"></i> <?php echo __("download_sample_template") ?? "Download Sample Template"; ?>
</a>
</div>"""
content = re.sub(
r'<div class="mb-3">\s*<label class="form-label"><\?php echo __\("select_file"\); \?></label>\s*<input type="file" name="file" class="form-control" accept="\.xls,\.xlsx" required>\s*<div class="form-text mt-2 text-muted">\s*<i class="bi bi-info-circle me-1"></i> <\?php echo __\("excel_format_info"\); \?>\s*</div>\s*</div>',
new_body,
content
)
with open("includes/layout/footer.php", "w") as f:
f.write(content)

View File

@ -51,8 +51,11 @@ try {
$items = $stmt->fetchAll();
// Fetch Company Settings (Logo, Address, etc.)
$stmt = $db->query("SELECT * FROM settings WHERE id = 1");
$settings = $stmt->fetch();
$stmt = $db->query("SELECT setting_key, setting_value FROM settings");
$settings = [];
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$settings[$row[setting_key]] = $row[setting_value];
}
$lang = $_SESSION['lang'] ?? 'en';
} catch (Exception $e) {

View File

@ -59,8 +59,11 @@ try {
}
// Fetch Company Settings (Logo, Address, etc.)
$stmt = $db->query("SELECT * FROM settings WHERE id = 1");
$settings = $stmt->fetch();
$stmt = $db->query("SELECT setting_key, setting_value FROM settings");
$settings = [];
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$settings[$row[setting_key]] = $row[setting_value];
}
$lang = $_SESSION['lang'] ?? 'en';
} catch (Exception $e) {

View File

@ -51,6 +51,14 @@ try {
$stmt->execute([$visit_id]);
$prescriptions = $stmt->fetchAll();
// Fetch Company Settings
$stmt = $db->query("SELECT setting_key, setting_value FROM settings");
$settings = [];
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$settings[$row["setting_key"]] = $row["setting_value"];
}
$lang = $_SESSION['lang'] ?? 'en';
} catch (Exception $e) {
die("Error: " . $e->getMessage());
@ -66,6 +74,7 @@ try {
<style>
body { font-family: 'Times New Roman', Times, serif; }
.prescription-header { border-bottom: 2px solid #000; padding-bottom: 20px; margin-bottom: 30px; }
.company-logo { max-height: 80px; }
.prescription-footer { border-top: 2px solid #000; padding-top: 20px; margin-top: 50px; }
.rx-symbol { font-size: 40px; font-weight: bold; font-family: cursive; margin-bottom: 10px; }
@ -92,9 +101,16 @@ try {
</div>
<div class="prescription-header text-center">
<h2>Hospital Management System</h2>
<p>123 Medical Center Street, City, Country</p>
<p>Phone: +123 456 7890 | Email: info@hospital.com</p>
<?php if (!empty($settings["company_logo"])): ?>
<img src="<?php echo htmlspecialchars($settings["company_logo"]); ?>" alt="Logo" class="company-logo mb-2">
<?php endif; ?>
<h2 class="fw-bold m-0"><?php echo htmlspecialchars($settings["company_name"] ?? "Hospital Management System"); ?></h2>
<p class="mb-1"><?php echo htmlspecialchars($settings["company_address"] ?? "123 Medical Center Street, City, Country"); ?></p>
<p class="mb-0">
<?php if (!empty($settings["company_phone"])) echo "Phone: " . htmlspecialchars($settings["company_phone"]); ?>
<?php if (!empty($settings["company_phone"]) && !empty($settings["company_email"])) echo " | "; ?>
<?php if (!empty($settings["company_email"])) echo "Email: " . htmlspecialchars($settings["company_email"]); ?>
</p>
</div>
<div class="row mb-4">

View File

@ -17,8 +17,8 @@ try {
throw new Exception("Invalid Visit ID");
}
$stmt = $db->prepare("
SELECT
$stmt = $db->prepare(
"SELECT
v.*,
p.name as patient_name,
p.dob,
@ -31,8 +31,8 @@ try {
JOIN patients p ON v.patient_id = p.id
LEFT JOIN employees e ON v.doctor_id = e.id
LEFT JOIN departments dept ON e.department_id = dept.id
WHERE v.id = ?
");
WHERE v.id = ?"
);
$stmt->execute([$visit_id]);
$visit = $stmt->fetch();
@ -41,6 +41,14 @@ try {
}
$lang = $_SESSION['lang'] ?? 'en';
// Fetch Company Settings (Logo, Address, etc.)
$stmt = $db->query("SELECT setting_key, setting_value FROM settings");
$settings = [];
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$settings[$row['setting_key']] = $row['setting_value'];
}
} catch (Exception $e) {
die("Error: " . $e->getMessage());
}
@ -55,6 +63,7 @@ try {
<style>
body { font-family: 'Times New Roman', Times, serif; }
.prescription-header { border-bottom: 2px solid #000; padding-bottom: 20px; margin-bottom: 30px; }
.company-logo { max-height: 80px; }
.prescription-footer { border-top: 2px solid #000; padding-top: 20px; margin-top: 50px; }
.certificate-title { font-size: 32px; font-weight: bold; text-align: center; text-transform: uppercase; margin-bottom: 40px; text-decoration: underline; }
.content-body { font-size: 18px; line-height: 2; margin-bottom: 40px; }
@ -75,9 +84,35 @@ try {
</div>
<div class="prescription-header text-center">
<h2>Hospital Management System</h2>
<p>123 Medical Center Street, City, Country</p>
<p>Phone: +123 456 7890 | Email: info@hospital.com</p>
<?php if (!empty($settings['company_logo'])): ?>
<img src="<?php echo htmlspecialchars($settings['company_logo']); ?>" alt="Logo" class="company-logo mb-2">
<?php endif; ?>
<h2 class="fw-bold m-0"><?php echo htmlspecialchars($settings['company_name'] ?? 'Hospital Management System'); ?></h2>
<p class="mb-1"><?php echo htmlspecialchars($settings['company_address'] ?? '123 Medical Center Street, City, Country'); ?></p>
<p class="mb-0">
<?php if (!empty($settings['company_phone'])): ?>
Phone: <?php echo htmlspecialchars($settings['company_phone']); ?>
<?php else: ?>
Phone: +123 456 7890
<?php endif; ?>
<?php if ((!empty($settings['company_phone']) || true) && (!empty($settings['company_email']) || true)) echo ' | '; ?>
<?php if (!empty($settings['company_email'])): ?>
Email: <?php echo htmlspecialchars($settings['company_email']); ?>
<?php else: ?>
Email: info@hospital.com
<?php endif; ?>
</p>
<p class="mb-0 small text-muted">
<?php if (!empty($settings['company_ctr_no'])) echo 'CTR No: ' . htmlspecialchars($settings['company_ctr_no']); ?>
<?php if (!empty($settings['company_ctr_no']) && !empty($settings['company_registration_no'])) echo ' | ';
?>
<?php if (!empty($settings['company_registration_no'])) echo 'Reg No: ' . htmlspecialchars($settings['company_registration_no']); ?>
<?php if ((!empty($settings['company_ctr_no']) || !empty($settings['company_registration_no'])) && !empty($settings['company_vat_no'])) echo ' | ';
?>
<?php if (!empty($settings['company_vat_no'])) echo 'VAT No: ' . htmlspecialchars($settings['company_vat_no']); ?>
</p>
</div>
<div class="certificate-title">
@ -142,4 +177,4 @@ try {
</div>
</body>
</html>
</html>

17
sick_leave_report.php Normal file
View File

@ -0,0 +1,17 @@
<?php
$section = 'sick_leave_report';
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/helpers.php';
require_once __DIR__ . '/includes/auth.php';
check_auth();
$db = db();
$lang = $_SESSION['lang'];
require_once __DIR__ . '/includes/actions.php';
require_once __DIR__ . '/includes/common_data.php';
require_once __DIR__ . '/includes/layout/header.php';
require_once __DIR__ . '/includes/pages/sick_leave_report.php';
require_once __DIR__ . '/includes/layout/footer.php';