Autosave: 20260311-183230

This commit is contained in:
Flatlogic Bot 2026-03-11 18:32:30 +00:00
parent 6ede6271b7
commit 813c9596f7
5 changed files with 166 additions and 49 deletions

View File

@ -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(); $trial_balance = get_trial_balance();
$balance_sheet = get_balance_sheet(); $balance_sheet = get_balance_sheet();
?> ?>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css" rel="stylesheet" />
<div class="container mt-4" dir="rtl"> <div class="container mt-4" dir="rtl">
<h2 class="text-right">المحاسبة (Accounting)</h2> <h2 class="text-right">المحاسبة (Accounting)</h2>
@ -47,7 +60,7 @@ $balance_sheet = get_balance_sheet();
<div class="card bg-primary text-white text-center mb-3"> <div class="card bg-primary text-white text-center mb-3">
<div class="card-body"> <div class="card-body">
<h5>الأصول</h5> <h5>الأصول</h5>
<h3><?= number_format($balance_sheet['Assets'], 2) ?></h3> <h3><?= number_format($balance_sheet['أصول'], 2) ?></h3>
</div> </div>
</div> </div>
</div> </div>
@ -55,7 +68,7 @@ $balance_sheet = get_balance_sheet();
<div class="card bg-danger text-white text-center mb-3"> <div class="card bg-danger text-white text-center mb-3">
<div class="card-body"> <div class="card-body">
<h5>الخصوم</h5> <h5>الخصوم</h5>
<h3><?= number_format($balance_sheet['Liabilities'], 2) ?></h3> <h3><?= number_format($balance_sheet['خصوم'], 2) ?></h3>
</div> </div>
</div> </div>
</div> </div>
@ -63,7 +76,7 @@ $balance_sheet = get_balance_sheet();
<div class="card bg-success text-white text-center mb-3"> <div class="card bg-success text-white text-center mb-3">
<div class="card-body"> <div class="card-body">
<h5>حقوق الملكية</h5> <h5>حقوق الملكية</h5>
<h3><?= number_format($balance_sheet['Equity'], 2) ?></h3> <h3><?= number_format($balance_sheet['حقوق ملكية'], 2) ?></h3>
</div> </div>
</div> </div>
</div> </div>
@ -71,7 +84,7 @@ $balance_sheet = get_balance_sheet();
<div class="card bg-info text-white text-center mb-3"> <div class="card bg-info text-white text-center mb-3">
<div class="card-body"> <div class="card-body">
<h5>صافي الربح/الخسارة</h5> <h5>صافي الربح/الخسارة</h5>
<h3><?= number_format($balance_sheet['Revenue'] - $balance_sheet['Expenses'], 2) ?></h3> <h3><?= number_format($balance_sheet['إيرادات'] - $balance_sheet['مصروفات'], 2) ?></h3>
</div> </div>
</div> </div>
</div> </div>
@ -97,7 +110,7 @@ $balance_sheet = get_balance_sheet();
</div> </div>
<div class="col-md-2"> <div class="col-md-2">
<label>الحساب</label> <label>الحساب</label>
<select name="account" class="form-control" required> <select name="account" id="accountSelect" class="form-select" required style="width: 100%;">
<?php foreach (get_all_accounts() as $acc): ?> <?php foreach (get_all_accounts() as $acc): ?>
<option value="<?= htmlspecialchars($acc['name']) ?>"><?= htmlspecialchars($acc['name']) ?></option> <option value="<?= htmlspecialchars($acc['name']) ?>"><?= htmlspecialchars($acc['name']) ?></option>
<?php endforeach; ?> <?php endforeach; ?>
@ -139,8 +152,29 @@ $balance_sheet = get_balance_sheet();
</tbody> </tbody>
</table> </table>
</div> </div>
<nav>
<ul class="pagination justify-content-center">
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
<li class="page-item <?= $i == $page ? 'active' : '' ?>">
<a class="page-link" href="?p=<?= $i ?>"><?= $i ?></a>
</li>
<?php endfor; ?>
</ul>
</nav>
</div> </div>
</div> </div>
</div> </div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
$(document).ready(function() {
$('#accountSelect').select2({
theme: 'bootstrap-5',
dir: 'rtl'
});
});
</script>
<?php require_once 'includes/footer.php'; ?> <?php require_once 'includes/footer.php'; ?>

