Skip to content

Commit

Permalink
afup#1428 compta regle auto DB + CRUD
Browse files Browse the repository at this point in the history
  • Loading branch information
stakovicz committed Mar 3, 2024
1 parent f51bc85 commit 94ae03f
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 35 deletions.
1 change: 1 addition & 0 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ parameters:
- compta_conf_operation
- compta_conf_reglement
- compta_conf_compte
- compta_conf_regle
compta_recherche:
nom: 'Recherche comptable'
niveau: 'ROLE_ADMIN'
Expand Down
25 changes: 25 additions & 0 deletions db/migrations/20240120222107_compta_regle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Phinx\Migration\AbstractMigration;

class ComptaRegle extends AbstractMigration
{
public function change()
{
$sql = <<<EOF
CREATE TABLE compta_regle
(
`id` tinyint(5) NOT NULL AUTO_INCREMENT,
`label` VARCHAR(255) NOT NULL,
`condition` VARCHAR(255) NOT NULL,
`is_credit` TINYINT(2) NULL,
`vat` VARCHAR(7) NULL,
`category_id` TINYINT(5) NULL,
`event_id` TINYINT(5) NULL,
`attachment_required` TINYINT(2) NULL,
PRIMARY KEY (`id`)
);
EOF;
$this->execute($sql);
}
}
78 changes: 78 additions & 0 deletions htdocs/pages/administration/compta_conf_regle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

use Afup\Site\Comptabilite\Comptabilite;
use Afup\Site\Utils\Logs;
use AppBundle\Controller\LegacyController;

/** @var LegacyController $this */

// Impossible to access the file itself
if (!defined('PAGE_LOADED_USING_INDEX')) {
trigger_error("Direct access forbidden.", E_USER_ERROR);
exit;
}

$action = verifierAction(array('lister', 'ajouter', 'modifier'));

$smarty->assign('action', $action);

$compta = new Comptabilite($bdd);

if ($action == 'lister') {
$data = $compta->obtenirListRegles(true);
$smarty->assign('data', $data);
} elseif ($action == 'ajouter' || $action == 'modifier') {
$formulaire = instancierFormulaire();

if ($action == 'modifier') {
$champs = $compta->obtenirListRegles('', intval($_GET['id']));
$formulaire->setDefaults($champs);

$formulaire->addElement('hidden', 'id', intval($_GET['id']));
}

// partie saisie
$formulaire->addElement('header', '', '');
$formulaire->addElement('text', 'label', 'Nom de la règle', array('size' => 30, 'maxlength' => 255));
$formulaire->addElement('text', 'condition', 'Condition', array('size' => 30, 'maxlength' => 255));
$formulaire->addElement('select', 'is_credit', 'Sens', array(null => 'Les deux', '1' => 'Crédit', '0' => 'Débit'));
$formulaire->addElement('select', 'vat', 'Taux de TVA', array('0' => 'Non soumis', '5.50' => '5.5%', '10.00' => '10%', '20.00' => '20%'));
$formulaire->addElement('select', 'category_id', 'Catégorie', $compta->obtenirListCategories());
$formulaire->addElement('select', 'event_id', 'Évènement', $compta->obtenirListEvenements());

$formulaire->addRule('label' , 'Nom manquant' , 'required');
$formulaire->addRule('condition' , 'Condition manquante' , 'required');

// boutons
$formulaire->addElement('header', 'boutons', '');
$formulaire->addElement('submit', 'soumettre', ucfirst($action));


if ($formulaire->validate()) {
$valeur = $formulaire->exportValues();

if ($action == 'ajouter') {
$ok = $compta->ajouterRegle($valeur['label'], $valeur['condition'], $valeur['is_credit'], $valeur['vat'], $valeur['category_id'], $valeur['event_id']);
} else {
$ok = $compta->modifierRegle($valeur['id'], $valeur['label'], $valeur['condition'], $valeur['is_credit'], $valeur['vat'], $valeur['category_id'], $valeur['event_id']);
}

if ($ok) {
if ($action == 'ajouter') {
Logs::log('Ajout une règle '.$formulaire->exportValue('label'));
} else {
Logs::log('Modification une règle '.$formulaire->exportValue('label').' ('.$_GET['id'].')');
}
afficherMessage(
'La règle a été '.(($action == 'ajouter') ? 'ajoutée' : 'modifiée'),
'index.php?page=compta_conf_regle&action=lister'
);
} else {
$smarty->assign(
'erreur',
'Une erreur est survenue lors de '.(($action == 'ajouter') ? "l'ajout" : 'la modification').' de la règle'
);
}
}
$smarty->assign('formulaire', genererFormulaire($formulaire));
}
8 changes: 1 addition & 7 deletions htdocs/templates/administration/compta_conf_categorie.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
{if $action == 'lister' }
<h2>Configuration</h2>

