Commit ea22df8a authored by Mahmoud Aglan's avatar Mahmoud Aglan

fixed serial duplication

parent 1be9b982
...@@ -129,7 +129,7 @@ class CoachController extends Controller ...@@ -129,7 +129,7 @@ class CoachController extends Controller
'hourly_rate' => $hourlyRate !== '' ? (float) $hourlyRate : null, 'hourly_rate' => $hourlyRate !== '' ? (float) $hourlyRate : null,
'session_rate' => $sessionRate !== '' ? (float) $sessionRate : null, 'session_rate' => $sessionRate !== '' ? (float) $sessionRate : null,
'monthly_rate' => $monthlyRate !== '' ? (float) $monthlyRate : null, 'monthly_rate' => $monthlyRate !== '' ? (float) $monthlyRate : null,
'max_groups' => $maxGroups !== '' ? (int) $maxGroups : null, 'max_groups' => $maxGroups !== '' ? (int) $maxGroups : 10,
'bio_ar' => $bioAr ?: null, 'bio_ar' => $bioAr ?: null,
'is_active' => 1, 'is_active' => 1,
'branch_id' => App::getInstance()->session()->get('branch_id', 1), 'branch_id' => App::getInstance()->session()->get('branch_id', 1),
...@@ -273,7 +273,7 @@ class CoachController extends Controller ...@@ -273,7 +273,7 @@ class CoachController extends Controller
'hourly_rate' => $hourlyRate !== '' ? (float) $hourlyRate : null, 'hourly_rate' => $hourlyRate !== '' ? (float) $hourlyRate : null,
'session_rate' => $sessionRate !== '' ? (float) $sessionRate : null, 'session_rate' => $sessionRate !== '' ? (float) $sessionRate : null,
'monthly_rate' => $monthlyRate !== '' ? (float) $monthlyRate : null, 'monthly_rate' => $monthlyRate !== '' ? (float) $monthlyRate : null,
'max_groups' => $maxGroups !== '' ? (int) $maxGroups : null, 'max_groups' => $maxGroups !== '' ? (int) $maxGroups : 10,
'bio_ar' => $bioAr ?: null, 'bio_ar' => $bioAr ?: null,
'updated_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'),
], '`id` = ?', [(int) $id]); ], '`id` = ?', [(int) $id]);
......
...@@ -123,12 +123,10 @@ class PlayerController extends Controller ...@@ -123,12 +123,10 @@ class PlayerController extends Controller
} }
// Generate registration serial // Generate registration serial
$lastSerial = $db->selectOne("SELECT registration_serial FROM sa_players ORDER BY id DESC LIMIT 1"); $maxSerial = $db->selectOne(
$nextNum = 1; "SELECT MAX(CAST(SUBSTRING(registration_serial, 5) AS UNSIGNED)) as max_num FROM sa_players WHERE registration_serial LIKE 'SAP-%'"
if ($lastSerial && !empty($lastSerial['registration_serial'])) { );
$parts = explode('-', $lastSerial['registration_serial']); $nextNum = ((int) ($maxSerial['max_num'] ?? 0)) + 1;
$nextNum = (int) end($parts) + 1;
}
$serialNumber = 'SAP-' . str_pad((string) $nextNum, 5, '0', STR_PAD_LEFT); $serialNumber = 'SAP-' . str_pad((string) $nextNum, 5, '0', STR_PAD_LEFT);
$data = [ $data = [
...@@ -184,11 +182,21 @@ class PlayerController extends Controller ...@@ -184,11 +182,21 @@ class PlayerController extends Controller
$employee = App::getInstance()->currentEmployee(); $employee = App::getInstance()->currentEmployee();
$canApproveMedical = $employee && method_exists($employee, 'hasPermission') && $employee->hasPermission('sa.medical.approve'); $canApproveMedical = $employee && method_exists($employee, 'hasPermission') && $employee->hasPermission('sa.medical.approve');
$unpaidSubs = $db->select(
"SELECT s.*, g.name_ar as group_name
FROM sa_subscriptions s
LEFT JOIN sa_groups g ON g.id = s.group_id
WHERE s.player_id = ? AND s.payment_status IN ('unpaid', 'overdue', 'partial')
ORDER BY s.period_start DESC",
[(int) $id]
);
return $this->view('SportsActivity.Views.players.show', [ return $this->view('SportsActivity.Views.players.show', [
'player' => $player, 'player' => $player,
'documents' => $documents, 'documents' => $documents,
'medicalHistory' => $medicalHistory, 'medicalHistory' => $medicalHistory,
'canApproveMedical' => $canApproveMedical, 'canApproveMedical' => $canApproveMedical,
'unpaidSubs' => $unpaidSubs,
]); ]);
} }
......
...@@ -225,6 +225,56 @@ $relationLabels = ['father' => 'أب', 'mother' => 'أم', 'brother' => 'أخ', ...@@ -225,6 +225,56 @@ $relationLabels = ['father' => 'أب', 'mother' => 'أم', 'brother' => 'أخ',
<?php endif; ?> <?php endif; ?>
</div> </div>
<!-- Unpaid Subscriptions -->
<?php if (!empty($unpaidSubs)): ?>
<div class="card" style="margin-bottom:20px;">
<div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;justify-content:space-between;align-items:center;">
<h3 style="margin:0;font-size:16px;font-weight:600;">
<i data-lucide="alert-circle" style="width:18px;height:18px;vertical-align:middle;margin-left:6px;color:#DC2626;"></i>
اشتراكات غير مدفوعة
<span style="padding:2px 8px;border-radius:10px;font-size:12px;font-weight:700;background:#FEE2E2;color:#DC2626;margin-right:8px;"><?= count($unpaidSubs) ?></span>
</h3>
</div>
<div class="table-responsive">
<table class="data-table">
<thead>
<tr>
<th>المجموعة</th>
<th>الفترة</th>
<th>المبلغ</th>
<th>الحالة</th>
<th>إجراء</th>
</tr>
</thead>
<tbody>
<?php
$subStatusLabels = ['unpaid' => 'غير مدفوع', 'overdue' => 'متأخر', 'partial' => 'جزئي'];
$subStatusColors = ['unpaid' => '#D97706', 'overdue' => '#DC2626', 'partial' => '#1D4ED8'];
?>
<?php foreach ($unpaidSubs as $sub): ?>
<?php $sColor = $subStatusColors[$sub['payment_status'] ?? ''] ?? '#6B7280'; ?>
<tr>
<td style="font-weight:600;"><?= e($sub['group_name'] ?? '—') ?></td>
<td style="font-size:13px;"><?= e($sub['period_start'] ?? '') ?><?= e($sub['period_end'] ?? '') ?></td>
<td style="font-weight:600;color:#059669;"><?= money((float) ($sub['final_amount'] ?? 0)) ?></td>
<td>
<span style="padding:2px 8px;border-radius:8px;font-size:11px;font-weight:600;background:<?= $sColor ?>15;color:<?= $sColor ?>;">
<?= e($subStatusLabels[$sub['payment_status'] ?? ''] ?? '') ?>
</span>
</td>
<td>
<a href="/sa/subscriptions/<?= (int) $sub['id'] ?>" class="btn btn-sm btn-primary" style="padding:4px 10px;font-size:11px;">
<i data-lucide="banknote" style="width:12px;height:12px;vertical-align:middle;margin-left:3px;"></i> ادفع
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php endif; ?>
<!-- Documents Section --> <!-- Documents Section -->
<div class="card"> <div class="card">
<div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;justify-content:space-between;align-items:center;"> <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;justify-content:space-between;align-items:center;">
......
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