[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: create.php
<?php require_once '../config/database.php'; require_once '../config/functions.php'; requireAuth('representative'); // Check if user has active shift $active_shift = getActiveShift($pdo, $_SESSION['user_id']); if (!$active_shift) { header("Location: /shifts/request_start.php?error=no_active_shift"); exit; } // Get clients with outstanding debts $stmt = $pdo->prepare("SELECT * FROM clients WHERE balance > 0 ORDER BY name ASC"); $stmt->execute(); $clients = $stmt->fetchAll(); $error = ''; $success = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $client_id = $_POST['client_id'] ?? ''; $amount = floatval($_POST['amount'] ?? 0); if (!$client_id) { $error = 'يرجى اختيار العميل'; } elseif ($amount <= 0) { $error = 'مبلغ الدفعة يجب أن يكون أكبر من صفر'; } else { try { $pdo->beginTransaction(); // Get client current balance $stmt = $pdo->prepare("SELECT balance FROM clients WHERE id = ?"); $stmt->execute([$client_id]); $client = $stmt->fetch(); if (!$client) { throw new Exception('العميل غير موجود'); } $previous_balance = $client['balance']; if ($amount > $previous_balance) { throw new Exception("مبلغ الدفعة ($amount جنيه) أكبر من الرصيد المديون ($previous_balance جنيه)"); } $new_balance = $previous_balance - $amount; // Apply payment to oldest invoices (FIFO) $applied_invoices = applyPaymentToInvoices($pdo, $client_id, $amount); // Generate receipt number $receipt_number = generateReceiptNumber(); // Insert payment record $stmt = $pdo->prepare(" INSERT INTO payments (receipt_number, client_id, representative_id, shift_id, amount, previous_balance, new_balance, payment_type) VALUES (?, ?, ?, ?, ?, ?, ?, 'cash') "); $stmt->execute([ $receipt_number, $client_id, $_SESSION['user_id'], $active_shift['id'], $amount, $previous_balance, $new_balance ]); $payment_id = $pdo->lastInsertId(); // Update client balance $stmt = $pdo->prepare("UPDATE clients SET balance = ? WHERE id = ?"); $stmt->execute([$new_balance, $client_id]); // Update shift total payments $stmt = $pdo->prepare(" UPDATE shifts SET total_payments = total_payments + ? WHERE id = ? "); $stmt->execute([$amount, $active_shift['id']]); // Add audit log addAuditLog($pdo, $_SESSION['user_id'], 'create_payment', 'payment', $payment_id, null, [ 'receipt_number' => $receipt_number, 'client_id' => $client_id, 'amount' => $amount, 'applied_invoices' => $applied_invoices ], "تسجيل دفعة رقم $receipt_number بقيمة $amount جنيه"); $pdo->commit(); // Redirect to print page header("Location: /payments/print.php?id=$payment_id"); exit; } catch (Exception $e) { $pdo->rollBack(); $error = $e->getMessage(); } } } ?> <!DOCTYPE html> <html lang="ar" dir="rtl"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>تسجيل دفعة - حسابات عربية بن فريش</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.rtl.min.css" rel="stylesheet"> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet"> <style> .client-card { cursor: pointer; transition: all 0.3s ease; border: 2px solid transparent; } .client-card:hover { border-color: #0d6efd; transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.1); } .client-card.selected { border-color: #198754; background-color: #f8f9fa; } .debt-amount { font-size: 1.2rem; font-weight: bold; color: #dc3545; } .payment-summary { background: linear-gradient(135deg, #198754, #20c997); color: white; border-radius: 15px; } </style> </head> <body class="bg-light"> <div class="container mt-4"> <div class="d-flex justify-content-between align-items-center mb-4"> <h2><i class="fas fa-money-bill me-2"></i>تسجيل دفعة</h2> <a href="/dashboard.php" class="btn btn-outline-secondary"> <i class="fas fa-arrow-left me-1"></i>العودة </a> </div> <?php if ($error): ?> <div class="alert alert-danger" role="alert"> <i class="fas fa-exclamation-triangle me-2"></i><?= htmlspecialchars($error) ?> </div> <?php endif; ?> <?php if (empty($clients)): ?> <div class="alert alert-info text-center"> <h4><i class="fas fa-info-circle me-2"></i>لا توجد مديونيات</h4> <p>جميع العملاء لا يوجد عليهم مديونية حالياً</p> <a href="/invoices/create.php" class="btn btn-primary">إنشاء فاتورة جديدة</a> </div> <?php else: ?> <form method="POST" id="paymentForm"> <div class="row"> <div class="col-md-8"> <div class="card"> <div class="card-header bg-primary text-white"> <h5 class="mb-0">اختر العميل</h5> </div> <div class="card-body"> <div class="row"> <?php foreach ($clients as $client): ?> <div class="col-md-6 mb-3"> <div class="client-card card h-100" onclick="selectClient(<?= $client['id'] ?>, '<?= htmlspecialchars($client['name']) ?>', <?= $client['balance'] ?>, '<?= htmlspecialchars($client['phone']) ?>')"> <div class="card-body"> <h6 class="card-title"><?= htmlspecialchars($client['name']) ?></h6> <p class="card-text"> <i class="fas fa-phone me-1"></i><?= htmlspecialchars($client['phone']) ?> </p> <div class="debt-amount"> المديونية: <?= formatCurrency($client['balance']) ?> </div> </div> </div> </div> <?php endforeach; ?> </div> <input type="hidden" id="client_id" name="client_id" required> </div> </div> </div> <div class="col-md-4"> <div class="card"> <div class="card-header bg-success text-white"> <h5 class="mb-0">تفاصيل الدفعة</h5> </div> <div class="card-body"> <div id="payment_details" class="d-none"> <div class="mb-3"> <label class="form-label">العميل المحدد</label> <div class="form-control bg-light" id="selected_client_name">لم يتم اختيار عميل</div> </div> <div class="mb-3"> <label class="form-label">المديونية الحالية</label> <div class="form-control bg-light debt-amount" id="current_debt">0.00 جنيه</div> </div> <div class="mb-3"> <label for="amount" class="form-label">مبلغ الدفعة *</label> <input type="number" class="form-control form-control-lg" id="amount" name="amount" min="0.01" step="0.01" placeholder="0.00" onchange="updatePaymentSummary()" required> </div> <div class="payment-summary p-3 mb-3" id="payment_summary" style="display: none;"> <h6>ملخص الدفعة</h6> <div class="d-flex justify-content-between"> <span>المبلغ المدفوع:</span> <span id="amount_display">0.00 جنيه</span> </div> <div class="d-flex justify-content-between"> <span>الرصيد السابق:</span> <span id="prev_balance_display">0.00 جنيه</span> </div> <hr> <div class="d-flex justify-content-between"> <strong>الرصيد الجديد:</strong> <strong id="new_balance_display">0.00 جنيه</strong> </div> </div> <button type="submit" class="btn btn-success btn-lg w-100"> <i class="fas fa-save me-2"></i>تسجيل الدفعة </button> </div> <div id="no_client_selected" class="text-center text-muted"> <i class="fas fa-hand-pointer fa-3x mb-3"></i> <p>اختر العميل أولاً</p> </div> </div> </div> </div> </div> </form> <?php endif; ?> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script> let selectedClientBalance = 0; function selectClient(clientId, clientName, balance, phone) { // Clear previous selection document.querySelectorAll('.client-card').forEach(card => { card.classList.remove('selected'); }); // Mark this card as selected event.currentTarget.classList.add('selected'); // Update form document.getElementById('client_id').value = clientId; document.getElementById('selected_client_name').textContent = clientName; document.getElementById('current_debt').textContent = balance.toFixed(2) + ' جنيه'; selectedClientBalance = balance; // Set max amount document.getElementById('amount').setAttribute('max', balance); // Show payment details document.getElementById('payment_details').classList.remove('d-none'); document.getElementById('no_client_selected').style.display = 'none'; // Clear amount input document.getElementById('amount').value = ''; document.getElementById('payment_summary').style.display = 'none'; } function updatePaymentSummary() { const amount = parseFloat(document.getElementById('amount').value || 0); if (amount > 0) { const newBalance = selectedClientBalance - amount; document.getElementById('amount_display').textContent = amount.toFixed(2) + ' جنيه'; document.getElementById('prev_balance_display').textContent = selectedClientBalance.toFixed(2) + ' جنيه'; document.getElementById('new_balance_display').textContent = newBalance.toFixed(2) + ' جنيه'; document.getElementById('payment_summary').style.display = 'block'; } else { document.getElementById('payment_summary').style.display = 'none'; } } // Validate amount on input document.getElementById('amount').addEventListener('input', function() { const amount = parseFloat(this.value || 0); if (amount > selectedClientBalance) { alert(`المبلغ المدخل (${amount} جنيه) أكبر من المديونية (${selectedClientBalance} جنيه)`); this.value = selectedClientBalance.toFixed(2); } updatePaymentSummary(); }); </script> </body> </html>
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium320.web-hosting.com
Server IP: 66.29.153.54
PHP Version: 8.2.29
Server Software: LiteSpeed
System: Linux premium320.web-hosting.com 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 76.87 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: aoneqssk
User ID (UID): 1285
Group ID (GID): 1290
Script Owner UID: 1285
Current Dir Owner: 1285