Adding columns on Criminal to track sentences progression

This commit is contained in:
2023-07-08 02:45:16 +02:00
parent 30995316ae
commit 545f7facaf
5 changed files with 152 additions and 6 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Entity;
use \OutOfRangeException;
use App\Entity\Document;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\CriminalRepository;
@@ -13,6 +14,10 @@ use Symfony\Component\Validator\Constraints as Assert;
*/
class Criminal extends Document
{
const TYPE_JAIL = 'jail';
const TYPE_FINE = 'fine';
const TYPE_COMMUNITY_WORK = 'community_work';
/**
* @ORM\ManyToOne(targetEntity=Directory::class, inversedBy="criminals")
* @ORM\JoinColumn(nullable=false)
@@ -47,6 +52,24 @@ class Criminal extends Document
*/
private $content;
/**
* @ORM\Column(type="float", nullable=true)
* @Gedmo\Versioned
*/
private $amountMoneySettled;
/**
* @ORM\Column(type="integer", nullable=true)
* @Gedmo\Versioned
*/
private $amountTimeSettled;
/**
* @ORM\Column(type="integer", nullable=true)
* @Gedmo\Versioned
*/
private $amountCommunityWorkSettled;
public function __construct(User $user)
{
parent::__construct($user);
@@ -112,4 +135,64 @@ class Criminal extends Document
return $this;
}
public function getAmountMoneySettled(): ?float
{
return $this->amountMoneySettled;
}
public function setAmountMoneySettled(?float $amountMoneySettled): self
{
$this->amountMoneySettled = $amountMoneySettled;
return $this;
}
public function getAmountTimeSettled(): ?int
{
return $this->amountTimeSettled;
}
public function setAmountTimeSettled(?int $amountTimeSettled): self
{
$this->amountTimeSettled = $amountTimeSettled;
return $this;
}
public function getAmountCommunityWorkSettled(): ?int
{
return $this->amountCommunityWorkSettled;
}
public function setAmountCommunityWorkSettled(?int $amountCommunityWorkSettled): self
{
$this->amountCommunityWorkSettled = $amountCommunityWorkSettled;
return $this;
}
public function addSettlement($type, $amount) {
if ($type == Criminal::TYPE_FINE) {
if ($this->getAmountMoney() - $this->getAmountMoneySettled() < $amount) {
throw new OutOfRangeException();
}
$this->setAmountMoneySettled($this->getAmountMoneySettled() + $amount);
} elseif ($type == Criminal::TYPE_JAIL) {
if ($this->getAmountTime() - $this->getAmountTimeSettled() < $amount) {
throw new OutOfRangeException();
}
$this->setAmountTimeSettled($this->getAmountTimeSettled() + $amount);
} elseif ($type == Criminal::TYPE_COMMUNITY_WORK) {
if ($this->getAmountCommunityWork() - $this->getAmountCommunityWorkSettled() < $amount) {
throw new OutOfRangeException();
}
$this->setAmountCommunityWorkSettled($this->getAmountCommunityWorkSettled() + $amount);
} else {
throw new OutOfRangeException();
}
return $this;
}
}

View File

@@ -21,6 +21,9 @@ class CriminalType extends DocumentType
->add('amountMoney', null, ['label' => 'form_label_amount', 'help' => 'form_help_amount'])
->add('amountTime', null, ['label' => 'form_label_time', 'help' => 'form_help_time'])
->add('amountCommunityWork', null, ['label' => 'form_label_community_work', 'help' => 'form_help_community_work'])
->add('amountMoneySettled', null, ['label' => 'form_label_amount_settled', 'help' => 'form_help_amount_settled'])
->add('amountTimeSettled', null, ['label' => 'form_label_time_settled', 'help' => 'form_help_time_settled'])
->add('amountCommunityWorkSettled', null, ['label' => 'form_label_community_work_settled', 'help' => 'form_help_community_work_settled'])
;
}