97 lines
3.4 KiB
PHP
97 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\BobotKriteria;
|
|
use App\Models\PerbandinganKriteria;
|
|
use App\Models\PerbandinganAlternatif;
|
|
use App\Models\ConsistencyRatioAlternatif;
|
|
use App\Models\SkorMakanan;
|
|
use App\Models\Kriteria;
|
|
use App\Models\Makanan;
|
|
use Illuminate\Http\Request;
|
|
use Carbon\Carbon;
|
|
|
|
class HistoryAHPController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
try {
|
|
// Ambil tanggal dari request atau gunakan hari ini
|
|
$tanggal = $request->input('tanggal')
|
|
? Carbon::parse($request->input('tanggal'))->format('Y-m-d')
|
|
: now()->format('Y-m-d');
|
|
|
|
// Parse tanggal untuk query
|
|
$tanggalCarbon = Carbon::parse($tanggal)->startOfDay();
|
|
|
|
// Ambil data history perhitungan untuk tanggal yang dipilih
|
|
$bobotKriteria = [
|
|
$tanggal => BobotKriteria::with('kriteria')
|
|
->whereDate('created_at', $tanggalCarbon)
|
|
->orderBy('created_at', 'desc')
|
|
->get()
|
|
];
|
|
|
|
$perbandinganKriteria = [
|
|
$tanggal => PerbandinganKriteria::with(['kriteria1', 'kriteria2'])
|
|
->whereDate('created_at', $tanggalCarbon)
|
|
->orderBy('created_at', 'desc')
|
|
->get()
|
|
];
|
|
|
|
$perbandinganAlternatif = [
|
|
$tanggal => PerbandinganAlternatif::with(['alternatif1', 'alternatif2', 'kriteria'])
|
|
->whereDate('created_at', $tanggalCarbon)
|
|
->orderBy('created_at', 'desc')
|
|
->get()
|
|
];
|
|
|
|
$consistencyRatios = [
|
|
$tanggal => ConsistencyRatioAlternatif::with(['kriteria', 'komponen'])
|
|
->whereDate('created_at', $tanggalCarbon)
|
|
->orderBy('created_at', 'desc')
|
|
->get()
|
|
];
|
|
|
|
$skorMakanan = [
|
|
$tanggal => SkorMakanan::with(['makanan', 'kriteria'])
|
|
->whereDate('created_at', $tanggalCarbon)
|
|
->orderBy('created_at', 'desc')
|
|
->get()
|
|
];
|
|
|
|
// Filter out empty collections
|
|
$bobotKriteria = array_filter($bobotKriteria, function($collection) {
|
|
return $collection->isNotEmpty();
|
|
});
|
|
|
|
$perbandinganKriteria = array_filter($perbandinganKriteria, function($collection) {
|
|
return $collection->isNotEmpty();
|
|
});
|
|
|
|
$perbandinganAlternatif = array_filter($perbandinganAlternatif, function($collection) {
|
|
return $collection->isNotEmpty();
|
|
});
|
|
|
|
$consistencyRatios = array_filter($consistencyRatios, function($collection) {
|
|
return $collection->isNotEmpty();
|
|
});
|
|
|
|
$skorMakanan = array_filter($skorMakanan, function($collection) {
|
|
return $collection->isNotEmpty();
|
|
});
|
|
|
|
return view('admin.history.ahp', compact(
|
|
'bobotKriteria',
|
|
'perbandinganKriteria',
|
|
'perbandinganAlternatif',
|
|
'consistencyRatios',
|
|
'skorMakanan',
|
|
'tanggal'
|
|
));
|
|
} catch (\Exception $e) {
|
|
return redirect()->back()->with('error', 'Terjadi kesalahan saat memuat data history: ' . $e->getMessage());
|
|
}
|
|
}
|
|
}
|