From 813c9596f7423e099a999dc38a6f88b3c2bddf05 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Wed, 11 Mar 2026 18:32:30 +0000 Subject: [PATCH] Autosave: 20260311-183230 --- accounting.php | 46 ++++++- accounts.php | 112 ++++++++++++++---- .../fix_accounting_accounts_type.php | 12 ++ includes/accounting_functions.php | 8 +- scripts/seed_accounts.php | 37 +++--- 5 files changed, 166 insertions(+), 49 deletions(-) create mode 100644 db/migrations/fix_accounting_accounts_type.php diff --git a/accounting.php b/accounting.php index 363ef2c..0f66122 100644 --- a/accounting.php +++ b/accounting.php @@ -31,11 +31,24 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_entry'])) { } } -$ledger = get_full_ledger(); +// Pagination setup +$page = isset($_GET['p']) ? (int)$_GET['p'] : 1; +$limit = 10; +$offset = ($page - 1) * $limit; + +// Fetch ledger data with pagination +$ledger_all = get_full_ledger(); +$total_items = count($ledger_all); +$total_pages = ceil($total_items / $limit); +$ledger = array_slice($ledger_all, $offset, $limit); + $trial_balance = get_trial_balance(); $balance_sheet = get_balance_sheet(); ?> + + +

المحاسبة (Accounting)

@@ -47,7 +60,7 @@ $balance_sheet = get_balance_sheet();
الأصول
-

+

@@ -55,7 +68,7 @@ $balance_sheet = get_balance_sheet();
الخصوم
-

+

@@ -63,7 +76,7 @@ $balance_sheet = get_balance_sheet();
حقوق الملكية
-

+

@@ -71,7 +84,7 @@ $balance_sheet = get_balance_sheet();
صافي الربح/الخسارة
-

+

@@ -97,7 +110,7 @@ $balance_sheet = get_balance_sheet();
- @@ -139,8 +152,29 @@ $balance_sheet = get_balance_sheet();
+ + + + + + \ No newline at end of file diff --git a/accounts.php b/accounts.php index 4e11663..18b658f 100644 --- a/accounts.php +++ b/accounts.php @@ -14,44 +14,85 @@ if (!$stmt->fetch()) { } // Handle form submission -if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_account'])) { - $name = $_POST['name']; - $type = $_POST['type']; // Assets, Liabilities, Equity, Revenue, Expenses - $stmt = db()->prepare("INSERT INTO accounting_accounts (name, type) VALUES (?, ?)"); - $stmt->execute([$name, $type]); - $message = "تم إضافة الحساب بنجاح."; +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['add_account'])) { + $name = $_POST['name']; + $type = $_POST['type']; + $stmt = db()->prepare("INSERT INTO accounting_accounts (name, type) VALUES (?, ?)"); + $stmt->execute([$name, $type]); + $message = "تم إضافة الحساب بنجاح."; + } elseif (isset($_POST['delete_account'])) { + $id = $_POST['id']; + $stmt = db()->prepare("DELETE FROM accounting_accounts WHERE id = ?"); + $stmt->execute([$id]); + $message = "تم حذف الحساب."; + } elseif (isset($_POST['edit_account'])) { + $id = $_POST['id']; + $name = $_POST['name']; + $type = $_POST['type']; + $stmt = db()->prepare("UPDATE accounting_accounts SET name = ?, type = ? WHERE id = ?"); + $stmt->execute([$name, $type, $id]); + $message = "تم تحديث الحساب بنجاح."; + } } -$accounts = db()->query("SELECT * FROM accounting_accounts ORDER BY type, name")->fetchAll(PDO::FETCH_ASSOC); +// Pagination +$page = isset($_GET['p']) ? (int)$_GET['p'] : 1; +$limit = 10; +$offset = ($page - 1) * $limit; + +$totalAccounts = db()->query("SELECT COUNT(*) FROM accounting_accounts")->fetchColumn(); +$totalPages = ceil($totalAccounts / $limit); + +$accounts = db()->prepare("SELECT * FROM accounting_accounts ORDER BY type, name LIMIT ? OFFSET ?"); +$accounts->bindValue(1, $limit, PDO::PARAM_INT); +$accounts->bindValue(2, $offset, PDO::PARAM_INT); +$accounts->execute(); +$accounts = $accounts->fetchAll(PDO::FETCH_ASSOC); + +// Map English types to Arabic +$typeMap = [ + 'Assets' => 'أصول', + 'Liabilities' => 'خصوم', + 'Equity' => 'حقوق ملكية', + 'Revenue' => 'إيرادات', + 'Expenses' => 'مصروفات', + 'أصول' => 'أصول', + 'خصوم' => 'خصوم', + 'حقوق ملكية' => 'حقوق ملكية', + 'إيرادات' => 'إيرادات', + 'مصروفات' => 'مصروفات' +]; ?>
-

دليل الحسابات (Chart of Accounts)

+

دليل الحسابات

$message
"; ?>
-
إضافة حساب جديد
+
إضافة/تعديل حساب
-
- + + +
- +
- + + + + +
- +
@@ -59,16 +100,45 @@ $accounts = db()->query("SELECT * FROM accounting_accounts ORDER BY type, name")
- + - + +
الاسمالنوع
الاسمالنوعإجراءات
+ +
+ + + +
+
+ +
+ + diff --git a/db/migrations/fix_accounting_accounts_type.php b/db/migrations/fix_accounting_accounts_type.php new file mode 100644 index 0000000..7a65822 --- /dev/null +++ b/db/migrations/fix_accounting_accounts_type.php @@ -0,0 +1,12 @@ +exec("ALTER TABLE accounting_accounts MODIFY type VARCHAR(100) NOT NULL"); + echo "Successfully updated accounting_accounts table structure."; +} catch (PDOException $e) { + echo "Error: " . $e->getMessage(); +} +?> diff --git a/includes/accounting_functions.php b/includes/accounting_functions.php index c1f3542..9471237 100644 --- a/includes/accounting_functions.php +++ b/includes/accounting_functions.php @@ -34,9 +34,11 @@ function get_balance_sheet() { LEFT JOIN accounting_entries e ON a.name = e.account_name GROUP BY a.name, a.type"); $data = $stmt->fetchAll(PDO::FETCH_ASSOC); - $sheet = ['Assets' => 0, 'Liabilities' => 0, 'Equity' => 0, 'Revenue' => 0, 'Expenses' => 0]; + $sheet = ['أصول' => 0, 'خصوم' => 0, 'حقوق ملكية' => 0, 'إيرادات' => 0, 'مصروفات' => 0]; foreach($data as $row) { - $sheet[$row['type']] += $row['balance']; + if (isset($sheet[$row['type']])) { + $sheet[$row['type']] += $row['balance']; + } } return $sheet; } @@ -64,4 +66,4 @@ function add_journal_entry($date, $description, $reference, $entries) { return false; } } -?> \ No newline at end of file +?> diff --git a/scripts/seed_accounts.php b/scripts/seed_accounts.php index ea802dc..2c0626c 100644 --- a/scripts/seed_accounts.php +++ b/scripts/seed_accounts.php @@ -1,25 +1,25 @@ prepare("INSERT IGNORE INTO accounting_accounts (name, type) VALUES (?, ?)"); @@ -28,5 +28,4 @@ foreach ($common_accounts as $account) { $stmt->execute($account); } -echo "Common accounts have been added."; -?> +echo "تمت إضافة الحسابات الشائعة بنجاح."; \ No newline at end of file