[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: manage.php
<?php require_once '../config/database.php'; require_once '../config/functions.php'; requireAuth('accountant'); // Get pending shift requests $stmt = $pdo->prepare(" SELECT s.*, u.full_name as representative_name, u.phone as representative_phone FROM shifts s JOIN users u ON s.representative_id = u.id WHERE s.status IN ('requested', 'end_requested') ORDER BY s.start_requested_at DESC "); $stmt->execute(); $pending_shifts = $stmt->fetchAll(); // Get active shifts $stmt = $pdo->prepare(" SELECT s.*, u.full_name as representative_name, u.phone as representative_phone FROM shifts s JOIN users u ON s.representative_id = u.id WHERE s.status = 'active' ORDER BY s.started_at DESC "); $stmt->execute(); $active_shifts = $stmt->fetchAll(); // Get all products for assignment $stmt = $pdo->prepare("SELECT * FROM products WHERE is_active = 1 ORDER BY name ASC"); $stmt->execute(); $products = $stmt->fetchAll(); $error = ''; $success = ''; // Handle shift actions if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; $shift_id = $_POST['shift_id'] ?? ''; if (!$shift_id) { $error = 'معرف الوردية مطلوب'; } else { try { $pdo->beginTransaction(); if ($action === 'approve_start') { $opening_cash = floatval($_POST['opening_cash'] ?? 0); $product_quantities = $_POST['product_quantities'] ?? []; // Update shift status $stmt = $pdo->prepare(" UPDATE shifts SET status = 'active', started_at = NOW(), started_by = ?, opening_cash = ? WHERE id = ? AND status = 'requested' "); $stmt->execute([$_SESSION['user_id'], $opening_cash, $shift_id]); if ($stmt->rowCount() === 0) { throw new Exception('الوردية غير موجودة أو تم الموافقة عليها مسبقاً'); } // Assign products to shift foreach ($product_quantities as $product_id => $quantity) { $quantity = floatval($quantity); if ($quantity > 0) { $stmt = $pdo->prepare(" INSERT INTO shift_products (shift_id, product_id, assigned_quantity, remaining_quantity) VALUES (?, ?, ?, ?) "); $stmt->execute([$shift_id, $product_id, $quantity, $quantity]); } } addAuditLog($pdo, $_SESSION['user_id'], 'approve_shift_start', 'shift', $shift_id, ['status' => 'requested'], ['status' => 'active'], "الموافقة على بدء الوردية"); $success = 'تم الموافقة على بدء الوردية بنجاح'; } elseif ($action === 'reject_start') { $rejection_reason = trim($_POST['rejection_reason'] ?? ''); $stmt = $pdo->prepare(" UPDATE shifts SET status = 'rejected', notes = CONCAT(COALESCE(notes, ''), '\n\nسبب الرفض: ', ?) WHERE id = ? AND status = 'requested' "); $stmt->execute([$rejection_reason, $shift_id]); addAuditLog($pdo, $_SESSION['user_id'], 'reject_shift_start', 'shift', $shift_id, ['status' => 'requested'], ['status' => 'rejected'], "رفض بدء الوردية: $rejection_reason"); $success = 'تم رفض طلب بدء الوردية'; } elseif ($action === 'approve_end') { $closing_cash = floatval($_POST['closing_cash'] ?? 0); $stmt = $pdo->prepare(" UPDATE shifts SET status = 'closed', ended_at = NOW(), ended_by = ?, closing_cash = ? WHERE id = ? AND status = 'end_requested' "); $stmt->execute([$_SESSION['user_id'], $closing_cash, $shift_id]); addAuditLog($pdo, $_SESSION['user_id'], 'approve_shift_end', 'shift', $shift_id, ['status' => 'end_requested'], ['status' => 'closed'], "الموافقة على إنهاء الوردية"); $success = 'تم إنهاء الوردية بنجاح'; } elseif ($action === 'reject_end') { $rejection_reason = trim($_POST['rejection_reason'] ?? ''); $stmt = $pdo->prepare(" UPDATE shifts SET status = 'active', notes = CONCAT(COALESCE(notes, ''), '\n\nسبب رفض الإنهاء: ', ?) WHERE id = ? AND status = 'end_requested' "); $stmt->execute([$rejection_reason, $shift_id]); addAuditLog($pdo, $_SESSION['user_id'], 'reject_shift_end', 'shift', $shift_id, ['status' => 'end_requested'], ['status' => 'active'], "رفض إنهاء الوردية: $rejection_reason"); $success = 'تم رفض طلب إنهاء الوردية'; } $pdo->commit(); // Refresh data header("Location: /shifts/manage.php?success=" . urlencode($success)); exit; } catch (Exception $e) { $pdo->rollBack(); $error = $e->getMessage(); } } } if (isset($_GET['success'])) { $success = $_GET['success']; } ?> <!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> .shift-card { border-radius: 15px; transition: all 0.3s ease; } .shift-card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.1); } .status-requested { border-left: 5px solid #ffc107; } .status-end-requested { border-left: 5px solid #fd7e14; } .status-active { border-left: 5px solid #198754; } .product-assignment { background: #f8f9fa; border-radius: 10px; padding: 15px; margin-top: 15px; } </style> </head> <body class="bg-light"> <div class="container-fluid mt-4"> <div class="d-flex justify-content-between align-items-center mb-4"> <h2><i class="fas fa-user-clock 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; ?> <!-- Pending Requests --> <div class="row mb-4"> <div class="col-12"> <div class="card"> <div class="card-header bg-warning text-dark"> <h5 class="mb-0"> <i class="fas fa-clock me-2"></i> الطلبات المعلقة (<?= count($pending_shifts) ?>) </h5> </div> <div class="card-body"> <?php if (empty($pending_shifts)): ?> <div class="text-center text-muted py-4"> <i class="fas fa-check-circle fa-3x mb-3"></i> <p>لا توجد طلبات معلقة</p> </div> <?php else: ?> <div class="row"> <?php foreach ($pending_shifts as $shift): ?> <div class="col-md-6 mb-3"> <div class="shift-card card status-<?= $shift['status'] === 'requested' ? 'requested' : 'end-requested' ?>"> <div class="card-body"> <div class="d-flex justify-content-between align-items-start mb-3"> <div> <h6 class="card-title"><?= htmlspecialchars($shift['representative_name']) ?></h6> <small class="text-muted"><?= htmlspecialchars($shift['representative_phone']) ?></small> </div> <span class="badge bg-<?= $shift['status'] === 'requested' ? 'warning' : 'info' ?>"> <?= $shift['status'] === 'requested' ? 'طلب بدء' : 'طلب إنهاء' ?> </span> </div> <div class="mb-3"> <small class="text-muted"> <?= $shift['status'] === 'requested' ? 'طلب البدء:' : 'طلب الإنهاء:' ?> <?= date('Y-m-d H:i', strtotime($shift['status'] === 'requested' ? $shift['start_requested_at'] : $shift['end_requested_at'])) ?> </small> </div> <?php if ($shift['notes']): ?> <div class="mb-3"> <small class="text-muted">الملاحظات:</small> <p class="small"><?= nl2br(htmlspecialchars($shift['notes'])) ?></p> </div> <?php endif; ?> <?php if ($shift['status'] === 'requested'): ?> <!-- Start Shift Approval --> <form method="POST" class="mb-2"> <input type="hidden" name="shift_id" value="<?= $shift['id'] ?>"> <input type="hidden" name="action" value="approve_start"> <div class="mb-3"> <label class="form-label">النقد الافتتاحي</label> <input type="number" class="form-control form-control-sm" name="opening_cash" step="0.01" value="0" required> </div> <div class="product-assignment"> <h6>تخصيص المنتجات</h6> <div class="row"> <?php foreach ($products as $product): ?> <div class="col-md-6 mb-2"> <label class="form-label small"><?= htmlspecialchars($product['name']) ?></label> <input type="number" class="form-control form-control-sm" name="product_quantities[<?= $product['id'] ?>]" step="0.01" min="0" placeholder="0"> </div> <?php endforeach; ?> </div> </div> <div class="d-flex gap-2 mt-3"> <button type="submit" class="btn btn-success btn-sm"> <i class="fas fa-check me-1"></i>موافقة </button> </div> </form> <form method="POST" class="d-inline"> <input type="hidden" name="shift_id" value="<?= $shift['id'] ?>"> <input type="hidden" name="action" value="reject_start"> <div class="input-group input-group-sm mb-2"> <input type="text" class="form-control" name="rejection_reason" placeholder="سبب الرفض" required> <button type="submit" class="btn btn-danger"> <i class="fas fa-times me-1"></i>رفض </button> </div> </form> <?php else: // end_requested ?> <!-- End Shift Approval --> <form method="POST" class="mb-2"> <input type="hidden" name="shift_id" value="<?= $shift['id'] ?>"> <input type="hidden" name="action" value="approve_end"> <div class="mb-3"> <label class="form-label">النقد الختامي</label> <input type="number" class="form-control form-control-sm" name="closing_cash" step="0.01" value="0" required> </div> <div class="d-flex gap-2"> <button type="submit" class="btn btn-success btn-sm"> <i class="fas fa-check me-1"></i>إنهاء الوردية </button> </div> </form> <form method="POST" class="d-inline"> <input type="hidden" name="shift_id" value="<?= $shift['id'] ?>"> <input type="hidden" name="action" value="reject_end"> <div class="input-group input-group-sm"> <input type="text" class="form-control" name="rejection_reason" placeholder="سبب رفض الإنهاء" required> <button type="submit" class="btn btn-warning"> <i class="fas fa-times me-1"></i>رفض الإنهاء </button> </div> </form> <?php endif; ?> </div> </div> </div> <?php endforeach; ?> </div> <?php endif; ?> </div> </div> </div> </div> <!-- Active Shifts --> <div class="row"> <div class="col-12"> <div class="card"> <div class="card-header bg-success text-white"> <h5 class="mb-0"> <i class="fas fa-play-circle me-2"></i> الورديات النشطة (<?= count($active_shifts) ?>) </h5> </div> <div class="card-body"> <?php if (empty($active_shifts)): ?> <div class="text-center text-muted py-4"> <i class="fas fa-pause-circle fa-3x mb-3"></i> <p>لا توجد ورديات نشطة</p> </div> <?php else: ?> <div class="row"> <?php foreach ($active_shifts as $shift): ?> <div class="col-md-4 mb-3"> <div class="shift-card card status-active"> <div class="card-body"> <h6 class="card-title"><?= htmlspecialchars($shift['representative_name']) ?></h6> <p class="card-text"> <small class="text-muted"> بدأت: <?= date('Y-m-d H:i', strtotime($shift['started_at'])) ?> </small> </p> <div class="d-flex justify-content-between text-center"> <div> <small class="text-muted">المبيعات</small> <div class="fw-bold"><?= formatCurrency($shift['total_sales']) ?></div> </div> <div> <small class="text-muted">المدفوعات</small> <div class="fw-bold"><?= formatCurrency($shift['total_payments']) ?></div> </div> </div> <div class="mt-2"> <a href="/shifts/details.php?id=<?= $shift['id'] ?>" class="btn btn-outline-success btn-sm w-100"> <i class="fas fa-eye me-1"></i>عرض التفاصيل </a> </div> </div> </div> </div> <?php endforeach; ?> </div> <?php endif; ?> </div> </div> </div> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></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