(int)$customer['id'],
'customer_name' => $customer['title'],
'amount' => $amount,
'payment_method' => $method,
'payment_method_label' => payment_method_label($method),
'notes' => $notes,
'created_date' => date('Y-m-d H:i'),
'created_by' => current_user()['username'] ?? 'system',
],
'posted'
);
set_flash('success', 'تم ترحيل مقبوضات العميل بنجاح.');
redirect('accounting.php');
}
}
if ($action === 'supplier_payment') {
$supplierId = (int)($_POST['supplier_id'] ?? 0);
$amount = (float)($_POST['amount'] ?? 0);
$method = (string)($_POST['payment_method'] ?? 'bank_transfer');
$notes = trim((string)($_POST['notes'] ?? ''));
$supplier = fetch_record('supplier', $supplierId);
if (!$supplier) {
$errors[] = 'اختر موردًا صحيحًا لتسجيل الدفعة.';
}
if ($amount <= 0) {
$errors[] = 'أدخل مبلغ دفعة أكبر من صفر.';
}
if (!array_key_exists($method, payment_method_options())) {
$errors[] = 'طريقة السداد غير صحيحة.';
}
if (!$errors && $supplier) {
create_record(
'supplier_payment',
'دفعة إلى ' . $supplier['title'],
next_code('SPAY', 'supplier_payment'),
[
'supplier_id' => (int)$supplier['id'],
'supplier_name' => $supplier['title'],
'amount' => $amount,
'payment_method' => $method,
'payment_method_label' => payment_method_label($method),
'notes' => $notes,
'created_date' => date('Y-m-d H:i'),
'created_by' => current_user()['username'] ?? 'system',
],
'posted'
);
set_flash('success', 'تم ترحيل دفعة المورد بنجاح.');
redirect('accounting.php');
}
}
if ($action === 'expense_entry') {
$title = trim((string)($_POST['title'] ?? ''));
$category = (string)($_POST['category'] ?? 'operations');
$amount = (float)($_POST['amount'] ?? 0);
$notes = trim((string)($_POST['notes'] ?? ''));
if ($title === '') {
$errors[] = 'أدخل اسم المصروف.';
}
if ($amount <= 0) {
$errors[] = 'أدخل مبلغ مصروف أكبر من صفر.';
}
if (!array_key_exists($category, expense_category_options())) {
$errors[] = 'تصنيف المصروف غير صحيح.';
}
if (!$errors) {
create_record(
'expense_entry',
$title,
next_code('EXP', 'expense_entry'),
[
'category' => $category,
'category_label' => expense_category_label($category),
'amount' => $amount,
'notes' => $notes,
'created_date' => date('Y-m-d H:i'),
'created_by' => current_user()['username'] ?? 'system',
],
'posted'
);
set_flash('success', 'تم ترحيل المصروف بنجاح.');
redirect('accounting.php');
}
}
}
$counts = fetch_counts();
$summary = accounting_summary();
$customerStatements = customer_statement_rows();
$supplierStatements = supplier_statement_rows();
$customerPayments = fetch_records('customer_payment');
$supplierPayments = fetch_records('supplier_payment');
$expenses = fetch_records('expense_entry');
$activity = recent_accounting_activity(10);
$customers = customer_dataset();
$suppliers = supplier_dataset();
render_header('المحاسبة والتقارير المالية', 'إدارة المقبوضات والمدفوعات والمصروفات وكشوف حساب العملاء والموردين مع مؤشرات ربح وتدفق نقدي.', 'accounting');
?>
تسحب هذه الصفحة الذمم المدينة من فواتير المبيعات، والذمم الدائنة من أوامر الشراء المستلمة، ثم تخصم منها المقبوضات والمدفوعات والمصروفات لتكوين صورة مالية فورية.محاسبة تشغيلية مرتبطة بالمبيعات والمشتريات.
تُخصم تلقائيًا من رصيد العميل المستحق.
تُخصم من الذمم الدائنة على المورد مباشرة.
يؤثر مباشرة على الربح المتوقع والتدفق النقدي.
الرصيد = فواتير المبيعات - المقبوضات المسجلة.
| العميل | الفواتير | المقبوضات | الرصيد |
|---|---|---|---|
| = e($row['name']) ?> = e($row['code']) ?> |
= e(format_money((float)$row['invoices'])) ?> | = e(format_money((float)$row['payments'])) ?> | = e(format_money((float)$row['balance'])) ?> |
الرصيد = مشتريات مستلمة - مدفوعات الموردين.
| المورد | المشتريات | المدفوعات | الرصيد |
|---|---|---|---|
| = e($row['name']) ?> = e($row['code']) ?> |
= e(format_money((float)$row['purchases'])) ?> | = e(format_money((float)$row['payments'])) ?> | = e(format_money((float)$row['balance'])) ?> |
يشمل المقبوضات والمدفوعات والمصروفات في سجل سريع.
آخر الحركات المالية المسجلة يدويًا داخل النظام.
| النوع | المرجع | الطرف | التفصيل | المبلغ |
|---|---|---|---|---|
| = e(match ((string)$row['record_type']) { 'customer_payment' => 'مقبوضات', 'supplier_payment' => 'مدفوعات', default => 'مصروف' }) ?> | = e($row['code']) ?> | = e($payload['customer_name'] ?? $payload['supplier_name'] ?? 'مصروف داخلي') ?> | = e($payload['payment_method_label'] ?? $payload['category_label'] ?? '') ?> = e($payload['notes']) ?> |
= e(format_money((float)($payload['amount'] ?? 0))) ?> |