Adding a page to list all non executed sentences
This commit is contained in:
112
src/Controller/UnsettledSentenceController.php
Normal file
112
src/Controller/UnsettledSentenceController.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Criminal;
|
||||
use App\Entity\Directory;
|
||||
use App\Entity\SentenceSettlement;
|
||||
use App\Entity\User;
|
||||
use App\Form\SearchBarType;
|
||||
use App\Form\SentenceSettlementType;
|
||||
use App\Repository\CriminalRepository;
|
||||
use App\Repository\DirectoryRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Knp\Component\Pager\PaginatorInterface;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
#[Route('/unsettled_sentence', name: 'unsettled_sentence_')]
|
||||
class UnsettledSentenceController extends AbstractController
|
||||
{
|
||||
#[Route('/list/{type?*}', name: 'list')]
|
||||
public function list(
|
||||
PaginatorInterface $paginator,
|
||||
Request $request,
|
||||
CriminalRepository $CriminalRepository,
|
||||
string $type = 'fine'
|
||||
): Response {
|
||||
|
||||
$searchForm = $this->createForm(SearchBarType::class);
|
||||
$searchForm->handleRequest($request);
|
||||
|
||||
$pagination = $paginator->paginate(
|
||||
$CriminalRepository->listForUser($this->getUser())
|
||||
->search((
|
||||
$searchForm->isSubmitted()
|
||||
&& $searchForm->isValid()
|
||||
&& $searchForm->getData()['subject'] !== null
|
||||
) ? $searchForm->getData()['subject'] : null)
|
||||
->limitUnsettled($type)
|
||||
->order(['createdAt' => 'DESC'])
|
||||
->getResult(),
|
||||
$request->query->getInt('page', 1)
|
||||
);
|
||||
|
||||
foreach ($pagination as $i => $criminal) {
|
||||
$sentence = new SentenceSettlement($criminal, $type);
|
||||
$form = $this->createForm(
|
||||
SentenceSettlementType::class,
|
||||
$sentence,
|
||||
[
|
||||
'action'=> $this->generateUrl('unsettled_sentence_settle'),
|
||||
]);
|
||||
$pagination[$i]->form = $form->createView();
|
||||
}
|
||||
|
||||
return $this->render('sentence/list.html.twig', [
|
||||
'controller_name' => 'AdminController',
|
||||
'type' => $type,
|
||||
'pagination' => $pagination,
|
||||
'count' => $pagination->getTotalItemCount(),
|
||||
'searchForm' => $searchForm->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/settle', name: 'settle')]
|
||||
public function settle(
|
||||
Request $request,
|
||||
CriminalRepository $CriminalRepository
|
||||
) {
|
||||
$type = null;
|
||||
$sentenceForm = $this->createForm(SentenceSettlementType::class);
|
||||
$sentenceForm->handleRequest($request);
|
||||
|
||||
if ($sentenceForm->isSubmitted() && $sentenceForm->isValid()) {
|
||||
$formData = $sentenceForm->getData();
|
||||
$type = $formData['type'];
|
||||
$criminal = $CriminalRepository->find($formData['criminal_id']);
|
||||
if (!$criminal) {
|
||||
$sentenceForm->addError(new FormError('error_document_not_found'));
|
||||
} else {
|
||||
try {
|
||||
$criminal->addSettlement($type, $formData['amount']);
|
||||
} catch (\OutOfRangeException $e) {
|
||||
$sentenceForm->addError(new FormError('error_value_out_of_bound'));
|
||||
}
|
||||
}
|
||||
if ($sentenceForm->isValid()) {
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->persist($criminal);
|
||||
try {
|
||||
$entityManager->flush();
|
||||
} catch (\Throwable $th) {
|
||||
if ($_ENV['APP_ENV'] === 'dev') {
|
||||
throw $th; //DEBUG
|
||||
} else {
|
||||
$this->logger->error($th);
|
||||
}
|
||||
|
||||
$this->addFlash('danger', 'alert_error_editing_document');
|
||||
return $this->redirectToRoute($request->getRequestUri());
|
||||
}
|
||||
} else {
|
||||
$this->addFlash('warning', 'alert_error_form_post');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('unsettled_sentence_list', ['type' => $type]);
|
||||
}
|
||||
}
|
||||
79
src/Entity/SentenceSettlement.php
Normal file
79
src/Entity/SentenceSettlement.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
class SentenceSettlement
|
||||
{
|
||||
const TYPE_JAIL = 'jail';
|
||||
const TYPE_FINE = 'fine';
|
||||
const TYPE_COMMUNITY_WORK = 'community_work';
|
||||
|
||||
private Criminal $criminal;
|
||||
private string $type;
|
||||
private $amount = null;
|
||||
|
||||
public function __construct(
|
||||
Criminal $criminal,
|
||||
string $type
|
||||
)
|
||||
{
|
||||
$this->criminal = $criminal;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Criminal
|
||||
*/
|
||||
public function getCriminal(): Criminal
|
||||
{
|
||||
return $this->criminal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Criminal $criminal
|
||||
*/
|
||||
public function setCriminal(Criminal $criminal): void
|
||||
{
|
||||
$this->criminal = $criminal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Criminal
|
||||
*/
|
||||
public function getCriminalId(): int
|
||||
{
|
||||
return $this->criminal->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*/
|
||||
public function setType(string $type): void
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getAmount()
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $amount
|
||||
*/
|
||||
public function setAmount($amount): void
|
||||
{
|
||||
$this->amount = $amount;
|
||||
}
|
||||
}
|
||||
60
src/Form/SentenceSettlementType.php
Normal file
60
src/Form/SentenceSettlementType.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Document;
|
||||
use App\Form\Type\AllowedGroupsType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use App\Form\Type\UserGroupSubGroupsType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
|
||||
class SentenceSettlementType extends AbstractType
|
||||
{
|
||||
private TokenStorageInterface $TokenStorage;
|
||||
|
||||
public function __construct(TokenStorageInterface $TokenStorage)
|
||||
{
|
||||
$this->TokenStorage = $TokenStorage;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$sentence = $builder->getData();
|
||||
|
||||
if ($sentence) {
|
||||
if ($sentence->getType() == "fine") {
|
||||
$amountType = NumberType::class;
|
||||
$amountLabel = 'form_label_paid';
|
||||
} else {
|
||||
$amountType = IntegerType::class;
|
||||
$amountLabel = 'form_label_executed';
|
||||
}
|
||||
} else {
|
||||
$amountType = null;
|
||||
$amountLabel = null;
|
||||
}
|
||||
|
||||
$builder->add('criminal_id', HiddenType::class)
|
||||
->add('type', HiddenType::class)
|
||||
->add('amount', $amountType, ['label' => $amountLabel])
|
||||
->add('submit', SubmitType::class, [
|
||||
'label' => 'form_button_submit',
|
||||
'priority' => -900,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return ''; // return an empty string here
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -19,4 +19,22 @@ class CriminalRepository extends DocumentRepositoriesExtension
|
||||
parent::__construct($registry, Criminal::class);
|
||||
$this->fields = ['amountMoney', 'amountTime', 'content']; //with title, list fields we can search in
|
||||
}
|
||||
|
||||
public function limitUnsettled(string $type) {
|
||||
if ($type == Criminal::TYPE_FINE) {
|
||||
$column = 'd.amountMoney';
|
||||
} elseif ($type == Criminal::TYPE_JAIL) {
|
||||
$column = 'd.amountTime';
|
||||
} elseif ($type == Criminal::TYPE_COMMUNITY_WORK) {
|
||||
$column = 'd.amountCommunityWork';
|
||||
} else {
|
||||
throw new \OutOfRangeException($type);
|
||||
}
|
||||
|
||||
$settledColumn = $column . 'Settled';
|
||||
|
||||
$this->qb->where("$column <> $settledColumn OR ($column IS NOT NULL AND $settledColumn IS NULL)");
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
class DocumentRepositoriesExtension extends ServiceEntityRepository
|
||||
{
|
||||
public array $fields = [];
|
||||
private QueryBuilder $qb;
|
||||
protected QueryBuilder $qb;
|
||||
private ?QueryBuilder $qbsearch = null;
|
||||
private ?Group $group = null;
|
||||
private ?User $user = null;
|
||||
|
||||
@@ -152,7 +152,10 @@
|
||||
<li class="pc-item">
|
||||
<a href="{{ path('document_list', {type: 'medical'}) }}" class="pc-link"><span class="pc-micon"><i class="material-icons-two-tone">vaccines</i></span><span class="pc-mtext">{% trans %}title_medicals{% endtrans %}</span></a>
|
||||
</li>
|
||||
|
||||
<li class="pc-item">
|
||||
<a href="{{ path('unsettled_sentence_list', {type: 'fine'}) }}" class="pc-link"><span class="pc-micon"><i class="material-icons-two-tone">sports</i></span><span class="pc-mtext">{% trans %}title_unsettled_sentence_list{% endtrans %}</span></a>
|
||||
</li>
|
||||
|
||||
{% if app.user.hasPermission('group_administrate') %}
|
||||
<li class="pc-item pc-caption">
|
||||
<label>{% trans %}title_management{% endtrans %}</label>
|
||||
|
||||
31
templates/sentence/line.html.twig
Normal file
31
templates/sentence/line.html.twig
Normal file
@@ -0,0 +1,31 @@
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{{ path('directory_view', {'id': i.directory.id}) }}" >{{ i.directory.firstname }} {{ i.directory.lastname }} {% if i.directory.dead %}, {% trans %}title_dead{% endtrans %}{% endif %}</a>
|
||||
</td>
|
||||
<td>
|
||||
{% trans %}title_missing{% endtrans %}:
|
||||
{% if type == 'fine' %}
|
||||
{{ i.amountMoney - i.amountMoneySettled }} {{'currency_symbol'|trans}}
|
||||
{% elseif type == 'jail' %}
|
||||
{{ i.amountTime - i.amountTimeSettled }} {{'title_hours'|trans}}
|
||||
{% elseif type == 'community_work' %}
|
||||
{{ i.amountCommunityWork - i.amountCommunityWorkSettled }} {{'title_hours'|trans}}
|
||||
{% endif %}
|
||||
<br/>
|
||||
{{ form_start(i.form) }}
|
||||
<span class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">{{ form_label(i.form.amount) }}</span>
|
||||
</div>
|
||||
{{ form_widget(i.form.amount) }}
|
||||
{{ form_widget(i.form.submit, { 'label': 'button_ok' }) }}
|
||||
</span>
|
||||
{{ form_end(i.form) }}
|
||||
</td>
|
||||
<td>
|
||||
{{i.createdAt |date('_datetime.format'|trans)}}
|
||||
</td>
|
||||
<td>
|
||||
{% include '_cells/documentActions.html.twig' with {'document': i, 'noedit': true, 'nodelete': true, 'noarchive': true} %}
|
||||
</td>
|
||||
</tr>
|
||||
63
templates/sentence/list.html.twig
Normal file
63
templates/sentence/list.html.twig
Normal file
@@ -0,0 +1,63 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}{{ "title_unsettled_sentence_list"|trans }}{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-12">{{form(searchForm)}}</div>
|
||||
</div>
|
||||
<div class="btn-group d-flex">
|
||||
<a href="fine" class="btn btn-outline-primary w-100{% if type=="fine" %} disabled{% endif %}">{% trans %}title_fines{% endtrans %}</a>
|
||||
<a href="jail" class="btn btn-outline-primary w-100{% if type=="jail" %} disabled{% endif %}">{% trans %}title_jail_time{% endtrans %}</a>
|
||||
<a href="community_work" class="btn btn-outline-primary w-100{% if type=="community_work" %} disabled{% endif %}">{% trans %}title_community_work{% endtrans %}</a>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-12"><hr><p>{{ 'title_count'|trans }}: {{ count }}</p>
|
||||
{% if pagination[0].directory is not defined %}{% set nodirectorylink = true %}{% endif %}
|
||||
{% set slicelimit = (limit is defined)? limit : null %}
|
||||
{% set counter = 0 %}
|
||||
|
||||
{% if pagination|length > 0 %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-dark table-striped table-hover align-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">{% trans %}title_name{% endtrans %}</th>
|
||||
<th scope="col">{% trans %}title_missing{% endtrans %}</th>
|
||||
<th scope="col">{% trans %}title_date{% endtrans %}</th>
|
||||
{% if noaction is not defined %}
|
||||
<th scope="col">{% trans %}tooltip_view{% endtrans %}</th>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for i in pagination |slice(0, slicelimit) %}
|
||||
{% set counter = counter + 1 %}
|
||||
{% include 'sentence/line.html.twig' with {'sentence': i, 'type': type } %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% if slicelimit is not null and pagination|length > slicelimit %}
|
||||
<div class="row my-2">
|
||||
<div class="col">
|
||||
{% if nodirectorylink is not defined %}
|
||||
<a class="btn btn-primary btn-sm" href="{{ path('document_list', {'type': pagination[0].classShort, 'directory': pagination[0].directory.id}) }}">{% trans %}button_view_more{% endtrans %}</a>
|
||||
{% else %}
|
||||
<a class="btn btn-primary btn-sm" href="{{ path('document_list', {'type': pagination[0].classShort}) }}">{% trans %}button_view_more{% endtrans %}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<p>{% trans %}no_data{% endtrans %}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="row">
|
||||
{{ knp_pagination_render(pagination) }}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -304,6 +304,7 @@ form_label_content: Content
|
||||
form_label_dead: Deceased
|
||||
form_label_download_image: Download picture
|
||||
form_label_email: Email Adress
|
||||
form_label_executed: Executed
|
||||
form_label_firstname: Firstname
|
||||
form_label_folder_name: Folder name
|
||||
form_label_gang_info: Informations about Group member
|
||||
@@ -335,6 +336,7 @@ form_label_model: Template
|
||||
form_label_motd: M.O.T.D.
|
||||
form_label_name: Name
|
||||
form_label_numberplate: Numberplate
|
||||
form_label_paid: Paid
|
||||
form_label_password: Password
|
||||
form_label_permissions: Permissions
|
||||
form_label_power: Power
|
||||
@@ -704,6 +706,7 @@ title_errorpage_error: Error
|
||||
title_faceImage: Face photo
|
||||
title_field: Fields
|
||||
title_filter: Filters
|
||||
title_fines: Fines
|
||||
title_folder_add_directories: List of Directories for adding to a folder
|
||||
title_folder_add_directory: Adding a directory to the folder
|
||||
title_folder_add_documents: Adding a document to the folder
|
||||
@@ -736,6 +739,7 @@ title_group_view_documents: Group's documents
|
||||
title_group_view: View group
|
||||
title_group: group
|
||||
title_groups: groups
|
||||
title_jail_time: Jail
|
||||
title_hasnopapers: without papers
|
||||
title_height: Height
|
||||
title_history: History
|
||||
@@ -775,6 +779,7 @@ title_medical_trusted: Trusted people
|
||||
title_medicals: Medical visits
|
||||
title_members: Members
|
||||
title_merge_directory: Merges directories
|
||||
title_missing: Missing
|
||||
title_model: Template
|
||||
title_motd: M.O.T.D
|
||||
title_name: Name
|
||||
@@ -819,7 +824,8 @@ title_users_book: Book
|
||||
title_users_documents: User's documents
|
||||
title_users_list: List of users
|
||||
title_users_sanctions: User's sanctions
|
||||
title_users: Users
|
||||
title_users: Users
|
||||
title_unsettled_sentence_list: Unsettled sentences
|
||||
title_value: Value
|
||||
title_verified: Verified
|
||||
title_versus: Versus
|
||||
|
||||
@@ -304,6 +304,7 @@ form_label_content: Contenu
|
||||
form_label_dead: Individu décédé
|
||||
form_label_download_image: Télécharger l'image
|
||||
form_label_email: Adresse Email
|
||||
form_label_executed: Effectuées
|
||||
form_label_firstname: Prénom
|
||||
form_label_folder_name: Nom du dossier
|
||||
form_label_gang_info: Informations du membre dans le Groupe associé
|
||||
@@ -335,6 +336,7 @@ form_label_model: Modèle
|
||||
form_label_motd: M.O.T.D.
|
||||
form_label_name: Nom
|
||||
form_label_numberplate: Plaque d'immatriculation
|
||||
form_label_paid: Payée
|
||||
form_label_password: Mot de passe
|
||||
form_label_permissions: Permissions
|
||||
form_label_power: Power
|
||||
@@ -703,6 +705,7 @@ title_errorpage_error: Ouups !
|
||||
title_faceImage: Photo de Face
|
||||
title_field: Champs
|
||||
title_filter: Filtre
|
||||
title_fines: Amendes
|
||||
title_folder_add_directories: Liste des fiches pour ajout au dossier
|
||||
title_folder_add_directory: Ajouter une fiche au dossier
|
||||
title_folder_add_documents: Ajouter un document au dossier
|
||||
@@ -735,6 +738,7 @@ title_group_view_documents: Voir les documents du groupe
|
||||
title_group_view: Voir un groupe
|
||||
title_group: Groupe
|
||||
title_groups: Groupes
|
||||
title_jail_time: Prison
|
||||
title_hasnopapers: Sans papier
|
||||
title_height: Taille
|
||||
title_history: Historique
|
||||
@@ -776,6 +780,7 @@ title_members: Membres
|
||||
title_merge_directory: Fusionner les fiches
|
||||
title_model: Modèle
|
||||
title_motd: M.O.T.D
|
||||
title_missing: Manquant
|
||||
title_name: Nom
|
||||
title_navigation: Menu
|
||||
title_noauthor: Pas d'utilisateur
|
||||
@@ -819,6 +824,7 @@ title_users_documents: Documents de l'utilisateur
|
||||
title_users_list: Liste des Utilisateurs
|
||||
title_users_sanctions: Sanctions de l'utilisateur
|
||||
title_users: Utilisateurs
|
||||
title_unsettled_sentence_list: Sentences en cours
|
||||
title_value: Valeur
|
||||
title_verified: Vérifié
|
||||
title_versus: Contre
|
||||
|
||||
Reference in New Issue
Block a user