134 lines
5.2 KiB
PHP
134 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Verifikasi\SK;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Verifikasi\SK\Concerns\FormatKolomSk;
|
|
use App\Models\Verifikator\Periode;
|
|
use App\Models\Verifikator\Team;
|
|
use App\Services\SiskaService;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Yajra\DataTables\Facades\DataTables;
|
|
|
|
class PerluPerbaikanController extends Controller
|
|
{
|
|
use FormatKolomSk;
|
|
|
|
private $siskaService;
|
|
|
|
private $auth;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->siskaService = new SiskaService;
|
|
$this->auth = Auth::user();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$title = 'Perlu Perbaikan';
|
|
$units = [];
|
|
|
|
// Ambil daftar unit kerja hanya untuk Superuser
|
|
if ($this->auth->hasRole('Superuser')) {
|
|
$allUnits = $this->siskaService->daftarUnits();
|
|
|
|
// Cek jika service SISKA tidak tersedia
|
|
if ($allUnits === null) {
|
|
return redirect()->back()->with('info', 'Service SISKA sedang melakukan Maintenance, silahkan coba beberapa saat lagi.');
|
|
}
|
|
|
|
// Filter hanya unit kerja dengan ID 1-10
|
|
$units = array_filter($allUnits, function ($unit) {
|
|
return $unit['id'] >= 1 && $unit['id'] <= 10;
|
|
});
|
|
}
|
|
|
|
$periode = Periode::where('status', true)->first();
|
|
|
|
return view('verifikasi.sk.perlu-perbaikan.index', compact('title', 'units', 'periode'));
|
|
}
|
|
|
|
public function data(Request $request)
|
|
{
|
|
$team = Team::find(session('team_id'));
|
|
|
|
// Jika Superuser dan memilih unit tertentu
|
|
if ($this->auth->hasRole('Superuser') && $request->filled('unit_id')) {
|
|
$unit = $request->unit_id;
|
|
} else {
|
|
$unit = $team->unit_kerja_id === null ? null : $team->unit_kerja_id + 1;
|
|
}
|
|
|
|
if ($request->no_sk) {
|
|
$response = $this->siskaService->searchStatusPerbaikanByNomorSk($unit, $request->no_sk, 'Belum Diperbaiki', 1, 10000);
|
|
} else {
|
|
if ($unit) {
|
|
if ($unit > 1 && $unit <= 10) {
|
|
$response = $this->siskaService->statusPerbaikan($unit, 'Belum Diperbaiki', 1, 10000);
|
|
} else {
|
|
// Untuk unit selain 1-10, ambil semua data
|
|
$response = $this->siskaService->statusPerbaikan(null, 'Belum Diperbaiki', 1, 10000);
|
|
}
|
|
} else {
|
|
// Jika tidak ada unit, ambil semua data
|
|
$response = $this->siskaService->statusPerbaikan(null, 'Belum Diperbaiki', 1, 10000);
|
|
}
|
|
}
|
|
|
|
$data = $response['data'] ?? [];
|
|
|
|
return DataTables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('tanggal_sk', function ($row) {
|
|
return $row['tanggal_sk'] ? Carbon::parse($row['tanggal_sk'])->format('d/m/Y') : '-';
|
|
})
|
|
->addColumn('status_verifikator', function ($row) {
|
|
if ($row['must_fix']) {
|
|
return '<span class="badge bg-secondary rounded-pill fs-6 px-2 py-1">Perlu Perbaikan</span>';
|
|
} elseif ($row['must_fix'] === 0) {
|
|
return '<span class="badge bg-info rounded-pill fs-6 px-2 py-1">Sudah Diperbaiki</span>';
|
|
} elseif ($row['status_verifikator'] === null) {
|
|
return '<span class="badge bg-warning rounded-pill fs-6 px-2 py-1">Belum Diverifikasi</span>';
|
|
} elseif ($row['status_verifikator'] == 1 && $row['finalisasi']) {
|
|
return '<span class="badge bg-success rounded-pill fs-6 px-2 py-1">Sudah Finalisasi</span>';
|
|
} elseif ($row['status_verifikator'] == 1 && ! $row['finalisasi']) {
|
|
return '<span class="badge bg-primary rounded-pill fs-6 px-2 py-1">Belum Finalisasi</span>';
|
|
} else {
|
|
return '<span class="badge bg-danger rounded-pill fs-6 px-2 py-1">Ditolak</span>';
|
|
}
|
|
})
|
|
->addColumn('pdf', function ($row) {
|
|
if ($row['sk']) {
|
|
return '<a href="'.$row['sk'].'" target="_blank" class="btn btn-sm btn-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="Lihat PDF SK"><i class="uil-file-alt"></i></a>';
|
|
}
|
|
|
|
return '<span class="text-muted">-</span>';
|
|
})
|
|
->addColumn('url_detail', function ($row) {
|
|
return route('sk.detail.index', $row['id']);
|
|
})
|
|
->addColumn('no_anggota', function ($row) {
|
|
return empty($row['anggota']);
|
|
})
|
|
->editColumn('no_sk', function ($row) {
|
|
$peringatan = empty($row['anggota'])
|
|
? [$this->peringatanSk('SK ini tidak memiliki anggota')]
|
|
: [];
|
|
|
|
return $this->kolomNoSk(
|
|
$row['no_sk'] ?? null,
|
|
$row['id_unit_penandatangan'] ?? $row['id_unit'] ?? null,
|
|
$peringatan
|
|
);
|
|
})
|
|
->addColumn('tentang', function ($row) {
|
|
return $this->kolomTentang($row['tentang'] ?? null, $row['id']);
|
|
})
|
|
->escapeColumns([])
|
|
->make(true);
|
|
}
|
|
}
|