akaunting/app/Widgets/IncomeByCategory.php

35 lines
894 B
PHP
Raw Normal View History

2019-12-29 03:01:19 +03:00
<?php
namespace App\Widgets;
use App\Abstracts\Widget;
use App\Models\Setting\Category;
class IncomeByCategory extends Widget
{
2020-01-16 00:42:20 +03:00
public $default_name = 'widgets.income_by_category';
2020-01-10 17:49:31 +03:00
2020-01-16 00:42:20 +03:00
public $default_settings = [
'width' => 'col-md-6',
];
2020-01-10 17:49:31 +03:00
2019-12-29 03:01:19 +03:00
public function show()
{
Category::with('income_transacions')->type('income')->each(function ($category) {
2019-12-29 03:01:19 +03:00
$amount = 0;
$this->applyFilters($category->income_transacions())->each(function ($transaction) use (&$amount) {
$amount += $transaction->getAmountConvertedToDefault();
});
2019-12-29 03:01:19 +03:00
$this->addMoneyToDonut($category->color, $amount, $category->name);
});
$chart = $this->getDonutChart(trans_choice('general.incomes', 1), 0, 160, 6);
2020-01-03 19:00:38 +03:00
return $this->view('widgets.donut_chart', [
2019-12-29 03:01:19 +03:00
'chart' => $chart,
]);
}
}