Skip to content

Commit

Permalink
Merge pull request #59 from devmount/bugs/fix-monthly-income-widget
Browse files Browse the repository at this point in the history
Fix monthly income widget
  • Loading branch information
devmount authored Aug 21, 2024
2 parents 77982c5 + baa715c commit d9432d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
13 changes: 6 additions & 7 deletions app/Filament/Widgets/MonthlyIncomeChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions app/Filament/Widgets/SalesChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Filament\Widgets;

use App\Enums\ExpenseCategory;
use App\Models\Expense;
use App\Models\Invoice;
use Carbon\Carbon;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d9432d1

Please sign in to comment.