Add notes to category #4002

This commit is contained in:
James Cole
2020-10-28 06:32:37 +01:00
parent 3aa835a985
commit ca3d836c83
7 changed files with 92 additions and 9 deletions

View File

@@ -25,6 +25,7 @@ namespace FireflyIII\Transformers;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
use Illuminate\Support\Collection;
@@ -33,8 +34,8 @@ use Illuminate\Support\Collection;
*/
class CategoryTransformer extends AbstractTransformer
{
/** @var OperationsRepositoryInterface */
private $opsRepository;
private OperationsRepositoryInterface $opsRepository;
private CategoryRepositoryInterface $repository;
/**
* CategoryTransformer constructor.
@@ -44,6 +45,7 @@ class CategoryTransformer extends AbstractTransformer
public function __construct()
{
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->repository = app(CategoryRepositoryInterface::class);
}
/**
@@ -56,6 +58,7 @@ class CategoryTransformer extends AbstractTransformer
public function transform(Category $category): array
{
$this->opsRepository->setUser($category->user);
$this->repository->setUser($category->user);
$spent = [];
$earned = [];
@@ -65,11 +68,14 @@ class CategoryTransformer extends AbstractTransformer
$earned = $this->beautify($this->opsRepository->sumIncome($start, $end, null, new Collection([$category])));
$spent = $this->beautify($this->opsRepository->sumExpenses($start, $end, null, new Collection([$category])));
}
$notes = $this->repository->getNoteText($category);
return [
'id' => (int)$category->id,
'created_at' => $category->created_at->toAtomString(),
'updated_at' => $category->updated_at->toAtomString(),
'name' => $category->name,
'notes' => $notes,
'spent' => $spent,
'earned' => $earned,
'links' => [
@@ -90,7 +96,7 @@ class CategoryTransformer extends AbstractTransformer
{
$return = [];
foreach ($array as $data) {
$data['sum'] = number_format((float) $data['sum'], (int) $data['currency_decimal_places'], '.', '');
$data['sum'] = number_format((float)$data['sum'], (int)$data['currency_decimal_places'], '.', '');
$return[] = $data;
}