first commit
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Verifikasi\SK;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Verifikator\Periode;
|
||||
use App\Models\Verifikator\Sk;
|
||||
use App\Models\Verifikator\Team;
|
||||
use App\Services\SiskaService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class DitolakController extends Controller
|
||||
{
|
||||
private $siskaService;
|
||||
|
||||
private $periodeAktif;
|
||||
|
||||
private $auth;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->siskaService = new SiskaService;
|
||||
$this->periodeAktif = Periode::where('status', true)->first()->id_periode;
|
||||
$this->auth = Auth::user();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$title = 'Ditolak';
|
||||
$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.ditolak.index', compact('title', 'units', 'periode'));
|
||||
}
|
||||
|
||||
public function data(Request $request)
|
||||
{
|
||||
$team = Team::find(session('team_id'));
|
||||
$sks = Sk::select(
|
||||
'id_sk as id',
|
||||
'tanggal as tanggal_sk',
|
||||
'no_sk',
|
||||
'tentang',
|
||||
'verif_verifikator as status_verifikator',
|
||||
'finalisasi',
|
||||
'sk_jadi as sk',
|
||||
DB::raw('(SELECT note FROM verifikator.log_verifikasi_sks WHERE id_sk = verifikator.sks.id_sk::varchar AND status = false ORDER BY created_at DESC LIMIT 1) as alasan_tolak')
|
||||
)
|
||||
->where('periode', $this->periodeAktif)
|
||||
->where('verif_verifikator', 0)
|
||||
->where('finalisasi', 0)
|
||||
->orderBy('created_at', 'desc')
|
||||
->when($this->auth->hasRole('Superuser') && $request->filled('unit_id'), function ($query) use ($request) {
|
||||
if ($request->unit_id == 1) {
|
||||
$query->where(function ($subquery) {
|
||||
$subquery->where('id_unit_penandatangan', 1)
|
||||
->orWhere('id_unit_penandatangan', '>', 10);
|
||||
});
|
||||
} else {
|
||||
$query->where('id_unit_penandatangan', $request->unit_id);
|
||||
}
|
||||
})
|
||||
->when(! $this->auth->hasRole('Superuser') && $team->unit_kerja_id !== null, function ($query) use ($team) {
|
||||
$unitId = $team->unit_kerja_id + 1;
|
||||
if ($team->unit_kerja_id === 0) {
|
||||
return $query->where(function ($subquery) {
|
||||
$subquery->where('id_unit_penandatangan', 1)
|
||||
->orWhere('id_unit_penandatangan', '>', 10);
|
||||
});
|
||||
}
|
||||
$query->where('id_unit_penandatangan', $unitId);
|
||||
})
|
||||
->when($request->filled('kategori') && $request->kategori == 0, function ($query) {
|
||||
$query->whereHas('anggota', function ($query) {
|
||||
$query->whereNull('kategori_id');
|
||||
});
|
||||
})
|
||||
->when($request->kategori == -1, function ($query) {
|
||||
$query->whereHas('anggota', function ($query) {
|
||||
$query->select(DB::raw('COUNT(DISTINCT(kategori_id)) as kategori'))
|
||||
->havingRaw('COUNT(DISTINCT(kategori_id)) > 1');
|
||||
});
|
||||
})
|
||||
->when($request->kategori > 0, function ($query) use ($request) {
|
||||
$query->whereHas('anggota', function ($query) use ($request) {
|
||||
$query->where('kategori_id', $request->kategori);
|
||||
});
|
||||
});
|
||||
|
||||
$data = $sks->when($request->tentang !== '', function ($query) {
|
||||
$query->where('tentang', 'ilike', '%'.request()->tentang.'%');
|
||||
})->when($request->no_sk !== '', function ($query) {
|
||||
$query->where('no_sk', 'ilike', '%'.request()->no_sk.'%');
|
||||
})->when($request->filled('penandatangan'), function ($query) {
|
||||
$query->where('id_pimpinan', request()->penandatangan);
|
||||
});
|
||||
|
||||
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('tentang', function ($row) {
|
||||
$tentang = e($row->tentang ?? '-');
|
||||
$alasan = $row->alasan_tolak;
|
||||
if ($alasan) {
|
||||
return $tentang
|
||||
.'<br><small class="text-danger fw-bold"><i class="uil-ban"></i> '
|
||||
.e($alasan)
|
||||
.'</small>';
|
||||
}
|
||||
|
||||
return $tentang;
|
||||
})
|
||||
->escapeColumns([])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user