formatting

This commit is contained in:
Denis Duliçi 2022-07-21 16:36:34 +03:00
parent 52bbd32bd8
commit ebfc67709a
4 changed files with 13 additions and 14 deletions

View File

@ -17,7 +17,6 @@ use App\Models\Setting\Category;
use App\Traits\Charts; use App\Traits\Charts;
use App\Traits\DateTime; use App\Traits\DateTime;
use App\Traits\SearchString; use App\Traits\SearchString;
use App\Traits\Tailwind;
use App\Traits\Translations; use App\Traits\Translations;
use App\Utilities\Date; use App\Utilities\Date;
use App\Utilities\Export as ExportHelper; use App\Utilities\Export as ExportHelper;
@ -25,7 +24,7 @@ use Illuminate\Support\Str;
abstract class Report abstract class Report
{ {
use Charts, DateTime, SearchString, Tailwind, Translations; use Charts, DateTime, SearchString, Translations;
public $model; public $model;
@ -236,9 +235,7 @@ abstract class Report
foreach ($tmp_values as $id => $value) { foreach ($tmp_values as $id => $value) {
$labels[$id] = $this->row_names[$table_key][$id]; $labels[$id] = $this->row_names[$table_key][$id];
$color = ($group == 'category') ? Category::withSubCategory()->find($id)?->color : '#' . dechex(rand(0x000000, 0xFFFFFF)); $colors[$id] = ($group == 'category') ? Category::withSubCategory()->find($id)?->colorHexCode : '#' . dechex(rand(0x000000, 0xFFFFFF));
$colors[$id] = $this->getHexCodeOfTailwindClass($color);
$values[$id] = round(($value * 100 / $total), 0); $values[$id] = round(($value * 100 / $total), 0);
} }

View File

@ -8,6 +8,7 @@ use App\Models\Document\Document;
use App\Relations\HasMany\Category as HasMany; use App\Relations\HasMany\Category as HasMany;
use App\Scopes\Category as Scope; use App\Scopes\Category as Scope;
use App\Traits\Categories; use App\Traits\Categories;
use App\Traits\Tailwind;
use App\Traits\Transactions; use App\Traits\Transactions;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
@ -15,7 +16,7 @@ use Illuminate\Database\Eloquent\Model as EloquentModel;
class Category extends Model class Category extends Model
{ {
use Categories, HasFactory, Transactions; use Categories, HasFactory, Tailwind, Transactions;
public const INCOME_TYPE = 'income'; public const INCOME_TYPE = 'income';
public const EXPENSE_TYPE = 'expense'; public const EXPENSE_TYPE = 'expense';
@ -217,6 +218,14 @@ class Category extends Model
return $query->withoutGlobalScope(new Scope); return $query->withoutGlobalScope(new Scope);
} }
/**
* Get the hex code of the color.
*/
public function getColorHexCodeAttribute(): string
{
return $this->getHexCodeOfTailwindClass($this->color);
}
/** /**
* Get the line actions. * Get the line actions.
* *

View File

@ -3,13 +3,10 @@
namespace App\Traits; namespace App\Traits;
use Akaunting\Apexcharts\Chart; use Akaunting\Apexcharts\Chart;
use App\Traits\Tailwind;
use Balping\JsonRaw\Raw; use Balping\JsonRaw\Raw;
trait Charts trait Charts
{ {
use Tailwind;
public $bar = [ public $bar = [
'colors' => [], 'colors' => [],
'labels' => [], 'labels' => [],
@ -37,8 +34,6 @@ trait Charts
$label .= ' - ' . $description; $label .= ' - ' . $description;
} }
$color = $this->getHexCodeOfTailwindClass($color);
$this->addToDonut($color, $label, $amount); $this->addToDonut($color, $label, $amount);
} }
@ -74,8 +69,6 @@ trait Charts
public function addToBar($color, $label, $value) public function addToBar($color, $label, $value)
{ {
$color = $this->getHexCodeOfTailwindClass($color);
$this->bar['colors'][] = $color; $this->bar['colors'][] = $color;
$this->bar['labels'][] = $label; $this->bar['labels'][] = $label;
$this->bar['values'][] = (int) $value; $this->bar['values'][] = (int) $value;

View File

@ -22,7 +22,7 @@ class ExpensesByCategory extends Widget
$amount += $transaction->getAmountConvertedToDefault(); $amount += $transaction->getAmountConvertedToDefault();
}); });
$this->addMoneyToDonut($category->color, $amount, $category->name); $this->addMoneyToDonut($category->colorHexCode, $amount, $category->name);
}); });
$chart = $this->getDonutChart(trans_choice('general.expenses', 2), '100%', 300, 6); $chart = $this->getDonutChart(trans_choice('general.expenses', 2), '100%', 300, 6);