Siopas Inventory PETI for ISTW Website
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.

142 lines
4.6 KiB

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class HomeController extends Controller
{
public function index()
{
$data = [
'reminder' => \App\Models\asset_status::whereNull('enter_at')->count(),
1 year ago
'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);
}
1 year ago
public function notification()
{
$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('layouts.navbar_list', $data);
}
public function indexUser()
{
$data = [
'reminder' => \App\Models\asset_status::whereNull('enter_at')->count(),
'jumlahPeminjaman' => \App\Models\asset_status::count(),
'jumlahPengembalian' => \App\Models\asset_status::whereNotNull('enter_at')->count(),
'active' => 'menu-user',
];
return view('pages.user.index', $data);
}
//data pertahun untuk bar chart
public function generateChartData()
{
1 year ago
$years = [];
$exitData = [];
$enterData = [];
$monthNames = [
'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni',
'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'
];
1 year ago
// 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();
1 year ago
$yearExitData[] = $exitCount;
$yearEnterData[] = $enterCount;
}
1 year ago
$exitData[] = $yearExitData;
$enterData[] = $yearEnterData;
}
1 year ago
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');
}
}