<div class="ui top attached tabular menu">
<a class="item" href="index.php?page=compta_conf_evenement">Évènements</a>
<a class="active item" href="index.php?page=compta_conf_categorie">Catégories</a>
<a class="item" href="index.php?page=compta_conf_operation">Opérations</a><br />
<a class="item" href="index.php?page=compta_conf_reglement">Modes de réglements</a><br />
<a class="item" href="index.php?page=compta_conf_compte">Comptes</a><br />
</div>
{include file="compta_conf_menu.html" page=compta_conf_categorie}

<div class="ui bottom attached segment">
<div class="ui menu">
Expand Down
8 changes: 1 addition & 7 deletions htdocs/templates/administration/compta_conf_compte.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
{if $action == 'lister' }
<h2>Configuration</h2>

<div class="ui top attached tabular menu">
<a class="item" href="index.php?page=compta_conf_evenement">Évènements</a>
<a class="item" href="index.php?page=compta_conf_categorie">Catégories</a>
<a class="item" href="index.php?page=compta_conf_operation">Opérations</a><br />
<a class="item" href="index.php?page=compta_conf_reglement">Modes de réglements</a><br />
<a class="active item" href="index.php?page=compta_conf_compte">Comptes</a><br />
</div>
{include file="compta_conf_menu.html" page=compta_conf_compte}

<div class="ui bottom attached segment">
<div class="ui menu">
Expand Down
8 changes: 1 addition & 7 deletions htdocs/templates/administration/compta_conf_evenement.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
{if $action == 'lister' }
<h2>Configuration</h2>

<div class="ui top attached tabular menu">
<a class="active item" href="index.php?page=compta_conf_evenement">Évènements</a>
<a class="item" href="index.php?page=compta_conf_categorie">Catégories</a>
<a class="item" href="index.php?page=compta_conf_operation">Opérations</a><br />
<a class="item" href="index.php?page=compta_conf_reglement">Modes de réglements</a><br />
<a class="item" href="index.php?page=compta_conf_compte">Comptes</a><br />
</div>
{include file="compta_conf_menu.html" page=compta_conf_evenement}

<div class="ui bottom attached segment">
<div class="ui menu">
Expand Down
8 changes: 8 additions & 0 deletions htdocs/templates/administration/compta_conf_menu.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="ui top attached tabular menu">
<a class="{if $page eq 'compta_conf_evenement'}active{/if} item" href="index.php?page=compta_conf_evenement">Évènements</a>
<a class="{if $page eq 'compta_conf_categorie'}active{/if} item" href="index.php?page=compta_conf_categorie">Catégories</a>
<a class="{if $page eq 'compta_conf_operation'}active{/if} item" href="index.php?page=compta_conf_operation">Opérations</a>
<a class="{if $page eq 'compta_conf_reglement'}active{/if} item" href="index.php?page=compta_conf_reglement">Modes de réglements</a>
<a class="{if $page eq 'compta_conf_compte'}active{/if} item" href="index.php?page=compta_conf_compte">Comptes</a>
<a class="{if $page eq 'compta_conf_regle'}active{/if} item" href="index.php?page=compta_conf_regle">Règles</a>
</div>
8 changes: 1 addition & 7 deletions htdocs/templates/administration/compta_conf_operation.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
{if $action == 'lister' }
<h2>Configuration</h2>

<div class="ui top attached tabular menu">
<a class="item" href="index.php?page=compta_conf_evenement">Évènements</a>
<a class="item" href="index.php?page=compta_conf_categorie">Catégories</a>
<a class="active item" href="index.php?page=compta_conf_operation">Opérations</a><br />
<a class="item" href="index.php?page=compta_conf_reglement">Modes de réglements</a><br />
<a class="item" href="index.php?page=compta_conf_compte">Comptes</a><br />
</div>
{include file="compta_conf_menu.html" page=compta_conf_operation}

<div class="ui bottom attached segment">
<div class="ui menu">
Expand Down
53 changes: 53 additions & 0 deletions htdocs/templates/administration/compta_conf_regle.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{if $action == 'lister' }
<h2>Configuration des règles</h2>

{include file="compta_conf_menu.html" page=compta_conf_regle}

