Skip to content

Commit

Permalink
Add command payments:change_vat to PaymentsModule
Browse files Browse the repository at this point in the history
The command was originally internal and it's now being
extracted to the open-sourced module. Internals are moved
to the event handlers.

remp/crm#3357
  • Loading branch information
rootpd committed Nov 28, 2024
1 parent 3515795 commit 5aa82c7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/Events/SubscriptionTypeItemEventInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Crm\SubscriptionsModule\Events;

use Nette\Database\Table\ActiveRow;

interface SubscriptionTypeItemEventInterface
{
public function getSubscriptionTypeItem(): ?ActiveRow;
}
23 changes: 23 additions & 0 deletions src/Events/SubscriptionTypeItemUpdatedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Crm\SubscriptionsModule\Events;

use League\Event\AbstractEvent;
use Nette\Database\Table\ActiveRow;

class SubscriptionTypeItemUpdatedEvent extends AbstractEvent implements SubscriptionTypeEventInterface, SubscriptionTypeItemEventInterface
{
public function __construct(private ActiveRow $subscriptionTypeItem)
{
}

public function getSubscriptionTypeItem(): ?ActiveRow
{
return $this->subscriptionTypeItem;
}

public function getSubscriptionType(): ActiveRow
{
return $this->subscriptionTypeItem->subscription_type;
}
}
14 changes: 9 additions & 5 deletions src/Repositories/SubscriptionTypeItemsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use Crm\ApplicationModule\Models\DataProvider\DataProviderManager;
use Crm\ApplicationModule\Models\Database\Repository;
use Crm\SubscriptionsModule\DataProviders\CanUpdateSubscriptionTypeItemDataProviderInterface;
use Crm\SubscriptionsModule\Events\SubscriptionTypeItemUpdatedEvent;
use Exception;
use League\Event\Emitter;
use Nette\Caching\Storage;
use Nette\Database\Explorer;
use Nette\Database\Table\ActiveRow;
Expand All @@ -16,15 +18,13 @@ class SubscriptionTypeItemsRepository extends Repository
{
protected $tableName = 'subscription_type_items';

private $dataProviderManager;

public function __construct(
Explorer $database,
DataProviderManager $dataProviderManager,
private DataProviderManager $dataProviderManager,
private Emitter $emitter,
Storage $cacheStorage = null,
) {
parent::__construct($database, $cacheStorage);
$this->dataProviderManager = $dataProviderManager;
}

final public function add(ActiveRow $subscriptionType, string $name, float $amount, float $vat, int $sorting = null)
Expand All @@ -47,7 +47,11 @@ public function update(ActiveRow &$row, $data, bool $force = false)
}

$data['updated_at'] = new DateTime();
return parent::update($row, $data);
$result = parent::update($row, $data);

$this->emitter->emit(new SubscriptionTypeItemUpdatedEvent($row));

return $result;
}

final public function exists(ActiveRow $subscriptionType, string $name): int
Expand Down

0 comments on commit 5aa82c7

Please sign in to comment.