Update DashboardController.php

This commit is contained in:
Jagad R R
2025-05-08 20:00:20 +07:00
parent ec2ed137b9
commit a917f1987e
@@ -15,37 +15,53 @@ use App\Models\FormMeetingSeminar;
use App\Models\FormOthers; use App\Models\FormOthers;
use App\Models\UserHasCabang; use App\Models\UserHasCabang;
use App\Models\Notifications; use App\Models\Notifications;
use Carbon\Carbon;
class DashboardController extends Controller class DashboardController extends Controller
{ {
public function index() public function index()
{ {
$role = auth()->user()->getRoleNames()[0]; $role = auth()->user()->getRoleNames()[0];
$startDate = date('Y-m-' . env('STARTING_DATE')); // Starting date from .env for the current month $startDay = (int) env('STARTING_DATE', 11);
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE'); // Closing date for the next month $closingDay = (int) env('CLOSING_DATE', 10);
// Referensi waktu sekarang
$now = Carbon::now();
// Tentukan periode
if ($now->day >= $startDay) {
// Mulai dari tanggal START bulan ini
$startDate = Carbon::create($now->year, $now->month, $startDay)->startOfDay();
// Sampai tanggal CLOSING bulan depan
$closingDate = Carbon::create($now->copy()->addMonth()->year, $now->copy()->addMonth()->month, $closingDay)->endOfDay();
} else {
// Mulai dari tanggal START bulan lalu
$startDate = Carbon::create($now->copy()->subMonth()->year, $now->copy()->subMonth()->month, $startDay)->startOfDay();
// Sampai tanggal CLOSING bulan ini
$closingDate = Carbon::create($now->year, $now->month, $closingDay)->endOfDay();
}
$forms = [ $forms = [
'vehicle' => FormVehicleRunningCost::whereMonth('tanggal', date('m')) 'vehicle' => FormVehicleRunningCost::whereMonth('tanggal', date('m'))
->whereBetween('tanggal', [$startDate, $closingDateNextMonth]) ->whereBetween('tanggal', [$startDate, $closingDate])
->orderBy('tanggal', 'desc') ->orderBy('tanggal', 'desc')
->get(), ->get(),
'upcountry' => FormUpCountry::whereMonth('tanggal', date('m')) 'upcountry' => FormUpCountry::whereMonth('tanggal', date('m'))
->whereBetween('tanggal', [$startDate, $closingDateNextMonth]) ->whereBetween('tanggal', [$startDate, $closingDate])
->orderBy('tanggal', 'desc') ->orderBy('tanggal', 'desc')
->get(), ->get(),
'entertainment' => FormEntertaimentPresentation::whereMonth('tanggal', date('m')) 'entertainment' => FormEntertaimentPresentation::whereMonth('tanggal', date('m'))
->whereBetween('tanggal', [$startDate, $closingDateNextMonth]) ->whereBetween('tanggal', [$startDate, $closingDate])
->orderBy('tanggal', 'desc') ->orderBy('tanggal', 'desc')
->get(), ->get(),
'meeting' => FormMeetingSeminar::whereMonth('created_at', date('m')) 'meeting' => FormMeetingSeminar::whereMonth('created_at', date('m'))
->whereBetween('created_at', [$startDate, $closingDateNextMonth]) ->whereBetween('created_at', [$startDate, $closingDate])
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->get(), ->get(),
'others' => FormOthers::whereMonth('tanggal', date('m')) 'others' => FormOthers::whereMonth('tanggal', date('m'))
->whereBetween('tanggal', [$startDate, $closingDateNextMonth]) ->whereBetween('tanggal', [$startDate, $closingDate])
->orderBy('tanggal', 'desc') ->orderBy('tanggal', 'desc')
->get(), ->get(),
]; ];
if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') { if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {