fix financial issues
This commit is contained in:
@@ -15,23 +15,65 @@ $totalSurprise = array_sum(array_column($classResults, 'surprises'));
|
||||
$totalMissed = array_sum(array_column($classResults, 'missed'));
|
||||
$overallAccuracy = $totalPredicted > 0 ? round($totalConfirmed / $totalPredicted * 100) : ($totalActual === 0 ? 100 : 0);
|
||||
|
||||
$pct = static function (int $count, int $total): string {
|
||||
return $total > 0 ? number_format(($count / $total) * 100, 1) . '%' : '0.0%';
|
||||
};
|
||||
|
||||
$genderKey = static function (?string $gender): string {
|
||||
$value = strtolower(trim((string)$gender));
|
||||
|
||||
return match (true) {
|
||||
in_array($value, ['male', 'm', 'boy', 'boys'], true) => 'boys',
|
||||
in_array($value, ['female', 'f', 'girl', 'girls'], true) => 'girls',
|
||||
default => 'other',
|
||||
};
|
||||
};
|
||||
|
||||
$genderStats = static function (array $items) use ($genderKey): array {
|
||||
$stats = ['boys' => 0, 'girls' => 0, 'other' => 0];
|
||||
|
||||
foreach ($items as $item) {
|
||||
$stats[$genderKey($item['gender'] ?? '')]++;
|
||||
}
|
||||
|
||||
return $stats;
|
||||
};
|
||||
|
||||
// Winner gender breakdown.
|
||||
// "Winner" means actual year-end trophy winner.
|
||||
$totalWinnerBoys = 0;
|
||||
$totalWinnerGirls = 0;
|
||||
$totalWinnerOther = 0;
|
||||
$allStudentsFlat = [];
|
||||
$passStudents = [];
|
||||
$trophyStudents = [];
|
||||
|
||||
// Sticker names.
|
||||
// 2 columns x 10 rows = 20 stickers per page.
|
||||
// Stickers print NAME ONLY.
|
||||
$winnerStickerNames = [];
|
||||
// 2 columns x 7 rows = 14 stickers per page.
|
||||
// Stickers print name and class section.
|
||||
$stickerColumns = 2;
|
||||
$stickerRows = 7;
|
||||
$stickerWidthInches = 4.0;
|
||||
$stickerHeightInches = 1.33;
|
||||
$stickerPrintablePageWidthInches = 8.0;
|
||||
$stickerPrintablePageHeightInches = 10.5;
|
||||
$stickersPerPage = $stickerColumns * $stickerRows;
|
||||
$winnerStickers = [];
|
||||
|
||||
foreach ($classResults as $cls) {
|
||||
foreach (($cls['students'] ?? []) as $s) {
|
||||
$allStudentsFlat[] = $s;
|
||||
|
||||
if (isset($s['year_score']) && is_numeric($s['year_score']) && (float)$s['year_score'] >= 60) {
|
||||
$passStudents[] = $s;
|
||||
}
|
||||
|
||||
if (empty($s['actual'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$trophyStudents[] = $s;
|
||||
|
||||
$gender = strtolower(trim((string)($s['gender'] ?? '')));
|
||||
|
||||
if (in_array($gender, ['male', 'm', 'boy', 'boys'], true)) {
|
||||
@@ -43,9 +85,13 @@ foreach ($classResults as $cls) {
|
||||
}
|
||||
|
||||
$name = trim((string)($s['name'] ?? ''));
|
||||
$sectionName = trim((string)($cls['section_name'] ?? ''));
|
||||
|
||||
if ($name !== '') {
|
||||
$winnerStickerNames[] = $name;
|
||||
$winnerStickers[] = [
|
||||
'name' => $name,
|
||||
'section' => $sectionName,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,6 +101,10 @@ $totalWinners = $totalWinnerBoys + $totalWinnerGirls + $totalWinnerOther;
|
||||
$winnerBoysPct = $totalWinners > 0 ? round(($totalWinnerBoys / $totalWinners) * 100, 1) : 0;
|
||||
$winnerGirlsPct = $totalWinners > 0 ? round(($totalWinnerGirls / $totalWinners) * 100, 1) : 0;
|
||||
$winnerOtherPct = $totalWinners > 0 ? round(($totalWinnerOther / $totalWinners) * 100, 1) : 0;
|
||||
$allGenderStats = $genderStats($allStudentsFlat);
|
||||
$passGenderStats = $genderStats($passStudents);
|
||||
$trophyGenderStats = $genderStats($trophyStudents);
|
||||
$totalPass = count($passStudents);
|
||||
?>
|
||||
|
||||
<style>
|
||||
@@ -68,7 +118,7 @@ $winnerOtherPct = $totalWinners > 0 ? round(($totalWinnerOther / $totalWinners)
|
||||
|
||||
@page {
|
||||
size: Letter portrait;
|
||||
margin: 0.35in;
|
||||
margin: 0.25in;
|
||||
}
|
||||
|
||||
@media print {
|
||||
@@ -162,11 +212,18 @@ $winnerOtherPct = $totalWinners > 0 ? round(($totalWinnerOther / $totalWinners)
|
||||
|
||||
body.print-stickers-mode .sticker-page {
|
||||
display: grid !important;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
grid-template-rows: repeat(10, 1fr);
|
||||
grid-template-columns: repeat(<?= $stickerColumns ?>, <?= rtrim(rtrim(number_format($stickerWidthInches, 2, '.', ''), '0'), '.') ?>in);
|
||||
grid-template-rows: repeat(<?= $stickerRows ?>, <?= rtrim(rtrim(number_format($stickerHeightInches, 2, '.', ''), '0'), '.') ?>in);
|
||||
gap: 0;
|
||||
width: 100%;
|
||||
height: 10.3in;
|
||||
width: <?= rtrim(rtrim(number_format($stickerPrintablePageWidthInches, 2, '.', ''), '0'), '.') ?>in;
|
||||
height: <?= rtrim(rtrim(number_format($stickerPrintablePageHeightInches, 2, '.', ''), '0'), '.') ?>in;
|
||||
margin: 0 auto;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
align-content: start;
|
||||
justify-content: center;
|
||||
page-break-inside: avoid;
|
||||
break-inside: avoid-page;
|
||||
page-break-after: always;
|
||||
break-after: page;
|
||||
}
|
||||
@@ -186,16 +243,36 @@ $winnerOtherPct = $totalWinners > 0 ? round(($totalWinnerOther / $totalWinners)
|
||||
overflow: hidden;
|
||||
min-height: 0;
|
||||
box-sizing: border-box;
|
||||
width: <?= rtrim(rtrim(number_format($stickerWidthInches, 2, '.', ''), '0'), '.') ?>in;
|
||||
height: <?= rtrim(rtrim(number_format($stickerHeightInches, 2, '.', ''), '0'), '.') ?>in;
|
||||
}
|
||||
|
||||
body.print-stickers-mode .sticker-name {
|
||||
display: block !important;
|
||||
font-size: 20pt;
|
||||
font-size: 18pt;
|
||||
font-weight: 700;
|
||||
line-height: 1.1;
|
||||
color: #000 !important;
|
||||
}
|
||||
|
||||
body.print-stickers-mode .sticker-content {
|
||||
display: flex !important;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
transform: translateY(0.22in);
|
||||
}
|
||||
|
||||
body.print-stickers-mode .sticker-section {
|
||||
display: block !important;
|
||||
margin-top: 0.08in;
|
||||
font-size: 10pt;
|
||||
font-weight: 600;
|
||||
line-height: 1.1;
|
||||
color: #000 !important;
|
||||
}
|
||||
|
||||
body.print-stickers-mode .sticker-empty {
|
||||
visibility: hidden !important;
|
||||
}
|
||||
@@ -219,7 +296,7 @@ $winnerOtherPct = $totalWinners > 0 ? round(($totalWinnerOther / $totalWinners)
|
||||
|
||||
<div class="d-flex gap-2 flex-wrap">
|
||||
<button onclick="printWithCharts()" class="btn btn-outline-secondary btn-sm">
|
||||
<i class="bi bi-printer-fill me-1"></i>Print
|
||||
<i class="bi bi-printer-fill me-1"></i>Print Stats
|
||||
</button>
|
||||
|
||||
<button onclick="printWinnerStickers()" class="btn btn-warning btn-sm">
|
||||
@@ -548,13 +625,6 @@ $winnerOtherPct = $totalWinners > 0 ? round(($totalWinnerOther / $totalWinners)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-lg-3">
|
||||
<div class="border rounded p-3 text-center h-100">
|
||||
<div class="text-muted small mb-1">Unknown / Other</div>
|
||||
<div class="display-6 fw-bold text-secondary"><?= (int)$totalWinnerOther ?></div>
|
||||
<div class="fw-semibold"><?= number_format($winnerOtherPct, 1) ?>%</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
@@ -577,17 +647,6 @@ $winnerOtherPct = $totalWinners > 0 ? round(($totalWinnerOther / $totalWinners)
|
||||
aria-valuemax="100">
|
||||
Girls <?= number_format($winnerGirlsPct, 1) ?>%
|
||||
</div>
|
||||
|
||||
<?php if ($totalWinnerOther > 0): ?>
|
||||
<div class="progress-bar bg-secondary"
|
||||
role="progressbar"
|
||||
style="width: <?= $winnerOtherPct ?>%;"
|
||||
aria-valuenow="<?= $winnerOtherPct ?>"
|
||||
aria-valuemin="0"
|
||||
aria-valuemax="100">
|
||||
Other <?= number_format($winnerOtherPct, 1) ?>%
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<div class="progress-bar bg-secondary"
|
||||
role="progressbar"
|
||||
@@ -619,6 +678,50 @@ $winnerOtherPct = $totalWinners > 0 ? round(($totalWinnerOther / $totalWinners)
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<h3 style="margin-bottom:6px;">Print Stats</h3>
|
||||
<table data-no-mgmt-sticky style="margin-bottom:12px;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Metric</th>
|
||||
<th style="text-align:center;">Count</th>
|
||||
<th style="text-align:center;">Percent</th>
|
||||
<th style="text-align:center;">Boys</th>
|
||||
<th style="text-align:center;">Boys %</th>
|
||||
<th style="text-align:center;">Girls</th>
|
||||
<th style="text-align:center;">Girls %</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Total Students</td>
|
||||
<td style="text-align:center;"><?= $totalStudents ?></td>
|
||||
<td style="text-align:center;">100.0%</td>
|
||||
<td style="text-align:center;"><?= $allGenderStats['boys'] ?></td>
|
||||
<td style="text-align:center;"><?= $pct($allGenderStats['boys'], $totalStudents) ?></td>
|
||||
<td style="text-align:center;"><?= $allGenderStats['girls'] ?></td>
|
||||
<td style="text-align:center;"><?= $pct($allGenderStats['girls'], $totalStudents) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Pass</td>
|
||||
<td style="text-align:center;"><?= $totalPass ?></td>
|
||||
<td style="text-align:center;"><?= $pct($totalPass, $totalStudents) ?></td>
|
||||
<td style="text-align:center;"><?= $passGenderStats['boys'] ?></td>
|
||||
<td style="text-align:center;"><?= $pct($passGenderStats['boys'], $totalPass) ?></td>
|
||||
<td style="text-align:center;"><?= $passGenderStats['girls'] ?></td>
|
||||
<td style="text-align:center;"><?= $pct($passGenderStats['girls'], $totalPass) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Trophies</td>
|
||||
<td style="text-align:center;"><?= $totalWinners ?></td>
|
||||
<td style="text-align:center;"><?= $pct($totalWinners, $totalStudents) ?></td>
|
||||
<td style="text-align:center;"><?= $trophyGenderStats['boys'] ?></td>
|
||||
<td style="text-align:center;"><?= $pct($trophyGenderStats['boys'], $totalWinners) ?></td>
|
||||
<td style="text-align:center;"><?= $trophyGenderStats['girls'] ?></td>
|
||||
<td style="text-align:center;"><?= $pct($trophyGenderStats['girls'], $totalWinners) ?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3 style="margin-bottom:4px;">Student Detail</h3>
|
||||
<table data-no-mgmt-sticky>
|
||||
<thead>
|
||||
@@ -638,11 +741,15 @@ $winnerOtherPct = $totalWinners > 0 ? round(($totalWinnerOther / $totalWinners)
|
||||
|
||||
<tbody>
|
||||
<?php
|
||||
$rank = 0;
|
||||
foreach ($classResults as $cls):
|
||||
foreach ($cls['students'] as $s):
|
||||
if (!in_array($s['status'], ['confirmed', 'surprise'], true)) continue;
|
||||
$rank++;
|
||||
$classPrintRows = array_values(array_filter(
|
||||
$cls['students'],
|
||||
static fn (array $student): bool => in_array($student['status'], ['confirmed', 'surprise'], true)
|
||||
));
|
||||
$classPrintRows = array_reverse($classPrintRows);
|
||||
|
||||
foreach ($classPrintRows as $idx => $s):
|
||||
$rank = count($classPrintRows) - $idx;
|
||||
$genderNorm = strtolower(trim((string)($s['gender'] ?? '')));
|
||||
$isMale = in_array($genderNorm, ['male', 'm', 'boy'], true);
|
||||
$statusLabel = match ($s['status']) {
|
||||
@@ -761,13 +868,6 @@ $winnerOtherPct = $totalWinners > 0 ? round(($totalWinnerOther / $totalWinners)
|
||||
<td style="text-align:center;"><?= (int)$totalWinnerGirls ?></td>
|
||||
<td style="text-align:center;"><?= number_format($winnerGirlsPct, 1) ?>%</td>
|
||||
</tr>
|
||||
<?php if ($totalWinnerOther > 0): ?>
|
||||
<tr>
|
||||
<td>Unknown / Other</td>
|
||||
<td style="text-align:center;"><?= (int)$totalWinnerOther ?></td>
|
||||
<td style="text-align:center;"><?= number_format($winnerOtherPct, 1) ?>%</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
|
||||
<tfoot>
|
||||
@@ -784,16 +884,19 @@ $winnerOtherPct = $totalWinners > 0 ? round(($totalWinnerOther / $totalWinners)
|
||||
|
||||
<!-- Winner sticker print area: names only, no header, no score, no class -->
|
||||
<div id="winnerStickerPrintArea" class="winner-sticker-print-area">
|
||||
<?php if (!empty($winnerStickerNames)): ?>
|
||||
<?php foreach (array_chunk($winnerStickerNames, 20) as $chunk): ?>
|
||||
<?php if (!empty($winnerStickers)): ?>
|
||||
<?php foreach (array_chunk($winnerStickers, $stickersPerPage) as $chunk): ?>
|
||||
<div class="sticker-page">
|
||||
<?php foreach ($chunk as $winnerName): ?>
|
||||
<?php foreach ($chunk as $winnerSticker): ?>
|
||||
<div class="sticker-cell">
|
||||
<div class="sticker-name"><?= esc($winnerName) ?></div>
|
||||
<div class="sticker-content">
|
||||
<div class="sticker-name"><?= esc($winnerSticker['name']) ?></div>
|
||||
<div class="sticker-section"><?= esc($winnerSticker['section']) ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php for ($i = 0, $remaining = 20 - count($chunk); $i < $remaining; $i++): ?>
|
||||
<?php for ($i = 0, $remaining = $stickersPerPage - count($chunk); $i < $remaining; $i++): ?>
|
||||
<div class="sticker-cell sticker-empty"></div>
|
||||
<?php endfor; ?>
|
||||
</div>
|
||||
@@ -971,4 +1074,4 @@ window.addEventListener('beforeprint', function () {
|
||||
</script>
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
Reference in New Issue
Block a user