ganti label & perbaikan fungsi report & matting
This commit is contained in:
@@ -8,14 +8,12 @@ use App\Exports\UnifiedReportExport;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Gate; // WAJIB DIIMPORT untuk sistem permission
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class ReportController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
// PERBAIKAN UTAMA: Proteksi menggunakan matriks permission slug 'reports'
|
||||
// Ini menggantikan pengecekan manual 'admin'
|
||||
Gate::authorize('check-access', ['reports', 'read']);
|
||||
|
||||
$module = $request->get('module', 'cats');
|
||||
@@ -78,6 +76,19 @@ class ReportController extends Controller
|
||||
{
|
||||
$status = $request->status;
|
||||
|
||||
// TAMBAHAN: Logika Filter untuk Modul Cats (Sehat/Sakit)
|
||||
// Ini yang membuat filter status di populasi kucing bekerja
|
||||
if ($module === 'cats' && $request->filled('status')) {
|
||||
match($status) {
|
||||
'sakit' => $query->whereNotNull('riwayat_sakit_terakhir')->where('riwayat_sakit_terakhir', '!=', ''),
|
||||
'sehat' => $query->where(function($q) {
|
||||
$q->whereNull('riwayat_sakit_terakhir')
|
||||
->orWhere('riwayat_sakit_terakhir', '');
|
||||
}),
|
||||
default => null
|
||||
};
|
||||
}
|
||||
|
||||
// Modul Maintenance
|
||||
if (in_array($module, ['vaccine', 'deworming', 'flea', 'grooming']) && $request->filled('status')) {
|
||||
$dateCol = $this->getDateColumn($module);
|
||||
@@ -112,7 +123,7 @@ class ReportController extends Controller
|
||||
|
||||
private function getDateColumn($module) {
|
||||
return match($module) {
|
||||
'cats' => 'tanggal_lahir',
|
||||
'cats' => 'tanggal_lahir',
|
||||
'medicine', 'food', 'supplies' => 'expired_date',
|
||||
'vaccine' => 'jadwal_vaksin',
|
||||
'deworming' => 'jadwal_obat_cacing',
|
||||
@@ -124,7 +135,6 @@ class ReportController extends Controller
|
||||
|
||||
protected function processExport($data, $module, $format)
|
||||
{
|
||||
// Proteksi Tambahan: Pastikan user punya izin Export (opsional, bisa disatukan dengan Read)
|
||||
$fileName = "Report_{$module}_" . now()->format('Ymd_His');
|
||||
if ($format === 'xlsx') {
|
||||
return Excel::download(new UnifiedReportExport($data, $module), "{$fileName}.xlsx");
|
||||
|
||||
Reference in New Issue
Block a user