widget data

This commit is contained in:
Akaunting 2026-02-07 18:55:11 +00:00 committed by GitHub
parent a44d9d156b
commit 9da40446e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 67 additions and 17 deletions

View File

@ -28,6 +28,8 @@ abstract class Widget
'header' => 'components.widgets.header',
];
public array $data = [];
public function __construct($model = null)
{
$this->model = $model;

View File

@ -14,6 +14,13 @@ class AccountBalance extends Widget
public $report_class = 'App\Reports\IncomeExpense';
public function show()
{
$this->setData();
return $this->view('widgets.account_balance', $this->data);
}
public function setData(): void
{
$accounts = Account::with('income_transactions', 'expense_transactions')->enabled()->take(5)->get()->map(function($account) {
$account->balance_formatted = money($account->balance, $account->currency_code);
@ -21,8 +28,8 @@ class AccountBalance extends Widget
return $account;
})->all();
return $this->view('widgets.account_balance', [
$this->data = [
'accounts' => $accounts,
]);
];
}
}

View File

@ -31,6 +31,13 @@ class CashFlow extends Widget
public $period;
public function show()
{
$this->setData();
return $this->view('widgets.cash_flow', $this->data);
}
public function setData(): void
{
$this->setFilter();
@ -66,10 +73,10 @@ class CashFlow extends Widget
'profit_for_humans' => $profit_amount->formatForHumans(),
];
return $this->view('widgets.cash_flow', [
$this->data = [
'chart' => $chart,
'totals' => $totals,
]);
];
}
public function setFilter(): void

View File

@ -11,11 +11,17 @@ class Currencies extends Widget
public function show()
{
$currencies = Currency::enabled()->take(5)->get();
$this->setData();
return $this->view('widgets.currencies', [
'currencies' => $currencies,
]);
return $this->view('widgets.currencies', $this->data);
}
public function setData(): void
{
$currencies = Currency::enabled()->take(5)->get();
$this->data = [
'currencies' => $currencies,
];
}
}

View File

@ -14,6 +14,13 @@ class ExpensesByCategory extends Widget
public $report_class = 'App\Reports\ExpenseSummary';
public function show()
{
$this->setData();
return $this->view('widgets.donut_chart', $this->data);
}
public function setData(): void
{
Category::with('expense_transactions')->expense()->withSubCategory()->getWithoutChildren()->each(function ($category) {
$amount = 0;
@ -30,8 +37,8 @@ class ExpensesByCategory extends Widget
$chart->options['legend']['width'] = 160;
$chart->options['legend']['position'] = 'right';
return $this->view('widgets.donut_chart', [
$this->data = [
'chart' => $chart,
]);
];
}
}

View File

@ -15,6 +15,13 @@ class Payables extends Widget
public $report_class = 'Modules\AgedReceivablesPayables\Reports\AgedPayables';
public function show()
{
$this->setData();
return $this->view('widgets.receivables_payables', $this->data);
}
public function setData(): void
{
$open = $overdue = 0;
@ -68,12 +75,12 @@ class Payables extends Widget
$grand_total_text = trans('widgets.total_unpaid_bills');
return $this->view('widgets.receivables_payables', [
$this->data = [
'totals' => $totals,
'has_progress' => $has_progress,
'progress' => $progress,
'periods' => $periods,
'grand_total_text' => $grand_total_text,
]);
];
}
}

View File

@ -28,6 +28,13 @@ class ProfitLoss extends Widget
public $period;
public function show()
{
$this->setData();
return $this->view('widgets.bar_chart', $this->data);
}
public function setData(): void
{
$this->setFilter();
@ -44,9 +51,9 @@ class ProfitLoss extends Widget
->setDataset(trans_choice('general.incomes', 1), 'column', array_values($this->getIncome()))
->setDataset(trans_choice('general.expenses', 1), 'column', array_values($this->getExpense()));
return $this->view('widgets.bar_chart', [
$this->data = [
'chart' => $chart,
]);
];
}
public function setFilter(): void

View File

@ -15,6 +15,13 @@ class Receivables extends Widget
public $report_class = 'Modules\AgedReceivablesPayables\Reports\AgedReceivables';
public function show()
{
$this->setData();
return $this->view('widgets.receivables_payables', $this->data);
}
public function setData(): void
{
$open = $overdue = 0;
@ -68,12 +75,12 @@ class Receivables extends Widget
$grand_total_text = trans('widgets.total_unpaid_invoices');
return $this->view('widgets.receivables_payables', [
$this->data = [
'totals' => $totals,
'has_progress' => $has_progress,
'progress' => $progress,
'periods' => $periods,
'grand_total_text' => $grand_total_text,
]);
];
}
}