diff --git a/app/Abstracts/Report.php b/app/Abstracts/Report.php index 5c9447042..d540d4395 100644 --- a/app/Abstracts/Report.php +++ b/app/Abstracts/Report.php @@ -40,6 +40,8 @@ abstract class Report public $has_money = true; + public $group; + public $groups = []; public $year; @@ -259,6 +261,41 @@ abstract class Report return view($this->views['print'], ['print' => true])->with('class', $this); } + public function array(): array + { + $data = []; + + $group = Str::plural($this->group ?? $this->getSetting('group')); + + foreach ($this->tables as $table_key => $table_name) { + if (! isset($this->row_values[$table_key])) { + continue; + } + + foreach ($this->row_values[$table_key] as $key => $values) { + if (empty($this->row_names[$table_key][$key])) { + continue; + } + + if ($this->has_money) { + $values = array_map(fn($value) => money($value)->format(), $values); + } + + $data[$table_key][$group][$this->row_names[$table_key][$key]] = $values; + } + + $footer_totals = $this->footer_totals[$table_key]; + + if ($this->has_money) { + $footer_totals = array_map(fn($value) => money($value)->format(), $footer_totals); + } + + $data[$table_key]['totals'] = $footer_totals; + } + + return $data; + } + public function pdf() { $view = view($this->views['print'], ['print' => true])->with('class', $this)->render(); diff --git a/app/Reports/ProfitLoss.php b/app/Reports/ProfitLoss.php index 46891b796..5f0567248 100644 --- a/app/Reports/ProfitLoss.php +++ b/app/Reports/ProfitLoss.php @@ -97,4 +97,19 @@ class ProfitLoss extends Report } } } + + public function array(): array + { + $data = parent::array(); + + $net_profit = $this->net_profit; + + if ($this->has_money) { + $net_profit = array_map(fn($value) => money($value)->format(), $net_profit); + } + + $data['net_profit'] = $net_profit; + + return $data; + } } diff --git a/app/Reports/TaxSummary.php b/app/Reports/TaxSummary.php index f75951223..9768b652e 100644 --- a/app/Reports/TaxSummary.php +++ b/app/Reports/TaxSummary.php @@ -19,6 +19,8 @@ class TaxSummary extends Report public $category = 'general.accounting'; + public $group = 'tax'; + public $icon = 'percent'; public $type = 'detail';