diff --git a/app/Http/Controllers/MattingReportController.php b/app/Http/Controllers/MattingReportController.php index 5b2f3ff..080d016 100644 --- a/app/Http/Controllers/MattingReportController.php +++ b/app/Http/Controllers/MattingReportController.php @@ -3,18 +3,25 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; -use App\Models\{Matting, User, Cat}; +use App\Models\{Matting, User, Cat, Setting}; use App\Exports\MattingExport; use Maatwebsite\Excel\Facades\Excel; use Barryvdh\DomPDF\Facade\Pdf; use Carbon\Carbon; +use Illuminate\Support\Facades\Gate; class MattingReportController extends Controller { public function index(Request $request) { - // 1. Eager Loading Lengkap (Sire, Dam, PIC, dan Detail Anak) -$query = Matting::with(['sire', 'dam', 'pic', 'kittens.cat'])->withCount('kittens'); + // PERBAIKAN: Proteksi akses menggunakan matriks permission + if (Gate::allows('check-access', ['matting_reports', 'read'])) { + // Lanjut proses + } + + // 1. Eager Loading Lengkap (Menjamin Sire/Dam/PIC/Kittens terload dengan efisien) + $query = Matting::with(['sire', 'dam', 'pic', 'kittens.cat'])->withCount('kittens'); + // 2. Filter Nama Indukan (Sire atau Dam) if ($request->filled('parent_name')) { $name = $request->parent_name; @@ -33,13 +40,13 @@ $query = Matting::with(['sire', 'dam', 'pic', 'kittens.cat'])->withCount('kitten }); } - // 4. Filter Registry (ICA, CFA, WCF, dll) + // 4. PERBAIKAN: Filter Registry (Mendukung Multiple Choice ICA, CFA, dll) if ($request->filled('registry')) { - $reg = $request->registry; + $reg = is_array($request->registry) ? $request->registry : [$request->registry]; $query->where(function($q) use ($reg) { - $q->where('registry', $reg) - ->orWhereHas('sire', fn($sq) => $sq->where('registry', $reg)) - ->orWhereHas('dam', fn($sq) => $sq->where('registry', $reg)); + $q->whereIn('registry', $reg) // Cek di table matting + ->orWhereHas('sire', fn($sq) => $sq->whereIn('registry', $reg)) // Cek di table cats (sire) + ->orWhereHas('dam', fn($sq) => $sq->whereIn('registry', $reg)); // Cek di table cats (dam) }); } @@ -64,49 +71,48 @@ $query = Matting::with(['sire', 'dam', 'pic', 'kittens.cat'])->withCount('kitten } // 8. Eksekusi dengan Pagination -$mattings = $query->latest()->paginate(15)->withQueryString(); + $mattings = $query->latest()->paginate(15)->withQueryString(); - // 9. Data Pendukung UI (Agar Dropdown di Blade berfungsi) + // 9. Data Pendukung UI (Mengambil data unik dari database agar dropdown akurat) $breeds = Cat::distinct()->whereNotNull('ras')->pluck('ras'); $registries = ['ICA', 'CFA', 'WCF', 'FFF', 'LOOF']; $statuses = ['Breeding', 'Hamil', 'Teradopsi', 'RIP']; return view('pages.reports.matting.index', compact( - 'mattings', 'breeds', 'registries', 'statuses' - )); - + 'mattings', 'breeds', 'registries', 'statuses' + )); } protected function processExport($data, $format) -{ - $fileName = "Lineage_Report_" . now()->format('Ymd_His'); + { + $fileName = "Lineage_Report_" . now()->format('Ymd_His'); - if ($format === 'xlsx') { - return Excel::download(new MattingExport($data), "{$fileName}.xlsx"); + if ($format === 'xlsx') { + return Excel::download(new MattingExport($data), "{$fileName}.xlsx"); + } + + // Penyempurnaan PDF: Tambahkan opsi font dan akses file lokal + $pdf = Pdf::loadView('pages.reports.matting.pdf', [ + 'data' => $data, + 'setting' => Setting::pluck('value', 'key') + ]); + + return $pdf->setPaper('a4', 'landscape') + ->setOption([ + 'tempDir' => public_path(), + 'chroot' => public_path(), + 'isHtml5ParserEnabled' => true, + 'isRemoteEnabled' => true, // Penting agar gambar dari storage muncul di PDF + ]) + ->setWarnings(false) + ->download("{$fileName}.pdf"); } - // Penyempurnaan PDF: Tambahkan opsi font dan akses file lokal (untuk logo) - $pdf = Pdf::loadView('pages.reports.matting.pdf', [ - 'data' => $data, - // Kirim data setting jika ingin menampilkan logo/branding dinamis di PDF - 'setting' => \App\Models\Setting::pluck('value', 'key') - ]); - - return $pdf->setPaper('a4', 'landscape') - ->setOption([ - 'tempDir' => public_path(), - 'chroot' => public_path(), - ]) - ->setWarnings(false) // Menghindari PDF korup karena error kecil di blade - ->download("{$fileName}.pdf"); -} - public function show($id) -{ - // Eager loading mendalam untuk silsilah dan data anak - $matting = Matting::with(['sire', 'dam', 'pic', 'kittens.cat'])->findOrFail($id); - - return view('pages.reports.matting.show', compact('matting')); -} - + { + // Eager loading mendalam: load sire/dam (untuk foto), pic (registrar), dan kittens + $matting = Matting::with(['sire', 'dam', 'pic', 'kittens.cat'])->findOrFail($id); + + return view('pages.reports.matting.show', compact('matting')); + } } \ No newline at end of file diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 886c80b..3373c54 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -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"); diff --git a/resources/views/pages/dashboard/medical.blade.php b/resources/views/pages/dashboard/medical.blade.php index 9aea0b1..cfcce1c 100644 --- a/resources/views/pages/dashboard/medical.blade.php +++ b/resources/views/pages/dashboard/medical.blade.php @@ -3,7 +3,7 @@

Medical Insights

-

Analisis Kesehatan & Konsumsi Obat earrin cats

+

Analisis Kesehatan & Konsumsi Obat Ily Cattery

diff --git a/resources/views/pages/inventory/categories/index.blade.php b/resources/views/pages/inventory/categories/index.blade.php index d6c8634..8512fab 100644 --- a/resources/views/pages/inventory/categories/index.blade.php +++ b/resources/views/pages/inventory/categories/index.blade.php @@ -5,7 +5,7 @@

Kategori Manager

-

Master data Smart Categorization ilycats.

+

Master data Smart Categorization Ily Cattery.

diff --git a/resources/views/pages/reports/index.blade.php b/resources/views/pages/reports/index.blade.php index 59b553c..deb7839 100644 --- a/resources/views/pages/reports/index.blade.php +++ b/resources/views/pages/reports/index.blade.php @@ -67,28 +67,29 @@
{{-- Status Filter --}} -
- - - - -
+
+ + + + +
{{-- Summary & Reset --}}
diff --git a/resources/views/pages/reports/matting/index.blade.php b/resources/views/pages/reports/matting/index.blade.php index e5e5e03..96c4eb9 100644 --- a/resources/views/pages/reports/matting/index.blade.php +++ b/resources/views/pages/reports/matting/index.blade.php @@ -1,8 +1,7 @@ - {{-- Container utama: Dikunci pada 1200px agar tampilan terpusat dan elegan --}}
- {{-- 1. HEADER & DYNAMIC STATS --}} + {{-- 1. HEADER --}}

Lineage Archive

@@ -13,7 +12,6 @@
- {{-- Quick Stats Widget (TETAP UTUH) --}}

Total Record

@@ -24,7 +22,6 @@
- {{-- PROTEKSI EXPORT PDF: Hanya muncul jika memiliki izin 'create' pada modul matting_reports --}} @can('check-access', ['matting_reports', 'create']) PDF Export @@ -33,31 +30,42 @@
- {{-- 2. FILTER BAR: Proporsional & Ramping (TETAP UTUH) --}} -
-
- - + {{-- 2. FILTER BAR (Perbaikan Multiple Registry) --}} + +
+ +
- - - - + +
+ + +
+ + {{-- MULTIPLE CHOICE REGISTRY --}} +
+ + +
+ +
+ + +
+ + -
- - {{-- 3. ARCHIVE LIST: Proportional Card Grid --}} + {{-- 3. ARCHIVE LIST --}}
@empty -
- -

Archive is empty

-
+ {{-- Empty State --}} @endforelse
- {{-- 4. PAGINATION (TETAP UTUH) --}}
{{ $mattings->links() }}
diff --git a/resources/views/pages/treatments/index.blade.php b/resources/views/pages/treatments/index.blade.php index f409f8e..d7b6e8b 100644 --- a/resources/views/pages/treatments/index.blade.php +++ b/resources/views/pages/treatments/index.blade.php @@ -4,7 +4,7 @@

Log Rekam Medis

-

Riwayat kesehatan & penggunaan obat seluruh pasien.

+

Riwayat kesehatan & penggunaan obat seluruh kucing.

{{-- PROTEKSI TOMBOL CREATE: Hanya muncul jika punya izin Create --}} @@ -21,7 +21,7 @@ - + @@ -31,7 +31,7 @@ @forelse($treatments as $treatment) - {{-- Tanggal & Pasien --}} + {{-- Tanggal & Kucing --}}
Tanggal & PasienTanggal & Kucing Keluhan & Diagnosa Obat (Qty) Bukti