From baa715cff6504e34f537a641e60ebd12608bf92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Wed, 21 Aug 2024 20:01:17 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Fix=20monthly=20income=20widget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Filament/Widgets/MonthlyIncomeChart.php | 13 ++++++------- app/Filament/Widgets/SalesChart.php | 5 +++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Filament/Widgets/MonthlyIncomeChart.php b/app/Filament/Widgets/MonthlyIncomeChart.php index e80282e..0f0d7ef 100644 --- a/app/Filament/Widgets/MonthlyIncomeChart.php +++ b/app/Filament/Widgets/MonthlyIncomeChart.php @@ -33,7 +33,7 @@ protected function getData(): array ->oldest('paid_at') ->get(); $taxes = Expense::whereNotNull('expended_at') - ->whereIn('category', ['vat', 'tax']) + ->whereIn('category', ExpenseCategory::taxCategories()) ->oldest('expended_at') ->get(); $period = Carbon::parse($invoices[0]->paid_at)->startOfYear()->yearsUntil(now()->addYear()); @@ -51,12 +51,11 @@ protected function getData(): array }; } } - foreach ($taxes as $obj) { - if ( - CarbonPeriod::create($date, $period[$i+1])->contains(Carbon::parse($obj->expended_at)->subYear()) && - $this->filter === 'net' - ) { - $invoiceData[$i] -= $obj->net; + if ($this->filter === 'net') { + foreach ($taxes as $obj) { + if (CarbonPeriod::create($date, $period[$i+1])->contains(Carbon::parse($obj->expended_at))) { + $invoiceData[$i] -= $obj->net; + } } } $invoiceData[$i] = round($invoiceData[$i]/($i == count($period)-2 ? now()->month : 12), 2); diff --git a/app/Filament/Widgets/SalesChart.php b/app/Filament/Widgets/SalesChart.php index 09908f4..f63ec02 100644 --- a/app/Filament/Widgets/SalesChart.php +++ b/app/Filament/Widgets/SalesChart.php @@ -2,6 +2,7 @@ namespace App\Filament\Widgets; +use App\Enums\ExpenseCategory; use App\Models\Expense; use App\Models\Invoice; use Carbon\Carbon; @@ -33,11 +34,11 @@ protected function getData(): array ->oldest('paid_at') ->get(); $expenses = Expense::whereNotNull('expended_at') - ->where('taxable', 1) + ->whereIn('category', ExpenseCategory::deliverableCategories()) ->oldest('expended_at') ->get(); $taxes = Expense::whereNotNull('expended_at') - ->where('taxable', 0) + ->whereIn('category', ExpenseCategory::taxCategories()) ->oldest('expended_at') ->get(); $period = match($this->filter) {