View File

@ -14,44 +14,85 @@ if (!$stmt->fetch()) {
} }
// Handle form submission // Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_account'])) { if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name']; if (isset($_POST['add_account'])) {
$type = $_POST['type']; // Assets, Liabilities, Equity, Revenue, Expenses $name = $_POST['name'];
$stmt = db()->prepare("INSERT INTO accounting_accounts (name, type) VALUES (?, ?)"); $type = $_POST['type'];
$stmt->execute([$name, $type]); $stmt = db()->prepare("INSERT INTO accounting_accounts (name, type) VALUES (?, ?)");
$message = "تم إضافة الحساب بنجاح."; $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' => 'مصروفات',
'أصول' => 'أصول',
'خصوم' => 'خصوم',
'حقوق ملكية' => 'حقوق ملكية',
'إيرادات' => 'إيرادات',
'مصروفات' => 'مصروفات'
];
?> ?>
<div class="container mt-4" dir="rtl"> <div class="container mt-4" dir="rtl">
<h2 class="text-right">دليل الحسابات (Chart of Accounts)</h2> <h2 class="text-right">دليل الحسابات</h2>
<?php if (isset($message)) echo "<div class='alert alert-success'>$message</div>"; ?> <?php if (isset($message)) echo "<div class='alert alert-success'>$message</div>"; ?>
<div class="card mb-4"> <div class="card mb-4">
<div class="card-header">إضافة حساب جديد</div> <div class="card-header">إضافة/تعديل حساب</div>
<div class="card-body"> <div class="card-body">
<form method="POST"> <form method="POST" id="accountForm">
<input type="hidden" name="add_account" value="1"> <input type="hidden" name="add_account" value="1" id="formAction">
<input type="hidden" name="id" id="editId">
<div class="row"> <div class="row">
<div class="col-md-5"> <div class="col-md-5">
<label>اسم الحساب</label> <label>اسم الحساب</label>
<input type="text" name="name" class="form-control" required> <input type="text" name="name" class="form-control" id="editName" required>
</div> </div>
<div class="col-md-5"> <div class="col-md-5">
<label>نوع الحساب</label> <label>نوع الحساب</label>
<select name="type" class="form-control" required> <select name="type" class="form-control" id="editType" required>
<option value="Assets">أصول (Assets)</option> <option value="أصول">أصول</option>
<option value="Liabilities">خصوم (Liabilities)</option> <option value="خصوم">خصوم</option>
<option value="Equity">حقوق ملكية (Equity)</option> <option value="حقوق ملكية">حقوق ملكية</option>
<option value="Revenue">إيرادات (Revenue)</option> <option value="إيرادات">إيرادات</option>
<option value="Expenses">مصروفات (Expenses)</option> <option value="مصروفات">مصروفات</option>
</select> </select>
</div> </div>
<div class="col-md-2 d-flex align-items-end"> <div class="col-md-2 d-flex align-items-end">
<button type="submit" class="btn btn-primary">إضافة</button> <button type="submit" class="btn btn-primary" id="formButton">إضافة</button>
</div> </div>
</div> </div>
</form> </form>
@ -59,16 +100,45 @@ $accounts = db()->query("SELECT * FROM accounting_accounts ORDER BY type, name")
</div> </div>
<table class="table table-bordered text-right"> <table class="table table-bordered text-right">
<thead><tr><th>الاسم</th><th>النوع</th></tr></thead> <thead><tr><th>الاسم</th><th>النوع</th><th>إجراءات</th></tr></thead>
<tbody> <tbody>
<?php foreach ($accounts as $account): ?> <?php foreach ($accounts as $account): ?>
<tr> <tr>
<td><?= htmlspecialchars($account['name']) ?></td> <td><?= htmlspecialchars($account['name']) ?></td>
<td><?= htmlspecialchars($account['type']) ?></td> <td><?= htmlspecialchars($typeMap[$account['type']] ?? $account['type']) ?></td>
<td>
<button class="btn btn-sm btn-info" onclick="editAccount(<?= $account['id'] ?>, '<?= htmlspecialchars($account['name']) ?>', '<?= $account['type'] ?>')">
<i class="fas fa-pencil-alt"></i>
</button>
<form method="POST" onsubmit="return confirm('هل أنت متأكد؟');" style="display:inline;">
<input type="hidden" name="delete_account" value="1">
<input type="hidden" name="id" value="<?= $account['id'] ?>">
<button type="submit" class="btn btn-danger btn-sm"><i class="fas fa-trash-alt"></i></button>
</form>
</td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
<nav>
<ul class="pagination">
<?php for ($i = 1; $i <= $totalPages; $i++): ?>
<li class="page-item <?= $i == $page ? 'active' : '' ?>"><a class="page-link" href="?p=<?= $i ?>"><?= $i ?></a></li>
<?php endfor; ?>
</ul>
</nav>
</div> </div>
<script>
function editAccount(id, name, type) {
document.getElementById('formAction').name = 'edit_account';
document.getElementById('editId').value = id;
document.getElementById('editName').value = name;
document.getElementById('editType').value = type;
document.getElementById('formButton').innerText = 'تعديل';
window.scrollTo({top: 0, behavior: 'smooth'});
}
</script>
<?php require_once 'includes/footer.php'; ?> <?php require_once 'includes/footer.php'; ?>

