You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
4.1 KiB
132 lines
4.1 KiB
<?php |
|
|
|
namespace App\Http\Controllers; |
|
|
|
use Illuminate\Http\Request; |
|
use Illuminate\Support\Facades\Auth; |
|
|
|
class HomeController extends Controller |
|
{ |
|
//halaman Admin |
|
public function index() |
|
{ |
|
$data = [ |
|
'reminder' => \App\Models\asset_status::whereNull('enter_at')->count(), |
|
'jumlahPeti' => \App\Models\Peti::count(), |
|
'jumlahPeminjaman' => \App\Models\asset_status::count(), |
|
'jumlahPengembalian' => \App\Models\asset_status::whereNotNull('enter_at')->count(), |
|
'active' => 'menu-admin', |
|
]; |
|
|
|
return view('dashboard.index', $data); |
|
} |
|
|
|
public function notification() |
|
{ |
|
$notification = \App\Models\asset_status::whereNull('enter_at') |
|
->whereDate('est_pengembalian', \Carbon\Carbon::today()) |
|
->get(); |
|
|
|
$data = [ |
|
'notifikasi' => $notification, |
|
'active' => 'menu-admin', |
|
]; |
|
|
|
return view('layouts.navbar_list', $data); |
|
} |
|
|
|
//data pertahun untuk bar chart |
|
public function generateChartData() |
|
{ |
|
$years = []; |
|
$exitData = []; |
|
$enterData = []; |
|
$monthNames = [ |
|
'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', |
|
'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember' |
|
]; |
|
|
|
// Ambil data tahun dari kolom exit_at |
|
$exitYears = \App\Models\asset_status::selectRaw('YEAR(exit_at) as year') |
|
->distinct() |
|
->orderBy('year', 'asc') |
|
->get() |
|
->pluck('year') |
|
->toArray(); |
|
|
|
// Ambil data tahun dari kolom enter_at |
|
$enterYears = \App\Models\asset_status::selectRaw('YEAR(enter_at) as year') |
|
->distinct() |
|
->orderBy('year', 'asc') |
|
->get() |
|
->pluck('year') |
|
->toArray(); |
|
|
|
// Gabungkan dan sortir tahun-tahun dari kedua kolom |
|
$years = array_merge($exitYears, $enterYears); |
|
$years = array_unique($years); |
|
sort($years); |
|
|
|
foreach ($years as $year) { |
|
$yearExitData = []; |
|
$yearEnterData = []; |
|
|
|
// Ambil data untuk setiap bulan dalam tahun tersebut |
|
foreach ($monthNames as $monthName) { |
|
$exitCount = \App\Models\asset_status::whereYear('exit_at', $year) |
|
->whereMonth('exit_at', array_search($monthName, $monthNames) + 1) |
|
->count(); |
|
$enterCount = \App\Models\asset_status::whereYear('enter_at', $year) |
|
->whereMonth('enter_at', array_search($monthName, $monthNames) + 1) |
|
->count(); |
|
|
|
$yearExitData[] = $exitCount; |
|
$yearEnterData[] = $enterCount; |
|
} |
|
|
|
$exitData[] = $yearExitData; |
|
$enterData[] = $yearEnterData; |
|
} |
|
|
|
return compact('years', 'exitData', 'enterData', 'monthNames'); |
|
} |
|
|
|
public function generateChartDataPie() |
|
{ |
|
$years = []; |
|
$enterData = []; |
|
$monthNames = [ |
|
'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', |
|
'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember' |
|
]; |
|
|
|
// Ambil data tahun dari kolom date_pembuatan |
|
$enterYears = \App\Models\Peti::selectRaw('YEAR(date_pembuatan) as year') |
|
->distinct() |
|
->orderBy('year', 'asc') |
|
->get() |
|
->pluck('year') |
|
->toArray(); |
|
|
|
// Gabungkan dan sortir tahun-tahun dari kolom date_pembuatan |
|
$years = array_unique($enterYears); |
|
sort($years); |
|
|
|
foreach ($years as $year) { |
|
$yearEnterData = []; |
|
|
|
// Ambil data untuk setiap bulan dalam tahun tersebut |
|
foreach ($monthNames as $monthName) { |
|
$enterCount = \App\Models\Peti::whereYear('date_pembuatan', $year) |
|
->whereMonth('date_pembuatan', array_search($monthName, $monthNames) + 1) |
|
->count(); |
|
|
|
$yearEnterData[] = $enterCount; |
|
} |
|
|
|
$enterData[] = $yearEnterData; |
|
} |
|
|
|
return compact('years', 'enterData', 'monthNames'); |
|
} |
|
}
|
|
|