Skip to content

Commit

Permalink
afup#1428 qualification comptable code review
Browse files Browse the repository at this point in the history
  • Loading branch information
stakovicz committed Mar 3, 2024
1 parent 6b322b9 commit d29d5a3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions htdocs/pages/administration/compta_conf_regle.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
$valeur = $formulaire->exportValues();

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

if ($ok) {
Expand Down
25 changes: 11 additions & 14 deletions sources/Afup/Comptabilite/Comptabilite.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ function extraireComptaDepuisCSVBanque(Importer $importer)
return false;
}

$qualifier = new AutoQualifier($this->obtenirListRegles());
$qualifier = new AutoQualifier($this->obtenirListRegles(true));

foreach ($importer->extract() as $operation) {
$numero_operation = $operation->getNumeroOperation();
Expand Down Expand Up @@ -1123,7 +1123,7 @@ public function rechercher($query)
function obtenirListRegles($filtre = '', $where = '')
{
$requete = 'SELECT ';
$requete .= '`id`, `label`, `condition`, `vat`, `category_id`, `event_id`, `attachment_required` ';
$requete .= '`id`, `label`, `condition`, `is_credit`, `vat`, `category_id`, `event_id`, `mode_regl_id`, `attachment_required` ';
$requete .= 'FROM ';
$requete .= 'compta_regle ';
$wheres = [];
Expand All @@ -1142,34 +1142,29 @@ function obtenirListRegles($filtre = '', $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)
function ajouterRegle($label, $condition, $is_credit, $tva, $category_id, $event_id, $mode_regl_id, $attachment_required)
{
$requete = 'INSERT INTO ';
$requete .= 'compta_regle (';
$requete .= '`label`, `condition`, `is_credit`, `vat`, `category_id`, `event_id`) ';
$requete .= '`label`, `condition`, `is_credit`, `vat`, `category_id`, `event_id`, `mode_regl_id`, `attachment_required`) ';
$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 .= $this->_bdd->echapper($event_id) . ', ';
$requete .= $this->_bdd->echapper($mode_regl_id) . ', ';
$requete .= $this->_bdd->echapper($attachment_required) . ' ';
$requete .= ');';

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

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

$requete = 'UPDATE ';
Expand All @@ -1180,7 +1175,9 @@ function modifierRegle($id, $label, $condition, $is_credit, $tva, $category_id,
$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 .= '`event_id` = ' . $this->_bdd->echapper($event_id) . ', ';
$requete .= '`mode_regl_id` = ' . $this->_bdd->echapper($mode_regl_id) . ', ';
$requete .= '`attachment_required` = ' . $this->_bdd->echapper($attachment_required) . ' ';
$requete .= 'WHERE ';
$requete .= 'id = ' . intval($id) . ' ';

Expand Down
5 changes: 3 additions & 2 deletions sources/AppBundle/Compta/Importer/AutoQualifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AppBundle\Compta\Importer;

use Afup\Site\Utils\Vat;
use AppBundle\Model\ComptaModeReglement;

class AutoQualifier
Expand Down Expand Up @@ -57,7 +58,7 @@ public function qualify(Operation $operation): array

foreach ($this->rules as $rule) {
if (($operation->isCredit() === (bool) $rule['is_credit']) || is_null($rule['is_credit'])) {
if (0 === strpos($operationQualified['description'], $rule['condition'])) {
if (false !== strpos($operationQualified['description'], $rule['condition'])) {
if (null !== $rule['event_id']) {
$operationQualified['evenement'] = $rule['event_id'];
}
Expand All @@ -72,7 +73,7 @@ public function qualify(Operation $operation): array
}
if (null !== $rule['vat']) {
$tx = ['0' => 0, '5_5' => 0.055, '10' => 0.1, '20' => 0.2];
$operationQualified['montant_ht_soumis_tva_' . $rule['vat']] = round($operationQualified['montant'] / (1+$tx[$rule['vat']]), 2);
$operationQualified['montant_ht_soumis_tva_' . $rule['vat']] = Vat::getRoundedWithoutVatPriceFromPriceWithVat($operationQualified['montant'], $tx[$rule['vat']]);
}
break;
}
Expand Down
10 changes: 9 additions & 1 deletion tests/behat/features/Admin/Tresorerie/Configuration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ Feature: Administration - Trésorerie - Configuration
Then the ".content .message" element should contain "L'écriture a été ajoutée"
And I should see "Un super compte"


Scenario: Création/liste des règles
Given I am logged in as admin and on the Administration
When I follow "Configuration"
Expand All @@ -85,3 +84,12 @@ Feature: Administration - Trésorerie - Configuration
Then the ".content .message" element should contain "La règle a été ajoutée"
And I should see "Une nouvelle règle REM INSCRIPTION"

When I follow the button of tooltip "Modifier la règle Une nouvelle règle"
And The "label" field should only contain the follow values "Une nouvelle règle"
And The "condition" field should only contain the follow values "REM INSCRIPTION"
And The "is_credit" field should has the following selected value "1"
And The "mode_regl_id" field should has the following selected value "2"
And The "vat" field should has the following selected value "5_5"
And The "category_id" field should has the following selected value "26"
And The "event_id" field should has the following selected value "27"
And The "attachment_required" field should has the following selected value "1"

0 comments on commit d29d5a3

Please sign in to comment.