From 9da40446e60f84ecf578cfec8b92ce9f38f98699 Mon Sep 17 00:00:00 2001 From: Akaunting <64906316+AkauntingOfficial@users.noreply.github.com> Date: Sat, 7 Feb 2026 18:55:11 +0000 Subject: [PATCH] widget data --- app/Abstracts/Widget.php | 2 ++ app/Widgets/AccountBalance.php | 11 +++++++++-- app/Widgets/CashFlow.php | 11 +++++++++-- app/Widgets/Currencies.php | 16 +++++++++++----- app/Widgets/ExpensesByCategory.php | 11 +++++++++-- app/Widgets/Payables.php | 11 +++++++++-- app/Widgets/ProfitLoss.php | 11 +++++++++-- app/Widgets/Receivables.php | 11 +++++++++-- 8 files changed, 67 insertions(+), 17 deletions(-) diff --git a/app/Abstracts/Widget.php b/app/Abstracts/Widget.php index 32d03248b..62e743f66 100644 --- a/app/Abstracts/Widget.php +++ b/app/Abstracts/Widget.php @@ -28,6 +28,8 @@ abstract class Widget 'header' => 'components.widgets.header', ]; + public array $data = []; + public function __construct($model = null) { $this->model = $model; diff --git a/app/Widgets/AccountBalance.php b/app/Widgets/AccountBalance.php index 318e019ac..09e30b2e8 100644 --- a/app/Widgets/AccountBalance.php +++ b/app/Widgets/AccountBalance.php @@ -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, - ]); + ]; } } diff --git a/app/Widgets/CashFlow.php b/app/Widgets/CashFlow.php index 1efc9149c..879785b8b 100644 --- a/app/Widgets/CashFlow.php +++ b/app/Widgets/CashFlow.php @@ -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 diff --git a/app/Widgets/Currencies.php b/app/Widgets/Currencies.php index dcec7427c..b78d8c210 100644 --- a/app/Widgets/Currencies.php +++ b/app/Widgets/Currencies.php @@ -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); } -} \ No newline at end of file + public function setData(): void + { + $currencies = Currency::enabled()->take(5)->get(); + + $this->data = [ + 'currencies' => $currencies, + ]; + } +} diff --git a/app/Widgets/ExpensesByCategory.php b/app/Widgets/ExpensesByCategory.php index 2513ed16f..f9527fb6e 100644 --- a/app/Widgets/ExpensesByCategory.php +++ b/app/Widgets/ExpensesByCategory.php @@ -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, - ]); + ]; } } diff --git a/app/Widgets/Payables.php b/app/Widgets/Payables.php index b7fea7c4e..883f46d87 100644 --- a/app/Widgets/Payables.php +++ b/app/Widgets/Payables.php @@ -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, - ]); + ]; } } diff --git a/app/Widgets/ProfitLoss.php b/app/Widgets/ProfitLoss.php index ff9bfd0fe..84ff04337 100644 --- a/app/Widgets/ProfitLoss.php +++ b/app/Widgets/ProfitLoss.php @@ -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 diff --git a/app/Widgets/Receivables.php b/app/Widgets/Receivables.php index face911b5..8f639f45e 100644 --- a/app/Widgets/Receivables.php +++ b/app/Widgets/Receivables.php @@ -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, - ]); + ]; } }