Skip to content
Merged
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
23 changes: 23 additions & 0 deletions sources/AppBundle/Accounting/Entity/Account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace AppBundle\Accounting\Entity;

use Doctrine\ORM\Mapping as ORM;

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

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

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

declare(strict_types=1);

namespace AppBundle\Accounting\Entity\Repository;

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

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

/**
* @return array<Account>
*/
public function getAllSortedByName(): array
{
return $this->createQueryBuilder('c')
->orderBy('c.name', 'asc')
->getQuery()
->execute();
}


/**
* @return array<Account>
*/
public function getActiveAccounts(): array
{
return $this->createQueryBuilder('c')
->where('c.archivedAt IS NULL')
->orderBy('c.name', 'asc')
->getQuery()
->execute();
}

}
58 changes: 0 additions & 58 deletions sources/AppBundle/Accounting/Model/Account.php

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace AppBundle\Controller\Admin\Accounting\Configuration;

use AppBundle\Accounting\Form\AccountType;
use AppBundle\Accounting\Model\Account;
use AppBundle\Accounting\Model\Repository\AccountRepository;
use AppBundle\Accounting\Entity\Account;
use AppBundle\Accounting\Entity\Repository\AccountRepository;
use AppBundle\AuditLog\Audit;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -26,8 +26,8 @@ public function __invoke(Request $request): Response
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->accountRepository->save($account);
$this->audit->log('Ajout du compte ' . $account->getName());
$this->addFlash('notice', 'Le compte ' . $account->getName() . ' a été créé');
$this->audit->log('Ajout du compte ' . $account->name);
$this->addFlash('notice', 'Le compte ' . $account->name . ' a été créé');
return $this->redirectToRoute('admin_accounting_accounts_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\Model\Account;
use AppBundle\Accounting\Model\Repository\AccountRepository;
use AppBundle\Accounting\Entity\Account;
use AppBundle\Accounting\Entity\Repository\AccountRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;

Expand All @@ -15,15 +15,15 @@ public function __construct(private readonly AccountRepository $accountRepositor

public function __invoke(int $id): RedirectResponse
{
$account = $this->accountRepository->get($id);
$account = $this->accountRepository->find($id);

if (!$account instanceof Account) {
$this->addFlash('error', 'Compte non trouvé');

return $this->redirectToRoute('admin_accounting_accounts_list');
}

$account->setArchivedAt(new \DateTime());
$account->archivedAt = new \DateTimeImmutable();
$this->accountRepository->save($account);

return $this->redirectToRoute('admin_accounting_accounts_edit', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace AppBundle\Controller\Admin\Accounting\Configuration;

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

public function __invoke(int $id,Request $request): Response
{
$account = $this->accountRepository->get($id);
$account = $this->accountRepository->find($id);
$form = $this->createForm(AccountType::class, $account);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->accountRepository->save($account);
$this->audit->log('Modification du compte ' . $account->getName());
$this->addFlash('notice', 'Le compte ' . $account->getName() . ' a été modifié');
$this->audit->log('Modification du compte ' . $account->name);
$this->addFlash('notice', 'Le compte ' . $account->name . ' a été modifié');
return $this->redirectToRoute('admin_accounting_accounts_list');
}

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

namespace AppBundle\Controller\Admin\Accounting\Configuration;

use AppBundle\Accounting\Model\Repository\AccountRepository;
use AppBundle\Accounting\Entity\Repository\AccountRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;
Expand All @@ -18,7 +18,7 @@ public function __construct(

public function __invoke(Request $request): Response
{
$accounts = $this->accountRepository->getAll();
$accounts = $this->accountRepository->findAll();

return new Response($this->twig->render('admin/accounting/configuration/account_list.html.twig', [
'accounts' => $accounts,
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\Model\Account;
use AppBundle\Accounting\Model\Repository\AccountRepository;
use AppBundle\Accounting\Entity\Account;
use AppBundle\Accounting\Entity\Repository\AccountRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;

Expand All @@ -15,15 +15,15 @@ public function __construct(private readonly AccountRepository $accountRepositor

public function __invoke(int $id): RedirectResponse
{
$account = $this->accountRepository->get($id);
$account = $this->accountRepository->find($id);

if (!$account instanceof Account) {
$this->addFlash('error', 'Compte non trouvé');

return $this->redirectToRoute('admin_accounting_accounts_list');
}

$account->setArchivedAt(null);
$account->archivedAt = null;
$this->accountRepository->save($account);

return $this->redirectToRoute('admin_accounting_accounts_edit', [
Expand Down
Loading