-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkontrol-merkezi.php
More file actions
481 lines (449 loc) · 22.3 KB
/
Copy pathkontrol-merkezi.php
File metadata and controls
481 lines (449 loc) · 22.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
<?php
declare(strict_types=1);
require_once __DIR__ . '/uygulama/baslat.php';
Auth::requireLogin();
$pdo = Database::getInstance()->getConnection();
$isAdmin = Auth::isAdmin();
$deptId = Auth::getDepartmentId();
$pageTitle = 'Kontrol Merkezi';
$activeNav = 'dashboard';
if ($isAdmin) {
$stats = $pdo->query(
"SELECT
(SELECT COUNT(*) FROM actions WHERE status != 'cancelled' AND deleted_at IS NULL) AS total_actions,
(SELECT COUNT(*) FROM activities WHERE is_active = 1 AND deleted_at IS NULL) AS total_activities,
(SELECT COUNT(*) FROM kpis WHERE is_active = 1 AND deleted_at IS NULL) AS total_kpis,
(SELECT COUNT(*) FROM data_entries WHERE deleted_at IS NULL) AS total_entries,
(SELECT COUNT(*) FROM data_entries WHERE workflow_status IN ('submitted','needs_revision') AND deleted_at IS NULL) AS pending_verify,
(SELECT COUNT(*) FROM departments WHERE is_active = 1) AS total_depts,
(SELECT COUNT(*) FROM users WHERE is_active = 1 AND deleted_at IS NULL) AS total_users"
)->fetch();
$deptProgress = $pdo->query(
"SELECT d.name AS dept_name, d.slug,
COUNT(DISTINCT a.id) AS total_actions,
COUNT(DISTINCT k.id) AS total_kpis,
COUNT(de.id) AS total_entries,
SUM(CASE WHEN de.year = YEAR(NOW()) THEN 1 ELSE 0 END) AS entries_this_year
FROM departments d
LEFT JOIN actions a ON a.responsible_department_id = d.id AND a.status != 'cancelled' AND a.deleted_at IS NULL
LEFT JOIN kpis k ON k.action_id = a.id AND k.is_active = 1 AND k.deleted_at IS NULL
LEFT JOIN data_entries de ON de.department_id = d.id AND de.deleted_at IS NULL
WHERE d.is_active = 1 AND d.slug NOT LIKE '%-dis-paydas'
GROUP BY d.id
ORDER BY total_entries DESC"
)->fetchAll();
$recentEntries = $pdo->query(
"SELECT de.year, de.value, de.is_verified, de.workflow_status, de.created_at,
k.name AS kpi_name, k.unit,
a.code AS action_code,
d.name AS dept_name,
u.full_name AS user_name
FROM data_entries de
JOIN kpis k ON k.id = de.kpi_id
JOIN actions a ON a.id = de.action_id
JOIN departments d ON d.id = de.department_id
JOIN users u ON u.id = de.entered_by
WHERE de.deleted_at IS NULL
AND a.deleted_at IS NULL
ORDER BY de.created_at DESC
LIMIT 10"
)->fetchAll();
$statusDist = $pdo->query(
"SELECT status, COUNT(*) AS cnt FROM actions WHERE status != 'cancelled' AND deleted_at IS NULL GROUP BY status"
)->fetchAll();
$catDist = $pdo->query(
"SELECT COALESCE(category, 'Diğer') AS category, COUNT(*) AS cnt
FROM actions WHERE status != 'cancelled' AND deleted_at IS NULL
GROUP BY category ORDER BY cnt DESC LIMIT 8"
)->fetchAll();
} else {
$accessibleActionIds = Auth::getAccessibleActionIds($pdo);
$stats = [
'total_actions' => count($accessibleActionIds),
'total_kpis' => 0,
'total_entries' => 0,
'entries_this_year' => 0,
'pending_verify' => 0,
];
if (!empty($accessibleActionIds)) {
$kpiStmt = $pdo->prepare(
"SELECT COUNT(DISTINCT k.id)
FROM kpis k
JOIN actions a ON a.id = k.action_id
WHERE k.is_active = 1
AND k.deleted_at IS NULL
AND a.deleted_at IS NULL
AND a.status != 'cancelled'
AND (
a.responsible_department_id = :dept_id
OR EXISTS (
SELECT 1
FROM action_departments ad
WHERE ad.action_id = a.id
AND ad.department_id = :dept_id_extra
)
)"
);
$kpiStmt->execute([
':dept_id' => $deptId,
':dept_id_extra' => $deptId,
]);
$stats['total_kpis'] = (int) $kpiStmt->fetchColumn();
$actionProgress = $pdo->prepare(
"SELECT a.code, a.title, a.status, a.end_year,
COUNT(DISTINCT k.id) AS total_kpis,
COUNT(DISTINCT de.id) AS entries_this_year
FROM actions a
LEFT JOIN kpis k ON k.action_id = a.id AND k.is_active = 1 AND k.deleted_at IS NULL
LEFT JOIN data_entries de
ON de.action_id = a.id
AND de.department_id = ?
AND de.year = YEAR(NOW())
AND de.deleted_at IS NULL
WHERE a.deleted_at IS NULL
AND a.status != 'cancelled'
AND (
a.responsible_department_id = ?
OR EXISTS (
SELECT 1
FROM action_departments ad
WHERE ad.action_id = a.id
AND ad.department_id = ?
)
)
GROUP BY a.id
ORDER BY a.code"
);
$actionProgress->execute([$deptId, $deptId, $deptId]);
$actionProgress = $actionProgress->fetchAll();
} else {
$actionProgress = [];
}
$stmt = $pdo->prepare(
"SELECT
COUNT(*) AS total_entries,
SUM(CASE WHEN year = YEAR(NOW()) THEN 1 ELSE 0 END) AS entries_this_year,
SUM(CASE WHEN workflow_status IN ('submitted','needs_revision') THEN 1 ELSE 0 END) AS pending_verify
FROM data_entries
WHERE department_id = :dept_id AND deleted_at IS NULL"
);
$stmt->execute([':dept_id' => $deptId]);
$entryStats = $stmt->fetch() ?: [];
$stats['total_entries'] = (int) ($entryStats['total_entries'] ?? 0);
$stats['entries_this_year'] = (int) ($entryStats['entries_this_year'] ?? 0);
$stats['pending_verify'] = (int) ($entryStats['pending_verify'] ?? 0);
$recentEntries = $pdo->prepare(
"SELECT de.year, de.value, de.is_verified, de.workflow_status, de.created_at,
k.name AS kpi_name, k.unit,
a.code AS action_code
FROM data_entries de
JOIN kpis k ON k.id = de.kpi_id
JOIN actions a ON a.id = de.action_id
WHERE de.department_id = :dept_id
AND de.deleted_at IS NULL
AND a.deleted_at IS NULL
ORDER BY de.created_at DESC
LIMIT 5"
);
$recentEntries->execute([':dept_id' => $deptId]);
$recentEntries = $recentEntries->fetchAll();
}
$statusLabels = [
'planned' => ['label' => 'Planlandı', 'cls' => 'rozet-planli'],
'ongoing' => ['label' => 'Devam Ediyor', 'cls' => 'rozet-devam'],
'completed' => ['label' => 'Tamamlandı', 'cls' => 'rozet-tamamlandi'],
'cancelled' => ['label' => 'İptal', 'cls' => 'rozet-iptal'],
];
require_once APP_ROOT . '/uygulama/yerlesim/ust.php';
?>
<div class="row g-3 mb-4">
<?php if ($isAdmin): ?>
<?php
$statCards = [
['label' => 'Toplam Eylem', 'value' => $stats['total_actions'], 'icon' => 'bi-lightning-charge-fill', 'color' => '#E8F5E9', 'icolor' => '#2E7D32'],
['label' => 'Faaliyet', 'value' => $stats['total_activities'],'icon' => 'bi-activity', 'color' => '#E3F2FD', 'icolor' => '#1565C0'],
['label' => 'Toplam KPI', 'value' => $stats['total_kpis'], 'icon' => 'bi-bar-chart-fill', 'color' => '#EDE7F6', 'icolor' => '#4527A0'],
['label' => 'Veri Girişi', 'value' => $stats['total_entries'], 'icon' => 'bi-database-fill', 'color' => '#FFF8E1', 'icolor' => '#FF8F00'],
['label' => 'Onay Bekleyen', 'value' => $stats['pending_verify'], 'icon' => 'bi-hourglass-split', 'color' => '#FCE4EC', 'icolor' => '#C2185B'],
['label' => 'Kullanıcı', 'value' => $stats['total_users'], 'icon' => 'bi-people-fill', 'color' => '#E0F7FA', 'icolor' => '#00838F'],
];
?>
<?php foreach ($statCards as $sc): ?>
<div class="col-6 col-md-4 col-xl-2">
<div class="card istatistik-karti h-100 p-3">
<div class="ist-simge mb-2" style="background:<?= $sc['color'] ?>; color:<?= $sc['icolor'] ?>;">
<i class="bi <?= $sc['icon'] ?>"></i>
</div>
<div class="ist-deger"><?= !empty($sc['decimal']) ? number_format((float)$sc['value'], 1, ',', '.') : number_format((int)$sc['value']) ?></div>
<div class="ist-etiket"><?= $sc['label'] ?></div>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<?php
$statCards = [
['label' => 'Eylemim', 'value' => $stats['total_actions'], 'icon' => 'bi-lightning-charge-fill', 'color' => '#E8F5E9', 'icolor' => '#2E7D32'],
['label' => 'KPI\'larım', 'value' => $stats['total_kpis'], 'icon' => 'bi-bar-chart-fill', 'color' => '#E3F2FD', 'icolor' => '#1565C0'],
['label' => 'Toplam Giriş', 'value' => $stats['total_entries'], 'icon' => 'bi-database-fill', 'color' => '#FFF8E1', 'icolor' => '#FF8F00'],
['label' => 'Bu Yıl Giriş', 'value' => $stats['entries_this_year'],'icon' => 'bi-calendar-check', 'color' => '#F3E5F5', 'icolor' => '#6A1B9A'],
];
?>
<?php foreach ($statCards as $sc): ?>
<div class="col-6 col-md-3">
<div class="card istatistik-karti h-100 p-3">
<div class="ist-simge mb-2" style="background:<?= $sc['color'] ?>; color:<?= $sc['icolor'] ?>;">
<i class="bi <?= $sc['icon'] ?>"></i>
</div>
<div class="ist-deger"><?= number_format((int)$sc['value']) ?></div>
<div class="ist-etiket"><?= $sc['label'] ?></div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<div class="row g-3">
<div class="col-12 col-xl-7">
<?php if ($isAdmin): ?>
<div class="row g-3 mb-3">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<i class="bi bi-pie-chart me-2 text-success"></i>Eylem Durumları
</div>
<div class="card-body">
<div class="chart-container" style="height:220px;">
<canvas id="statusChart"></canvas>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-header">
<i class="bi bi-tag me-2 text-primary"></i>Kategori Dağılımı
</div>
<div class="card-body">
<div class="chart-container" style="height:220px;">
<canvas id="categoryChart"></canvas>
</div>
</div>
</div>
</div>
</div>
<div class="card mb-3">
<div class="card-header d-flex justify-content-between align-items-center">
<span><i class="bi bi-building me-2 text-success"></i>Müdürlük Bazlı İlerleme</span>
<a href="<?= BASE_PATH ?>/yonetim/veri-izleme" class="btn btn-sm btn-outline-success">Detaylı İzleme</a>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead class="table-light">
<tr>
<th>Müdürlük</th>
<th class="text-center">Eylem</th>
<th class="text-center">KPI</th>
<th class="text-center">Bu Yıl</th>
<th>Doluluk</th>
</tr>
</thead>
<tbody>
<?php foreach ($deptProgress as $dp): ?>
<?php
$pct = $dp['total_kpis'] > 0
? min(100, (int)(($dp['entries_this_year'] / $dp['total_kpis']) * 100))
: 0;
$barCls = $pct >= 80 ? 'bg-success' : ($pct >= 40 ? 'bg-warning' : 'bg-danger');
?>
<tr>
<td class="fw-medium"><?= htmlspecialchars($dp['dept_name'], ENT_QUOTES, 'UTF-8') ?></td>
<td class="text-center"><?= (int)$dp['total_actions'] ?></td>
<td class="text-center"><?= (int)$dp['total_kpis'] ?></td>
<td class="text-center"><?= (int)$dp['entries_this_year'] ?></td>
<td style="min-width:120px;">
<div class="d-flex align-items-center gap-2">
<div class="progress flex-grow-1">
<div class="progress-bar <?= $barCls ?>" style="width:<?= $pct ?>%"></div>
</div>
<small class="text-muted" style="font-size:.75rem; width:32px;"><?= $pct ?>%</small>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php else: ?>
<div class="card mb-3">
<div class="card-header d-flex justify-content-between align-items-center">
<span><i class="bi bi-lightning-charge me-2 text-success"></i>Eylem İlerleme Durumu (<?= date('Y') ?>)</span>
<a href="<?= BASE_PATH ?>/mudurluk/eylemlerim" class="btn btn-sm btn-outline-success">Tümünü Gör</a>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead class="table-light">
<tr>
<th>Kod</th>
<th>Eylem Başlığı</th>
<th class="text-center">KPI</th>
<th class="text-center">Bu Yıl</th>
<th>Durum</th>
</tr>
</thead>
<tbody>
<?php foreach ($actionProgress as $ap): ?>
<?php $sl = $statusLabels[$ap['status']] ?? ['label'=>$ap['status'],'cls'=>'']; ?>
<tr>
<td><code class="eylem-kodu"><?= htmlspecialchars($ap['code'], ENT_QUOTES, 'UTF-8') ?></code></td>
<td>
<?= htmlspecialchars($ap['title'], ENT_QUOTES, 'UTF-8') ?>
</td>
<td class="text-center"><?= (int)$ap['total_kpis'] ?></td>
<td class="text-center">
<span class="badge <?= (int)$ap['entries_this_year'] > 0 ? 'bg-success' : 'bg-secondary' ?>">
<?= (int)$ap['entries_this_year'] ?>
</span>
</td>
<td>
<span class="badge <?= $sl['cls'] ?>"><?= $sl['label'] ?></span>
</td>
</tr>
<?php endforeach; ?>
<?php if (empty($actionProgress)): ?>
<tr><td colspan="5" class="text-center text-muted py-3">Henüz eylem tanımlanmamış.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php endif; ?>
</div>
<div class="col-12 col-xl-5">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<span><i class="bi bi-clock-history me-2 text-success"></i>Son Veri Girişleri</span>
<?php if ($isAdmin): ?>
<a href="<?= BASE_PATH ?>/yonetim/veri-onay" class="btn btn-sm btn-outline-success">Tümünü Gör</a>
<?php else: ?>
<a href="<?= BASE_PATH ?>/mudurluk/veri-gecmisim" class="btn btn-sm btn-outline-success">Tümünü Gör</a>
<?php endif; ?>
</div>
<div class="list-group list-group-flush">
<?php if (empty($recentEntries)): ?>
<div class="bos-durum">
<i class="bi bi-inbox"></i>
Henüz veri girişi yok.
</div>
<?php endif; ?>
<?php foreach ($recentEntries as $re): ?>
<?php
$entryStatus = $re['workflow_status'] ?? ($re['is_verified'] ? 'approved' : 'submitted');
$isApproved = $entryStatus === 'approved';
?>
<div class="list-group-item px-3 py-3" style="border-color:var(--kenar-acik);">
<div class="d-flex align-items-center gap-3">
<div style="width:36px; height:36px; border-radius:50%; display:flex; align-items:center; justify-content:center; flex-shrink:0;
background:<?= $isApproved ? 'var(--renk-vurgu-soluk)' : '#FFFbeb' ?>;
color:<?= $isApproved ? '#00A669' : '#D97706' ?>; font-size:.85rem;">
<i class="bi bi-<?= $isApproved ? 'check-circle-fill' : 'hourglass-split' ?>"></i>
</div>
<div style="flex:1; min-width:0;">
<div class="fw-semibold yazi-kucuk-arti hucre-kirp">
<?= htmlspecialchars($re['kpi_name'], ENT_QUOTES, 'UTF-8') ?>
</div>
<div class="text-muted yazi-xs">
<code class="eylem-kodu" style="font-size:.65rem; padding:.1rem .35rem;"><?= htmlspecialchars($re['action_code'], ENT_QUOTES, 'UTF-8') ?></code>
<?php if ($isAdmin && isset($re['dept_name'])): ?>
· <?= htmlspecialchars($re['dept_name'], ENT_QUOTES, 'UTF-8') ?>
<?php endif; ?>
<?php if ($isAdmin && isset($re['user_name'])): ?>
· <?= htmlspecialchars($re['user_name'], ENT_QUOTES, 'UTF-8') ?>
<?php endif; ?>
· <?= date('d.m.Y', strtotime($re['created_at'])) ?>
<div class="mt-1"><?= V2::entryStatusBadge($entryStatus) ?></div>
</div>
</div>
<div class="text-end flex-shrink-0 ms-2">
<div style="font-family:'Outfit',sans-serif; font-weight:700; font-size:.9rem; color:var(--yazi-baslik);">
<?= number_format((float)$re['value'], 2) ?>
<small class="text-muted yazi-2xs" style="font-weight:600;"><?= htmlspecialchars($re['unit'], ENT_QUOTES, 'UTF-8') ?></small>
</div>
<span style="font-size:.65rem; color:var(--yazi-ucuncul); background:var(--arkaplan-gecis); padding:.1rem .4rem; border-radius:99px;"><?= $re['year'] ?></span>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
<?php
if ($isAdmin) {
$statusColors = [
'planned' => '#9ca3af',
'ongoing' => '#3b82f6',
'completed' => '#10b981',
];
$chartStatusLabels = [];
$chartStatusValues = [];
$chartStatusColors = [];
foreach ($statusDist as $sd) {
$chartStatusLabels[] = $statusLabels[$sd['status']]['label'] ?? $sd['status'];
$chartStatusValues[] = (int)$sd['cnt'];
$chartStatusColors[] = $statusColors[$sd['status']] ?? '#6b7280';
}
$chartCatLabels = array_column($catDist, 'category');
$chartCatValues = array_map('intval', array_column($catDist, 'cnt'));
$jsonFlags = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE;
$extraJs = "<script>
new Chart(document.getElementById('statusChart'), {
type: 'doughnut',
data: {
labels: " . json_encode($chartStatusLabels, $jsonFlags) . ",
datasets: [{
data: " . json_encode($chartStatusValues, $jsonFlags) . ",
backgroundColor: " . json_encode($chartStatusColors, $jsonFlags) . ",
borderWidth: 0,
spacing: 2,
borderRadius: 4
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
cutout: '70%',
plugins: {
legend: { position: 'bottom', labels: { padding: 16, font: { size: 12, family: 'Manrope', weight: '600' }, color: '#5C6573', usePointStyle: true, pointStyle: 'circle' } }
}
}
});
new Chart(document.getElementById('categoryChart'), {
type: 'bar',
data: {
labels: " . json_encode($chartCatLabels, $jsonFlags) . ",
datasets: [{
data: " . json_encode($chartCatValues, $jsonFlags) . ",
backgroundColor: '#00D084',
borderRadius: 4,
maxBarThickness: 24
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
indexAxis: 'y',
plugins: { legend: { display: false } },
scales: {
x: { grid: { color: '#E6E8EB', drawBorder: false }, ticks: { font: { size: 11, family: 'Manrope', weight: '600' }, color: '#8B94A3' } },
y: { grid: { display: false, drawBorder: false }, ticks: { font: { size: 11, family: 'Manrope', weight: '600' }, color: '#5C6573' } }
}
}
});
</script>";
}
?>
<?php require_once APP_ROOT . '/uygulama/yerlesim/alt.php'; ?>