View File

@ -0,0 +1,12 @@
<?php
require_once 'db/config.php';
try {
$db = db();
// Allow for longer Arabic type names
$db->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();
}
?>

View File

@ -34,9 +34,11 @@ function get_balance_sheet() {
LEFT JOIN accounting_entries e ON a.name = e.account_name LEFT JOIN accounting_entries e ON a.name = e.account_name
GROUP BY a.name, a.type"); GROUP BY a.name, a.type");
$data = $stmt->fetchAll(PDO::FETCH_ASSOC); $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) { foreach($data as $row) {
$sheet[$row['type']] += $row['balance']; if (isset($sheet[$row['type']])) {
$sheet[$row['type']] += $row['balance'];
}
} }
return $sheet; return $sheet;
} }
@ -64,4 +66,4 @@ function add_journal_entry($date, $description, $reference, $entries) {
return false; return false;
} }
} }
?> ?>

View File

@ -1,25 +1,25 @@
<?php <?php
require_once __DIR__ . '/db/config.php'; require_once __DIR__ . '/../db/config.php';
$pdo = db(); $pdo = db();
$common_accounts = [ $common_accounts = [
['Cash', 'Assets'], ['النقدية', 'أصول'],
['Accounts Receivable', 'Assets'], ['حسابات القبض', 'أصول'],
['Inventory', 'Assets'], ['المخزون', 'أصول'],
['Fixed Assets', 'Assets'], ['الأصول الثابتة', 'أصول'],
['Accounts Payable', 'Liabilities'], ['حسابات الدفع', 'خصوم'],
['Short-term Loans', 'Liabilities'], ['قروض قصيرة الأجل', 'خصوم'],
['Long-term Loans', 'Liabilities'], ['قروض طويلة الأجل', 'خصوم'],
['Capital', 'Equity'], ['رأس المال', 'حقوق ملكية'],
['Retained Earnings', 'Equity'], ['الأرباح المحتجزة', 'حقوق ملكية'],
['Sales Revenue', 'Revenue'], ['إيرادات المبيعات', 'إيرادات'],
['Other Revenue', 'Revenue'], ['إيرادات أخرى', 'إيرادات'],
['Cost of Goods Sold', 'Expenses'], ['تكلفة البضاعة المباعة', 'مصروفات'],
['Salaries Expense', 'Expenses'], ['مصروفات الرواتب', 'مصروفات'],
['Rent Expense', 'Expenses'], ['مصروفات الإيجار', 'مصروفات'],
['Utilities Expense', 'Expenses'], ['مصروفات المرافق', 'مصروفات'],
['Marketing Expense', 'Expenses'] ['مصروفات التسويق', 'مصروفات']
]; ];
$stmt = $pdo->prepare("INSERT IGNORE INTO accounting_accounts (name, type) VALUES (?, ?)"); $stmt = $pdo->prepare("INSERT IGNORE INTO accounting_accounts (name, type) VALUES (?, ?)");
@ -28,5 +28,4 @@ foreach ($common_accounts as $account) {
$stmt->execute($account); $stmt->execute($account);
} }
echo "Common accounts have been added."; echo "تمت إضافة الحسابات الشائعة بنجاح.";
?>