diff --git a/accounting.php b/accounting.php index 01cc8e3..ffb8055 100644 --- a/accounting.php +++ b/accounting.php @@ -2,6 +2,7 @@ require_once 'db/config.php'; require_once 'includes/header.php'; require_once 'includes/accounting_functions.php'; +require_once 'includes/pagination.php'; // Check permission $user_id = $_SESSION['user_id'] ?? 0; @@ -60,18 +61,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } // Pagination and Filtering setup -$page = isset($_GET['p']) ? (int)$_GET['p'] : 1; +$page = isset($_GET['page']) ? (int)$_GET['page'] : 1; // Standardized to 'page' +if ($page < 1) $page = 1; $limit = 10; $offset = ($page - 1) * $limit; + $search = $_GET['search'] ?? ''; $date_from = $_GET['date_from'] ?? ''; $date_to = $_GET['date_to'] ?? ''; -// Fetch ledger data with filters -$ledger_all = get_full_ledger_filtered($search, $date_from, $date_to); -$total_items = count($ledger_all); -$total_pages = ceil($total_items / $limit); -$ledger = array_slice($ledger_all, $offset, $limit); +// Fetch ledger data with filters using optimized functions +$totalFiltered = get_ledger_count($search, $date_from, $date_to); +$ledger = get_ledger_paginated($search, $date_from, $date_to, $limit, $offset); + ?> @@ -237,6 +239,9 @@ $ledger = array_slice($ledger_all, $offset, $limit); + + + @@ -262,15 +267,8 @@ $ledger = array_slice($ledger_all, $offset, $limit);
التاريخالوصفالمرجعالحسابمديندائنالإجراءات
لا توجد قيود.
- + + diff --git a/hr_attendance.php b/hr_attendance.php index 2a3b5c5..ef3c8e7 100644 --- a/hr_attendance.php +++ b/hr_attendance.php @@ -1,5 +1,6 @@ ليس لديك صلاحية للوصول إلى هذه الصفحة."; @@ -44,13 +45,25 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_attendance'])) { } } +// Pagination +$page = isset($_GET['page']) ? (int)$_GET['page'] : 1; +if ($page < 1) $page = 1; +$limit = 10; +$offset = ($page - 1) * $limit; + +// Count Total Employees +$countStmt = db()->prepare("SELECT COUNT(*) FROM hr_employees WHERE status = 'active'"); +$countStmt->execute(); +$totalFiltered = $countStmt->fetchColumn(); + // Fetch Employees and their attendance for the selected date $sql = "SELECT e.id, e.first_name, e.last_name, e.job_title, a.id as att_id, a.status, a.check_in, a.check_out, a.notes FROM hr_employees e LEFT JOIN hr_attendance a ON e.id = a.employee_id AND a.date = ? WHERE e.status = 'active' - ORDER BY e.first_name"; + ORDER BY e.first_name + LIMIT $limit OFFSET $offset"; $stmt = db()->prepare($sql); $stmt->execute([$date]); $records = $stmt->fetchAll(); @@ -74,7 +87,7 @@ $records = $stmt->fetchAll();
-
+
@@ -90,6 +103,11 @@ $records = $stmt->fetchAll(); + + + + + @@ -158,6 +176,9 @@ $records = $stmt->fetchAll();
لا يوجد موظفين نشطين.
+ + +
@@ -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();
-
+
+
+
تسجيل توريد جديد
+
@@ -133,4 +167,48 @@ $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 + + + + +

لا يوجد أصناف مطابقة.

+ + + @@ -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();
-
+
+
+
تسجيل عملية صرف
+
@@ -141,4 +175,56 @@ $items = db()->query("SELECT * FROM stock_items ORDER BY name ASC")->fetchAll();
- + +
+
+
سجل عمليات الصرف
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#النوعالصنفالمستودعالكميةبواسطةالتاريخالمرجع
لا توجد عمليات صرف سابقة.
+ + تالف + + صرف + + -
+
+ + + +
+ + \ No newline at end of file