Skip to content

Commit

Permalink
add: reporting feature in admin jurusan
Browse files Browse the repository at this point in the history
  • Loading branch information
FarrelAD committed Dec 22, 2024
1 parent f57b2be commit 096063c
Show file tree
Hide file tree
Showing 8 changed files with 1,814 additions and 42 deletions.
42 changes: 41 additions & 1 deletion app/controllers/AdminJurusanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

use App\Core\Controller;
use App\Models\Mahasiswa;
use App\Repository\{AdminRepository, MahasiswaRepository};
use App\Repository\{AdminRepository, MahasiswaRepository, StatistikRepository};
use App\Models\Admin;
use Dompdf\{Dompdf, Options};

class AdminJurusanController extends Controller
{
Expand Down Expand Up @@ -423,4 +424,43 @@ public function catatanAktivitas(): void
$this->view("pages/admin_jurusan/catatan_aktivitas");
$this->view("templates/footer");
}

public function viewLaporan(): void
{
$this->view("templates/header", [
'title' => "Laporan",
'css' => ["assets/css/sidebar"]
]);
$this->view("pages/admin_jurusan/laporan", [
'active_page' => 'laporan'
]);
$this->view("templates/footer");
}

public function viewLaporanUmum(): void
{
$d4_ti = StatistikRepository::getTotalPaidOffAndUnpaidStudent("D4 Teknik Informatika");
$d4_sib = StatistikRepository::getTotalPaidOffAndUnpaidStudent("D4 Sistem Informasi Bisnis");
$d2_ppls = StatistikRepository::getTotalPaidOffAndUnpaidStudent("D2 Pengembangan Perangkat Lunak Situs");

ob_start();
$this->view("templates/summary_report", [
'd4_ti' => $d4_ti,
'd4_sib' => $d4_sib,
'd2_ppls' => $d2_ppls
]);
$document = ob_get_clean();

$options = new Options();
$options->set('isHtml5ParserEnabled', true);
$options->set('isPhpEnabled', true);
$options->set('isRemoteEnabled', true);

$pdf = new Dompdf($options);

$pdf->loadHtml($document);
$pdf->setPaper('A4', 'portrait');
$pdf->render();
$pdf->stream("report.pdf", array("Attachment" => 0));
}
}
32 changes: 32 additions & 0 deletions app/repository/StatistikRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,36 @@ public static function getTotalUserStatistic(): bool|array
throw new \PDOException($e->getMessage());
}
}

public static function getTotalPaidOffAndUnpaidStudent(string $department): array
{
try {
$stmt = Database::getConnection()
->prepare(<<<SQL
SELECT
COUNT(CASE WHEN status = 'lunas' THEN 1 END) AS lunas,
COUNT(CASE WHEN status = 'belum_lunas' THEN 1 END) AS belum_lunas
FROM (
SELECT
t.nim,
CASE
WHEN SUM(CASE WHEN jenis_tanggungan = 'Tanggungan TA' AND status_tanggungan = 'Selesai' THEN 1 ELSE 0 END) > 0
AND SUM(CASE WHEN jenis_tanggungan = 'Tanggungan Prodi' AND status_tanggungan = 'Selesai' THEN 1 ELSE 0 END) > 0
THEN 'lunas'
ELSE 'belum_lunas'
END AS status
FROM BERKAS.Tanggungan t
GROUP BY t.nim
) AS raw
INNER JOIN USERS.Mahasiswa m ON raw.nim = m.nim
WHERE m.prodi = :department
SQL);
$stmt->bindValue(':department', $department, \PDO::PARAM_STR);
$stmt->execute();
return $stmt->fetch();
} catch (\PDOException $e) {
error_log(ErrorLog::formattedErrorLog($e->getMessage()), 3, LOG_FILE_PATH);
throw new \PDOException($e->getMessage());
}
}
}
14 changes: 14 additions & 0 deletions app/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,17 @@
'args' => 'admin jurusan'
]
]);
Router::add('GET', '/laporan', AdminJurusanController::class, 'viewLaporan', [
[
'class' => AuthMiddleware::class,
'function' => 'checkAuth',
'args' => 'admin jurusan'
]
]);
Router::add('GET', '/laporan/laporan-umum', AdminJurusanController::class, 'viewLaporanUmum', [
[
'class' => AuthMiddleware::class,
'function' => 'checkAuth',
'args' => 'admin jurusan'
]
]);
4 changes: 4 additions & 0 deletions app/views/components/admin_jurusan/sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
<a href="log-aktivity" class="sidebar-nav nav-link text-white w-100 ps-5 fw-bold">
Log Aktivitas
</a>

<a href="/laporan" id="nav-laporan" class="sidebar-nav nav-link text-white ps-5 fw-bold">
Laporan
</a>
</nav>

<div class="mt-auto w-100 mb-4 d-flex justify-content-center" style="">
Expand Down
18 changes: 18 additions & 0 deletions app/views/pages/admin_jurusan/laporan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="d-flex">
<?php include __DIR__ . '/../../components/admin_jurusan/sidebar.php' ?>
<div class="position-top w-100" style="margin-left: 35vh;">
<?php include __DIR__ . '/../../components/general/topbar.php' ?>
<main class="halaman mx-5 " style="min-height:100vh; margin-top:15vh;">
<h2 class="fw-bold">Laporan Sistem</h2>

<p>Pilih jenis laporan yang ingin dibuat</p>
<a href="/laporan/laporan-umum">
<button>Laporan umum</button>
</a>

<button>Laporan Aktivitas Admin</button>

<button>Laporan Analisa</button>
</main>
</div>
</div>
144 changes: 144 additions & 0 deletions app/views/templates/summary_report.php

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
]
},
"require": {
"vlucas/phpdotenv": "^5.6"
"vlucas/phpdotenv": "^5.6",
"barryvdh/laravel-dompdf": "^3.0"
},
"scripts": {
"db-schema": "php database/schema.php",
Expand Down
Loading

0 comments on commit 096063c

Please sign in to comment.