diff --git a/htdocs/pages/administration/compta_conf_regle.php b/htdocs/pages/administration/compta_conf_regle.php index 7f8af27d5..2da2c9724 100644 --- a/htdocs/pages/administration/compta_conf_regle.php +++ b/htdocs/pages/administration/compta_conf_regle.php @@ -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) { diff --git a/sources/Afup/Comptabilite/Comptabilite.php b/sources/Afup/Comptabilite/Comptabilite.php index 357367e14..c1fbffb77 100755 --- a/sources/Afup/Comptabilite/Comptabilite.php +++ b/sources/Afup/Comptabilite/Comptabilite.php @@ -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(); @@ -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 = []; @@ -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 '; @@ -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) . ' '; diff --git a/sources/AppBundle/Compta/Importer/AutoQualifier.php b/sources/AppBundle/Compta/Importer/AutoQualifier.php index 3a6ed8cbf..be72d492b 100644 --- a/sources/AppBundle/Compta/Importer/AutoQualifier.php +++ b/sources/AppBundle/Compta/Importer/AutoQualifier.php @@ -2,6 +2,7 @@ namespace AppBundle\Compta\Importer; +use Afup\Site\Utils\Vat; use AppBundle\Model\ComptaModeReglement; class AutoQualifier @@ -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']; } @@ -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; } diff --git a/tests/behat/features/Admin/Tresorerie/Configuration.feature b/tests/behat/features/Admin/Tresorerie/Configuration.feature index 75d99eb56..d30a2bc62 100644 --- a/tests/behat/features/Admin/Tresorerie/Configuration.feature +++ b/tests/behat/features/Admin/Tresorerie/Configuration.feature @@ -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" @@ -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"