Autosave: 20260311-183230
This commit is contained in:
parent
6ede6271b7
commit
813c9596f7
@ -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();
|
||||
?>
|
||||
|
||||
<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">
|
||||
<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-body">
|
||||
<h5>الأصول</h5>
|
||||
<h3><?= number_format($balance_sheet['Assets'], 2) ?></h3>
|
||||
<h3><?= number_format($balance_sheet['أصول'], 2) ?></h3>
|
||||
</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-body">
|
||||
<h5>الخصوم</h5>
|
||||
<h3><?= number_format($balance_sheet['Liabilities'], 2) ?></h3>
|
||||
<h3><?= number_format($balance_sheet['خصوم'], 2) ?></h3>
|
||||
</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-body">
|
||||
<h5>حقوق الملكية</h5>
|
||||
<h3><?= number_format($balance_sheet['Equity'], 2) ?></h3>
|
||||
<h3><?= number_format($balance_sheet['حقوق ملكية'], 2) ?></h3>
|
||||
</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-body">
|
||||
<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>
|
||||
@ -97,7 +110,7 @@ $balance_sheet = get_balance_sheet();
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<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): ?>
|
||||
<option value="<?= htmlspecialchars($acc['name']) ?>"><?= htmlspecialchars($acc['name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
@ -139,8 +152,29 @@ $balance_sheet = get_balance_sheet();
|
||||
</tbody>
|
||||
</table>
|
||||
</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>
|
||||
|
||||
<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'; ?>
|
||||
112
accounts.php
112
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' => 'مصروفات',
|
||||
'أصول' => 'أصول',
|
||||
'خصوم' => 'خصوم',
|
||||
'حقوق ملكية' => 'حقوق ملكية',
|
||||
'إيرادات' => 'إيرادات',
|
||||
'مصروفات' => 'مصروفات'
|
||||
];
|
||||
?>
|
||||
|
||||
<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>"; ?>
|
||||
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">إضافة حساب جديد</div>
|
||||
<div class="card-header">إضافة/تعديل حساب</div>
|
||||
<div class="card-body">
|
||||
<form method="POST">
|
||||
<input type="hidden" name="add_account" value="1">
|
||||
<form method="POST" id="accountForm">
|
||||
<input type="hidden" name="add_account" value="1" id="formAction">
|
||||
<input type="hidden" name="id" id="editId">
|
||||
<div class="row">
|
||||
<div class="col-md-5">
|
||||
<label>اسم الحساب</label>
|
||||
<input type="text" name="name" class="form-control" required>
|
||||
<input type="text" name="name" class="form-control" id="editName" required>
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<label>نوع الحساب</label>
|
||||
<select name="type" class="form-control" required>
|
||||
<option value="Assets">أصول (Assets)</option>
|
||||
<option value="Liabilities">خصوم (Liabilities)</option>
|
||||
<option value="Equity">حقوق ملكية (Equity)</option>
|
||||
<option value="Revenue">إيرادات (Revenue)</option>
|
||||
<option value="Expenses">مصروفات (Expenses)</option>
|
||||
<select name="type" class="form-control" id="editType" required>
|
||||
<option value="أصول">أصول</option>
|
||||
<option value="خصوم">خصوم</option>
|
||||
<option value="حقوق ملكية">حقوق ملكية</option>
|
||||
<option value="إيرادات">إيرادات</option>
|
||||
<option value="مصروفات">مصروفات</option>
|
||||
</select>
|
||||
</div>
|
||||
<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>
|
||||
</form>
|
||||
@ -59,16 +100,45 @@ $accounts = db()->query("SELECT * FROM accounting_accounts ORDER BY type, name")
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<?php foreach ($accounts as $account): ?>
|
||||
<tr>
|
||||
<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>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</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>
|
||||
|
||||
<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'; ?>
|
||||
|
||||
12
db/migrations/fix_accounting_accounts_type.php
Normal file
12
db/migrations/fix_accounting_accounts_type.php
Normal 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();
|
||||
}
|
||||
?>
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
||||
@ -1,25 +1,25 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
require_once __DIR__ . '/../db/config.php';
|
||||
|
||||
$pdo = db();
|
||||
|
||||
$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 (?, ?)");
|
||||
@ -28,5 +28,4 @@ foreach ($common_accounts as $account) {
|
||||
$stmt->execute($account);
|
||||
}
|
||||
|
||||
echo "Common accounts have been added.";
|
||||
?>
|
||||
echo "تمت إضافة الحسابات الشائعة بنجاح.";
|
||||
Loading…
x
Reference in New Issue
Block a user