Commit 78d2ad89 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fdgfjdhfmghcm

parent d28573d7
......@@ -13,6 +13,7 @@ use App\Modules\ActivitySubscriptions\Services\ActivitySubscriptionService;
use App\Modules\ActivitySubscriptions\Services\ActivityPricingService;
use App\Modules\Payments\Services\PaymentService;
use App\Modules\Disciplines\Models\SportDiscipline;
use App\Modules\Academies\Models\Academy;
class ActivitySubscriptionController extends Controller
{
......@@ -180,11 +181,30 @@ class ActivitySubscriptionController extends Controller
$page = max(1, (int) $request->get('page', 1));
$result = ActivityPricing::search($filters, 25, $page);
// Build name lookup maps so the view shows real names instead of "#1"
$academies = Academy::allActive();
$disciplines = SportDiscipline::allActive();
$academyNames = [];
foreach ($academies as $a) {
$id = (int) ($a['id'] ?? $a->id ?? 0);
$academyNames[$id] = $a['name_ar'] ?? $a->name_ar ?? '';
}
$disciplineNames = [];
foreach ($disciplines as $d) {
$id = (int) ($d['id'] ?? $d->id ?? 0);
$disciplineNames[$id] = $d['name_ar'] ?? $d->name_ar ?? '';
}
return $this->view('ActivitySubscriptions.Views.pricing', [
'pricings' => $result['data'],
'pagination' => $result['pagination'],
'filters' => $filters,
'pricingTypes' => ActivityPricing::getPricingTypes(),
'pricings' => $result['data'],
'pagination' => $result['pagination'],
'filters' => $filters,
'pricingTypes' => ActivityPricing::getPricingTypes(),
'academyNames' => $academyNames,
'disciplineNames' => $disciplineNames,
'academies' => $academies,
'disciplines' => $disciplines,
]);
}
......
......@@ -10,6 +10,37 @@ $__template->layout('Layout.main');
<?php $__template->section('content'); ?>
<?php
// Build a helper to resolve reference_id → name
$refName = function(string $type, int $refId) use ($academyNames, $disciplineNames): string {
if ($type === 'academy') {
return $academyNames[$refId] ?? "أكاديمية #{$refId}";
}
if ($type === 'discipline') {
return $disciplineNames[$refId] ?? "نشاط #{$refId}";
}
return "#{$refId}";
};
// Find which academies/disciplines already have pricing
$existingRefs = [];
foreach (($pricings ?? []) as $p) {
$existingRefs[($p['pricing_type'] ?? '') . '_' . (int) ($p['reference_id'] ?? 0)] = true;
}
?>
<!-- Explanation Card -->
<div class="card" style="margin-bottom:20px;padding:20px;border-right:4px solid #0D7377;">
<div style="display:flex;align-items:start;gap:12px;">
<i data-lucide="info" style="width:20px;height:20px;color:#0D7377;flex-shrink:0;margin-top:2px;"></i>
<div style="font-size:13px;color:#374151;line-height:1.8;">
<strong>ما هذه الصفحة؟</strong> هنا تحدد سعر الاشتراك الشهري لكل أكاديمية أو نشاط رياضي.<br>
عند توليد الاشتراكات الشهرية، يستخدم النظام هذه الأسعار لحساب المبلغ المطلوب من كل لاعب.<br>
<strong>عضو</strong> = لاعب عضو بالنادي &nbsp;&middot;&nbsp; <strong>غير عضو</strong> = لاعب خارجي &nbsp;&middot;&nbsp; <strong>مسائي</strong> = فترة مسائية (بعد <?= e(date('g', mktime(17, 0))) ?>:00 م)
</div>
</div>
</div>
<!-- Filter Bar -->
<div class="card" style="margin-bottom:20px;padding:15px;">
<form method="GET" action="/activity-subscriptions/pricing" style="display:flex;flex-wrap:wrap;gap:10px;align-items:end;">
......@@ -35,6 +66,56 @@ $__template->layout('Layout.main');
</form>
</div>
<!-- Add New Pricing -->
<div class="card" style="margin-bottom:20px;">
<div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;">
<i data-lucide="plus-circle" style="width:18px;height:18px;color:#0D7377;"></i>
<h3 style="margin:0;color:#0D7377;font-size:15px;">إضافة تسعير جديد</h3>
</div>
<div style="padding:20px;">
<form method="POST" action="/activity-subscriptions/pricing" style="display:flex;flex-wrap:wrap;gap:12px;align-items:end;">
<?= csrf_field() ?>
<div style="min-width:160px;">
<label class="form-label" style="font-size:11px;">النوع</label>
<select name="pricing_type" class="form-input" id="new-pricing-type" onchange="updateReferenceOptions()" required>
<option value="">-- اختر --</option>
<option value="academy">أكاديمية</option>
<option value="discipline">نشاط</option>
</select>
</div>
<div style="min-width:200px;">
<label class="form-label" style="font-size:11px;">الأكاديمية / النشاط</label>
<select name="reference_id" class="form-input" id="new-reference-id" required>
<option value="">-- اختر النوع أولاً --</option>
</select>
</div>
<div style="flex:1;min-width:110px;">
<label class="form-label" style="font-size:11px;">سعر العضو</label>
<input type="number" step="0.01" min="0" name="member_rate" value="0" class="form-input" style="font-size:13px;" required>
</div>
<div style="flex:1;min-width:110px;">
<label class="form-label" style="font-size:11px;">سعر غير العضو</label>
<input type="number" step="0.01" min="0" name="nonmember_rate" value="0" class="form-input" style="font-size:13px;" required>
</div>
<div style="flex:1;min-width:110px;">
<label class="form-label" style="font-size:11px;">عضو (مسائي)</label>
<input type="number" step="0.01" min="0" name="member_rate_pm" value="0" class="form-input" style="font-size:13px;">
</div>
<div style="flex:1;min-width:110px;">
<label class="form-label" style="font-size:11px;">غير عضو (مسائي)</label>
<input type="number" step="0.01" min="0" name="nonmember_rate_pm" value="0" class="form-input" style="font-size:13px;">
</div>
<div style="min-width:130px;">
<label class="form-label" style="font-size:11px;">سريان من</label>
<input type="date" name="effective_from" value="<?= e(date('Y-m-d')) ?>" class="form-input" style="font-size:13px;">
</div>
<button type="submit" class="btn btn-primary" style="font-size:13px;height:38px;">
<i data-lucide="plus" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> إضافة
</button>
</form>
</div>
</div>
<!-- Pricing Table -->
<?php if (!empty($pricings)): ?>
<div class="card" style="padding:0;overflow-x:auto;">
......@@ -42,13 +123,13 @@ $__template->layout('Layout.main');
<thead>
<tr style="background:#F9FAFB;border-bottom:2px solid #E5E7EB;">
<th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">النوع</th>
<th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">المرجع</th>
<th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">عضو</th>
<th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">غير عضو</th>
<th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">عضو (م)</th>
<th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">غير عضو (م)</th>
<th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">من</th>
<th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">إلى</th>
<th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">الأكاديمية / النشاط</th>
<th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">سعر العضو</th>
<th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">سعر غير العضو</th>
<th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">عضو (مسائي)</th>
<th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">غير عضو (مسائي)</th>
<th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">سريان من</th>
<th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">سريان إلى</th>
<th style="padding:12px 16px;text-align:center;font-weight:600;color:#374151;">الحالة</th>
<th style="padding:12px 16px;text-align:center;font-weight:600;color:#374151;">إجراءات</th>
</tr>
......@@ -57,6 +138,7 @@ $__template->layout('Layout.main');
<?php foreach ($pricings as $idx => $p):
$typeLabel = ActivityPricing::getPricingTypeLabel($p['pricing_type'] ?? '');
$isActive = (int) ($p['is_active'] ?? 0);
$name = $refName($p['pricing_type'] ?? '', (int) ($p['reference_id'] ?? 0));
?>
<tr style="border-bottom:1px solid #F3F4F6;" id="row-<?= $idx ?>">
<td style="padding:12px 16px;">
......@@ -64,7 +146,7 @@ $__template->layout('Layout.main');
<?= e($typeLabel) ?>
</span>
</td>
<td style="padding:12px 16px;font-weight:600;">#<?= (int) ($p['reference_id'] ?? 0) ?></td>
<td style="padding:12px 16px;font-weight:600;"><?= e($name) ?></td>
<td style="padding:12px 16px;"><?= money($p['member_rate'] ?? 0) ?></td>
<td style="padding:12px 16px;"><?= money($p['nonmember_rate'] ?? 0) ?></td>
<td style="padding:12px 16px;"><?= money($p['member_rate_pm'] ?? 0) ?></td>
......@@ -147,12 +229,57 @@ $__template->layout('Layout.main');
<?php if (!empty($filters['pricing_type']) || ($filters['is_active'] ?? '') !== ''): ?>
لا توجد نتائج مطابقة. جرب تغيير معايير البحث.
<?php else: ?>
لم يتم إعداد تسعير بعد.
لم يتم إعداد تسعير بعد. استخدم النموذج أعلاه لإضافة أسعار.
<?php endif; ?>
</p>
</div>
<?php endif; ?>
<!-- Academies/Disciplines without pricing -->
<?php
$missingAcademies = [];
foreach ($academies as $a) {
$aid = (int) ($a['id'] ?? $a->id ?? 0);
if (!isset($existingRefs['academy_' . $aid])) {
$missingAcademies[] = $a;
}
}
$missingDisciplines = [];
foreach ($disciplines as $d) {
$did = (int) ($d['id'] ?? $d->id ?? 0);
if (!isset($existingRefs['discipline_' . $did])) {
$missingDisciplines[] = $d;
}
}
?>
<?php if (!empty($missingAcademies) || !empty($missingDisciplines)): ?>
<div class="card" style="margin-top:20px;border-right:4px solid #D97706;">
<div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;">
<i data-lucide="alert-triangle" style="width:18px;height:18px;color:#D97706;"></i>
<h3 style="margin:0;color:#D97706;font-size:15px;">بدون تسعير (<?= count($missingAcademies) + count($missingDisciplines) ?>)</h3>
</div>
<div style="padding:15px 20px;font-size:13px;color:#6B7280;">
<p style="margin:0 0 10px;">الأكاديميات والأنشطة التالية ليس لها أسعار محددة. لن يتم توليد اشتراكات لها حتى يتم تحديد أسعارها.</p>
<?php if (!empty($missingAcademies)): ?>
<div style="margin-bottom:8px;">
<strong>أكاديميات:</strong>
<?php foreach ($missingAcademies as $ma): ?>
<span style="display:inline-block;background:#FEF3C7;color:#92400E;font-size:12px;padding:3px 10px;border-radius:8px;margin:2px 2px;"><?= e($ma['name_ar'] ?? $ma->name_ar ?? '') ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if (!empty($missingDisciplines)): ?>
<div>
<strong>أنشطة:</strong>
<?php foreach ($missingDisciplines as $md): ?>
<span style="display:inline-block;background:#FEF3C7;color:#92400E;font-size:12px;padding:3px 10px;border-radius:8px;margin:2px 2px;"><?= e($md['name_ar'] ?? $md->name_ar ?? '') ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<script>
document.addEventListener('DOMContentLoaded', function() {
if (typeof lucide !== 'undefined') lucide.createIcons();
......@@ -162,7 +289,6 @@ function toggleEditRow(idx) {
var editRow = document.getElementById('edit-row-' + idx);
if (!editRow) return;
if (editRow.style.display === 'none' || editRow.style.display === '') {
// Close all other edit rows first
var allEditRows = document.querySelectorAll('[id^="edit-row-"]');
for (var i = 0; i < allEditRows.length; i++) {
allEditRows[i].style.display = 'none';
......@@ -172,5 +298,33 @@ function toggleEditRow(idx) {
editRow.style.display = 'none';
}
}
// Dynamic reference dropdown for the "Add new" form
var academyOptions = [
<?php foreach ($academies as $a): ?>
{id: <?= (int) ($a['id'] ?? $a->id ?? 0) ?>, name: <?= json_encode($a['name_ar'] ?? $a->name_ar ?? '', JSON_UNESCAPED_UNICODE) ?>},
<?php endforeach; ?>
];
var disciplineOptions = [
<?php foreach ($disciplines as $d): ?>
{id: <?= (int) ($d['id'] ?? $d->id ?? 0) ?>, name: <?= json_encode($d['name_ar'] ?? $d->name_ar ?? '', JSON_UNESCAPED_UNICODE) ?>},
<?php endforeach; ?>
];
function updateReferenceOptions() {
var typeSelect = document.getElementById('new-pricing-type');
var refSelect = document.getElementById('new-reference-id');
var type = typeSelect.value;
refSelect.innerHTML = '<option value="">-- اختر --</option>';
var options = type === 'academy' ? academyOptions : (type === 'discipline' ? disciplineOptions : []);
for (var i = 0; i < options.length; i++) {
var opt = document.createElement('option');
opt.value = options[i].id;
opt.textContent = options[i].name;
refSelect.appendChild(opt);
}
}
</script>
<?php $__template->endSection(); ?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment