[
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 $stmt = $pdo->prepare("SELECT * FROM clients ORDER BY name ASC"); $stmt->execute(); $clients = $stmt->fetchAll(); // Get products sold in this shift $stmt = $pdo->prepare(" SELECT DISTINCT p.id, p.name, p.unit, p.price FROM invoice_items ii JOIN invoices i ON ii.invoice_id = i.id JOIN products p ON ii.product_id = p.id WHERE i.shift_id = ? ORDER BY p.name ASC "); $stmt->execute([$active_shift['id']]); $available_products = $stmt->fetchAll(); $error = ''; $success = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $client_id = $_POST['client_id'] ?? ''; $product_id = $_POST['product_id'] ?? ''; $quantity = floatval($_POST['quantity'] ?? 0); $reason = trim($_POST['reason'] ?? ''); if (!$client_id) { $error = 'يرجى اختيار العميل'; } elseif (!$product_id) { $error = 'يرجى اختيار المنتج'; } elseif ($quantity <= 0) { $error = 'الكمية يجب أن تكون أكبر من صفر'; } elseif (!$reason) { $error = 'يرجى كتابة سبب المرتجع'; } else { try { // Get product info $stmt = $pdo->prepare("SELECT * FROM products WHERE id = ?"); $stmt->execute([$product_id]); $product = $stmt->fetch(); if (!$product) { throw new Exception('المنتج غير موجود'); } // Check if client bought this product in this shift $stmt = $pdo->prepare(" SELECT SUM(ii.quantity) as total_bought FROM invoice_items ii JOIN invoices i ON ii.invoice_id = i.id WHERE i.client_id = ? AND i.shift_id = ? AND ii.product_id = ? "); $stmt->execute([$client_id, $active_shift['id'], $product_id]); $bought_data = $stmt->fetch(); $total_bought = $bought_data['total_bought'] ?? 0; if ($quantity > $total_bought) { throw new Exception("الكمية المطلوب إرجاعها ($quantity) أكبر من الكمية المشتراة ($total_bought)"); } // Get client current balance $stmt = $pdo->prepare("SELECT balance FROM clients WHERE id = ?"); $stmt->execute([$client_id]); $client = $stmt->fetch(); $client_balance_before = $client['balance']; $return_value = $quantity * $product['price']; $return_number = generateReturnNumber(); // Insert return request $stmt = $pdo->prepare(" INSERT INTO returns (return_number, client_id, representative_id, shift_id, product_id, quantity, unit_price, return_value, reason, client_balance_before, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending') "); $stmt->execute([ $return_number, $client_id, $_SESSION['user_id'], $active_shift['id'], $product_id, $quantity, $product['price'], $return_value, $reason, $client_balance_before ]); $return_id = $pdo->lastInsertId(); // Add audit log addAuditLog($pdo, $_SESSION['user_id'], 'create_return', 'return', $return_id, null, [ 'return_number' => $return_number, 'client_id' => $client_id, 'product_id' => $product_id, 'quantity' => $quantity, 'value' => $return_value, 'reason' => $reason ], "طلب مرتجع رقم $return_number"); $success = "تم إرسال طلب المرتجع رقم $return_number بنجاح. سيتم مراجعته من قبل الإدارة."; // Clear form $_POST = []; } catch (Exception $e) { $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> .return-card { background: linear-gradient(135deg, #fd7e14, #ffc107); color: white; border-radius: 15px; } .client-info { background: #f8f9fa; border-radius: 10px; padding: 15px; margin-bottom: 20px; } .product-info { background: #e3f2fd; border-radius: 10px; padding: 15px; margin-bottom: 20px; } </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-undo 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 ($success): ?> <div class="alert alert-success" role="alert"> <i class="fas fa-check-circle me-2"></i><?= htmlspecialchars($success) ?> </div> <?php endif; ?> <div class="row"> <div class="col-md-8 mx-auto"> <div class="return-card p-4 mb-4"> <h4 class="text-center mb-4"> <i class="fas fa-exclamation-triangle me-2"></i> طلب إرجاع منتج </h4> <p class="text-center mb-0"> يرجى ملء البيانات بدقة. سيتم مراجعة الطلب من قبل الإدارة. </p> </div> <form method="POST" id="returnForm"> <div class="card"> <div class="card-header bg-warning text-dark"> <h5 class="mb-0">بيانات المرتجع</h5> </div> <div class="card-body"> <div class="row mb-3"> <div class="col-md-6"> <label for="client_id" class="form-label">العميل *</label> <select class="form-select" id="client_id" name="client_id" required onchange="loadClientProducts()"> <option value="">اختر العميل</option> <?php foreach ($clients as $client): ?> <option value="<?= $client['id'] ?>" data-phone="<?= htmlspecialchars($client['phone']) ?>" data-balance="<?= $client['balance'] ?>" <?= ($_POST['client_id'] ?? '') == $client['id'] ? 'selected' : '' ?>> <?= htmlspecialchars($client['name']) ?> </option> <?php endforeach; ?> </select> </div> <div class="col-md-6"> <label class="form-label">رصيد العميل الحالي</label> <div class="form-control bg-light" id="client_balance">اختر العميل أولاً</div> </div> </div> <div id="client_info" class="client-info d-none"> <h6><i class="fas fa-user me-2"></i>معلومات العميل</h6> <div class="row"> <div class="col-md-6"> <strong>الهاتف:</strong> <span id="client_phone">-</span> </div> <div class="col-md-6"> <strong>الرصيد:</strong> <span id="client_balance_display">-</span> </div> </div> </div> <div class="row mb-3"> <div class="col-md-6"> <label for="product_id" class="form-label">المنتج *</label> <select class="form-select" id="product_id" name="product_id" required onchange="updateProductInfo()"> <option value="">اختر المنتج</option> <?php foreach ($available_products as $product): ?> <option value="<?= $product['id'] ?>" data-price="<?= $product['price'] ?>" data-unit="<?= htmlspecialchars($product['unit']) ?>" <?= ($_POST['product_id'] ?? '') == $product['id'] ? 'selected' : '' ?>> <?= htmlspecialchars($product['name']) ?> - <?= formatCurrency($product['price']) ?> </option> <?php endforeach; ?> </select> </div> <div class="col-md-6"> <label for="quantity" class="form-label">الكمية *</label> <input type="number" class="form-control" id="quantity" name="quantity" min="0.01" step="0.01" placeholder="0" value="<?= htmlspecialchars($_POST['quantity'] ?? '') ?>" onchange="updateReturnValue()" required> <small class="text-muted" id="max_quantity"></small> </div> </div> <div id="product_info" class="product-info d-none"> <h6><i class="fas fa-box me-2"></i>معلومات المنتج</h6> <div class="row"> <div class="col-md-4"> <strong>السعر:</strong> <span id="product_price">-</span> </div> <div class="col-md-4"> <strong>الوحدة:</strong> <span id="product_unit">-</span> </div> <div class="col-md-4"> <strong>قيمة المرتجع:</strong> <span id="return_value">0.00 جنيه</span> </div> </div> </div> <div class="mb-4"> <label for="reason" class="form-label">سبب المرتجع *</label> <textarea class="form-control" id="reason" name="reason" rows="4" placeholder="اكتب سبب طلب إرجاع المنتج بالتفصيل..." required><?= htmlspecialchars($_POST['reason'] ?? '') ?></textarea> </div> <div class="text-center"> <button type="submit" class="btn btn-warning btn-lg me-3"> <i class="fas fa-paper-plane me-2"></i>إرسال طلب المرتجع </button> <a href="/dashboard.php" class="btn btn-secondary btn-lg"> <i class="fas fa-times me-2"></i>إلغاء </a> </div> </div> </div> </form> </div> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script> const shiftId = <?= $active_shift['id'] ?>; // Update client info when client is selected document.getElementById('client_id').addEventListener('change', function() { const selectedOption = this.options[this.selectedIndex]; if (selectedOption.value) { const phone = selectedOption.getAttribute('data-phone'); const balance = parseFloat(selectedOption.getAttribute('data-balance') || 0); document.getElementById('client_phone').textContent = phone; document.getElementById('client_balance_display').textContent = balance.toFixed(2) + ' جنيه'; document.getElementById('client_balance').textContent = balance.toFixed(2) + ' جنيه'; document.getElementById('client_info').classList.remove('d-none'); loadClientProducts(); } else { document.getElementById('client_info').classList.add('d-none'); document.getElementById('client_balance').textContent = 'اختر العميل أولاً'; } }); function loadClientProducts() { const clientId = document.getElementById('client_id').value; if (!clientId) return; // This would typically load products bought by this client via AJAX // For now, we'll use the available products } function updateProductInfo() { const select = document.getElementById('product_id'); const selectedOption = select.options[select.selectedIndex]; if (selectedOption.value) { const price = parseFloat(selectedOption.getAttribute('data-price') || 0); const unit = selectedOption.getAttribute('data-unit') || ''; document.getElementById('product_price').textContent = price.toFixed(2) + ' جنيه'; document.getElementById('product_unit').textContent = unit; document.getElementById('product_info').classList.remove('d-none'); updateReturnValue(); } else { document.getElementById('product_info').classList.add('d-none'); } } function updateReturnValue() { const select = document.getElementById('product_id'); const selectedOption = select.options[select.selectedIndex]; const quantity = parseFloat(document.getElementById('quantity').value || 0); if (selectedOption.value && quantity > 0) { const price = parseFloat(selectedOption.getAttribute('data-price') || 0); const returnValue = price * quantity; document.getElementById('return_value').textContent = returnValue.toFixed(2) + ' جنيه'; } else { document.getElementById('return_value').textContent = '0.00 جنيه'; } } // Initialize if form has values document.addEventListener('DOMContentLoaded', function() { if (document.getElementById('client_id').value) { document.getElementById('client_id').dispatchEvent(new Event('change')); } if (document.getElementById('product_id').value) { updateProductInfo(); } }); </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.86 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