69 lines
2.1 KiB
PHP
69 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\alternatif;
|
|
use App\Models\datakriteria;
|
|
use App\Models\datasubkriteria;
|
|
use App\Models\penduduk;
|
|
use App\Models\rangking;
|
|
use Illuminate\Http\Request;
|
|
|
|
class RangkingController extends Controller
|
|
{
|
|
|
|
|
|
|
|
public function index2()
|
|
{
|
|
$rangkings = Rangking::with('penduduk')->get();
|
|
$count = $rangkings->count();
|
|
|
|
return view('pages.rangking', compact('rangkings', 'count'));
|
|
}
|
|
public function cetak(Request $request)
|
|
{
|
|
$tahun = $request->tahun ?? date('Y'); // Ambil tahun dari request atau gunakan tahun saat ini jika tidak ada
|
|
|
|
$judul = 'Laporan Penerima Bantuan Tahun ' . $tahun;
|
|
$rangkings = Rangking::whereYear('created_at', $tahun)->get();
|
|
|
|
return view('pages.print4', compact('judul', 'rangkings'));
|
|
}
|
|
public function byYear($tahun)
|
|
{
|
|
$rangkingsByYear = Rangking::whereYear('created_at', $tahun)
|
|
->with('penduduk')
|
|
->orderByDesc('total')
|
|
->get();
|
|
|
|
$selectedYear = $tahun;
|
|
|
|
return view('pages.rangking.byYear', compact('rangkingsByYear', 'selectedYear'));
|
|
}
|
|
|
|
|
|
// Contoh di dalam fungsi di kontroler
|
|
public function showRankings(Request $request)
|
|
{
|
|
$year = $request->input('year', date('Y')); // Default to current year if not specified
|
|
$rangkings = $this->getRankingsByYear($year); // Implement this method to fetch data for the specified year
|
|
|
|
return view('pages.rangking', compact('rangkings', 'year'));
|
|
}
|
|
public function index3(Request $request)
|
|
{
|
|
$years = Rangking::selectRaw('YEAR(created_at) as year')
|
|
->groupBy('year')
|
|
->orderBy('year', 'desc')
|
|
->pluck('year');
|
|
|
|
$year = $request->input('year', date('Y')); // Ambil tahun dari input atau default ke tahun saat ini
|
|
|
|
$rangkings = Rangking::whereYear('created_at', $year)
|
|
->orderByDesc('total')
|
|
->get();
|
|
|
|
return view('pages.rangking', compact('rangkings', 'years', 'year'));
|
|
}
|
|
} |