Create formatNumber method in Helper class and get rid of thousands separator
ADD
app/Helper.php
+<?php
+
+namespace App;
+
+class Helper {
+ public static function formatNumber($number): string
+ {
+ return number_format($number, 2, '.', '');
+ }
+}

MODIFY
app/Http/Controllers/DashboardController.php
app/Http/Controllers/DashboardController.php
namespace App\Http\Controllers;
+use App\Helper;
use App\Repositories\TagRepository;
use Illuminate\Http\Request;
@@ -40,7 +41,7 @@ class DashboardController extends Controller {
->where('happened_on', $currentYear . '-' . $currentMonth . '-' . $i)
->sum('amount');
- $dailyBalance[$i] = number_format($balanceTick / 100, 2);
+ $dailyBalance[$i] = Helper::formatNumber($balanceTick / 100);
}
return view('dashboard', [

MODIFY
app/Http/Controllers/ReportController.php
app/Http/Controllers/ReportController.php
namespace App\Http\Controllers;
+use App\Helper;
use App\Repositories\TagRepository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@@ -32,7 +33,7 @@ class ReportController extends Controller {
->whereRaw('YEAR(happened_on) = ? AND WEEK(happened_on, ?) = ?', [$year, $weekMode, $i])
->sum('amount');
- $weeks[$i] = number_format($balance / 100, 2, '.', '');
+ $weeks[$i] = Helper::formatNumber($balance / 100);
}
return view('reports.weekly_report', [

MODIFY
app/Models/Earning.php
app/Models/Earning.php
@@ -4,6 +4,7 @@ namespace App\Models;
use App\Events\TransactionCreated;
use App\Events\TransactionDeleted;
+use App\Helper;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -21,7 +22,7 @@ class Earning extends Model {
// Accessors
public function getFormattedAmountAttribute() {
- return number_format($this->amount / 100, 2);
+ return Helper::formatNumber($this->amount / 100);
}
public function getFormattedHappenedOnAttribute() {

MODIFY
app/Models/Spending.php
app/Models/Spending.php
@@ -4,6 +4,7 @@ namespace App\Models;
use App\Events\TransactionCreated;
use App\Events\TransactionDeleted;
+use App\Helper;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -28,7 +29,7 @@ class Spending extends Model {
// Accessors
public function getFormattedAmountAttribute() {
- return number_format($this->amount / 100, 2);
+ return Helper::formatNumber($this->amount / 100);
}
public function getFormattedHappenedOnAttribute() {

MODIFY
resources/views/dashboard.blade.php
resources/views/dashboard.blade.php
<div class="row row--gutter row--responsive my-3">
<div class="row__column">
<div class="card card--blue">
- <h2 style="font-size: 20px;">{!! $currency !!} {{ number_format($balance / 100, 2) }}</h2>
+ <h2 style="font-size: 20px;">{!! $currency !!} {{ \App\Helper::formatNumber($balance / 100) }}</h2>
<div class="mt-1" style="color: #A7AEBB;">{{ __('general.balance') }}</div>
</div>
</div>
<div class="row__column">
<div class="card card--red">
- <h2 style="font-size: 20px;">{!! $currency !!} {{ number_format($recurrings / 100, 2) }}</h2>
+ <h2 style="font-size: 20px;">{!! $currency !!} {{ \App\Helper::formatNumber($recurrings / 100) }}</h2>
<div class="mt-1" style="color: #A7AEBB;">{{ __('general.recurrings') }}</div>
</div>
</div>
<div class="row__column">
<div class="card card--green">
- <h2 style="font-size: 20px;">{!! $currency !!} {{ number_format($leftToSpend / 100, 2) }}</h2>
+ <h2 style="font-size: 20px;">{!! $currency !!} {{ \App\Helper::formatNumber($leftToSpend / 100) }}</h2>
<div class="mt-1" style="color: #A7AEBB;">{{ __('general.left_to_spend') }}</div>
</div>
</div>
<div class="row__column row__column--middle">
<progress max="{{ $totalSpent }}" value="{{ $tag->amount }}"></progress>
</div>
- <div class="row__column row__column--middle text-right">{!! $currency !!} {{ number_format($tag->amount / 100, 2) }}</div>
+ <div class="row__column row__column--middle text-right">{!! $currency !!} {{ \App\Helper::formatNumber($tag->amount / 100) }}</div>
</div>
@endforeach
</div>

MODIFY
resources/views/emails/weekly_report.blade.php
resources/views/emails/weekly_report.blade.php
This week (#{{ $week }}) you've
<ul>
- <li>Spent {!! $space->currency->symbol !!} {{ number_format($totalSpent / 100, 2) }}</li>
+ <li>Spent {!! $space->currency->symbol !!} {{ \App\Helper::formatNumber($totalSpent / 100) }}</li>
@if (count($largestSpendingWithTag))
- <li>Most of which you've spent on {{ $largestSpendingWithTag[0]->tag_name }} ({!! $space->currency->symbol !!} {{ number_format($largestSpendingWithTag[0]->amount / 100, 2) }})</li>
+ <li>Most of which you've spent on {{ $largestSpendingWithTag[0]->tag_name }} ({!! $space->currency->symbol !!} {{ \App\Helper::formatNumber($largestSpendingWithTag[0]->amount / 100) }})</li>
@endif
</ul>

MODIFY
resources/views/recurrings/index.blade.php
resources/views/recurrings/index.blade.php
<a href="/recurrings/{{ $recurring->id }}">{{ $recurring->description }}</a>
</div>
<div class="row mt-1">
- <div class="row__column row__column--compact" style="font-size: 14px; font-weight: 600;">{!! $currency !!} {{ number_format($recurring->amount / 100, 2) }}</div>
+ <div class="row__column row__column--compact" style="font-size: 14px; font-weight: 600;">{!! $currency !!} {{ \App\Helper::formatNumber($recurring->amount / 100) }}</div>
@if ($recurring->due_days)
<div class="row__column row__column--compact ml-2" style="font-size: 14px; font-weight: 600;"><i class="fas fa-clock"></i> Due in {{ $recurring->due_days }} days</div>
@endif

MODIFY
resources/views/reports/most_expensive_tags.blade.php
resources/views/reports/most_expensive_tags.blade.php
<div class="row__column row__column--middle">
<progress max="{{ $totalSpent }}" value="{{ $tag->amount }}"></progress>
</div>
- <div class="row__column row__column--middle text-right">{!! $currency !!} {{ number_format($tag->amount / 100, 2) }} / {!! $currency !!} {{ number_format($totalSpent / 100, 2) }}</div>
+ <div class="row__column row__column--middle text-right">{!! $currency !!} {{ \App\Helper::formatNumber($tag->amount / 100) }} / {!! $currency !!} {{ \App\Helper::formatNumber($totalSpent / 100) }}</div>
</div>
@endforeach
</div>

Create formatNumber method in Helper class and get rid of thousands separator