diff --git a/src/EventListener/TransactionListener.php b/src/EventListener/TransactionListener.php index 0b176fd..f42922a 100644 --- a/src/EventListener/TransactionListener.php +++ b/src/EventListener/TransactionListener.php @@ -5,6 +5,7 @@ namespace App\EventListener; use App\Entity\Transaction; +use DateTime; use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener; use Doctrine\ORM\Event\PrePersistEventArgs; use Doctrine\ORM\Event\PreUpdateEventArgs; @@ -28,6 +29,10 @@ public function prePersist(PrePersistEventArgs $args): void /** @var Transaction $transaction */ $transaction = $args->getObject(); + if (!$transaction->getEffectiveOn()) { + $transaction->setEffectiveOn(new DateTime()); + } + if ($transaction->isApplied()) { $this->updatedTransactions[] = $transaction; } @@ -41,7 +46,7 @@ public function preUpdate(PreUpdateEventArgs $args): void /** @var Transaction $transaction */ $transaction = $args->getObject(); - + if ($args->hasChangedField('applied')) { $this->updatedTransactions[] = $transaction; }