Adding columns on Criminal to track sentences progression
This commit is contained in:
30
migrations/Version20230705133715.php
Normal file
30
migrations/Version20230705133715.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20230705133715 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use \OutOfRangeException;
|
||||||
use App\Entity\Document;
|
use App\Entity\Document;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use App\Repository\CriminalRepository;
|
use App\Repository\CriminalRepository;
|
||||||
@@ -13,6 +14,10 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
*/
|
*/
|
||||||
class Criminal extends Document
|
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\ManyToOne(targetEntity=Directory::class, inversedBy="criminals")
|
||||||
* @ORM\JoinColumn(nullable=false)
|
* @ORM\JoinColumn(nullable=false)
|
||||||
@@ -47,6 +52,24 @@ class Criminal extends Document
|
|||||||
*/
|
*/
|
||||||
private $content;
|
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)
|
public function __construct(User $user)
|
||||||
{
|
{
|
||||||
parent::__construct($user);
|
parent::__construct($user);
|
||||||
@@ -112,4 +135,64 @@ class Criminal extends Document
|
|||||||
|
|
||||||
return $this;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ class CriminalType extends DocumentType
|
|||||||
->add('amountMoney', null, ['label' => 'form_label_amount', 'help' => 'form_help_amount'])
|
->add('amountMoney', null, ['label' => 'form_label_amount', 'help' => 'form_help_amount'])
|
||||||
->add('amountTime', null, ['label' => 'form_label_time', 'help' => 'form_help_time'])
|
->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('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'])
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,15 +78,21 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% if i.amountMoney is defined %}
|
{% if i.amountMoney is defined %}
|
||||||
<br /><small>{% trans %}title_amount{% endtrans %}:</small>
|
<br /><small>{% trans %}title_amount{% endtrans %}:</small>
|
||||||
<small>{{ i.amountMoney ? i.amountMoney ~ ' ' ~'currency_symbol'|trans :'value_no_value'|trans }}</small>
|
<small>{{ i.amountMoney ? i.amountMoney ~ ' ' ~'currency_symbol'|trans : 'value_no_value'|trans }}
|
||||||
|
{{ i.amountMoney == i.amountMoneySettled ? '✅' : '❌'}}
|
||||||
|
</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if i.amountTime is defined %}
|
{% if i.amountTime is defined %}
|
||||||
<br /><small>{% trans %}title_hours{% endtrans %}:</small>
|
<br /><small>{% trans %}title_hours{% endtrans %}:</small>
|
||||||
<small>{{ i.amountTime ? i.amountTime ~ ' h' :'value_no_value'|trans}}</small>
|
<small>{{ i.amountTime ? i.amountTime ~ 'h' : 'value_no_value'|trans}}
|
||||||
|
{{ i.amountTime == i.amountTimeSettled ? '✅' : '❌'}}
|
||||||
|
</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if i.amountCommunityWork is defined %}
|
{% if i.amountCommunityWork is defined %}
|
||||||
<br /><small>{% trans %}title_community_work{% endtrans %}:</small>
|
<br /><small>{% trans %}title_community_work{% endtrans %}:</small>
|
||||||
<small>{{ i.amountCommunityWork ? i.amountCommunityWork ~ ' h' :'value_no_value'|trans}}</small>
|
<small>{{ i.amountCommunityWork ? i.amountCommunityWork ~ 'h' : 'value_no_value'|trans}}
|
||||||
|
{{ i.amountCommunityWork == i.amountCommunityWorkSettled ? '✅' : '❌'}}
|
||||||
|
</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if i.accessorySentence is defined and i.accessorySentence is not null %}
|
{% if i.accessorySentence is defined and i.accessorySentence is not null %}
|
||||||
<br /><small data-bs-toggle="tooltip" data-placement="top" title="{{ i.accessorySentence|striptags }}">{% trans %}title_accessorySentence{% endtrans %} : {{ 'value_yes'|trans}}</small>
|
<br /><small data-bs-toggle="tooltip" data-placement="top" title="{{ i.accessorySentence|striptags }}">{% trans %}title_accessorySentence{% endtrans %} : {{ 'value_yes'|trans}}</small>
|
||||||
|
|||||||
@@ -5,7 +5,31 @@
|
|||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<ul>
|
<ul>
|
||||||
<li>{% trans %}title_amount{% endtrans %} : {{ document.amountMoney }} {{'currency_symbol'|trans}}</li>
|
<li>{% trans %}title_amount{% endtrans %} : {{ document.amountMoney ? document.amountMoney ~ ' ' ~ 'currency_symbol'|trans : 'value_no_value'|trans }}
|
||||||
<li>{% trans %}title_hours{% endtrans %} : {{ document.amountTime }} {{ 'title_hours'| trans }}</li>
|
{% if document.amountMoney %}
|
||||||
<li>{% trans %}title_community_work{% endtrans %} : {{ document.amountCommunityWork }} {{ 'title_hours'| trans }}</li>
|
{% if document.amountMoney == document.amountMoneySettled %}
|
||||||
|
✅
|
||||||
|
{% else %}
|
||||||
|
❌ {% trans %}title_missing{% endtrans %}: {{ document.amountMoney - document.amountMoneySettled }}{{'currency_symbol'|trans}}
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
|
<li>{% trans %}title_hours{% endtrans %} : {{ document.amountTime ? document.amountTime ~ ' ' ~ 'title_hours'|trans : 'value_no_value'|trans }}
|
||||||
|
{% if document.amountTime %}
|
||||||
|
{% if document.amountTime == document.amountTimeSettled %}
|
||||||
|
✅
|
||||||
|
{% else %}
|
||||||
|
❌ {% trans %}title_missing{% endtrans %}: {{ document.amountTime - document.amountTimeSettled }} {{'title_hours'|trans}}
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
|
<li>{% trans %}title_community_work{% endtrans %} : {{ document.amountCommunityWork ? document.amountCommunityWork ~ ' ' ~ 'title_hours'|trans : 'value_no_value'|trans }}
|
||||||
|
{% if document.amountCommunityWork %}
|
||||||
|
{% if document.amountCommunityWork == document.amountCommunityWorkSettled %}
|
||||||
|
✅
|
||||||
|
{% else %}
|
||||||
|
❌ {% trans %}title_missing{% endtrans %}: {{ document.amountCommunityWork - document.amountCommunityWorkSettled }} {{'title_hours'|trans}}
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
Reference in New Issue
Block a user