@@ -212,16 +233,18 @@ $records = $stmt->fetchAll();
\ No newline at end of file
diff --git a/hr_leaves.php b/hr_leaves.php
index cc80148..4737dd5 100644
--- a/hr_leaves.php
+++ b/hr_leaves.php
@@ -1,5 +1,6 @@
ليس لديك صلاحية للوصول إلى هذه الصفحة.
";
@@ -64,14 +65,27 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Fetch Employees for Dropdown
$employees = db()->query("SELECT id, first_name, last_name FROM hr_employees WHERE status = 'active' ORDER BY first_name")->fetchAll();
+// Pagination
+$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
+if ($page < 1) $page = 1;
+$limit = 10;
+$offset = ($page - 1) * $limit;
+
// Fetch Leaves based on Tab
$where_clause = $tab === 'pending' ? "WHERE l.status = 'pending'" : "WHERE 1=1";
+
+// Count Total
+$countSql = "SELECT COUNT(*) FROM hr_leaves l $where_clause";
+$countStmt = db()->query($countSql);
+$totalFiltered = $countStmt->fetchColumn();
+
$sql = "SELECT l.*, e.first_name, e.last_name, u.full_name as approver_name
FROM hr_leaves l
JOIN hr_employees e ON l.employee_id = e.id
LEFT JOIN users u ON l.approved_by = u.id
$where_clause
- ORDER BY l.created_at DESC";
+ ORDER BY l.created_at DESC
+ LIMIT $limit OFFSET $offset";
$requests = db()->query($sql)->fetchAll();
?>
@@ -196,6 +210,9 @@ $requests = db()->query($sql)->fetchAll();
+
+
+
diff --git a/hr_payroll.php b/hr_payroll.php
index 94a932d..e29417b 100644
--- a/hr_payroll.php
+++ b/hr_payroll.php
@@ -1,6 +1,7 @@
ليس لديك صلاحية للوصول إلى هذه الصفحة.";
@@ -117,19 +118,34 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
}
+// Pagination
+$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
+if ($page < 1) $page = 1;
+$limit = 10;
+$offset = ($page - 1) * $limit;
+
// Fetch Payroll Records
$sql = "SELECT p.*, e.first_name, e.last_name, e.job_title
FROM hr_payroll p
JOIN hr_employees e ON p.employee_id = e.id
WHERE p.month = ? AND p.year = ?
- ORDER BY e.first_name";
+ ORDER BY e.first_name
+ LIMIT $limit OFFSET $offset";
$stmt = db()->prepare($sql);
$stmt->execute([$month, $year]);
$payrolls = $stmt->fetchAll();
-// Calculate Totals
-$total_salaries = 0;
-foreach ($payrolls as $p) $total_salaries += $p['net_salary'];
+// Count Total for Pagination
+$countSql = "SELECT COUNT(*) FROM hr_payroll WHERE month = ? AND year = ?";
+$countStmt = db()->prepare($countSql);
+$countStmt->execute([$month, $year]);
+$totalFiltered = $countStmt->fetchColumn();
+
+// Calculate Grand Total Salaries (for the stats card)
+$sumSql = "SELECT SUM(net_salary) FROM hr_payroll WHERE month = ? AND year = ?";
+$sumStmt = db()->prepare($sumSql);
+$sumStmt->execute([$month, $year]);
+$total_salaries = $sumStmt->fetchColumn() ?: 0;
?>
@@ -233,6 +249,9 @@ foreach ($payrolls as $p) $total_salaries += $p['net_salary'];
+
+
+
@@ -298,14 +317,16 @@ foreach ($payrolls as $p) $total_salaries += $p['net_salary'];
\ No newline at end of file
diff --git a/inbound.php b/inbound.php
index 90502ea..b10f537 100644
--- a/inbound.php
+++ b/inbound.php
@@ -1,5 +1,6 @@
prepare($countQuery);
+$countStmt->execute($params);
+$totalFiltered = $countStmt->fetchColumn();
+
$query = "SELECT m.*, s.name as status_name, s.color as status_color, u.full_name as assigned_to_name,
(SELECT GROUP_CONCAT(display_name SEPARATOR '|||') FROM inbound_attachments WHERE mail_id = m.id) as attachment_names
FROM inbound_mail m
LEFT JOIN mailbox_statuses s ON m.status_id = s.id
LEFT JOIN users u ON m.assigned_to = u.id
$where
- ORDER BY m.date_registered DESC, m.id DESC";
+ ORDER BY m.date_registered DESC, m.id DESC
+ LIMIT $limit OFFSET $offset";
$stmt = db()->prepare($query);
$stmt->execute($params);
@@ -290,6 +304,9 @@ if (isset($_GET['id'])) {
+
+
+
diff --git a/includes/accounting_functions.php b/includes/accounting_functions.php
index c6af7a3..1e90f9f 100644
--- a/includes/accounting_functions.php
+++ b/includes/accounting_functions.php
@@ -49,6 +49,64 @@ function get_full_ledger_filtered($search = '', $date_from = '', $date_to = '')
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
+function get_ledger_count($search = '', $date_from = '', $date_to = '') {
+ $db = db();
+ $sql = "SELECT COUNT(*)
+ FROM accounting_journal j
+ JOIN accounting_entries e ON j.id = e.journal_id
+ WHERE 1=1";
+ $params = [];
+
+ if ($search) {
+ $sql .= " AND (j.description LIKE ? OR j.reference LIKE ? OR e.account_name LIKE ?)";
+ $params[] = "%$search%";
+ $params[] = "%$search%";
+ $params[] = "%$search%";
+ }
+ if ($date_from) {
+ $sql .= " AND j.date >= ?";
+ $params[] = $date_from;
+ }
+ if ($date_to) {
+ $sql .= " AND j.date <= ?";
+ $params[] = $date_to;
+ }
+
+ $stmt = $db->prepare($sql);
+ $stmt->execute($params);
+ return $stmt->fetchColumn();
+}
+
+function get_ledger_paginated($search = '', $date_from = '', $date_to = '', $limit = 10, $offset = 0) {
+ $db = db();
+ $sql = "SELECT j.id, j.date, j.description, j.reference, e.account_name, e.debit, e.credit
+ FROM accounting_journal j
+ JOIN accounting_entries e ON j.id = e.journal_id
+ WHERE 1=1";
+ $params = [];
+
+ if ($search) {
+ $sql .= " AND (j.description LIKE ? OR j.reference LIKE ? OR e.account_name LIKE ?)";
+ $params[] = "%$search%";
+ $params[] = "%$search%";
+ $params[] = "%$search%";
+ }
+ if ($date_from) {
+ $sql .= " AND j.date >= ?";
+ $params[] = $date_from;
+ }
+ if ($date_to) {
+ $sql .= " AND j.date <= ?";
+ $params[] = $date_to;
+ }
+
+ $sql .= " ORDER BY j.date DESC, j.id DESC LIMIT $limit OFFSET $offset";
+
+ $stmt = $db->prepare($sql);
+ $stmt->execute($params);
+ return $stmt->fetchAll(PDO::FETCH_ASSOC);
+}
+
function get_trial_balance() {
$db = db();
$stmt = $db->query("SELECT account_name, SUM(debit) as total_debit, SUM(credit) as total_credit
diff --git a/outbound.php b/outbound.php
index 1b4fbcd..068a711 100644
--- a/outbound.php
+++ b/outbound.php
@@ -1,5 +1,6 @@
prepare($countQuery);
+$countStmt->execute($params);
+$totalFiltered = $countStmt->fetchColumn();
+
+
$query = "SELECT m.*, s.name as status_name, s.color as status_color, u.full_name as assigned_to_name,
(SELECT GROUP_CONCAT(display_name SEPARATOR '|||') FROM outbound_attachments WHERE mail_id = m.id) as attachment_names
FROM outbound_mail m
LEFT JOIN mailbox_statuses s ON m.status_id = s.id
LEFT JOIN users u ON m.assigned_to = u.id
$where
- ORDER BY m.date_registered DESC, m.id DESC";
+ ORDER BY m.date_registered DESC, m.id DESC
+ LIMIT $limit OFFSET $offset";
$stmt = db()->prepare($query);
$stmt->execute($params);
@@ -270,6 +285,9 @@ if (isset($_GET['id'])) {
+
+
+
@@ -517,4 +535,4 @@ document.addEventListener('DOMContentLoaded', function() {
});
-
+
\ No newline at end of file
diff --git a/stock_in.php b/stock_in.php
index 0f71bf0..dd87439 100644
--- a/stock_in.php
+++ b/stock_in.php
@@ -1,5 +1,6 @@
عذراً، ليس لديك صلاحية الوصول لهذه الصفحة.';
@@ -57,6 +58,36 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$stores = db()->query("SELECT * FROM stock_stores ORDER BY name ASC")->fetchAll();
$items = db()->query("SELECT * FROM stock_items ORDER BY name ASC")->fetchAll();
+// Pagination for History
+$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
+if ($page < 1) $page = 1;
+$limit = 10;
+$offset = ($page - 1) * $limit;
+
+$where = "WHERE t.transaction_type = 'in'";
+$params = [];
+
+// Count Total
+$countQuery = "SELECT COUNT(*) FROM stock_transactions t $where";
+$countStmt = db()->prepare($countQuery);
+$countStmt->execute($params);
+$totalFiltered = $countStmt->fetchColumn();
+
+// Fetch History
+$historyQuery = "
+ SELECT t.*, i.name as item_name, s.name as store_name, u.full_name as user_name
+ FROM stock_transactions t
+ JOIN stock_items i ON t.item_id = i.id
+ JOIN stock_stores s ON t.store_id = s.id
+ LEFT JOIN users u ON t.user_id = u.id
+ $where
+ ORDER BY t.created_at DESC
+ LIMIT $limit OFFSET $offset
+";
+$stmt = db()->prepare($historyQuery);
+$stmt->execute($params);
+$history = $stmt->fetchAll();
+
?>
@@ -80,9 +111,12 @@ $items = db()->query("SELECT * FROM stock_items ORDER BY name ASC")->fetchAll();
+
+
\ No newline at end of file
diff --git a/stock_items.php b/stock_items.php
index 4722961..e872dc6 100644
--- a/stock_items.php
+++ b/stock_items.php
@@ -1,5 +1,6 @@
عذراً، ليس لديك صلاحية الوصول لهذه الصفحة.
';
@@ -51,15 +52,45 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
}
+// Pagination & Search
+$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
+if ($page < 1) $page = 1;
+$limit = 10;
+$offset = ($page - 1) * $limit;
+
+$where = "WHERE 1=1";
+$params = [];
+
+if (isset($_GET['search']) && !empty($_GET['search'])) {
+ $where .= " AND (i.name LIKE ? OR i.sku LIKE ?)";
+ $search = "%" . $_GET['search'] . "%";
+ $params = array_merge($params, [$search, $search]);
+}
+
+if (isset($_GET['category_id']) && !empty($_GET['category_id'])) {
+ $where .= " AND i.category_id = ?";
+ $params[] = $_GET['category_id'];
+}
+
+// Count Total
+$countQuery = "SELECT COUNT(*) FROM stock_items i $where";
+$countStmt = db()->prepare($countQuery);
+$countStmt->execute($params);
+$totalFiltered = $countStmt->fetchColumn();
+
// Fetch Items with Category Name and Total Quantity
$query = "
SELECT i.*, c.name as category_name,
(SELECT SUM(quantity) FROM stock_quantities q WHERE q.item_id = i.id) as total_quantity
FROM stock_items i
LEFT JOIN stock_categories c ON i.category_id = c.id
+ $where
ORDER BY i.name ASC
+ LIMIT $limit OFFSET $offset
";
-$items = db()->query($query)->fetchAll();
+$stmt = db()->prepare($query);
+$stmt->execute($params);
+$items = $stmt->fetchAll();
// Fetch Categories for Dropdown
$categories = db()->query("SELECT * FROM stock_categories ORDER BY name ASC")->fetchAll();
@@ -89,6 +120,31 @@ $categories = db()->query("SELECT * FROM stock_categories ORDER BY name ASC")->f
+
+
+
+
+
+
+
@@ -105,6 +161,14 @@ $categories = db()->query("SELECT * FROM stock_categories ORDER BY name ASC")->f
+
+
+
+
+
لا يوجد أصناف مطابقة.
+
+
+
= htmlspecialchars($item['name']) ?>
@@ -136,6 +200,9 @@ $categories = db()->query("SELECT * FROM stock_categories ORDER BY name ASC")->f
+
+
+
@@ -201,10 +268,14 @@ $categories = db()->query("SELECT * FROM stock_categories ORDER BY name ASC")->f
-
+
\ No newline at end of file
diff --git a/stock_out.php b/stock_out.php
index 7d1dbb6..9af58e5 100644
--- a/stock_out.php
+++ b/stock_out.php
@@ -1,5 +1,6 @@
عذراً، ليس لديك صلاحية الوصول لهذه الصفحة.
';
@@ -57,6 +58,36 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$stores = db()->query("SELECT * FROM stock_stores ORDER BY name ASC")->fetchAll();
$items = db()->query("SELECT * FROM stock_items ORDER BY name ASC")->fetchAll();
+// Pagination for History
+$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
+if ($page < 1) $page = 1;
+$limit = 10;
+$offset = ($page - 1) * $limit;
+
+$where = "WHERE t.transaction_type IN ('out', 'damage')";
+$params = [];
+
+// Count Total
+$countQuery = "SELECT COUNT(*) FROM stock_transactions t $where";
+$countStmt = db()->prepare($countQuery);
+$countStmt->execute($params);
+$totalFiltered = $countStmt->fetchColumn();
+
+// Fetch History
+$historyQuery = "
+ SELECT t.*, i.name as item_name, s.name as store_name, u.full_name as user_name
+ FROM stock_transactions t
+ JOIN stock_items i ON t.item_id = i.id
+ JOIN stock_stores s ON t.store_id = s.id
+ LEFT JOIN users u ON t.user_id = u.id
+ $where
+ ORDER BY t.created_at DESC
+ LIMIT $limit OFFSET $offset
+";
+$stmt = db()->prepare($historyQuery);
+$stmt->execute($params);
+$history = $stmt->fetchAll();
+
?>
@@ -80,9 +111,12 @@ $items = db()->query("SELECT * FROM stock_items ORDER BY name ASC")->fetchAll();