skl/app/Http/Controllers/PelaporanController.php

45 lines
1.4 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Pelaporan;
use App\Models\PeriodePelaporan;
use App\Models\Perusahaan;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Inertia\Inertia;
class PelaporanController extends Controller
{
// public function index()
// {
// try {
// return Inertia::render('admin/pelaporan/index_pelaporan');
// } catch (\Exception $e) {
// Log::error('Error rendering view: ' . $e->getMessage());
// return back()->with('error', 'Something went wrong.');
// }
// }
public function index(Request $request)
{
// Ambil data perusahaan
$companies = Perusahaan::select('PerusahaanId', 'NamaPerusahaan')->get();
// Ambil data periode (misalnya Triwulan)
// Pastikan model PeriodePelaporan memiliki field 'NamaPeriode' atau 'Triwulan'
$periodes = PeriodePelaporan::select('PeriodePelaporanId', 'Nama')->get();
// Ambil data pelaporan lengkap dengan relasi perusahaan dan periode pelaporan
// (Sesuaikan nama relasinya dengan yang ada di model Pelaporan)
$pelaporan = Pelaporan::with(['perusahaan', 'periodePelaporan'])->get();
// Kirim data ke Inertia
return Inertia::render('admin/pelaporan/index_pelaporan', [
'companies' => $companies,
'periodes' => $periodes,
'pelaporan' => $pelaporan,
]);
}
}