Autosave: 20260312-031128
This commit is contained in:
parent
b573f5ceaa
commit
cc73fe5d8d
@ -4,7 +4,12 @@ require_once 'includes/header.php';
|
|||||||
require_once 'includes/accounting_functions.php';
|
require_once 'includes/accounting_functions.php';
|
||||||
|
|
||||||
// Check permission
|
// Check permission
|
||||||
$user_id = $_SESSION['user_id'];
|
$user_id = $_SESSION['user_id'] ?? 0;
|
||||||
|
if (!$user_id) {
|
||||||
|
header('Location: login.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$stmt = db()->prepare("SELECT * FROM user_permissions WHERE user_id = ? AND page = 'accounting' AND can_view = 1");
|
$stmt = db()->prepare("SELECT * FROM user_permissions WHERE user_id = ? AND page = 'accounting' AND can_view = 1");
|
||||||
$stmt->execute([$user_id]);
|
$stmt->execute([$user_id]);
|
||||||
if (!$stmt->fetch()) {
|
if (!$stmt->fetch()) {
|
||||||
@ -14,7 +19,8 @@ if (!$stmt->fetch()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle form submission
|
// Handle form submission
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_entry'])) {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
if (isset($_POST['add_entry'])) {
|
||||||
$date = $_POST["date"] ?? "";
|
$date = $_POST["date"] ?? "";
|
||||||
$description = $_POST["description"] ?? "";
|
$description = $_POST["description"] ?? "";
|
||||||
$reference = $_POST["reference"] ?? "";
|
$reference = $_POST["reference"] ?? "";
|
||||||
@ -28,6 +34,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_entry'])) {
|
|||||||
} else {
|
} else {
|
||||||
$error = "حدث خطأ أثناء إضافة القيد.";
|
$error = "حدث خطأ أثناء إضافة القيد.";
|
||||||
}
|
}
|
||||||
|
} elseif (isset($_POST['delete_entry'])) {
|
||||||
|
$id_to_delete = (int)$_POST['delete_id'];
|
||||||
|
if (delete_journal_entry($id_to_delete)) {
|
||||||
|
$message = "تم حذف القيد بنجاح.";
|
||||||
|
} else {
|
||||||
|
$error = "حدث خطأ أثناء حذف القيد.";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pagination and Filtering setup
|
// Pagination and Filtering setup
|
||||||
@ -50,8 +64,7 @@ $ledger = array_slice($ledger_all, $offset, $limit);
|
|||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
||||||
<style>
|
<style>
|
||||||
.table td, .table th { padding: 0.3rem 0.5rem; }
|
.table td, .table th { padding: 0.3rem 0.5rem; }
|
||||||
.action-container { cursor: pointer; display: inline-block; padding: 5px; }
|
.action-icon { background: none; border: none; padding: 0; margin: 0; cursor: pointer; display: inline-block; }
|
||||||
.action-container i { pointer-events: none; }
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="container mt-4" dir="rtl">
|
<div class="container mt-4" dir="rtl">
|
||||||
@ -159,8 +172,15 @@ $ledger = array_slice($ledger_all, $offset, $limit);
|
|||||||
<td><?= number_format($row['debit'], 2) ?></td>
|
<td><?= number_format($row['debit'], 2) ?></td>
|
||||||
<td><?= number_format($row['credit'], 2) ?></td>
|
<td><?= number_format($row['credit'], 2) ?></td>
|
||||||
<td>
|
<td>
|
||||||
<span class="action-container text-warning me-2" title="تعديل" onclick="alert('تعديل القيد <?= $row["id"] ?>')"><i class="fas fa-edit"></i></span>
|
<button type="button" class="btn btn-sm btn-link text-warning p-0 me-2" title="تعديل" onclick="alert('ميزة تعديل القيود قيد التطوير.')"><i class="fas fa-edit"></i></button>
|
||||||
<span class="action-container text-danger" title="حذف" onclick="if(confirm('هل أنت متأكد؟')) alert('حذف القيد <?= $row["id"] ?>')"><i class="fas fa-trash"></i></span>
|
|
||||||
|
<form method="POST" class="d-inline" onsubmit="return confirm('هل أنت متأكد من حذف هذا القيد بشكل نهائي؟ (سيتم حذف القيد من جميع الحسابات المرتبطة)')">
|
||||||
|
<input type="hidden" name="delete_entry" value="1">
|
||||||
|
<input type="hidden" name="delete_id" value="<?= htmlspecialchars($row['id']) ?>">
|
||||||
|
<button type="submit" class="btn btn-sm btn-link text-danger p-0" title="حذف">
|
||||||
|
<i class="fas fa-trash"></i>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|||||||
2
accounting_temp.php
Normal file
2
accounting_temp.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<span class="my-custom-action text-warning me-2" title="تعديل" onclick='alert("تعديل القيد " + <?= json_encode($row["id"]) ?>)'><i class="fas fa-edit"></i></span>
|
||||||
|
<span class="my-custom-action text-danger" title="حذف" onclick='if(confirm("هل أنت متأكد؟")) alert("حذف القيد " + <?= json_encode($row["id"]) ?>)'><i class="fas fa-trash"></i></span>
|
||||||
@ -12,7 +12,7 @@ function get_journal_entries() {
|
|||||||
|
|
||||||
function get_full_ledger() {
|
function get_full_ledger() {
|
||||||
$db = db();
|
$db = db();
|
||||||
$stmt = $db->query("SELECT j.date, j.description, j.reference, e.account_name, e.debit, e.credit
|
$stmt = $db->query("SELECT j.id, j.date, j.description, j.reference, e.account_name, e.debit, e.credit
|
||||||
FROM accounting_journal j
|
FROM accounting_journal j
|
||||||
JOIN accounting_entries e ON j.id = e.journal_id
|
JOIN accounting_entries e ON j.id = e.journal_id
|
||||||
ORDER BY j.date DESC, j.id DESC");
|
ORDER BY j.date DESC, j.id DESC");
|
||||||
@ -21,7 +21,7 @@ function get_full_ledger() {
|
|||||||
|
|
||||||
function get_full_ledger_filtered($search = '', $date_from = '', $date_to = '') {
|
function get_full_ledger_filtered($search = '', $date_from = '', $date_to = '') {
|
||||||
$db = db();
|
$db = db();
|
||||||
$sql = "SELECT j.date, j.description, j.reference, e.account_name, e.debit, e.credit
|
$sql = "SELECT j.id, j.date, j.description, j.reference, e.account_name, e.debit, e.credit
|
||||||
FROM accounting_journal j
|
FROM accounting_journal j
|
||||||
JOIN accounting_entries e ON j.id = e.journal_id
|
JOIN accounting_entries e ON j.id = e.journal_id
|
||||||
WHERE 1=1";
|
WHERE 1=1";
|
||||||
@ -96,4 +96,22 @@ function add_journal_entry($date, $description, $reference, $entries) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function delete_journal_entry($id) {
|
||||||
|
$db = db();
|
||||||
|
$db->beginTransaction();
|
||||||
|
try {
|
||||||
|
$stmt = $db->prepare("DELETE FROM accounting_entries WHERE journal_id = ?");
|
||||||
|
$stmt->execute([$id]);
|
||||||
|
|
||||||
|
$stmt = $db->prepare("DELETE FROM accounting_journal WHERE id = ?");
|
||||||
|
$stmt->execute([$id]);
|
||||||
|
|
||||||
|
$db->commit();
|
||||||
|
return true;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$db->rollBack();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
Loading…
x
Reference in New Issue
Block a user