<div class="ui bottom attached segment">
<div class="ui menu">
<a href="index.php?page=compta_conf_regle&amp;action=ajouter" class="item">
<div data-tooltip="Ajouter une règle" data-position="bottom left">
<i class="icon plus square"></i>
Ajouter
</div>
</a>
</div>

<table class="ui table striped compact celled">
<thead>
<tr>
<th>Règle</th>
<th></th>
</tr>
</thead>
<tbody>
{foreach from=$data item=regle}
<tr>
<td>{$regle.label}</td>
<td style="text-align: right">
<a href="index.php?page=compta_conf_regle&amp;action=modifier&amp;id={$regle.id}"
data-position="left center"
data-tooltip="Modifier la règle {$regle.label}"
class="compact ui icon button"
>
<i class="pencil alernate icon"></i>
</a>
</td>
</tr>
{foreachelse}
<tr>
<td><em>Aucune règle actuellement</em></td>
</tr>
{/foreach}
</tbody>
</table>
</div>

{else}
{if $action == 'ajouter'}
<h2>Ajouter une règle</h2>
{else}
<h2>Modifier une règle</h2>
{/if}
{include file="formulaire.html"}
{/if}
8 changes: 1 addition & 7 deletions htdocs/templates/administration/compta_conf_reglement.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
{if $action == 'lister' }
<h2>Configuration</h2>

<div class="ui top attached tabular menu">
<a class="item" href="index.php?page=compta_conf_evenement">Évènements</a>
<a class="item" href="index.php?page=compta_conf_categorie">Catégories</a>
<a class="item" href="index.php?page=compta_conf_operation">Opérations</a><br />
<a class="active item" href="index.php?page=compta_conf_reglement">Modes de réglements</a><br />
<a class="item" href="index.php?page=compta_conf_compte">Comptes</a><br />
</div>
{include file="compta_conf_menu.html" page=compta_conf_reglement}


<div class="ui bottom attached segment">
Expand Down
66 changes: 66 additions & 0 deletions sources/Afup/Comptabilite/Comptabilite.php
Original file line number Diff line number Diff line change
Expand Up @@ -1217,5 +1217,71 @@ public function rechercher($query)
return $results;
}

function obtenirListRegles($filtre = '', $where = '')
{
$requete = 'SELECT ';
$requete .= '`id`, `label`, `condition`, `vat`, `category_id`, `event_id`, `attachment_required` ';
$requete .= 'FROM ';
$requete .= 'compta_regle ';
$wheres = [];
if ($where) {
$wheres[] = 'id=' . intval($where) . ' ';
}

if (count($wheres)) {
$requete .= sprintf('WHERE %s ',implode(' AND ', $wheres));
}

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

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['label'];
}
return $result;
}
}

function ajouterRegle($label, $condition, $is_credit, $tva, $category_id, $event_id)
{
$requete = 'INSERT INTO ';
$requete .= 'compta_regle (';
$requete .= '`label`, `condition`, `is_credit`, `vat`, `category_id`, `event_id`) ';
$requete .= 'VALUES (';
$requete .= $this->_bdd->echapper($label) . ', ';
$requete .= $this->_bdd->echapper($condition) . ', ';
$requete .= $this->_bdd->echapper($is_credit) . ', ';
$requete .= $this->_bdd->echapper($tva) . ', ';
$requete .= $this->_bdd->echapper($category_id) . ', ';
$requete .= $this->_bdd->echapper($event_id) . ' ';
$requete .= ');';

return $this->_bdd->executer($requete);
}

function modifierRegle($id, $label, $condition, $is_credit, $tva, $category_id, $event_id)
{

$requete = 'UPDATE ';
$requete .= 'compta_regle ';
$requete .= 'SET ';
$requete .= '`label` = ' . $this->_bdd->echapper($label) . ', ';
$requete .= '`condition` = ' . $this->_bdd->echapper($condition) . ', ';
$requete .= '`is_credit` = ' . $this->_bdd->echapper($is_credit) . ', ';
$requete .= '`vat` = ' . $this->_bdd->echapper($tva) . ', ';
$requete .= '`category_id` = ' . $this->_bdd->echapper($category_id) . ', ';
$requete .= '`event_id` = ' . $this->_bdd->echapper($event_id) . ' ';
$requete .= 'WHERE ';
$requete .= 'id = ' . intval($id) . ' ';

return $this->_bdd->executer($requete);
}
}

0 comments on commit 94ae03f

Please sign in to comment.