Skip to content

Commit

Permalink
feat: added erru request to applied penalties (#674)
Browse files Browse the repository at this point in the history
* feat: added erru request to applied penalties

* feat: updated create and update tests for applied penalties

* fix: made changes to address PR feedback

* fix: fixed broken tests

* fix: changes to address PR comments

* fix: updated composer lock
  • Loading branch information
Ahmed7752 authored Mar 5, 2025
1 parent 7cd8ce8 commit f4e2a42
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 28 deletions.
14 changes: 7 additions & 7 deletions app/api/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Dvsa\Olcs\Api\Entity\Si\SeriousInfringement as SiEntity;
use Dvsa\Olcs\Api\Entity\Si\SiPenalty as SiPenaltyEntity;
use Dvsa\Olcs\Api\Entity\Si\SiPenaltyType as SiPenaltyTypeEntity;
use Dvsa\Olcs\Api\Entity\Si\SiPenaltyErruRequested as SiPenaltyErruRequestedEntity;
use Dvsa\Olcs\Transfer\Command\Cases\Si\Applied\Create as CreatePenaltyCmd;
use Dvsa\Olcs\Transfer\Command\CommandInterface;

Expand Down Expand Up @@ -45,6 +46,7 @@ public function handleCommand(CommandInterface $command)
}

$siPenaltyType = $this->getRepo()->getReference(SiPenaltyTypeEntity::class, $command->getSiPenaltyType());
$siRequestedErru = $this->getRepo()->getReference(SiPenaltyErruRequestedEntity::class, $command->getErruPenaltyRequested());
$startDate
= ($command->getStartDate() !== null)
? \DateTime::createFromFormat(self::DATE_FORMAT, $command->getStartDate()) : null;
Expand All @@ -55,6 +57,7 @@ public function handleCommand(CommandInterface $command)
$penalty = new SiPenaltyEntity(
$si,
$siPenaltyType,
$siRequestedErru,
$command->getImposed(),
$startDate,
$endDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Dvsa\Olcs\Api\Entity\Cases\Cases as CaseEntity;
use Dvsa\Olcs\Api\Entity\Si\ErruRequest as ErruRequestEntity;
use Dvsa\Olcs\Api\Entity\Si\SiPenalty as SiPenaltyEntity;
use Dvsa\Olcs\Api\Entity\Si\SiPenaltyErruRequested as SiPenaltyErruRequestedEntity;
use Dvsa\Olcs\Api\Entity\Si\SiPenaltyType as SiPenaltyTypeEntity;
use Dvsa\Olcs\Transfer\Command\Cases\Si\Applied\Update as UpdatePenaltyCmd;
use Dvsa\Olcs\Transfer\Command\CommandInterface;
Expand Down Expand Up @@ -44,6 +45,8 @@ public function handleCommand(CommandInterface $command)
}

$siPenaltyType = $this->getRepo()->getReference(SiPenaltyTypeEntity::class, $command->getSiPenaltyType());
$siRequestedErru = $this->getRepo()->getReference(SiPenaltyErruRequestedEntity::class, $command->getErruPenaltyRequested());

$startDate
= ($command->getStartDate() !== null)
? \DateTime::createFromFormat(self::DATE_FORMAT, $command->getStartDate()) : null;
Expand All @@ -53,6 +56,7 @@ public function handleCommand(CommandInterface $command)

