Merge pull request 'main' (#2) from main into production
Reviewed-on: #2
This commit is contained in:
commit
47793b680d
@ -8,14 +8,51 @@ use App\Exports\DashboardExport;
|
||||
use App\Exports\DashboardJawabanExport;
|
||||
use App\Models\Jawaban;
|
||||
use App\Models\JawabanDetail;
|
||||
use App\Models\MappingUnitPegawai;
|
||||
use App\Models\SoalDetail;
|
||||
use App\Models\UnitKerja;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Yajra\DataTables\DataTables;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
private function unitKey(?string $s):string
|
||||
{
|
||||
if (!$s) return '';
|
||||
|
||||
$s = Str::of($s)->lower()->trim();
|
||||
|
||||
// buang teks dalam kurung: (SIMRS) dll
|
||||
$s = $s->replaceMatches('/\s*\([^)]*\)\s*/u', ' ');
|
||||
|
||||
// expand singkatan penting
|
||||
$s = $s->replaceMatches('/\bksm\b/u', 'kelompok staf medik');
|
||||
$s = $s->replaceMatches('/\btimker\b/u', 'tim kerja');
|
||||
$s = $s->replaceMatches('/\bhumas\b/u', 'hubungan masyarakat');
|
||||
$s = $s->replaceMatches('/\bipt\b/u', 'instalasi perinatal terpadu');
|
||||
$s = $s->replaceMatches('/\bissb\b/u', 'instalasi sterilisasi sentral dan binatu');
|
||||
$s = $s->replaceMatches('/\bipsprs\b/u', 'instalasi pemeliharaan sarana prasarana rumah sakit');
|
||||
$s = $s->replaceMatches('/\binstalasi\s+rawat\s+intensif\s*\/\s*icu\b/u', 'instalasi rawat intensif');
|
||||
$s = $s->replaceMatches(
|
||||
'/\binstalasi\s+kl\s*(?:&|\/)?\s*k3rs\b/u',
|
||||
'instalasi kesehatan lingkungan dan keselamatan dan kesehatan kerja rumah sakit'
|
||||
);
|
||||
|
||||
|
||||
// samakan simbol
|
||||
$s = $s->replace(['&', '/', '-', '.', ',', ':', ';'], ' ');
|
||||
|
||||
// samakan kata penghubung
|
||||
$s = $s->replace(' dan ', ' ');
|
||||
|
||||
// rapikan spasi
|
||||
$s = $s->replaceMatches('/\s+/u', ' ')->trim();
|
||||
|
||||
return (string) $s;
|
||||
}
|
||||
//
|
||||
public function index()
|
||||
{
|
||||
@ -86,10 +123,7 @@ class AdminController extends Controller
|
||||
"Komite Medik",
|
||||
"Komite Keperawatan",
|
||||
"Komite PPI & PRA",
|
||||
"KTKL",
|
||||
"KFT",
|
||||
"KEH",
|
||||
"ULP",
|
||||
"KTKL", "KFT", "KEH", "ULP",
|
||||
"Timker Yankep",
|
||||
"Timker Yanjang",
|
||||
"Timker Perencanaan, Evaluasi dan Program",
|
||||
@ -116,12 +150,7 @@ class AdminController extends Controller
|
||||
"Instalasi Gawat Darurat",
|
||||
"Instalasi Verifikasi dan Penjaminan Pasien",
|
||||
"Instalasi KL & K3RS",
|
||||
"ISSB",
|
||||
"IPT",
|
||||
"IPJNI",
|
||||
"IPSPRS",
|
||||
"IPPB",
|
||||
"IPPISGB",
|
||||
"ISSB", "IPT", "IPJNI", "IPSPRS", "IPPB", "IPPISGB",
|
||||
"Instalasi Rawat Jalan Eksekutif",
|
||||
"Instalasi Teknologi Berbantu (TRB)",
|
||||
"Klinik Utama Bintaro",
|
||||
@ -132,35 +161,84 @@ class AdminController extends Controller
|
||||
"KSM Gigi & Mulut",
|
||||
"KSM Spesialis Lain",
|
||||
"KSM Umum",
|
||||
"Lainnya"
|
||||
"Lainnya",
|
||||
];
|
||||
$query = Jawaban::query()
|
||||
->select([
|
||||
'unit',
|
||||
DB::raw('COUNT(*) as total_unit'),
|
||||
])->whereNotNull('unit');
|
||||
|
||||
// 1) Total karyawan per UnitKerja (unik pegawai)
|
||||
$unitPegawai = UnitKerja::query()
|
||||
->where('statusenabled', true)
|
||||
->with([
|
||||
'mappingPegawai' => function ($q) {
|
||||
$q->where('statusenabled', true)
|
||||
->whereHas('pegawai', fn ($p) => $p->where('statusenabled', true)->where('kedudukanfk', 1))
|
||||
->with([
|
||||
'pegawai' => fn ($p) => $p->where('statusenabled', true)->where('kedudukanfk', 1)
|
||||
->select('id', 'namalengkap')
|
||||
]);
|
||||
}
|
||||
])
|
||||
->get();
|
||||
|
||||
$unitTotals = $unitPegawai->map(function ($unit) {
|
||||
$pegawaiUnik = $unit->mappingPegawai
|
||||
->pluck('pegawai')
|
||||
->filter()
|
||||
->unique('id');
|
||||
|
||||
return [
|
||||
'name' => $unit->name,
|
||||
'total_karyawan' => $pegawaiUnik->count(),
|
||||
];
|
||||
});
|
||||
|
||||
// map: key(normalized unit) => total_karyawan
|
||||
$unitTotalMaps = $unitTotals->mapWithKeys(function ($item) {
|
||||
return [$this->unitKey($item['name']) => (int)$item['total_karyawan']];
|
||||
});
|
||||
|
||||
// 2) Query Jawaban (ini yang nanti difilter)
|
||||
$query = Jawaban::query()
|
||||
->select('unit', DB::raw('COUNT(*) as total_unit'))
|
||||
->whereNotNull('unit');
|
||||
|
||||
if ($request->unit_kerja) {
|
||||
$query->whereIn('unit', (array) $request->unit_kerja);
|
||||
$masterUnits = array_intersect($masterUnits, $request->unit_kerja);
|
||||
}
|
||||
$query->groupBy('unit')
|
||||
->havingRaw('COUNT(*) > 0');
|
||||
$rekap = $query->get()->pluck('total_unit', 'unit');
|
||||
|
||||
$data = collect($masterUnits)
|
||||
->filter(fn($unit) => ($rekap[$unit] ?? 0) > 0)
|
||||
->map(fn($unit) => [
|
||||
'unit' => $unit,
|
||||
'total_unit' => $rekap[$unit],
|
||||
])
|
||||
$jawabanCounts = $query->groupBy('unit')->get();
|
||||
|
||||
// Map total karyawan: key(normalized) => total_karyawan (ini dari UnitKerja)
|
||||
$unitTotalMaps = $unitTotals->mapWithKeys(function ($item) {
|
||||
return [$this->unitKey($item['name']) => (int) $item['total_karyawan']];
|
||||
});
|
||||
|
||||
// Build data dari JAWABAN langsung (bukan masterUnits)
|
||||
$data = $jawabanCounts->map(function ($row) use ($unitTotalMaps) {
|
||||
|
||||
$key = $this->unitKey($row->unit);
|
||||
$sudahIsi = (int) $row->total_unit;
|
||||
|
||||
if (isset($unitTotalMaps[$key]) && (int)$unitTotalMaps[$key] > 0) {
|
||||
$totalKaryawan = (int) $unitTotalMaps[$key];
|
||||
$progress = $sudahIsi . ' / ' . $totalKaryawan;
|
||||
} else {
|
||||
$totalKaryawan = null; // tidak diketahui
|
||||
$progress = (string) $sudahIsi; // hanya angka, tanpa /0
|
||||
}
|
||||
|
||||
return [
|
||||
'unit' => $row->unit,
|
||||
'total_unit' => $progress
|
||||
];
|
||||
})
|
||||
->values();
|
||||
|
||||
return DataTables::of($data)->make(true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function download_report_data_pegawai_sudah_survey(Request $request)
|
||||
{
|
||||
$masterUnits = [
|
||||
@ -893,6 +971,9 @@ class AdminController extends Controller
|
||||
}
|
||||
|
||||
return DataTables::of($query)
|
||||
->addColumn('nama_pegawai', function($row){
|
||||
return $row?->pegawai?->nama ?? '-';
|
||||
})
|
||||
->addColumn('action', function ($row) {
|
||||
return '
|
||||
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#detail_jawaban" data-id="'. $row->id .'">
|
||||
|
||||
@ -194,7 +194,7 @@ class SoalController extends Controller
|
||||
$namaResponden = $answer;
|
||||
}
|
||||
|
||||
if (Str::contains($pertanyaan, 'unit/area kerja anda saat ini')) {
|
||||
if (Str::contains($pertanyaan, 'apa unit/area kerja anda saat ini')) {
|
||||
$unitKerja = $answer;
|
||||
}
|
||||
}
|
||||
@ -244,6 +244,8 @@ class SoalController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return redirect()->route('soal.thankyou')
|
||||
->with('success', 'Jawaban berhasil disimpan.');
|
||||
}
|
||||
|
||||
@ -9,11 +9,15 @@ class Jawaban extends Model
|
||||
protected $connection = 'dbLmsMutu';
|
||||
protected $table = 'public.lms_mutu_jawaban';
|
||||
protected $guarded = ['id'];
|
||||
protected $with = ['jawabanDetail'];
|
||||
protected $with = ['jawabanDetail', 'pegawai'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function jawabanDetail(){
|
||||
return $this->hasMany(JawabanDetail::class, 'lms_mutu_jawaban_id', 'id');
|
||||
}
|
||||
|
||||
public function pegawai(){
|
||||
return $this->belongsTo(Pegawai::class, 'pegawai_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
18
app/Models/MappingUnitPegawai.php
Normal file
18
app/Models/MappingUnitPegawai.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MappingUnitPegawai extends Model
|
||||
{
|
||||
protected $connection = 'dbSmartv1'; // nama connection di config/database.php
|
||||
protected $table = 'mappegawaijabatantounitkerja_m'; // atau 'public.pegawai_m' kalau pakai schema
|
||||
protected $primaryKey = 'id';
|
||||
protected $with = ['pegawai'];
|
||||
|
||||
public function pegawai(){
|
||||
return $this->belongsTo(Pegawai::class, 'objectpegawaifk', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
15
app/Models/Pegawai.php
Normal file
15
app/Models/Pegawai.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Pegawai extends Model
|
||||
{
|
||||
protected $connection = 'dbSmartv1'; // nama connection di config/database.php
|
||||
protected $table = 'pegawai_m'; // atau 'public.pegawai_m' kalau pakai schema
|
||||
protected $primaryKey = 'id';
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
}
|
||||
18
app/Models/UnitKerja.php
Normal file
18
app/Models/UnitKerja.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UnitKerja extends Model
|
||||
{
|
||||
protected $connection = 'dbSmartv1'; // nama connection di config/database.php
|
||||
protected $table = 'unitkerjapegawai_m'; // atau 'public.pegawai_m' kalau pakai schema
|
||||
protected $primaryKey = 'id';
|
||||
protected $with = ['mappingPegawai'];
|
||||
|
||||
public function mappingPegawai(){
|
||||
return $this->hasMany(MappingUnitPegawai::class, 'objectunitkerjapegawaifk', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
@ -44,6 +44,7 @@
|
||||
<thead class="bg-primary" id="table_header">
|
||||
<tr>
|
||||
<th class="text-white fs-5">Nama Pegawai</th>
|
||||
<th class="text-white fs-5">Inisial Pegawai</th>
|
||||
<th class="text-white fs-5">Unit Kerja</th>
|
||||
<th class="text-white fs-5">Action</th>
|
||||
</tr>
|
||||
@ -115,6 +116,7 @@
|
||||
}
|
||||
},
|
||||
columns: [
|
||||
{ data: 'nama_pegawai' },
|
||||
{ data: 'nama' },
|
||||
{ data: 'unit' },
|
||||
{ data: 'action' }
|
||||
|
||||
@ -17,7 +17,7 @@ Route::middleware('ceklogin')->group(function () {
|
||||
Route::get('/admin', [AdminController::class, 'index']);
|
||||
Route::post('/admin/get_data_pegawai_sudah_survey', [AdminController::class, 'get_data_pegawai_sudah_survey']);
|
||||
Route::post('/admin/get_data_pegawai_tidak_mau_survey', [AdminController::class, 'data_tidak_mau_survey']);
|
||||
Route::get('/admin/dashboard_jawaban', [AdminController::class, 'dashboard_analisis']);
|
||||
// Route::get('/admin/dashboard_jawaban', [AdminController::class, 'dashboard_analisis']);
|
||||
Route::post('/admin/get_data_dashboard_jawaban', [AdminController::class, 'get_data_dashboard_analisis']);
|
||||
Route::post('/admin/report', [AdminController::class, 'download_report_data_pegawai_sudah_survey']);
|
||||
Route::get('/admin/dashboard_analisis', [AdminController::class, 'dashboard_analisis']);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user