Update DashboardController.php
This commit is contained in:
@@ -15,37 +15,53 @@ use App\Models\FormMeetingSeminar;
|
||||
use App\Models\FormOthers;
|
||||
use App\Models\UserHasCabang;
|
||||
use App\Models\Notifications;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$role = auth()->user()->getRoleNames()[0];
|
||||
$startDate = date('Y-m-' . env('STARTING_DATE')); // Starting date from .env for the current month
|
||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE'); // Closing date for the next month
|
||||
$startDay = (int) env('STARTING_DATE', 11);
|
||||
$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 = [
|
||||
'vehicle' => FormVehicleRunningCost::whereMonth('tanggal', date('m'))
|
||||
->whereBetween('tanggal', [$startDate, $closingDateNextMonth])
|
||||
->orderBy('tanggal', 'desc')
|
||||
->get(),
|
||||
->whereBetween('tanggal', [$startDate, $closingDate])
|
||||
->orderBy('tanggal', 'desc')
|
||||
->get(),
|
||||
'upcountry' => FormUpCountry::whereMonth('tanggal', date('m'))
|
||||
->whereBetween('tanggal', [$startDate, $closingDateNextMonth])
|
||||
->orderBy('tanggal', 'desc')
|
||||
->get(),
|
||||
->whereBetween('tanggal', [$startDate, $closingDate])
|
||||
->orderBy('tanggal', 'desc')
|
||||
->get(),
|
||||
'entertainment' => FormEntertaimentPresentation::whereMonth('tanggal', date('m'))
|
||||
->whereBetween('tanggal', [$startDate, $closingDateNextMonth])
|
||||
->orderBy('tanggal', 'desc')
|
||||
->get(),
|
||||
->whereBetween('tanggal', [$startDate, $closingDate])
|
||||
->orderBy('tanggal', 'desc')
|
||||
->get(),
|
||||
'meeting' => FormMeetingSeminar::whereMonth('created_at', date('m'))
|
||||
->whereBetween('created_at', [$startDate, $closingDateNextMonth])
|
||||
->orderBy('created_at', 'desc')
|
||||
->get(),
|
||||
->whereBetween('created_at', [$startDate, $closingDate])
|
||||
->orderBy('created_at', 'desc')
|
||||
->get(),
|
||||
'others' => FormOthers::whereMonth('tanggal', date('m'))
|
||||
->whereBetween('tanggal', [$startDate, $closingDateNextMonth])
|
||||
->orderBy('tanggal', 'desc')
|
||||
->get(),
|
||||
->whereBetween('tanggal', [$startDate, $closingDate])
|
||||
->orderBy('tanggal', 'desc')
|
||||
->get(),
|
||||
];
|
||||
|
||||
if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
|
||||
|
||||
Reference in New Issue
Block a user