Overview
Comment: | Corrections et vérifications à l'ajout de cotisation |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
4c4c3db24daa72cdea0515eaca340996 |
User & Date: | bohwaz on 2014-04-07 16:26:19 |
Other Links: | manifest | tags |
Context
2014-04-10
| ||
17:50 | rc2 check-in: 1bb750bae9 user: bohwaz tags: trunk | |
2014-04-07
| ||
16:26 | Corrections et vérifications à l'ajout de cotisation check-in: 4c4c3db24d user: bohwaz tags: trunk | |
16:09 | Correction export des membres check-in: b46f155397 user: bohwaz tags: trunk | |
Changes
Modified src/include/class.cotisations_membres.php from [f2efd7acab] to [1e76b69c3c].
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?php namespace Garradin; class Cotisations_Membres { const ITEMS_PER_PAGE = 100; /** * Vérification des champs fournis pour la modification de donnée * @param array $data Tableau contenant les champs à ajouter/modifier * @return void */ | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <?php namespace Garradin; class Cotisations_Membres { const ITEMS_PER_PAGE = 100; /** * Vérification des champs fournis pour la modification de donnée * @param array $data Tableau contenant les champs à ajouter/modifier * @return void */ protected function _checkFields(&$data, $compta = false) { $db = DB::getInstance(); if (empty($data['date']) || !utils::checkDate($data['date'])) { throw new UserException('Date vide ou invalide.'); } |
︙ | ︙ | |||
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | if (empty($data['id_membre']) || !$db->simpleQuerySingle('SELECT 1 FROM membres WHERE id = ?;', false, (int) $data['id_membre'])) { throw new UserException('Membre inconnu ou invalide.'); } $data['id_membre'] = (int) $data['id_membre']; } /** * Enregistrer un événement de cotisation * @param array $data Tableau des champs à insérer * @return integer ID de l'événement créé */ public function add($data) { $db = DB::getInstance(); | > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > < < < | | | | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | if (empty($data['id_membre']) || !$db->simpleQuerySingle('SELECT 1 FROM membres WHERE id = ?;', false, (int) $data['id_membre'])) { throw new UserException('Membre inconnu ou invalide.'); } $data['id_membre'] = (int) $data['id_membre']; if ($compta) { if (!isset($data['moyen_paiement']) || trim($data['moyen_paiement']) === '') { throw new UserException('Moyen de paiement inconnu ou invalide.'); } if ($data['moyen_paiement'] != 'ES') { if (trim($data['banque']) == '') { throw new UserException('Le compte bancaire choisi est invalide.'); } if (!$db->simpleQuerySingle('SELECT 1 FROM compta_comptes_bancaires WHERE id = ?;', false, $data['banque'])) { throw new UserException('Le compte bancaire choisi n\'existe pas.'); } } } } /** * Enregistrer un événement de cotisation * @param array $data Tableau des champs à insérer * @return integer ID de l'événement créé */ public function add($data) { $db = DB::getInstance(); $co = $db->simpleQuerySingle('SELECT * FROM cotisations WHERE id = ?;', true, (int)$data['id_cotisation']); $this->_checkFields($data, !empty($co['id_categorie_compta'])); $check = $db->simpleQuerySingle('SELECT 1 FROM cotisations_membres WHERE id_cotisation = ? AND id_membre = ? AND date = ?;', false, (int)$data['id_cotisation'], (int)$data['id_membre'], $data['date']); if ($check) { throw new UserException('Cette cotisation a déjà été enregistrée pour ce jour-ci et ce membre-ci.'); } $db->exec('BEGIN;'); $db->simpleInsert('cotisations_membres', [ 'date' => $data['date'], 'id_cotisation' => $data['id_cotisation'], 'id_membre' => $data['id_membre'], ]); $id = $db->lastInsertRowId(); if ($co['id_categorie_compta'] && $co['montant'] > 0) { try { $id_operation = $this->addOperationCompta($id, [ 'id_categorie' => $co['id_categorie_compta'], 'libelle' => 'Cotisation (automatique)', 'montant' => $co['montant'], 'date' => $data['date'], 'moyen_paiement'=> $data['moyen_paiement'], 'numero_cheque' => isset($data['numero_cheque']) ? $data['numero_cheque'] : null, 'id_auteur' => $data['id_auteur'], 'banque' => isset($data['banque']) ? $data['banque'] : null, 'id_membre' => $data['id_membre'], ]); } catch (\Exception $e) { $db->exec('ROLLBACK;'); throw $e; |
︙ | ︙ | |||
139 140 141 142 143 144 145 | if (!isset($data['montant']) || !is_numeric($data['montant']) || (float)$data['montant'] < 0) { throw new UserException('Le montant doit être un nombre positif et valide.'); } $data['montant'] = (float) $data['montant']; | < < < < < < < < < < | < < < < < < < < < < < | 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | if (!isset($data['montant']) || !is_numeric($data['montant']) || (float)$data['montant'] < 0) { throw new UserException('Le montant doit être un nombre positif et valide.'); } $data['montant'] = (float) $data['montant']; if ($data['moyen_paiement'] != 'ES') { $debit = $data['banque']; } else { $debit = Compta_Comptes::CAISSE; } |
︙ | ︙ |
Modified src/templates/admin/membres/cotisations/ajout.tpl from [4ac3bc61b8] to [ef40dcb0a6].
︙ | ︙ | |||
82 83 84 85 86 87 88 | {csrf_field key="add_cotisation"} {if $membre}<input type="hidden" name="id_membre" value="{$membre.id|escape}" />{/if} <input type="submit" name="add" value="Enregistrer →" /> </p> </form> <script type="text/javascript"> | < < < < < < > > > > > | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | {csrf_field key="add_cotisation"} {if $membre}<input type="hidden" name="id_membre" value="{$membre.id|escape}" />{/if} <input type="submit" name="add" value="Enregistrer →" /> </p> </form> <script type="text/javascript"> {literal} (function () { window.changeMoyenPaiement = function() { var elm = $('#f_moyen_paiement'); toggleElementVisibility('.f_cheque', elm.value == 'CH'); toggleElementVisibility('.f_banque', elm.value != 'ES'); }; changeMoyenPaiement(); $('#f_moyen_paiement').onchange = changeMoyenPaiement; $('#f_id_cotisation').onchange = function () { if (this.options[this.selectedIndex].getAttribute('data-compta')) { toggleElementVisibility('.f_compta', true); changeMoyenPaiement(); } else { toggleElementVisibility('.f_compta', false); changeMoyenPaiement(); } }; if (!$('#f_id_cotisation').options[$('#f_id_cotisation').selectedIndex].getAttribute('data-compta')) { toggleElementVisibility('.f_compta', false); } } ()); {/literal} </script> {include file="admin/_foot.tpl"} |
Modified src/www/admin/membres/cotisations/ajout.php from [47528a9ba2] to [a67846c779].
︙ | ︙ | |||
44 45 46 47 48 49 50 | else { try { $data = [ 'date' => utils::post('date'), 'id_cotisation' => utils::post('id_cotisation'), 'id_membre' => utils::post('id_membre'), | < | < < < | | | > | < | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | else { try { $data = [ 'date' => utils::post('date'), 'id_cotisation' => utils::post('id_cotisation'), 'id_membre' => utils::post('id_membre'), 'id_auteur' => $user['id'], 'moyen_paiement' => utils::post('moyen_paiement'), 'numero_cheque' => utils::post('numero_cheque'), 'banque' => utils::post('banque'), ]; $m_cotisations->add($data); utils::redirect('/admin/membres/cotisations.php?id=' . (int)utils::post('id_membre')); } catch (UserException $e) { $error = $e->getMessage(); |
︙ | ︙ |