$penalty->update(
$siPenaltyType,
$siRequestedErru,
$command->getImposed(),
$startDate,
$endDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ final class Penalty extends AbstractQueryHandler

public function handleQuery(QueryInterface $query)
{
return $this->result($this->getRepo()->fetchUsingId($query), ['siPenaltyType']);
return $this->result($this->getRepo()->fetchUsingId($query), ['siPenaltyType', 'erruPenaltyRequested']);
}
}
2 changes: 1 addition & 1 deletion app/api/module/Api/src/Domain/QueryHandler/Cases/Si/Si.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function handleQuery(QueryInterface $query)
'memberStateCode',
'siCategory',
'siCategoryType',
'appliedPenalties' => ['siPenaltyType', 'seriousInfringement'],
'appliedPenalties' => ['siPenaltyType', 'seriousInfringement', 'erruPenaltyRequested'],
'imposedErrus' => ['executed', 'siPenaltyImposedType'],
'requestedErrus' => ['siPenaltyRequestedType'],
'case' => [
Expand Down
23 changes: 9 additions & 14 deletions app/api/module/Api/src/Entity/Si/SiPenalty.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\ORM\Mapping as ORM;
use Dvsa\Olcs\Api\Entity\Si\SeriousInfringement as SiEntity;
use Dvsa\Olcs\Api\Entity\Si\SiPenaltyType as SiPenaltyTypeEntity;
use Dvsa\Olcs\Api\Entity\Si\SiPenaltyErruRequested as SiPenaltyErruRequestedEntity;

/**
* SiPenalty Entity
Expand All @@ -21,36 +22,30 @@
*/
class SiPenalty extends AbstractSiPenalty
{
/**
* SiPenalty constructor.
* @param string $imposed
* @param string $reasonNotImposed
*/
public function __construct(
SiEntity $seriousInfringement,
SiPenaltyTypeEntity $siPenaltyType,
$imposed,
SiPenaltyErruRequestedEntity $requestedErru,
string $imposed,
\DateTime $startDate = null,
\DateTime $endDate = null,
$reasonNotImposed = null
string $reasonNotImposed = null
) {
$this->seriousInfringement = $seriousInfringement;
$this->update($siPenaltyType, $imposed, $startDate, $endDate, $reasonNotImposed);
$this->update($siPenaltyType, $requestedErru, $imposed, $startDate, $endDate, $reasonNotImposed);
}

/**
* @param string $imposed
* @param string $reasonNotImposed
*/
public function update(
SiPenaltyTypeEntity $siPenaltyType,
$imposed,
SiPenaltyErruRequestedEntity $requestedErru,
string $imposed,
\DateTime $startDate = null,
\DateTime $endDate = null,
$reasonNotImposed = null
string $reasonNotImposed = null
) {
$this->siPenaltyType = $siPenaltyType;
$this->imposed = $imposed;
$this->erruPenaltyRequested = $requestedErru;

if ($startDate !== null) {
$this->startDate = $startDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Dvsa\Olcs\Api\Domain\Repository\SeriousInfringement as SiRepo;
use Dvsa\Olcs\Api\Domain\Repository\SiPenalty as SiPenaltyRepo;
use Dvsa\Olcs\Api\Entity\Cases\Cases as CaseEntity;
use Dvsa\Olcs\Api\Entity\Si\ErruRequest as ErruRequestEntity;
use Dvsa\Olcs\Api\Entity\Si\SiPenaltyErruRequested as SiPenaltyErruRequestedEntity;
use Dvsa\Olcs\Api\Entity\Si\SeriousInfringement as SiEntity;
use Dvsa\Olcs\Api\Entity\Si\SiPenalty as SiPenaltyEntity;
use Dvsa\Olcs\Api\Entity\Si\SiPenaltyType as SiPenaltyTypeEntity;
Expand All @@ -33,7 +33,11 @@ protected function initReferences()
$this->references = [
SiPenaltyTypeEntity::class => [
999 => m::mock(SiPenaltyTypeEntity::class)
],
SiPenaltyErruRequestedEntity::class => [
888 => m::mock(SiPenaltyErruRequestedEntity::class)
]

];

parent::initReferences();
Expand All @@ -44,6 +48,7 @@ public function testHandleCommand()
$siPenaltyType = 999;
$siId = 333;
$penaltyId = 111;
$erruRequested = 888;
$startDate = '2015-12-25';
$endDate = '2015-12-26';
$imposed = 'Y';
Expand All @@ -56,7 +61,8 @@ public function testHandleCommand()
'imposed' => $imposed,
'startDate' => $startDate,
'endDate' => $endDate,
'imposedReason' => $imposedReason
'imposedReason' => $imposedReason,
'erruPenaltyRequested' => $erruRequested
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Dvsa\Olcs\Api\Domain\CommandHandler\Cases\Si\Applied\Update as UpdatePenalty;
use Dvsa\Olcs\Api\Domain\Repository\SiPenalty as SiPenaltyRepo;
use Dvsa\Olcs\Api\Entity\Si\SiPenalty as SiPenaltyEntity;
use Dvsa\Olcs\Api\Entity\Si\SiPenaltyErruRequested as SiPenaltyErruRequestedEntity;
use Dvsa\Olcs\Api\Entity\Si\SiPenaltyType as SiPenaltyTypeEntity;
use Dvsa\Olcs\Transfer\Command\Cases\Si\Applied\Update as Cmd;
use Dvsa\OlcsTest\Api\Domain\CommandHandler\AbstractCommandHandlerTestCase;
Expand All @@ -28,6 +29,9 @@ protected function initReferences()
$this->references = [
SiPenaltyTypeEntity::class => [
999 => m::mock(SiPenaltyTypeEntity::class)
],
SiPenaltyErruRequestedEntity::class => [
888 => m::mock(SiPenaltyErruRequestedEntity::class)
]
];

Expand All @@ -37,6 +41,7 @@ protected function initReferences()
public function testHandleCommand()
{
$siPenaltyType = 999;
$erruRequested = 888;
$penaltyId = 111;
$startDate = '2015-12-25';
$endDate = '2015-12-26';
Expand All @@ -50,7 +55,8 @@ public function testHandleCommand()
'imposed' => $imposed,
'startDate' => $startDate,
'endDate' => $endDate,
'imposedReason' => $imposedReason
'imposedReason' => $imposedReason,
'erruPenaltyRequested' => $erruRequested
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Dvsa\OlcsTest\Api\Entity\Si;

use Dvsa\Olcs\Api\Entity\Si\SiPenaltyErruRequested;
use Dvsa\OlcsTest\Api\Entity\Abstracts\EntityTester;
use Dvsa\Olcs\Api\Entity\Si\SiPenalty as Entity;
use Dvsa\Olcs\Api\Entity\Si\SeriousInfringement;
Expand Down Expand Up @@ -29,18 +30,20 @@ public function testCreateAndUpdate()
{
$si = m::mock(SeriousInfringement::class);
$penaltyType = m::mock(SiPenaltyType::class);
$erruRequested = m::mock(SiPenaltyErruRequested::class);
$startDate = new \DateTime('2015-12-25');
$endDate = new \DateTime('2015-12-26');
$imposed = 'Y';
$reasonNotImposed = 'reason not imposed';

$entity = new Entity($si, $penaltyType, $imposed, $startDate, $endDate, $reasonNotImposed);
$entity = new Entity($si, $penaltyType, $erruRequested, $imposed, $startDate, $endDate, $reasonNotImposed);

$this->assertEquals($si, $entity->getSeriousInfringement());
$this->assertEquals($penaltyType, $entity->getSiPenaltyType());
$this->assertEquals($startDate, $entity->getStartDate());
$this->assertEquals($endDate, $entity->getEndDate());
$this->assertEquals($imposed, $entity->getImposed());
$this->assertEquals($reasonNotImposed, $entity->getReasonNotImposed());
$this->assertEquals($erruRequested, $entity->getErruPenaltyRequested());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ protected function generateAppliedPenalty($id)
$entity = new SiPenalty(
m::mock(SeriousInfringement::class)->makePartial(),
$this->generateSiPenaltyType(533),
$this->generateRequestedErru(),
'imposed',
new \DateTime('2013-06-31'),
new \DateTime('2013-08-31'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Common\Service\Helper\FlashMessengerHelperService;
use Common\Service\Helper\FormHelperService;
use Common\Service\Helper\TranslationHelperService;
use Common\Service\Table\TableBuilderFactory;
use Laminas\Form\Form;
use Common\Service\Table\TableFactory;
use Dvsa\Olcs\Transfer\Command\Cases\Si\Applied\Create as CreateDto;
use Dvsa\Olcs\Transfer\Command\Cases\Si\Applied\Delete as DeleteDto;
Expand Down Expand Up @@ -158,4 +158,34 @@ private function getPenaltyData()

return $response->getResult();
}

/**
* Alters the form by setting value options for the erruPenaltyRequested field.
*/
private function alterForm($form): Form
{
$optionData = [];
foreach ($this->getPenaltyData()['requestedErrus'] as $datum) {
$optionData[$datum['id']] = $datum['siPenaltyRequestedType']['id'].' - '.$datum['siPenaltyRequestedType']['description'];
}
$form->get('fields')->get('erruPenaltyRequested')->setValueOptions($optionData);

return $form;
}

/**
* Alters the form for adding a new penalty.
*/
public function alterFormForAdd($form, $initialData): Form
{
return $this->alterForm($form);
}

/**
* Alters the form for editing an existing penalty.
*/
public function alterFormForEdit($form, $initialData): Form
{
return $this->alterForm($form);
}
}
11 changes: 11 additions & 0 deletions app/internal/module/Olcs/src/Form/Model/Fieldset/ErruPenalty.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ class ErruPenalty extends CaseBase
*/
public $siPenaltyType;


/**
* @Form\Options({
* "label": "Requested Penalty",
* "disable_inarray_validator": false,
* "empty_option": "Please Select",
* })
* @Form\Type("DynamicSelect")
*/
public $erruPenaltyRequested;

/**
* @Form\Attributes({"id":"startDate"})
* @Form\Options({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
'title' => 'Penalty type',
'formatter' => fn($data) => $data['siPenaltyType']['id'] . ' - ' . $data['siPenaltyType']['description'],
],
[
'title' => 'Requested Identifier',
'formatter' => fn($data) => $data['erruPenaltyRequested']['penaltyRequestedIdentifier'],
],
[
'title' => 'Start date',
'formatter' => function ($data, $column) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
'title' => 'Penalty type',
'formatter' => fn($data) => $data['siPenaltyRequestedType']['id'] . ' - ' . $data['siPenaltyRequestedType']['description'],
],
[
'title' => 'Requested Identifier',
'formatter' => fn($data) => $data['penaltyRequestedIdentifier'],
],
[
'title' => 'Duration',
'name' => 'duration',
Expand Down

0 comments on commit f4e2a42

Please sign in to comment.