{{-- 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
|
Incame / Expense |
Balance |
Needs |
Balance |
Wants |
Balance |
Savings |
Balance |
@foreach ($monthlyData as $month => $data)
{{-- @if ($month === $currentMonth || $month === $currentMonth - 1 || $month === $currentMonth + 0) --}}
{{ 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'] }} |
{{-- @endif --}}
@endforeach
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')) }} |
@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') }}
|