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.

134 lines
4.2 KiB

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class HomeController extends Controller
{
1 year ago
//halaman Admin
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
1 year ago
public function notification()
{
$notification = \App\Models\asset_status::whereNull('enter_at')
->whereDate('est_pengembalian', \Carbon\Carbon::today())
->get();
1 year ago
$data = [
'notifikasi' => $notification,
1 year ago
'active' => 'menu-admin',
];
return view('layouts.navbar_list', $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');
}
//data pertahun untuk pie chart
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');
}
}