diff --git a/migrations/Version20230705133715.php b/migrations/Version20230705133715.php
new file mode 100644
index 0000000..9319fa6
--- /dev/null
+++ b/migrations/Version20230705133715.php
@@ -0,0 +1,30 @@
+addSql('ALTER TABLE criminal ADD amount_money_settled DOUBLE PRECISION DEFAULT NULL, ADD amount_time_settled INT DEFAULT NULL, ADD amount_community_work_settled INT DEFAULT NULL');
+ $this->addSql('UPDATE criminal SET amount_money_settled = amount_money, amount_time_settled = amount_time, amount_community_work_settled = amount_community_work');
+ }
+
+ public function down(Schema $schema): void
+ {
+ $this->addSql('ALTER TABLE criminal DROP amount_money_settled, DROP amount_time_settled, DROP amount_community_work_settled');
+ }
+}
diff --git a/src/Entity/Criminal.php b/src/Entity/Criminal.php
index a6ac31e..dfbfe0a 100644
--- a/src/Entity/Criminal.php
+++ b/src/Entity/Criminal.php
@@ -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;
+ }
}
diff --git a/src/Form/CriminalType.php b/src/Form/CriminalType.php
index f1f78a4..900323a 100644
--- a/src/Form/CriminalType.php
+++ b/src/Form/CriminalType.php
@@ -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'])
;
}
diff --git a/templates/_cells/documentTable.html.twig b/templates/_cells/documentTable.html.twig
index 7f75a08..119ce09 100644
--- a/templates/_cells/documentTable.html.twig
+++ b/templates/_cells/documentTable.html.twig
@@ -78,15 +78,21 @@
{% endif %}
{% if i.amountMoney is defined %}
{% trans %}title_amount{% endtrans %}:
- {{ i.amountMoney ? i.amountMoney ~ ' ' ~'currency_symbol'|trans :'value_no_value'|trans }}
+ {{ i.amountMoney ? i.amountMoney ~ ' ' ~'currency_symbol'|trans : 'value_no_value'|trans }}
+ {{ i.amountMoney == i.amountMoneySettled ? '✅' : '❌'}}
+
{% endif %}
{% if i.amountTime is defined %}
{% trans %}title_hours{% endtrans %}:
- {{ i.amountTime ? i.amountTime ~ ' h' :'value_no_value'|trans}}
+ {{ i.amountTime ? i.amountTime ~ 'h' : 'value_no_value'|trans}}
+ {{ i.amountTime == i.amountTimeSettled ? '✅' : '❌'}}
+
{% endif %}
{% if i.amountCommunityWork is defined %}
{% trans %}title_community_work{% endtrans %}:
- {{ i.amountCommunityWork ? i.amountCommunityWork ~ ' h' :'value_no_value'|trans}}
+ {{ i.amountCommunityWork ? i.amountCommunityWork ~ 'h' : 'value_no_value'|trans}}
+ {{ i.amountCommunityWork == i.amountCommunityWorkSettled ? '✅' : '❌'}}
+
{% endif %}
{% if i.accessorySentence is defined and i.accessorySentence is not null %}
{% trans %}title_accessorySentence{% endtrans %} : {{ 'value_yes'|trans}}
diff --git a/templates/document/types/Criminal.html.twig b/templates/document/types/Criminal.html.twig
index cc053fd..8f72770 100644
--- a/templates/document/types/Criminal.html.twig
+++ b/templates/document/types/Criminal.html.twig
@@ -5,7 +5,31 @@