akaunting/app/Widgets/ExpensesByCategory.php

43 lines
1.0 KiB
PHP
Raw Normal View History

2019-11-16 10:21:14 +03:00
<?php
namespace App\Widgets;
2019-12-29 03:01:19 +03:00
use App\Abstracts\Widget;
2019-11-16 10:21:14 +03:00
use App\Models\Setting\Category;
2019-12-29 03:01:19 +03:00
class ExpensesByCategory extends Widget
2019-11-16 10:21:14 +03:00
{
2019-12-29 03:01:19 +03:00
public function show()
2019-11-16 10:21:14 +03:00
{
2019-12-29 10:20:27 +03:00
Category::with('expense_transactions')->type('expense')->enabled()->each(function ($category) {
2019-11-16 10:21:14 +03:00
$amount = 0;
$transactions = $this->applyFilters($category->expense_transactions())->get();
foreach ($transactions as $transacion) {
2019-12-29 03:01:19 +03:00
$amount += $transacion->getAmountConvertedToDefault();
2019-11-16 10:21:14 +03:00
}
2019-12-29 03:01:19 +03:00
$this->addMoneyToDonut($category->color, $amount, $category->name);
});
2019-11-16 10:21:14 +03:00
2019-12-29 03:01:19 +03:00
$chart = $this->getDonutChart(trans_choice('general.expenses', 2), 0, 160, 6);
2019-11-16 10:21:14 +03:00
2020-01-03 19:00:38 +03:00
return $this->view('widgets.donut_chart', [
2019-12-28 22:30:10 +03:00
'chart' => $chart,
2019-11-16 10:21:14 +03:00
]);
}
2019-12-31 02:20:10 +03:00
public function getDefaultName()
{
return trans('widgets.expenses_by_category');
}
public function getDefaultSettings()
{
return [
'width' => 'col-md-6',
];
}
2019-11-16 10:21:14 +03:00
}