Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions sources/AppBundle/Accounting/Entity/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace AppBundle\Accounting\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'compta_categorie')]
class Category
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
public ?int $id = null;

#[ORM\Column(name: 'categorie', length: 255, nullable: false)]
public string $name;

#[ORM\Column(name: 'idevenement', nullable: true)]
public ?int $eventId = null;

#[ORM\Column(type: 'datetime_immutable', nullable: true)]
public ?\DateTimeImmutable $hideInAccountingJournalAt = null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace AppBundle\Accounting\Entity\Repository;

use AppBundle\Accounting\Entity\Category;
use AppBundle\Doctrine\EntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
* @extends EntityRepository<Category>
*/
final class CategoryRepository extends EntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Category::class);
}

/**
* @return array<Category>
*/
public function getAllSortedByName(): array
{
return $this->createQueryBuilder('c')
->orderBy('c.name', 'asc')
->getQuery()
->execute();
}
}
5 changes: 3 additions & 2 deletions sources/AppBundle/Accounting/Entity/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ class Rule
#[ORM\Column(nullable: true)]
public ?string $vat = null;

#[ORM\Column(nullable: true)]
public ?int $categoryId = null;
#[ORM\OneToOne()]
#[ORM\JoinColumn(nullable: true)]
public ?Category $category = null;

#[ORM\Column(nullable: true)]
public ?int $eventId = null;
Expand Down
15 changes: 5 additions & 10 deletions sources/AppBundle/Accounting/Form/RuleType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

namespace AppBundle\Accounting\Form;

use AppBundle\Accounting\Model\Repository\CategoryRepository;
use AppBundle\Accounting\Entity\Category;
use AppBundle\Accounting\Model\Repository\EventRepository;
use AppBundle\Model\ComptaModeReglement;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
Expand All @@ -16,18 +17,11 @@
class RuleType extends AbstractType
{
public function __construct(
private readonly CategoryRepository $categoryRepository,
private readonly EventRepository $eventRepository,
) {}

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$categories = [];
$categories[''] = null;
foreach ($this->categoryRepository->getAllSortedByName() as $category) {
$categories[$category->getName()] = $category->getId();
}

$events = [];
$events[''] = null;
foreach ($this->eventRepository->getAllSortedByName() as $event) {
Expand Down Expand Up @@ -68,9 +62,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'placeholder' => false,
'choices' => ['N.C.' => '', '0%' => '0', '5.5%' => '5_5', '10%' => '10', '20%' => '20'],
'required' => false,
])->add('categoryId', ChoiceType::class, [
])->add('category', EntityType::class, [
'label' => 'Catégorie',
'choices' => $categories,
'class' => Category::class,
'choice_label' => 'name',
'required' => false,
])->add('eventId', ChoiceType::class, [
'label' => 'Évènement',
Expand Down
70 changes: 0 additions & 70 deletions sources/AppBundle/Accounting/Model/Category.php

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace AppBundle\Controller\Admin\Accounting\Configuration;

use AppBundle\Accounting\Entity\Category;
use AppBundle\Accounting\Entity\Repository\CategoryRepository;
use AppBundle\Accounting\Form\CategoryType;
use AppBundle\Accounting\Model\Category;
use AppBundle\Accounting\Model\Repository\CategoryRepository;
use AppBundle\AuditLog\Audit;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -26,7 +26,7 @@ public function __invoke(Request $request): Response
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->categoryRepository->save($category);
$this->audit->log('Ajout de la catégorie ' . $category->getName());
$this->audit->log('Ajout de la catégorie ' . $category->name);
$this->addFlash('notice', 'La catégorie a été ajoutée');
return $this->redirectToRoute('admin_accounting_categories_list');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace AppBundle\Controller\Admin\Accounting\Configuration;

use AppBundle\Accounting\Entity\Repository\CategoryRepository;
use AppBundle\Accounting\Form\CategoryType;
use AppBundle\Accounting\Model\Repository\CategoryRepository;
use AppBundle\AuditLog\Audit;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -20,12 +20,12 @@ public function __construct(

public function __invoke(int $id,Request $request): Response
{
$category = $this->categoryRepository->get($id);
$category = $this->categoryRepository->find($id);
$form = $this->createForm(CategoryType::class, $category);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->categoryRepository->save($category);
$this->audit->log('Modification de la catégorie ' . $category->getName());
$this->audit->log('Modification de la catégorie ' . $category->name);
$this->addFlash('notice', 'La catégorie a été modifiée');
return $this->redirectToRoute('admin_accounting_categories_list');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace AppBundle\Controller\Admin\Accounting\Configuration;

use AppBundle\Accounting\Model\Repository\CategoryRepository;
use AppBundle\Accounting\Entity\Repository\CategoryRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;

class ListCategoryAction
final readonly class ListCategoryAction
{
public function __construct(
private readonly CategoryRepository $categoryRepository,
private readonly Environment $twig,
private CategoryRepository $categoryRepository,
private Environment $twig,
) {}

public function __invoke(Request $request): Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{ form_row(form.isCredit) }}
{{ form_row(form.paymentTypeId) }}
{{ form_row(form.vat) }}
{{ form_row(form.categoryId) }}
{{ form_row(form.category) }}
{{ form_row(form.eventId) }}
{{ form_row(form.attachmentRequired) }}
</div>
Expand Down
4 changes: 2 additions & 2 deletions tests/behat/features/Admin/Tresorerie/Configuration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Feature: Administration - Trésorerie - Configuration
# TVA à 5.5%
When I fill in "rule[vat]" with "5_5"
# À determiner
When I fill in "rule[categoryId]" with "26"
When I fill in "rule[category]" with "26"
# Association AFUP
When I fill in "rule[eventId]" with "27"
# Justification obligatoire
Expand All @@ -119,6 +119,6 @@ Feature: Administration - Trésorerie - Configuration
And The "rule[isCredit]" field should have the following selected value "1"
And The "rule[paymentTypeId]" field should have the following selected value "2"
And The "rule[vat]" field should have the following selected value "5_5"
And The "rule[categoryId]" field should have the following selected value "26"
And The "rule[category]" field should have the following selected value "26"
And The "rule[eventId]" field should have the following selected value "27"
And The "rule[attachmentRequired]" field should have the following selected value "1"
Loading