added report data to array

This commit is contained in:
Cihan Şentürk 2025-05-01 13:21:37 +03:00 committed by GitHub
parent bd0fe0e0be
commit 79f7911e1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 0 deletions

View File

@ -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();

View File

@ -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;
}
}

View File

@ -19,6 +19,8 @@ class TaxSummary extends Report
public $category = 'general.accounting';
public $group = 'tax';
public $icon = 'percent';
public $type = 'detail';