Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
7 changes: 7 additions & 0 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,13 @@ ting:
default:
connection: main
database: "%database_name%"
accounting:
namespace : AppBundle\Accounting\Model\Repository
directory : "@AppBundle/Accounting/Model/Repository"
options:
default:
connection: main
database: '%database_name%'

knpu_oauth2_client:
clients:
Expand Down
4 changes: 4 additions & 0 deletions app/config/routing/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ admin_site:
resource: "admin_site.yml"
prefix: /site

admin_accounting:
resource: "admin_accounting.yml"
prefix: /accounting

admin_github_user_routes:
resource: "admin_github_user.yml"
prefix: /event/github-user
Expand Down
21 changes: 21 additions & 0 deletions app/config/routing/admin_accounting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
admin_accounting_accounts_edit:
path: /accounts/edit/{id}
defaults: {_controller: AppBundle\Controller\Admin\Accounting\Configuration\EditAccountAction}
requirements:
id: '\d+'

admin_accounting_accounts_add:
path: /accounts/add
defaults: {_controller: AppBundle\Controller\Admin\Accounting\Configuration\AddAccountAction}

admin_accounting_accounts_archive:
path: /accounts/archive/{id}
defaults: {_controller: AppBundle\Controller\Admin\Accounting\Configuration\ArchiveAccountAction}
requirements:
id: '\d+'

admin_accounting_accounts_restore:
path: /accounts/restore/{id}
defaults: {_controller: AppBundle\Controller\Admin\Accounting\Configuration\RestoreAccountAction}
requirements:
id: '\d+'
13 changes: 13 additions & 0 deletions db/migrations/20250801224020_add_archived_at_on_account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AddArchivedAtOnAccount extends AbstractMigration
{
public function change(): void
{
$this->execute('ALTER TABLE compta_compte ADD COLUMN archived_at DATETIME DEFAULT NULL');
}
}
10 changes: 10 additions & 0 deletions db/seeds/ComptaCompte.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function run(): void
[
'id' => 1,
'nom_compte' => 'Compte courant',
'archived_at' => (new DateTime('last year'))->format('Y-m-d H:i:s'),
],
[
'id' => 2,
Expand All @@ -20,11 +21,20 @@ public function run(): void
[
'id' => 3,
'nom_compte' => 'Livret A',
'archived_at' => (new DateTime('last year'))->format('Y-m-d H:i:s'),
],
[
'id' => 4,
'nom_compte' => 'Paypal',
],
[
'id' => 5,
'nom_compte' => 'Courant CM',
],
[
'id' => 6,
'nom_compte' => 'Livret A CM',
],
];

$table = $this->table('compta_compte');
Expand Down
9 changes: 1 addition & 8 deletions htdocs/pages/administration/compta_banque.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@
$listPeriode = $compta->obtenirListPeriode();
$smarty->assign('listPeriode', $listPeriode);

$listeComptes = [
'1' => 'Courant',
'5' => 'Courant CM',
'2' => 'Espece',
'3' => 'Livret A',
'6' => 'Livret A CM',
'4' => 'Paypal',
];
$listeComptes = $compta->obtenirListeComptesActifs('');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est déjà la valeur par défaut donc tu peux enlever la valeur :

Suggested change
$listeComptes = $compta->obtenirListeComptesActifs('');
$listeComptes = $compta->obtenirListeComptesActifs();

$smarty->assign('listeComptes', $listeComptes);
$smarty->assign('compte_id', $compte);

Expand Down
4 changes: 2 additions & 2 deletions htdocs/pages/administration/compta_conf_compte.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
$formulaire = instancierFormulaire();

