<?php

declare(strict_types=1);

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use App\Models\AuditTrail;
use App\Models\FormUpCountry;
use App\Models\FormEntertaimentPresentation;
use App\Models\FormMeetingSeminar;
use App\Models\FormVehicleRunningCost;
use App\Models\FormOthers;
use App\Models\UserHasCabang;
use Illuminate\Support\Facades\DB;
use App\Models\Cabang;
use App\Models\Region;
use App\Helpers\FormHelper;
use App\Helpers\BudgetHelper;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Schema;
use App\Models\Kategori;
use App\Models\BudgetControlLog;

class ReportController extends Controller
{   
    public function upcountry()
    {
        $role = auth()->user()->getRoleNames()[0];
        $cabangs = collect(); // Default empty collection
        $regions = collect(); // Default empty collection
        $formsQuery = FormUpCountry::with([
            'user.region',
            'user.cabang',
            'rayon'
        ]);

        if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
            $region_id = auth()->user()->getMyCabangAndRegionId()['region'];

            if ($region_id) {
                $cabangs = Cabang::where('region_id', $region_id)->get();
                $regions = Region::where('id', $region_id)->get();
                $userIds = UserHasCabang::whereIn('cabang_id', $cabangs->pluck('id'))->pluck('user_id');
                $formsQuery->whereIn('user_id', $userIds);
            }
        } elseif ($role == 'Area Manager Cabang') {
            $cabang_id = auth()->user()->getMyCabangAndRegionId()['cabang'];

            if ($cabang_id) {
                $cabangs = Cabang::where('id', $cabang_id)->get();
                $regions = Region::where('id', $cabangs->first()->region_id)->get();
                $userIds = UserHasCabang::where('cabang_id', $cabang_id)->pluck('user_id');
                $formsQuery->whereIn('user_id', $userIds);
            }
        } else {
            $cabangs = Cabang::all();
            $regions = Region::all();
        }

        // Apply filters from URL params
        $params = request()->all();

        if (isset($params['region'])) {
            $region = Region::where('code', $params['region'])->first();
            if ($region) {
                $userIds = UserHasCabang::whereIn('cabang_id', Cabang::where('region_id', $region->id)->pluck('id'))->pluck('user_id');
                $formsQuery->whereIn('user_id', $userIds);
            }
        }

        if (isset($params['cabang'])) {
            $cabang = Cabang::where('code', $params['cabang'])->first();
            if ($cabang) {
                $userIds = UserHasCabang::where('cabang_id', $cabang->id)->pluck('user_id');
                $formsQuery->whereIn('user_id', $userIds);
            }
        }

        if (isset($params['start_date']) || isset($params['end_date'])) {
            $startDate = $params['start_date'] ?? null;
            $endDate = $params['end_date'] ?? null;

            if ($startDate && $endDate) {
                $formsQuery->whereBetween('tanggal', [$startDate, $endDate]);
            } elseif ($startDate) {
                $formsQuery->where('tanggal', '>=', $startDate);
            } elseif ($endDate) {
                $formsQuery->where('tanggal', '<=', $endDate);
            }
        }

        if (isset($params['status'])) {
            $formsQuery->where('status', $params['status']);
        }

        // Fetch forms after applying all filters
        $forms = $formsQuery->get();

