35 lines
		
	
	
		
			977 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			977 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Widgets;
 | |
| 
 | |
| use App\Abstracts\Widget;
 | |
| use App\Models\Setting\Category;
 | |
| 
 | |
| class ExpensesByCategory extends Widget
 | |
| {
 | |
|     public $default_name = 'widgets.expenses_by_category';
 | |
| 
 | |
|     public $description = 'widgets.description.expenses_by_category';
 | |
| 
 | |
|     public $report_class = 'App\Reports\ExpenseSummary';
 | |
| 
 | |
|     public function show()
 | |
|     {
 | |
|         Category::withSubCategory()->with('expense_transactions')->expense()->each(function ($category) {
 | |
|             $amount = 0;
 | |
| 
 | |
|             $this->applyFilters($category->expense_transactions)->each(function ($transaction) use (&$amount) {
 | |
|                 $amount += $transaction->getAmountConvertedToDefault();
 | |
|             });
 | |
| 
 | |
|             $this->addMoneyToDonut($category->color, $amount, $category->name);
 | |
|         });
 | |
| 
 | |
|         $chart = $this->getDonutChart(trans_choice('general.expenses', 2), '100%', 300, 6);
 | |
| 
 | |
|         return $this->view('widgets.donut_chart', [
 | |
|             'chart' => $chart,
 | |
|         ]);
 | |
|     }
 | |
| }
 |