Admin Dashboard {{-- Dashboard --}}
{{-- Yearly Monthly Data Start --}}

Last 12 Month Income & Expense With 50% Needs, 30% Wants, 20% Savings Rule

@php $currentYear = date('Y'); $monthlyData = []; // $currentMonth = date('m'); for ($month = 1; $month <= 12; $month++) { $thisMonthIncome = App\Models\ExpenseCalculation::where('types', 'income') ->whereMonth('date', $month) ->whereYear('date', $currentYear) ->get(); $thisMonthSalaryIncome = App\Models\ExpenseCalculation::where('types', 'income') ->where('category_id', 1) ->whereMonth('date', $month) ->whereYear('date', $currentYear) ->get(); $thisMonthExpense = App\Models\ExpenseCalculation::where('types', 'expense') ->whereMonth('date', $month) ->whereYear('date', $currentYear) ->groupBy('category_id') ->select('category_id', \DB::raw('SUM(amount) as totalExpense')) ->get(); $thisMonthneeds = App\Models\ExpenseCalculation::where('rules', 'needs') ->whereMonth('date', $month) ->whereYear('date', $currentYear) ->sum('amount'); $thisMonthwants = App\Models\ExpenseCalculation::where('rules', 'wants') ->whereMonth('date', $month) ->whereYear('date', $currentYear) ->sum('amount'); $thisMonthsavings = App\Models\ExpenseCalculation::where('rules', 'savings') ->whereMonth('date', $month) ->whereYear('date', $currentYear) ->sum('amount'); $monthlyData[$month] = [ 'income' => $thisMonthIncome->sum('amount'), 'needs' => $thisMonthSalaryIncome->sum('amount') * 0.5, 'wants' => $thisMonthSalaryIncome->sum('amount') * 0.3, 'savings' => $thisMonthSalaryIncome->sum('amount') * 0.2, 'expense' => $thisMonthExpense->sum('totalExpense'), 'thisMonthneeds' => $thisMonthneeds, 'thisMonthwants' => $thisMonthwants, 'thisMonthsavings' => $thisMonthsavings, ]; } @endphp @foreach ($monthlyData as $month => $data) {{-- @if ($month === $currentMonth || $month === $currentMonth - 1 || $month === $currentMonth + 0) --}} {{-- @endif --}} @endforeach
Incame / Expense Balance Needs Balance Wants Balance Savings Balance
{{ date('F', mktime(0, 0, 0, $month, 1)) }} {{ $data['income'] }} {{ $data['income'] - $data['expense'] }} {{ $data['needs'] }} {{ $data['needs'] - $data['thisMonthneeds'] }} {{ $data['wants'] }} {{ $data['wants'] - $data['thisMonthwants'] }} {{ $data['savings'] }} {{ $data['savings'] - $data['thisMonthsavings'] }}
{{ $data['expense'] }} {{ $data['thisMonthneeds'] }} {{ $data['thisMonthwants'] }} {{ $data['thisMonthsavings'] }}
Total {{ array_sum(array_column($monthlyData, 'income')) }} {{ array_sum(array_column($monthlyData, 'income')) - array_sum(array_column($monthlyData, 'expense')) }} {{ array_sum(array_column($monthlyData, 'needs')) }} {{ array_sum(array_column($monthlyData, 'needs')) - array_sum(array_column($monthlyData, 'thisMonthneeds')) }} {{ array_sum(array_column($monthlyData, 'wants')) }} {{ array_sum(array_column($monthlyData, 'wants')) - array_sum(array_column($monthlyData, 'thisMonthwants')) }} {{ array_sum(array_column($monthlyData, 'savings')) }} {{ array_sum(array_column($monthlyData, 'savings')) - array_sum(array_column($monthlyData, 'thisMonthsavings')) }}
{{ array_sum(array_column($monthlyData, 'expense')) }} {{ array_sum(array_column($monthlyData, 'thisMonthneeds')) }} {{ array_sum(array_column($monthlyData, 'thisMonthwants')) }} {{ array_sum(array_column($monthlyData, 'thisMonthsavings')) }}
{{-- Yearly Monthly Data End --}}
@php // Get the current month and year from the selected values in the dropdowns $currentMonth = date('m'); $currentYear = date('Y'); if(isset($_GET['year'])) { $currentYear = $_GET['year']; } if(isset($_GET['month'])) { $currentMonth = $_GET['month']; } $thisMonthIncome = App\Models\ExpenseCalculation::where('types', 'income') ->whereMonth('date', $currentMonth) ->whereYear('date', $currentYear) ->get(); // $thisMonthIncome = App\Models\ExpenseCalculation::Where('types', 'income') // ->whereMonth('date', $currentMonth) // ->whereYear('date', $currentYear) // ->get(); // dd($thisMonthIncome); $thisMonthExpense = App\Models\ExpenseCalculation::where('types', 'expense') ->whereMonth('date', $currentMonth) ->whereYear('date', $currentYear) ->groupBy('category_id') ->select('category_id', \DB::raw('SUM(amount) as totalExpense')) ->get(); // dd($thisMonthExpense); $thisMonthneeds = App\Models\ExpenseCalculation::Where('rules', 'needs') ->whereMonth('date', $currentMonth) ->whereYear('date', $currentYear) ->sum('amount'); $thisMonthwants = App\Models\ExpenseCalculation::Where('rules', 'wants') ->whereMonth('date', $currentMonth) ->whereYear('date', $currentYear) ->sum('amount'); $thisMonthsavings = App\Models\ExpenseCalculation::Where('rules', 'savings') ->whereMonth('date', $currentMonth) ->whereYear('date', $currentYear) ->sum('amount'); $thisYearIncome = App\Models\ExpenseCalculation::Where('types', 'income') ->whereYear('date', $currentYear) ->get(); // dd($thisMonthIncome); $thisYearExpense = App\Models\ExpenseCalculation::Where('types', 'expense') ->whereYear('date', $currentYear) ->groupBy('category_id') ->select('category_id', \DB::raw('SUM(amount) as totalExpenseYear')) ->get(); @endphp

