Skip to content

Commit

Permalink
Adds DTI calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
cdterry87 committed Aug 12, 2024
1 parent fadf353 commit 65411e0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/Livewire/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public function render()
$monthlyIncome = auth()->user()->getMonthlyIncome();
$biWeeklyIncome = auth()->user()->getBiWeeklyIncome();
$weeklyIncome = auth()->user()->getWeeklyIncome();
$monthlyRemainder = auth()->user()->getMonthlyRemainder();
$dtiRatio = auth()->user()->getDtiRatio();

// Get notifications
$notifications = $this->getNotifications();
Expand All @@ -33,6 +35,8 @@ public function render()
'monthlyIncome' => $monthlyIncome,
'biWeeklyIncome' => $biWeeklyIncome,
'weeklyIncome' => $weeklyIncome,
'monthlyRemainder' => $monthlyRemainder,
'dtiRatio' => $dtiRatio,
'notifications' => $notifications,
'incomeVsBillsChart' => $incomeVsBillsChart,
'topCategoriesChart' => $topCategoriesChart,
Expand Down
29 changes: 29 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,33 @@ public function getWeeklyIncome(): string
$income = round($this->income * $this->frequency / 52, 2);
return $this->formatCurrency($income);
}

public function getMonthlyRemainderRaw(): float
{
$monthlyBillsTotal = $this->currentMonthBills()
->select('amount')
->sum('amount');

$monthlyIncome = $this->getMonthlyIncomeRaw();
return $monthlyIncome - $monthlyBillsTotal;
}

public function getMonthlyRemainder(): string
{
$monthlyRemainder = $this->getMonthlyRemainderRaw();

return $this->formatCurrency($monthlyRemainder);
}

public function getDtiRatio(): string
{
$monthlyBillsTotal = $this->currentMonthBills()
->select('amount')
->sum('amount');

$monthlyIncome = $this->getMonthlyIncomeRaw();
$dti = $monthlyBillsTotal / $monthlyIncome * 100;

return number_format($dti, 2) . '%';
}
}
10 changes: 9 additions & 1 deletion resources/views/livewire/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class="welcome--alert"
</x-alert>
@endif

<div class="income-summary--container grid grid-cols-2 lg:grid-cols-4 gap-3 sm:gap-6">
<div class="income-summary--container grid grid-cols-2 lg:grid-cols-3 gap-3 sm:gap-6">
<x-income-summary
label="Annual Income"
value="{{ $yearlyIncome }}"
Expand All @@ -47,6 +47,14 @@ class="welcome--alert"
label="Weekly Income"
value="{{ $weeklyIncome }}"
/>
<x-income-summary
label="Monthly Remainder"
value="{{ $monthlyRemainder }}"
/>
<x-income-summary
label="Debt/Income Ratio"
value="{{ $dtiRatio }}"
/>
</div>

<div class="charts--container grid grid-cols-1 md:grid-cols-2 gap-6">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class="flex flex-col gap-4 w-full"
Password: <strong class="underline">password1</strong>
</p>
</div>
<p class="text-xs italic">NOTE: All user settings and data are reset daily.</p>
<p class="text-xs italic">NOTE: Demo user and data are reset daily.</p>
</div>
</x-alert>

Expand Down

0 comments on commit 65411e0

Please sign in to comment.