2026-02-04 08:29:09 +01:00
|
|
|
<?php
|
|
|
|
|
|
2026-02-04 16:22:26 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-02-04 08:29:09 +01:00
|
|
|
namespace FireflyIII\Events\Model\TransactionGroup;
|
|
|
|
|
|
2026-02-04 16:16:27 +01:00
|
|
|
use FireflyIII\Models\Transaction;
|
|
|
|
|
use FireflyIII\Models\TransactionGroup;
|
|
|
|
|
use FireflyIII\Models\TransactionJournal;
|
2026-02-04 08:29:09 +01:00
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class collects all objects before and after the creation, removal or updating
|
|
|
|
|
* of a transaction group. The idea is that this class contains all relevant objects.
|
|
|
|
|
* Right now, that means journals, tags, accounts, budgets and categories.
|
|
|
|
|
*
|
|
|
|
|
* By collecting these objects (in case of an update: before AND after update) there
|
|
|
|
|
* is a unified set of objects to manage: update balances, recalculate credits, etc.
|
|
|
|
|
*/
|
|
|
|
|
class TransactionGroupEventObjects
|
|
|
|
|
{
|
|
|
|
|
public Collection $accounts;
|
|
|
|
|
public Collection $budgets;
|
|
|
|
|
public Collection $categories;
|
|
|
|
|
public Collection $tags;
|
|
|
|
|
public Collection $transactionJournals;
|
|
|
|
|
|
2026-02-04 16:22:26 +01:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->accounts = new Collection();
|
|
|
|
|
$this->budgets = new Collection();
|
|
|
|
|
$this->categories = new Collection();
|
|
|
|
|
$this->tags = new Collection();
|
2026-02-04 08:29:09 +01:00
|
|
|
$this->transactionJournals = new Collection();
|
|
|
|
|
}
|
2026-02-04 16:16:27 +01:00
|
|
|
|
|
|
|
|
public static function collectFromTransactionGroup(TransactionGroup $transactionGroup): self
|
|
|
|
|
{
|
2026-02-04 16:22:26 +01:00
|
|
|
$object = new self();
|
|
|
|
|
|
2026-02-04 16:16:27 +01:00
|
|
|
/** @var TransactionJournal $journal */
|
2026-02-04 16:22:26 +01:00
|
|
|
foreach ($transactionGroup->transactionJournals as $journal) {
|
2026-02-04 16:16:27 +01:00
|
|
|
$object->transactionJournals->push($journal);
|
2026-02-04 16:22:26 +01:00
|
|
|
$object->budgets = $object->tags->merge($journal->budgets);
|
2026-02-04 16:16:27 +01:00
|
|
|
$object->categories = $object->tags->merge($journal->categories);
|
2026-02-04 16:22:26 +01:00
|
|
|
$object->tags = $object->tags->merge($journal->tags);
|
2026-02-04 16:16:27 +01:00
|
|
|
|
|
|
|
|
/** @var Transaction $transaction */
|
2026-02-04 16:22:26 +01:00
|
|
|
foreach ($journal->transactions as $transaction) {
|
2026-02-04 16:16:27 +01:00
|
|
|
$object->accounts->push($transaction->account);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-04 16:22:26 +01:00
|
|
|
|
2026-02-04 16:16:27 +01:00
|
|
|
return $object;
|
|
|
|
|
}
|
2026-02-04 08:29:09 +01:00
|
|
|
}
|