{{ date('F') }} Net Income

Needs Wants Savings
Total Income {{ $thisMonthIncome->sum('amount') }} @php $needs = $thisMonthIncome->sum('amount') * 0.5; @endphp {{ $needs }} @php $wants = $thisMonthIncome->sum('amount') * 0.3; @endphp {{ $wants }} @php $savings = $thisMonthIncome->sum('amount') * 0.2; @endphp {{ $savings }}
Total Expense {{ $thisMonthExpense->sum('totalExpense') }} {{ $thisMonthneeds }} {{ $thisMonthwants }} {{ $thisMonthsavings }}
Net Income {{ $thisMonthIncome->sum('amount') - $thisMonthExpense->sum('totalExpense') }} {{ $needs - $thisMonthneeds }} {{ $wants - $thisMonthwants }} {{ $savings - $thisMonthsavings }}

{{ date('Y') }} Net Income

Total Income Total Expense
{{ $thisYearIncome->sum('amount') }} {{ $thisYearExpense->sum('totalExpenseYear') }}
Net Income: {{ $thisYearIncome->sum('amount') - $thisYearExpense->sum('totalExpenseYear') }}

Category ways Monthly Income

@foreach ($thisMonthIncome as $item) @endforeach
Date Name Amount
{{ $item->date }} {{ $item->name }} {{ $item->amount }}
Total Income: {{ $thisMonthIncome->sum('amount') }}

Category ways Monthly Expense

@foreach ($thisMonthExpense as $item) @endforeach
Category Amount
@php $category = App\Models\Category::find($item->category_id); @endphp {{ $category->name }} {{ $item->totalExpense }}
Total Expense: {{ $thisMonthExpense->sum('totalExpense') }}

{{ date('Y') }} Monthly Income

{{-- --}} @php $currentYear = date('Y'); $thisYearIncome = App\Models\ExpenseCalculation::where('types', 'income') ->whereYear('date', $currentYear) ->groupBy('category_id') ->select('category_id', \DB::raw('SUM(amount) as totalIncameYear')) ->get(); @endphp @foreach ($thisYearIncome as $item) @endforeach
DateName Amount
@php $category = App\Models\Category::find($item->category_id); @endphp {{ $category->name }} {{ $item->totalIncameYear }}
Total Income: {{ $thisYearIncome->sum('totalIncameYear') }}

{{ date('Y') }} Monthly Expense

@foreach ($thisYearExpense as $item) @endforeach
Name Amount
@php $category = App\Models\Category::find($item->category_id); @endphp {{ $category->name }} {{ $item->totalExpenseYear }}
Total Expense: {{ $thisYearExpense->sum('totalExpenseYear') }}