if ($action === 'modifier') {
$champsRecup = $compta->obtenirListCategories('',$_GET['id']);
$champs['categorie'] = $champsRecup['categorie'];
$champsRecup = $compta->obtenirListComptes('',$_GET['id']);
$champs['nom_compte'] = $champsRecup['nom_compte'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Au lieu de modifier ce code, il vaudrait mieux supprimer ce qui a été remplacé par du Symfony (tout sauf la liste des compte).

Là actuellement les anciennes urls de modification et création fonctionnent encore.

Après si tu compte refaire la liste des comptes en Symfony ça peut attendre.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai une branche locale avec la refonte de la page de listing sous SF. Si besoin, je peux l'intégrer à la PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mopolo au final j'ai ajouté la suppression de la page legacy de listing des comptes


$formulaire->setDefaults($champs);

Expand Down
2 changes: 1 addition & 1 deletion htdocs/pages/administration/compta_journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
// facture associé à un évènement
$formulaire->addElement('header' , '' , 'Sélectionner un Journal');
$formulaire->addElement('select' , 'idoperation', 'Type d\'opération', $compta->obtenirListOperations());
$formulaire->addElement('select' , 'idcompte' , 'Compte', $compta->obtenirListComptes());
$formulaire->addElement('select' , 'idcompte' , 'Compte', $compta->obtenirListeComptesActifs());
$formulaire->addElement('select' , 'idevenement', 'Evenement', $compta->obtenirListEvenements());

//detail facture
Expand Down
6 changes: 3 additions & 3 deletions htdocs/templates/administration/compta_conf_compte.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ <h2>Configuration</h2>

<div class="ui bottom attached segment">
<div class="ui menu">
<a href="index.php?page=compta_conf_compte&amp;action=ajouter" class="item">
<a href="/admin/accounting/accounts/add" class="item">
<div data-tooltip="Ajouter un compte" data-position="bottom left">
<i class="icon plus square"></i>
Ajouter
Expand All @@ -25,9 +25,9 @@ <h2>Configuration</h2>
<tr>
<td>{$ecriture.nom_compte}</td>
<td style="text-align: right">
<a href="index.php?page=compta_conf_compte&amp;action=modifier&amp;id={$ecriture.id}"
<a href="/admin/accounting/accounts/edit/{$ecriture.id}"
data-position="left center"
data-tooltip="Modifier la ligne {$ecriture.description}"
data-tooltip="Modifier la ligne {$ecriture.nom_compte}"
class="compact ui icon button"
>
<i class="pencil alernate icon"></i>
Expand Down
31 changes: 30 additions & 1 deletion sources/Afup/Comptabilite/Comptabilite.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public function obtenirListOperations($filtre = '', ?string $where = '')
public function obtenirListComptes($filtre = '', ?string $where = '')
{
$requete = 'SELECT ';
$requete .= 'id, nom_compte ';
$requete .= 'id, nom_compte, archived_at ';
$requete .= 'FROM ';
$requete .= 'compta_compte ';
if ($where) {
Expand All @@ -354,6 +354,35 @@ public function obtenirListComptes($filtre = '', ?string $where = '')
}
}

public function obtenirListeComptesActifs($filtre = '', ?string $where = '')
{
$requete = 'SELECT ';
$requete .= 'id, nom_compte ';
$requete .= 'FROM ';
$requete .= 'compta_compte ';
$requete .= 'WHERE archived_at IS NULL ';
if ($where) {
$requete .= 'AND id=' . $where . ' ';
}

$requete .= 'ORDER BY ';
$requete .= 'nom_compte ';

if ($where) {
return $this->_bdd->obtenirEnregistrement($requete);
} elseif ($filtre) {
return $this->_bdd->obtenirTous($requete);
} else {
$data = $this->_bdd->obtenirTous($requete);
$result[] = "";
foreach ($data as $row) {
$result[$row['id']] = $row['nom_compte'];
}

return $result;
}
}

public function obtenirListCategories($filtre = '', ?string $where = '', $usedInAccountingJournal = false)
{
$requete = 'SELECT ';
Expand Down
25 changes: 25 additions & 0 deletions sources/AppBundle/Accounting/Form/AccountType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace AppBundle\Accounting\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;

class AccountType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('name', TextType::class, [
'label' => 'Nom du compte',
'required' => true,
'constraints' => [
new Assert\NotBlank(),
new Assert\Type('string'),
],
]);
}
}
58 changes: 58 additions & 0 deletions sources/AppBundle/Accounting/Model/Account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace AppBundle\Accounting\Model;

use CCMBenchmark\Ting\Entity\NotifyProperty;
use CCMBenchmark\Ting\Entity\NotifyPropertyInterface;
use DateTime;

class Account implements NotifyPropertyInterface
{
use NotifyProperty;

private ?int $id = null;

private ?string $name = null;

private ?DateTime $archivedAt = null;

public function getId(): ?int
{
return $this->id;
}

public function setId(int $id): self
{
$this->propertyChanged('id', $this->id, $id);
$this->id = $id;
return $this;
}

public function getName(): ?string
{
return $this->name;
}

public function setName(?string $name): self
{
$this->propertyChanged('name', $this->name, $name);
$this->name = $name;

return $this;
}

public function getArchivedAt(): ?DateTime
{
return $this->archivedAt;
}

public function setArchivedAt(?DateTime $archivedAt): self
{
$this->propertyChanged('archivedAt', $this->archivedAt, $archivedAt);
$this->archivedAt = $archivedAt;

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace AppBundle\Accounting\Model\Repository;

use AppBundle\Accounting\Model\Account;
use CCMBenchmark\Ting\Repository\Metadata;
use CCMBenchmark\Ting\Repository\MetadataInitializer;
use CCMBenchmark\Ting\Repository\Repository;
use CCMBenchmark\Ting\Serializer\SerializerFactoryInterface;

/**
* @extends Repository<Account>
*/
class AccountRepository extends Repository implements MetadataInitializer
{
public static function initMetadata(SerializerFactoryInterface $serializerFactory, array $options = [])
{
$metadata = new Metadata($serializerFactory);

$metadata->setEntity(Account::class);
$metadata->setConnectionName('main');
$metadata->setDatabase($options['database']);
$metadata->setTable('compta_compte');

$metadata
->addField([
'columnName' => 'id',
'fieldName' => 'id',
'primary' => true,
'autoincrement' => true,
'type' => 'int',
])
->addField([
'columnName' => 'nom_compte',
'fieldName' => 'name',
'type' => 'string',
])
->addField([
'columnName' => 'archived_at',
'fieldName' => 'archivedAt',
'type' => 'datetime',
])
;

return $metadata;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace AppBundle\Controller\Admin\Accounting\Configuration;

use Afup\Site\Logger\DbLoggerTrait;
use AppBundle\Accounting\Form\AccountType;
use AppBundle\Accounting\Model\Account;
use AppBundle\Accounting\Model\Repository\AccountRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

final class AddAccountAction extends AbstractController
{
use DbLoggerTrait;

public function __construct(
private readonly AccountRepository $accountRepository,
) {}

public function __invoke(Request $request): Response
{
$account = new Account();
$form = $this->createForm(AccountType::class, $account);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->accountRepository->save($account);
$this->log('Ajout du compte ' . $account->getName());
$this->addFlash('notice', 'Le compte ' . $account->getName() . ' a été créé');
return $this->redirect('/pages/administration/index.php?page=compta_conf_compte&action=lister&filtre=' . $account->getName());
}

return $this->render('admin/accounting/configuration/account_add.html.twig', [
'form' => $form->createView(),
'account' => $account,
'formTitle' => 'Ajouter un compte',
'submitLabel' => 'Ajouter',
]);
}
}
Loading