        return view('backend.pages.report.upcountry', [
            'pageInfo' => [
                'title' => 'Generate Reports For Form Up Country',
            ],
            'forms' => $forms,
            'cabang' => $cabangs,
            'regions' => $regions
        ]);
    }


    public function vehicle()
    {
        $role = auth()->user()->getRoleNames()[0];
        $cabangs = collect(); // Default empty collection
        $regions = collect(); // Default empty collection
        $formsQuery = FormVehicleRunningCost::with([
            'user.region', // Eager load 'region' within 'user'
            'user.cabang', // Eager load 'cabang' within 'user'
        ]);

        // Apply role-based query logic
        if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
            $region_id = auth()->user()->getMyCabangAndRegionId()['region'];

            if ($region_id) {
                $cabangs = Cabang::where('region_id', $region_id)->get();
                $regions = Region::where('id', $region_id)->get();
                $userIds = UserHasCabang::whereIn('cabang_id', $cabangs->pluck('id'))->pluck('user_id');
                $formsQuery->whereIn('user_id', $userIds);
            }
        } elseif ($role == 'Area Manager Cabang') {
            $cabang_id = auth()->user()->getMyCabangAndRegionId()['cabang'];

            if ($cabang_id) {
                $cabangs = Cabang::where('id', $cabang_id)->get();
                $regions = Region::where('id', $cabangs->first()->region_id)->get();
                $userIds = UserHasCabang::where('cabang_id', $cabang_id)->pluck('user_id');
                $formsQuery->whereIn('user_id', $userIds);
            }
        } else {
            // Default behavior for other roles (if no specific role is matched)
            $cabangs = Cabang::all();
            $regions = Region::all();
        }

        // Get all params in URL for filtering
        $params = request()->all();

        if ($params) {
            // Filter by region
            if (isset($params['region'])) {
                $region = Region::where('code', $params['region'])->first();
                if ($region) {
                    $userIds = UserHasCabang::whereIn('cabang_id', Cabang::where('region_id', $region->id)->pluck('id'))->pluck('user_id');
                    $formsQuery->whereIn('user_id', $userIds);
                }
            }

            // Filter by cabang
            if (isset($params['cabang'])) {
                $cabang = Cabang::where('code', $params['cabang'])->first();
                if ($cabang) {
                    $userIds = UserHasCabang::where('cabang_id', $cabang->id)->pluck('user_id');
                    $formsQuery->whereIn('user_id', $userIds);
                }
            }

            // Filter by date range
            if (isset($params['start_date']) || isset($params['end_date'])) {
                $startDate = $params['start_date'] ?? null;
                $endDate = $params['end_date'] ?? null;

                if ($startDate && $endDate) {
                    $formsQuery->whereBetween('tanggal', [$startDate, $endDate]);
                } elseif ($startDate) {
                    $formsQuery->where('tanggal', '>=', $startDate);
                } elseif ($endDate) {
                    $formsQuery->where('tanggal', '<=', $endDate);
                }
            }

            // Filter by status
            if (isset($params['status'])) {
                $formsQuery->where('status', $params['status']);
            }
        }

        // Fetch forms after applying all filters
        $forms = $formsQuery->get();

        return view('backend.pages.report.vehicle', [
            'pageInfo' => [
                'title' => 'Generate Reports For Form Vehicle Running Cost',
            ],
            'forms' => $forms,
            'cabang' => $cabangs,
            'regions' => $regions
        ]);
    }

    public function entertainment()
    {
        $role = auth()->user()->getRoleNames()[0];
        $cabangs = Cabang::all();
        $regions = Region::all();
        $formsQuery = FormEntertaimentPresentation::with([
            'user.region', // Eager load 'region' within 'user'
            'user.cabang', // Eager load 'cabang' within 'user'
        ]);

        // Apply role-based query logic
        if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
            $region_id = auth()->user()->getMyCabangAndRegionId()['region'];

            if ($region_id) {
                $cabangs = Cabang::where('region_id', $region_id)->get();
                $regions = Region::where('id', $region_id)->get();
                $userIds = UserHasCabang::whereIn('cabang_id', $cabangs->pluck('id'))->pluck('user_id');
                $formsQuery->whereIn('user_id', $userIds);
            }
        } elseif ($role == 'Area Manager Cabang') {
            $cabang_id = auth()->user()->getMyCabangAndRegionId()['cabang'];

            if ($cabang_id) {
                $cabangs = Cabang::where('id', $cabang_id)->get();
                $regions = Region::where('id', $cabangs->first()->region_id)->get();
                $userIds = UserHasCabang::where('cabang_id', $cabang_id)->pluck('user_id');
                $formsQuery->whereIn('user_id', $userIds);
            }
        }

        // Get all params in URL for filtering
        $params = request()->all();

        if ($params) {
            // Filter by region
            if (isset($params['region'])) {
                $region = Region::where('code', $params['region'])->first();
                if ($region) {
                    $userIds = UserHasCabang::whereIn('cabang_id', Cabang::where('region_id', $region->id)->pluck('id'))->pluck('user_id');
                    $formsQuery->whereIn('user_id', $userIds);
                }
            }

            // Filter by cabang
            if (isset($params['cabang'])) {
                $cabang = Cabang::where('code', $params['cabang'])->first();
                if ($cabang) {
                    $userIds = UserHasCabang::where('cabang_id', $cabang->id)->pluck('user_id');
                    $formsQuery->whereIn('user_id', $userIds);
                }
            }

            // Filter by date range
            if (isset($params['start_date']) || isset($params['end_date'])) {
                $startDate = $params['start_date'] ?? null;
                $endDate = $params['end_date'] ?? null;

                if ($startDate && $endDate) {
                    $formsQuery->whereBetween('tanggal', [$startDate, $endDate]);
                } elseif ($startDate) {
                    $formsQuery->where('tanggal', '>=', $startDate);
                } elseif ($endDate) {
                    $formsQuery->where('tanggal', '<=', $endDate);
                }
            }

            // Filter by status
            if (isset($params['status'])) {
                $formsQuery->where('status', $params['status']);
            }
        }

        // Fetch forms after applying all filters
        $forms = $formsQuery->get();

        return view('backend.pages.report.entertainment', [
            'pageInfo' => [
                'title' => 'Generate Reports For Form Entertainment & Presentation',
            ],
            'forms' => $forms,
            'cabang' => $cabangs,
            'regions' => $regions
        ]);
    }

    public function meeting()
    {
        $role = auth()->user()->getRoleNames()[0];
        $cabangs = Cabang::all();
        $regions = Region::all();
        
        // Initialize the query for FormMeetingSeminar with eager loading
        $formsQuery = FormMeetingSeminar::with([
            'user.region', // Eager load 'region' within 'user'
            'user.cabang', // Eager load 'cabang' within 'user'
        ]);

        // Apply role-based query logic
        if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
            $region_id = auth()->user()->getMyCabangAndRegionId()['region'];

            if ($region_id) {
                $cabangs = Cabang::where('region_id', $region_id)->get();
                $regions = Region::where('id', $region_id)->get();
                $userIds = UserHasCabang::whereIn('cabang_id', $cabangs->pluck('id'))->pluck('user_id');
                $formsQuery->whereIn('user_id', $userIds);
            }
        } elseif ($role == 'Area Manager Cabang') {
            $cabang_id = auth()->user()->getMyCabangAndRegionId()['cabang'];

            if ($cabang_id) {
                $cabangs = Cabang::where('id', $cabang_id)->get();
                $regions = Region::where('id', $cabangs->first()->region_id)->get();
                $userIds = UserHasCabang::where('cabang_id', $cabang_id)->pluck('user_id');
                $formsQuery->whereIn('user_id', $userIds);
            }
        }

        // Get all params in URL for filtering
        $params = request()->all();

        if ($params) {
            // Filter by region
            if (isset($params['region'])) {
                $region = Region::where('code', $params['region'])->first();
                if ($region) {
                    $userIds = UserHasCabang::whereIn('cabang_id', Cabang::where('region_id', $region->id)->pluck('id'))->pluck('user_id');
                    $formsQuery->whereIn('user_id', $userIds);
                }
            }

            // Filter by cabang
            if (isset($params['cabang'])) {
                $cabang = Cabang::where('code', $params['cabang'])->first();
                if ($cabang) {
                    $userIds = UserHasCabang::where('cabang_id', $cabang->id)->pluck('user_id');
                    $formsQuery->whereIn('user_id', $userIds);
                }
            }

            // Filter by date range
            if (isset($params['start_date']) || isset($params['end_date'])) {
                $startDate = $params['start_date'] ?? null;
                $endDate = $params['end_date'] ?? null;

                if ($startDate && $endDate) {
                    $formsQuery->whereBetween('tanggal', [$startDate, $endDate]);
                } elseif ($startDate) {
                    $formsQuery->where('tanggal', '>=', $startDate);
                } elseif ($endDate) {
                    $formsQuery->where('tanggal', '<=', $endDate);
                }
            }

            // Filter by status
            if (isset($params['status'])) {
                $formsQuery->where('status', $params['status']);
            }
        }

        // Fetch forms after applying all filters
        $forms = $formsQuery->get();

        return view('backend.pages.report.meeting', [
            'pageInfo' => [
                'title' => 'Generate Reports For Form Meeting & Seminar',
            ],
            'forms' => $forms,
            'cabang' => $cabangs,
            'regions' => $regions
        ]);
    }

    public function others()
    {
        $role = auth()->user()->getRoleNames()[0];
        $cabangs = Cabang::all();
        $regions = Region::all();
        
        // Initialize the query for FormOthers with eager loading
        $formsQuery = FormOthers::with([
            'user.region', // Eager load 'region' within 'user'
            'user.cabang', // Eager load 'cabang' within 'user'
            'kategori'
        ]);

        // Apply role-based query logic
        if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
            $region_id = auth()->user()->getMyCabangAndRegionId()['region'];

            if ($region_id) {
                $cabangs = Cabang::where('region_id', $region_id)->get();
                $regions = Region::where('id', $region_id)->get();
                $userIds = UserHasCabang::whereIn('cabang_id', $cabangs->pluck('id'))->pluck('user_id');
                $formsQuery->whereIn('user_id', $userIds);
            }
        } elseif ($role == 'Area Manager Cabang') {
            $cabang_id = auth()->user()->getMyCabangAndRegionId()['cabang'];

            if ($cabang_id) {
                $cabangs = Cabang::where('id', $cabang_id)->get();
                $regions = Region::where('id', $cabangs->first()->region_id)->get();
                $userIds = UserHasCabang::where('cabang_id', $cabang_id)->pluck('user_id');
                $formsQuery->whereIn('user_id', $userIds);
            }
        }

        // Get all params in URL for filtering
        $params = request()->all();

        if ($params) {
            // Filter by region
            if (isset($params['region'])) {
                $region = Region::where('code', $params['region'])->first();
                if ($region) {
                    $userIds = UserHasCabang::whereIn('cabang_id', Cabang::where('region_id', $region->id)->pluck('id'))->pluck('user_id');
                    $formsQuery->whereIn('user_id', $userIds);
                }
            }

            // Filter by cabang
            if (isset($params['cabang'])) {
                $cabang = Cabang::where('code', $params['cabang'])->first();
                if ($cabang) {
                    $userIds = UserHasCabang::where('cabang_id', $cabang->id)->pluck('user_id');
                    $formsQuery->whereIn('user_id', $userIds);
                }
            }

            // Filter by date range
            if (isset($params['start_date']) || isset($params['end_date'])) {
                $startDate = $params['start_date'] ?? null;
                $endDate = $params['end_date'] ?? null;

                if ($startDate && $endDate) {
                    $formsQuery->whereBetween('tanggal', [$startDate, $endDate]);
                } elseif ($startDate) {
                    $formsQuery->where('tanggal', '>=', $startDate);
                } elseif ($endDate) {
                    $formsQuery->where('tanggal', '<=', $endDate);
                }
            }

            // Filter by status
            if (isset($params['status'])) {
                $formsQuery->where('status', $params['status']);
            }
        }

        // Fetch forms after applying all filters
        $forms = $formsQuery->get();

        return view('backend.pages.report.others', [
            'pageInfo' => [
                'title' => 'Generate Reports For Form Others',
            ],
            'forms' => $forms,
            'cabang' => $cabangs,
            'regions' => $regions
        ]);
    }

    public function all()
    {
        $role = auth()->user()->getRoleNames()[0];
        $cabangs = [];
        $regions = [];
        $forms = null;

        $availableBudget = 0;

        $month = date('F');
        $year = date('Y');

        $region_id = auth()->user()->getMyCabangAndRegionId()['region'] ?? null;
        $cabang_id = auth()->user()->getMyCabangAndRegionId()['cabang'] ?? null;
        $userId = auth()->user()->id;

        if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
            if ($region_id) {
                $users = UserHasCabang::whereHas('cabang', function ($query) use ($region_id) {
                    $query->where('region_id', $region_id);
                })->get();
                $userIds = $users->pluck('user_id')->toArray();
                $cabangs = Cabang::where('region_id', $region_id)->get();
                $regions = Region::where('id', $region_id)->get();
                $forms = FormHelper::getFormsByUserIds($userIds, $month, $year)->sortByDesc('created_at');
            }
        } elseif ($role == 'Area Manager Cabang') {
            if ($cabang_id) {
                $users = UserHasCabang::where('cabang_id', $cabang_id)->get();
                $userIds = $users->pluck('user_id')->toArray();
                $cabangs = Cabang::where('id', $cabang_id)->get();
                $regions = Region::where('id', $cabangs[0]->region_id)->get();
                $forms = FormHelper::getFormsByUserIds($userIds, $month, $year)->sortByDesc('created_at');
            }
        } else {
            $cabangs = Cabang::all();
            $regions = Region::all();
            $forms = FormHelper::getAllForms2()->sortByDesc('created_at');
        }

        // get all params in url
        $params = request()->all();

        if ($params) {
            // Filter by region
            if (isset($params['region'])) {
                $region = Region::where('code', $params['region'])->first();
                if ($region) {
                    $userIds = UserHasCabang::whereIn('cabang_id', Cabang::where('region_id', $region->id)->pluck('id'))->pluck('user_id')->toArray();
                    $forms = $forms->whereIn('user_id', $userIds);
                }
            }

            // Filter by cabang
            if (isset($params['cabang'])) {
                $cabang = Cabang::where('code', $params['cabang'])->first();
                if ($cabang) {
                    $userIds = UserHasCabang::where('cabang_id', $cabang->id)->pluck('user_id')->toArray();
                    $forms = isset($forms) ? $forms->whereIn('user_id', $userIds) : FormHelper::getFormsByUserIds($userIds); // Ensure $forms is updated
                    $availableBudget = BudgetHelper::getAvailableBudget($cabang->id);
                }
            }

            // Filter by date range
            if (isset($params['month']) || isset($params['year'])) {
                $month = $params['month'] ?? date('F');
                $year = $params['year'] ?? date('Y');

                $startOfMonth = Carbon::parse("first day of $month $year")->startOfDay();
                $endOfMonth = Carbon::parse("last day of $month $year")->endOfDay();

                if (isset($forms)) {
                    // Determine the date column to filter by
                    $dateColumn = Schema::hasColumn('forms', 'tanggal') ? 'tanggal' : 'created_at';

                    // Further filter existing forms by the determined date column
                    $forms = $forms->whereBetween($dateColumn, [$startOfMonth, $endOfMonth]);
                } else {
                    // Rebuild $forms using FormHelper and filter by role
                    if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
                        if ($region_id) {
                            $users = UserHasCabang::whereHas('cabang', function ($query) use ($region_id) {
                                $query->where('region_id', $region_id);
                            })->get();
                            $userIds = $users->pluck('user_id')->toArray();
                            $cabangs = Cabang::where('region_id', $region_id)->get();
                            $regions = Region::where('id', $region_id)->get();
                            $forms = FormHelper::getFormsByUserIds($userIds, $month, $year)->sortByDesc('tanggal')->sortByDesc('created_at');
                        }
                    } elseif ($role == 'Area Manager Cabang') {
                        if ($cabang_id) {
                            $users = UserHasCabang::where('cabang_id', $cabang_id)->get();
                            $userIds = $users->pluck('user_id')->toArray();
                            $cabangs = Cabang::where('id', $cabang_id)->get();
                            $regions = Region::where('id', $cabangs[0]->region_id)->get();
                            $forms = FormHelper::getFormsByUserIds($userIds, $month, $year)->sortByDesc('tanggal')->sortByDesc('created_at');
                        }
                    } elseif ($role == 'Medical Representatif') {
                        $cabangs = null;
                        $regions = null;
                        $forms = FormHelper::getFormsByUserIds([$userId], $month, $year)->sortByDesc('tanggal')->sortByDesc('created_at');
                    } else {
                        $cabangs = Cabang::all();
                        $regions = Region::all();
                        $forms = FormHelper::getAllForms($month, $year)->sortByDesc('tanggal')->sortByDesc('created_at');  
                    }
                }
            }

            // Filter by status
            if (isset($params['status'])) {
                $forms = isset($forms) ? $forms->where('status', $params['status']) : $forms;
            }
        }

        return view('backend.pages.report.all', [
            'pageInfo' => [
                'title' => 'Generate Reports For All Forms',
            ],
            'forms' => $forms,
            'cabang' => $cabangs,
            'regions' => $regions,
            'availableBudget' => $availableBudget
        ]);
    }

    public function jurnal()
    {
        $role = auth()->user()->getRoleNames()[0];
        $cabangs = [];
        $regions = [];

        if ($role == 'Admin Region' || $role == 'Marketing Operational Manager Region') {
            $region_id = auth()->user()->getMyCabangAndRegionId()['region'];

            if ($region_id) {
                $cabangs = Cabang::where('region_id', $region_id)->get();
                $regions = Region::where('id', $region_id)->get();
            }
        } else if ($role == 'Area Manager Cabang') {
            $cabang_id = auth()->user()->getMyCabangAndRegionId()['cabang'];

            if ($cabang_id) {
                $cabangs = Cabang::where('id', $cabang_id)->get();
                $regions = Region::where('id', $cabangs[0]->region_id)->get();
            }
        } else {
            $cabangs = Cabang::all();
            $regions = Region::all();
        }

        return view('backend.pages.report.jurnal', [
            'pageInfo' => [
                'title' => 'Generate Reports For Jurnal',
            ],
            'cabang' => $cabangs,
            'regions' => $regions
        ]);
    }

    public function generateJurnal() {
        $params = request()->all();

        $kategoris = Kategori::all();
        $kategori_bca = Kategori::where('name', 'Cash in Bank BCA')->first();
        $cabang = Cabang::with('cost')->where('code', $params['cabang'])->first();

        $year = $params['year'];
        $month = $params['month'];

        $budget = BudgetControlLog::where('cabang_id', $cabang->id)->where('periode_year', $year)->where('periode_month', $month)->orderBy('created_at', 'desc')->first();
        $userIds = UserHasCabang::where('cabang_id', $cabang->id)->pluck('user_id');

        // Fetch all relevant forms in one batch
        $forms = [
            'Up Country' => FormUpCountry::whereIn('user_id', $userIds)
                ->whereMonth('tanggal', '=', date('m', strtotime($month)))
                ->whereYear('tanggal', '=', $year)
                ->whereIn('status', ['Approved', 'Closed'])
                ->get(),
            'Vehicle Running Cost' => FormVehicleRunningCost::whereIn('user_id', $userIds)
                ->whereMonth('tanggal', '=', date('m', strtotime($month)))
                ->whereYear('tanggal', '=', $year)
                ->whereIn('status', ['Approved', 'Closed'])
                ->get(),
            'Entertainment' => FormEntertaimentPresentation::whereIn('user_id', $userIds)
                ->whereMonth('tanggal', '=', date('m', strtotime($month)))
                ->whereYear('tanggal', '=', $year)
                ->whereIn('status', ['Approved', 'Closed'])
                ->get(),
            'Meeting / Seminar' => FormMeetingSeminar::whereIn('user_id', $userIds)
                ->whereMonth('created_at', '=', date('m', strtotime($month)))
                ->whereYear('created_at', '=', $year)
                ->whereIn('status', ['Approved', 'Closed'])
                ->get(),
        ];

        // Fetch 'Others' forms by kategori
        $otherForms = FormOthers::whereIn('user_id', $userIds)
            ->whereMonth('tanggal', '=', date('m', strtotime($month)))
            ->whereYear('tanggal', '=', $year)
            ->whereIn('status', ['Approved', 'Closed'])
            ->get();

        // Precompute totals for each category
        $nominals = [];
        foreach ($kategoris as $item) {
            if (isset($forms[$item->name])) {
                $nominals[$item->id] = $forms[$item->name]->sum('approved_total');
            } else {
                $nominals[$item->id] = $otherForms->where('kategori_id', $item->id)->sum('approved_total');
            }
        }

        return view('backend.pages.report.generate_jurnal', [
            'pageInfo' => [
                'title' => 'Generate Reports For Jurnal',
            ],
            'kategori' => $kategoris,
            'cabang' => $cabang,
            'year' => $year,
            'month' => $month,
            'kategori_bca' => $kategori_bca,
            'nominals' => $nominals,
            'budget' => $budget
        ]);
    }
}
