Comment: | Modernisation: suppression des derniers appels aux méthodes simple* |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | dev |
Files: | files | file ages | folders |
SHA1: |
5c80b8c6f8762dc7b3aca317be6dd57a |
User & Date: | bohwaz on 2017-07-14 07:25:49 |
Other Links: | branch diff | manifest | tags |
2017-08-01
| ||
01:07 | Corrige les erreurs d'arrondi dans le report à nouveau (solde égal à 0,00), cf. [c20546bb90] check-in: d76c988ed8 user: bohwaz tags: dev | |
2017-07-14
| ||
07:25 | Modernisation: suppression des derniers appels aux méthodes simple* check-in: 5c80b8c6f8 user: bohwaz tags: dev | |
06:34 | Élimination des $_GET pour utiliser qg et qv() check-in: da2139e72e user: bohwaz tags: dev | |
Modified src/include/lib/Garradin/Compta/Categories.php from [09216dfdac] to [1997e6a481].
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
$where = is_null($type) ? '1' : 'cat.type = '.(int)$type; $query = sprintf('SELECT cat.id, cat.*, cc.libelle AS compte_libelle FROM compta_categories AS cat INNER JOIN compta_comptes AS cc ON cc.id = cat.compte WHERE %s ORDER BY cat.intitule;', $where); return $db->getAssocKey($query); } public function listMoyensPaiement() { $db = DB::getInstance(); return $db->getAssocKey('SELECT code, nom FROM compta_moyens_paiement ORDER BY nom COLLATE NOCASE;'); } public function getMoyenPaiement($code) { $db = DB::getInstance(); return $db->firstColumn('SELECT nom FROM compta_moyens_paiement WHERE code = ?;', $code); } |
| | |
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
$where = is_null($type) ? '1' : 'cat.type = '.(int)$type; $query = sprintf('SELECT cat.id, cat.*, cc.libelle AS compte_libelle FROM compta_categories AS cat INNER JOIN compta_comptes AS cc ON cc.id = cat.compte WHERE %s ORDER BY cat.intitule;', $where); return $db->getGrouped($query); } public function listMoyensPaiement() { $db = DB::getInstance(); return $db->getGrouped('SELECT code, nom FROM compta_moyens_paiement ORDER BY nom COLLATE NOCASE;'); } public function getMoyenPaiement($code) { $db = DB::getInstance(); return $db->firstColumn('SELECT nom FROM compta_moyens_paiement WHERE code = ?;', $code); } |
Modified src/include/lib/Garradin/Compta/Comptes.php from [f8161e4e86] to [25f947e684].
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
if (isset($data['parent']) || $force_parent_check) { if (empty($data['parent']) && !trim($data['parent'])) { throw new UserException('Le compte ne peut pas ne pas avoir de compte parent.'); } if (!($id = $db->simpleQuerySingle('SELECT id FROM compta_comptes WHERE id = ?;', false, $data['parent']))) { throw new UserException('Le compte parent indiqué n\'existe pas.'); } $data['parent'] = trim($id); } |
| |
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
if (isset($data['parent']) || $force_parent_check)
{
if (empty($data['parent']) && !trim($data['parent']))
{
throw new UserException('Le compte ne peut pas ne pas avoir de compte parent.');
}
if (!($id = $db->firstColumn('SELECT id FROM compta_comptes WHERE id = ?;', $data['parent'])))
{
throw new UserException('Le compte parent indiqué n\'existe pas.');
}
$data['parent'] = trim($id);
}
|
Modified src/include/lib/Garradin/Compta/Comptes_Bancaires.php from [7863573924] to [5768c2e53a].
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
return $return; } public function get($id) { $db = DB::getInstance(); return $db->simpleQuerySingle('SELECT * FROM compta_comptes AS c INNER JOIN compta_comptes_bancaires AS cc ON c.id = cc.id WHERE c.id = ?;', true, $id); } public function getList($parent = false) { $db = DB::getInstance(); return $db->simpleStatementFetchAssocKey('SELECT c.id AS id, * FROM compta_comptes AS c INNER JOIN compta_comptes_bancaires AS cc ON c.id = cc.id WHERE c.parent = '.self::NUMERO_PARENT_COMPTES.' ORDER BY c.id;'); } protected function _checkBankFields(&$data) { if (empty($data['banque']) || !trim($data['banque'])) { throw new UserException('Le nom de la banque ne peut rester vide.'); |
| | | | |
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
return $return; } public function get($id) { $db = DB::getInstance(); return $db->first('SELECT * FROM compta_comptes AS c INNER JOIN compta_comptes_bancaires AS cc ON c.id = cc.id WHERE c.id = ?;', $id); } public function getList($parent = false) { $db = DB::getInstance(); return $db->getGrouped('SELECT c.id AS id, * FROM compta_comptes AS c INNER JOIN compta_comptes_bancaires AS cc ON c.id = cc.id WHERE c.parent = ? ORDER BY c.id;', self::NUMERO_PARENT_COMPTES); } protected function _checkBankFields(&$data) { if (empty($data['banque']) || !trim($data['banque'])) { throw new UserException('Le nom de la banque ne peut rester vide.'); |
Modified src/include/lib/Garradin/Compta/Exercices.php from [c811ae1bf1] to [8789fda4c4].
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
$db = DB::getInstance();
return $db->firstColumn('SELECT id FROM compta_exercices WHERE cloture = 0 LIMIT 1;');
}
public function getList()
{
$db = DB::getInstance();
return $db->getAssocKey('SELECT id, *, strftime(\'%s\', debut) AS debut,
strftime(\'%s\', fin) AS fin,
(SELECT COUNT(*) FROM compta_journal WHERE id_exercice = compta_exercices.id) AS nb_operations
FROM compta_exercices ORDER BY fin DESC;');
}
protected function _checkFields(&$data)
{
|
| |
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
$db = DB::getInstance();
return $db->firstColumn('SELECT id FROM compta_exercices WHERE cloture = 0 LIMIT 1;');
}
public function getList()
{
$db = DB::getInstance();
return $db->getGrouped('SELECT id, *, strftime(\'%s\', debut) AS debut,
strftime(\'%s\', fin) AS fin,
(SELECT COUNT(*) FROM compta_journal WHERE id_exercice = compta_exercices.id) AS nb_operations
FROM compta_exercices ORDER BY fin DESC;');
}
protected function _checkFields(&$data)
{
|
Modified src/include/lib/Garradin/Compta/Import.php from [d0fb4b8ed7] to [60189afd5d].
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ... 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 ... 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 ... 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
$db->begin(); $comptes = new Comptes; $banques = new Comptes_Bancaires; $cats = new Categories; $journal = new Journal; $columns = array_flip($this->csv_header); $liste_comptes = $db->simpleStatementFetchAssoc('SELECT id, id FROM compta_comptes;'); $liste_cats = $db->simpleStatementFetchAssoc('SELECT intitule, id FROM compta_categories;'); $liste_moyens = $cats->listMoyensPaiement(); $col = function($column) use (&$row, &$columns) { if (!isset($columns[$column])) return null; ................................................................................ throw new UserException('Erreur sur la ligne ' . $line . ' : la date n\'est pas au format jj/mm/aaaa.'); } $date = explode('/', $date); $date = $date[2] . '-' . $date[1] . '-' . $date[0]; // En dehors de l'exercice courant if ($db->simpleQuerySingle('SELECT 1 FROM compta_exercices WHERE (? < debut OR ? > fin) AND cloture = 0;', false, $date, $date)) { continue; } $debit = $col('Compte de débit - numéro'); $credit = $col('Compte de crédit - numéro'); ................................................................................ $db->begin(); $comptes = new Comptes; $banques = new Comptes_Bancaires; $cats = new Categories; $journal = new Journal; $columns = []; $liste_comptes = $db->simpleStatementFetchAssoc('SELECT id, id FROM compta_comptes;'); $liste_cats = $db->simpleStatementFetchAssoc('SELECT intitule, id FROM compta_categories;'); $liste_moyens = $cats->listMoyensPaiement(); $get_compte = function ($compte, $intitule) use (&$liste_comptes, &$comptes, &$banques) { if (substr($compte, 0, 2) == '51') { $compte = '512' . substr($compte, -1); ................................................................................ $db->rollback(); throw new UserException('Erreur sur la ligne ' . $line . ' : la date n\'est pas au format jj/mm/aaaa.'); } $date = explode('/', $date); $date = $date[2] . '-' . $date[1] . '-' . $date[0]; if ($db->simpleQuerySingle('SELECT 1 FROM compta_exercices WHERE (? < debut OR ? > fin) AND cloture = 0;', false, $date, $date)) { continue; } $debit = $get_compte($col('Compte débité - Numéro'), $col('Compte débité - Intitulé')); $credit = $get_compte($col('Compte crédité - Numéro'), $col('Compte crédité - Intitulé')); |
| | < | | | < | |
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ... 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 ... 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 ... 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
$db->begin(); $comptes = new Comptes; $banques = new Comptes_Bancaires; $cats = new Categories; $journal = new Journal; $columns = array_flip($this->csv_header); $liste_comptes = $db->getAssoc('SELECT id, id FROM compta_comptes;'); $liste_cats = $db->getAssoc('SELECT intitule, id FROM compta_categories;'); $liste_moyens = $cats->listMoyensPaiement(); $col = function($column) use (&$row, &$columns) { if (!isset($columns[$column])) return null; ................................................................................ throw new UserException('Erreur sur la ligne ' . $line . ' : la date n\'est pas au format jj/mm/aaaa.'); } $date = explode('/', $date); $date = $date[2] . '-' . $date[1] . '-' . $date[0]; // En dehors de l'exercice courant if ($db->test('compta_exercices', '(? < debut OR ? > fin) AND cloture = 0', $date, $date)) { continue; } $debit = $col('Compte de débit - numéro'); $credit = $col('Compte de crédit - numéro'); ................................................................................ $db->begin(); $comptes = new Comptes; $banques = new Comptes_Bancaires; $cats = new Categories; $journal = new Journal; $columns = []; $liste_comptes = $db->getAssoc('SELECT id, id FROM compta_comptes;'); $liste_cats = $db->getAssoc('SELECT intitule, id FROM compta_categories;'); $liste_moyens = $cats->listMoyensPaiement(); $get_compte = function ($compte, $intitule) use (&$liste_comptes, &$comptes, &$banques) { if (substr($compte, 0, 2) == '51') { $compte = '512' . substr($compte, -1); ................................................................................ $db->rollback(); throw new UserException('Erreur sur la ligne ' . $line . ' : la date n\'est pas au format jj/mm/aaaa.'); } $date = explode('/', $date); $date = $date[2] . '-' . $date[1] . '-' . $date[0]; if ($db->test('compta_exercices', '(? < debut OR ? > fin) AND cloture = 0', $date, $date)) { continue; } $debit = $get_compte($col('Compte débité - Numéro'), $col('Compte débité - Intitulé')); $credit = $get_compte($col('Compte crédité - Numéro'), $col('Compte crédité - Intitulé')); |
Modified src/include/lib/Garradin/Compta/Journal.php from [9b02ce740c] to [528bb1a84c].
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 .. 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 .. 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 .. 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 ... 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 ... 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 ... 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 ... 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 ... 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 ... 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
protected function _checkOpenExercice($id) { if (is_null($id)) return true; $db = DB::getInstance(); $id = $db->simpleQuerySingle('SELECT id FROM compta_exercices WHERE cloture = 0 AND id = ? LIMIT 1;', false, (int)$id); if ($id) return true; return false; } ................................................................................ ? 'LIKE \'' . $db->escapeString(trim($id_compte)) . '%\'' : '= \'' . $db->escapeString(trim($id_compte)) . '\''; $debit = 'COALESCE((SELECT SUM(montant) FROM compta_journal WHERE compte_debit '.$compte.' AND id_exercice = '.(int)$exercice.'), 0)'; $credit = 'COALESCE((SELECT SUM(montant) FROM compta_journal WHERE compte_credit '.$compte.' AND id_exercice = '.(int)$exercice.'), 0)'; // L'actif augmente au débit, le passif au crédit $position = $db->simpleQuerySingle('SELECT position FROM compta_comptes WHERE id = ?;', false, $id_compte); if (($position & Comptes::ACTIF) || ($position & Comptes::CHARGE)) { $query = $debit . ' - ' . $credit; } else { ................................................................................ return $db->querySingle('SELECT ' . $query . ';'); } public function getJournalCompte($compte, $inclure_sous_comptes = false) { $db = DB::getInstance(); $position = $db->simpleQuerySingle('SELECT position FROM compta_comptes WHERE id = ?;', false, $compte); $exercice = $this->_getCurrentExercice(); $compte = $inclure_sous_comptes ? 'LIKE \'' . $db->escapeString(trim($compte)) . '%\'' : '= \'' . $db->escapeString(trim($compte)) . '\''; // L'actif et les charges augmentent au débit, le passif et les produits au crédit ................................................................................ $query = 'SELECT *, strftime(\'%s\', date) AS date, (CASE WHEN compte_debit '.$compte.' THEN '.$d.'montant ELSE '.$c.'montant END) AS solde FROM compta_journal WHERE (compte_debit '.$compte.' OR compte_credit '.$compte.') AND id_exercice = '.(int)$exercice.' ORDER BY date ASC;'; $result = $db->simpleStatementFetch($query); $solde = 0.0; foreach ($result as &$row) { $solde += $row['solde']; $row['solde'] = $solde; } ................................................................................ { $this->_checkFields($data); $db = DB::getInstance(); $data['id_exercice'] = $this->_getCurrentExercice(); $db->simpleInsert('compta_journal', $data); $id = $db->lastInsertRowId(); return $id; } public function edit($id, $data) { $db = DB::getInstance(); // Vérification que l'on peut éditer cette opération if (!$this->_checkOpenExercice($db->simpleQuerySingle('SELECT id_exercice FROM compta_journal WHERE id = ?;', false, $id))) { throw new UserException('Cette opération fait partie d\'un exercice qui a été clôturé.'); } $this->_checkFields($data); $db->simpleUpdate('compta_journal', $data, 'id = \''.trim($id).'\''); return true; } public function delete($id) { $db = DB::getInstance(); // Vérification que l'on peut éditer cette opération if (!$this->_checkOpenExercice($db->simpleQuerySingle('SELECT id_exercice FROM compta_journal WHERE id = ?;', false, $id))) { throw new UserException('Cette opération fait partie d\'un exercice qui a été clôturé.'); } $db->begin(); $db->simpleExec('DELETE FROM membres_operations WHERE id_operation = ?;', (int)$id); $db->simpleExec('DELETE FROM compta_rapprochement WHERE id_operation = ?;', (int)$id); $db->simpleExec('DELETE FROM compta_journal WHERE id = ?;', (int)$id); $db->commit(); return true; } public function get($id) { $db = DB::getInstance(); return $db->simpleQuerySingle('SELECT *, strftime(\'%s\', date) AS date FROM compta_journal WHERE id = ?;', true, $id); } /** * Compte le nombre d'écritures liées à un membre * @param integer $id Numéro de membre * @return integer Nombre d'écritures liées */ public function countForMember($id) { $db = DB::getInstance(); return $db->simpleQuerySingle('SELECT COUNT(*) FROM compta_journal WHERE id_auteur = ?;', false, (int)$id); } /** * Lister les écritures liées à un membre * @param integer $id Identifiant de membre * @param integer $exercice Identifiant d'exercice * @return array Liste des écritures liées */ public function listForMember($id, $exercice) { $db = DB::getInstance(); return $db->simpleStatementFetch('SELECT * FROM compta_journal WHERE id_auteur = ? AND id_exercice = ?;', \SQLITE3_ASSOC, (int)$id, (int)$exercice); } /** * Lister les membres liés à cette écriture * @param integer $id Numéro d'écriture * @return array Liste des membres liés */ public function listRelatedMembers($id) { $db = DB::getInstance(); $champ_id = Config::getInstance()->get('champ_identite'); return $db->simpleStatementFetch('SELECT id_membre, id_cotisation, m.'.$champ_id.' AS identite FROM membres_operations AS mo INNER JOIN membres AS m ON mo.id_membre = m.id WHERE mo.id_operation = ?;', \SQLITE3_ASSOC, (int)$id); } protected function _checkFields(&$data) { $db = DB::getInstance(); if (empty($data['libelle']) || !trim($data['libelle'])) ................................................................................ { throw new UserException('Le libellé ne peut rester vide.'); } $data['libelle'] = trim($data['libelle']); if (!empty($data['moyen_paiement']) && !$db->simpleQuerySingle('SELECT 1 FROM compta_moyens_paiement WHERE code = ?;', false, $data['moyen_paiement'])) { throw new UserException('Moyen de paiement invalide.'); } if (empty($data['date']) || !Utils::checkDate($data['date'])) { throw new UserException('Date vide ou invalide.'); } if (!$db->simpleQuerySingle('SELECT 1 FROM compta_exercices WHERE cloture = 0 AND debut <= :date AND fin >= :date;', false, ['date' => $data['date']])) { throw new UserException('La date ne correspond pas à l\'exercice en cours.'); } if (empty($data['moyen_paiement'])) { $data['moyen_paiement'] = null; ................................................................................ $data['moyen_paiement'] = strtoupper($data['moyen_paiement']); if ($data['moyen_paiement'] != 'CH') { $data['numero_cheque'] = null; } if (!$db->simpleQuerySingle('SELECT 1 FROM compta_moyens_paiement WHERE code = ? LIMIT 1;', false, $data['moyen_paiement'])) { throw new UserException('Moyen de paiement invalide.'); } } $data['montant'] = str_replace(',', '.', $data['montant']); $data['montant'] = (float)$data['montant']; ................................................................................ { $data[$champ] = trim($data[$champ]); } } if (!array_key_exists('compte_debit', $data) || (!is_null($data['compte_debit']) && !$db->simpleQuerySingle('SELECT 1 FROM compta_comptes WHERE id = ?;', false, $data['compte_debit']))) { throw new UserException('Compte débité inconnu.'); } if (!array_key_exists('compte_credit', $data) || (!is_null($data['compte_credit']) && !$db->simpleQuerySingle('SELECT 1 FROM compta_comptes WHERE id = ?;', false, $data['compte_credit']))) { throw new UserException('Compte crédité inconnu.'); } $data['compte_credit'] = is_null($data['compte_credit']) ? null : strtoupper(trim($data['compte_credit'])); $data['compte_debit'] = is_null($data['compte_debit']) ? null : strtoupper(trim($data['compte_debit'])); ................................................................................ if ($data['compte_credit'] == $data['compte_debit']) { throw new UserException('Compte crédité identique au compte débité.'); } if (isset($data['id_categorie'])) { if (!$db->simpleQuerySingle('SELECT 1 FROM compta_categories WHERE id = ?;', false, (int)$data['id_categorie'])) { throw new UserException('Catégorie inconnue.'); } $data['id_categorie'] = (int)$data['id_categorie']; } else ................................................................................ { $query.= 'id_categorie IN (SELECT id FROM compta_categories WHERE type = '.(int)$type.')'; } $query .= ' AND id_exercice = ' . (int)$exercice; $query .= ' ORDER BY date;'; return $db->simpleStatementFetch($query); } public function searchSQL($query) { $db = DB::getInstance(); if (!preg_match('/LIMIT\s+/i', $query)) |
| | | | | | | | < | | | | | | < | | | | | | | < | | | | | |
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 .. 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 .. 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 .. 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 ... 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 ... 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 ... 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 ... 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 ... 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 ... 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
protected function _checkOpenExercice($id) { if (is_null($id)) return true; $db = DB::getInstance(); $id = $db->firstColumn('SELECT id FROM compta_exercices WHERE cloture = 0 AND id = ? LIMIT 1;', (int)$id); if ($id) return true; return false; } ................................................................................ ? 'LIKE \'' . $db->escapeString(trim($id_compte)) . '%\'' : '= \'' . $db->escapeString(trim($id_compte)) . '\''; $debit = 'COALESCE((SELECT SUM(montant) FROM compta_journal WHERE compte_debit '.$compte.' AND id_exercice = '.(int)$exercice.'), 0)'; $credit = 'COALESCE((SELECT SUM(montant) FROM compta_journal WHERE compte_credit '.$compte.' AND id_exercice = '.(int)$exercice.'), 0)'; // L'actif augmente au débit, le passif au crédit $position = $db->firstColumn('SELECT position FROM compta_comptes WHERE id = ?;', $id_compte); if (($position & Comptes::ACTIF) || ($position & Comptes::CHARGE)) { $query = $debit . ' - ' . $credit; } else { ................................................................................ return $db->querySingle('SELECT ' . $query . ';'); } public function getJournalCompte($compte, $inclure_sous_comptes = false) { $db = DB::getInstance(); $position = $db->firstColumn('SELECT position FROM compta_comptes WHERE id = ?;', $compte); $exercice = $this->_getCurrentExercice(); $compte = $inclure_sous_comptes ? 'LIKE \'' . $db->escapeString(trim($compte)) . '%\'' : '= \'' . $db->escapeString(trim($compte)) . '\''; // L'actif et les charges augmentent au débit, le passif et les produits au crédit ................................................................................ $query = 'SELECT *, strftime(\'%s\', date) AS date, (CASE WHEN compte_debit '.$compte.' THEN '.$d.'montant ELSE '.$c.'montant END) AS solde FROM compta_journal WHERE (compte_debit '.$compte.' OR compte_credit '.$compte.') AND id_exercice = '.(int)$exercice.' ORDER BY date ASC;'; $result = $db->get($query); $solde = 0.0; foreach ($result as &$row) { $solde += $row['solde']; $row['solde'] = $solde; } ................................................................................ { $this->_checkFields($data); $db = DB::getInstance(); $data['id_exercice'] = $this->_getCurrentExercice(); $db->insert('compta_journal', $data); $id = $db->lastInsertRowId(); return $id; } public function edit($id, $data) { $db = DB::getInstance(); // Vérification que l'on peut éditer cette opération if (!$this->_checkOpenExercice($db->firstColumn('SELECT id_exercice FROM compta_journal WHERE id = ?;', $id))) { throw new UserException('Cette opération fait partie d\'un exercice qui a été clôturé.'); } $this->_checkFields($data); $db->update('compta_journal', $data, $db->where('id', trim($id))); return true; } public function delete($id) { $db = DB::getInstance(); // Vérification que l'on peut éditer cette opération if (!$this->_checkOpenExercice($db->firstColumn('SELECT id_exercice FROM compta_journal WHERE id = ?;', $id))) { throw new UserException('Cette opération fait partie d\'un exercice qui a été clôturé.'); } $db->begin(); $db->delete('membres_operations', $db->where('id_operation', (int)$id)); $db->delete('compta_rapprochement', $db->where('id_operation', (int)$id)); $db->delete('compta_journal', $db->where('id', (int)$id)); $db->commit(); return true; } public function get($id) { $db = DB::getInstance(); return $db->first('SELECT *, strftime(\'%s\', date) AS date FROM compta_journal WHERE id = ?;', $id); } /** * Compte le nombre d'écritures liées à un membre * @param integer $id Numéro de membre * @return integer Nombre d'écritures liées */ public function countForMember($id) { $db = DB::getInstance(); return $db->count('compta_journal', $db->where('id_auteur', $id)); } /** * Lister les écritures liées à un membre * @param integer $id Identifiant de membre * @param integer $exercice Identifiant d'exercice * @return array Liste des écritures liées */ public function listForMember($id, $exercice) { $db = DB::getInstance(); return $db->first('SELECT * FROM compta_journal WHERE id_auteur = ? AND id_exercice = ?;', (int)$id, (int)$exercice); } /** * Lister les membres liés à cette écriture * @param integer $id Numéro d'écriture * @return array Liste des membres liés */ public function listRelatedMembers($id) { $db = DB::getInstance(); $champ_id = Config::getInstance()->get('champ_identite'); return $db->first('SELECT id_membre, id_cotisation, m.'.$champ_id.' AS identite FROM membres_operations AS mo INNER JOIN membres AS m ON mo.id_membre = m.id WHERE mo.id_operation = ?;', (int)$id); } protected function _checkFields(&$data) { $db = DB::getInstance(); if (empty($data['libelle']) || !trim($data['libelle'])) ................................................................................ { throw new UserException('Le libellé ne peut rester vide.'); } $data['libelle'] = trim($data['libelle']); if (!empty($data['moyen_paiement']) && !$db->test('compta_moyens_paiement', $db->where('code', $data['moyen_paiement']))) { throw new UserException('Moyen de paiement invalide.'); } if (empty($data['date']) || !Utils::checkDate($data['date'])) { throw new UserException('Date vide ou invalide.'); } if (!$db->test('compta_exercices', 'cloture = 0 AND debut <= :date AND fin >= :date;', ['date' => $data['date']])) { throw new UserException('La date ne correspond pas à l\'exercice en cours.'); } if (empty($data['moyen_paiement'])) { $data['moyen_paiement'] = null; ................................................................................ $data['moyen_paiement'] = strtoupper($data['moyen_paiement']); if ($data['moyen_paiement'] != 'CH') { $data['numero_cheque'] = null; } if (!$db->test('compta_moyens_paiement', $db->where('code', $data['moyen_paiement']))) { throw new UserException('Moyen de paiement invalide.'); } } $data['montant'] = str_replace(',', '.', $data['montant']); $data['montant'] = (float)$data['montant']; ................................................................................ { $data[$champ] = trim($data[$champ]); } } if (!array_key_exists('compte_debit', $data) || (!is_null($data['compte_debit']) && !$db->test('compta_comptes', $db->where('id', $data['compte_debit'])))) { throw new UserException('Compte débité inconnu.'); } if (!array_key_exists('compte_credit', $data) || (!is_null($data['compte_credit']) && !$db->test('compta_comptes', $db->where('id', $data['compte_credit'])))) { throw new UserException('Compte crédité inconnu.'); } $data['compte_credit'] = is_null($data['compte_credit']) ? null : strtoupper(trim($data['compte_credit'])); $data['compte_debit'] = is_null($data['compte_debit']) ? null : strtoupper(trim($data['compte_debit'])); ................................................................................ if ($data['compte_credit'] == $data['compte_debit']) { throw new UserException('Compte crédité identique au compte débité.'); } if (isset($data['id_categorie'])) { if (!$db->test('compta_categories', $db->where('id', (int)$data['id_categorie']))) { throw new UserException('Catégorie inconnue.'); } $data['id_categorie'] = (int)$data['id_categorie']; } else ................................................................................ { $query.= 'id_categorie IN (SELECT id FROM compta_categories WHERE type = '.(int)$type.')'; } $query .= ' AND id_exercice = ' . (int)$exercice; $query .= ' ORDER BY date;'; return $db->get($query); } public function searchSQL($query) { $db = DB::getInstance(); if (!preg_match('/LIMIT\s+/i', $query)) |
Modified src/include/lib/Garradin/Compta/Rapprochement.php from [f49b02cffe] to [25acc9848e].
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
..
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
$exercice = $db->querySingle('SELECT id FROM compta_exercices WHERE cloture = 0 LIMIT 1;'); $query = 'SELECT COALESCE((SELECT SUM(montant) FROM compta_journal WHERE compte_debit = :compte AND id_exercice = :exercice AND date < :date), 0) - COALESCE((SELECT SUM(montant) FROM compta_journal WHERE compte_credit = :compte AND id_exercice = :exercice AND date < :date), 0)'; $solde_initial = $solde = $db->simpleQuerySingle($query, false, [ 'compte' => $compte, 'date' => $debut, 'exercice' => $exercice ]); $query = ' SELECT j.*, strftime(\'%s\', j.date) AS date, ................................................................................ r.date AS date_rapprochement FROM compta_journal AS j LEFT JOIN compta_rapprochement AS r ON r.id_operation = j.id WHERE (compte_debit = :compte OR compte_credit = :compte) AND id_exercice = :exercice AND j.date >= :debut AND j.date <= :fin ORDER BY date ASC;'; $result = $db->simpleStatementFetch($query, DB::ASSOC, [ 'compte' => $compte, 'debut' => $debut, 'fin' => $fin, 'exercice' => $exercice ]); foreach ($result as &$row) |
|
|
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
..
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
$exercice = $db->querySingle('SELECT id FROM compta_exercices WHERE cloture = 0 LIMIT 1;'); $query = 'SELECT COALESCE((SELECT SUM(montant) FROM compta_journal WHERE compte_debit = :compte AND id_exercice = :exercice AND date < :date), 0) - COALESCE((SELECT SUM(montant) FROM compta_journal WHERE compte_credit = :compte AND id_exercice = :exercice AND date < :date), 0)'; $solde_initial = $solde = $db->firstColumn($query, [ 'compte' => $compte, 'date' => $debut, 'exercice' => $exercice ]); $query = ' SELECT j.*, strftime(\'%s\', j.date) AS date, ................................................................................ r.date AS date_rapprochement FROM compta_journal AS j LEFT JOIN compta_rapprochement AS r ON r.id_operation = j.id WHERE (compte_debit = :compte OR compte_credit = :compte) AND id_exercice = :exercice AND j.date >= :debut AND j.date <= :fin ORDER BY date ASC;'; $result = $db->get($query, [ 'compte' => $compte, 'debut' => $debut, 'fin' => $fin, 'exercice' => $exercice ]); foreach ($result as &$row) |
Modified src/include/lib/Garradin/Config.php from [12077bf319] to [e8c8379b02].
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
}
public function setVersion($version)
{
$this->config['version'] = $version;
$db = DB::getInstance();
$db->simpleExec('INSERT OR REPLACE INTO config (cle, valeur) VALUES (?, ?);',
'version', $version);
return true;
}
public function set($key, $value)
{
|
| |
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
}
public function setVersion($version)
{
$this->config['version'] = $version;
$db = DB::getInstance();
$db->preparedQuery('INSERT OR REPLACE INTO config (cle, valeur) VALUES (?, ?);',
'version', $version);
return true;
}
public function set($key, $value)
{
|
Modified src/include/lib/Garradin/Membres.php from [dac59ded18] to [29f4b66141].
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
} if (empty($data)) { return true; } $success = $db->simpleUpdate('membres', $data, 'id = '.(int)$id); Plugin::fireSignal('membre.edit', $data); return $success; } public function get($id) |
| |
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
} if (empty($data)) { return true; } $success = $db->update('membres', $data, $db->where('id', (int)$id)); Plugin::fireSignal('membre.edit', $data); return $success; } public function get($id) |
Modified src/include/lib/Garradin/Membres/Session.php from [9bd410c499] to [c7ce83b00e].
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
if (!$this->getPGPFingerprint($data['clef_pgp']))
{
throw new UserException('Clé PGP invalide : impossible d\'extraire l\'empreinte.');
}
}
DB::getInstance()->simpleUpdate('membres', $data, 'id = '.(int)$this->id);
$this->updateSessionData();
return true;
}
public function getPGPFingerprint($key, $display = false)
{
|
| > |
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 |
if (!$this->getPGPFingerprint($data['clef_pgp'])) { throw new UserException('Clé PGP invalide : impossible d\'extraire l\'empreinte.'); } } $db = DB::getInstance(); $db->update('membres', $data, $db->where('id', (int)$this->id)); $this->updateSessionData(); return true; } public function getPGPFingerprint($key, $display = false) { |
Modified src/include/lib/Garradin/Rappels_Envoyes.php from [4cb0920949] to [194017d254].
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 ... 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 ... 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
*/ public function add($data) { $db = DB::getInstance(); $this->_checkFields($data); $db->simpleInsert('rappels_envoyes', $data); return $db->lastInsertRowId(); } /** * Supprimer un rappel enregistré * @param integer $id Numéro du rappel * @return boolean TRUE en cas de succès */ public function delete($id) { $db = DB::getInstance(); $db->simpleExec('DELETE FROM rappels_envoyes WHERE id = ?;', (int) $id); return true; } /** * Renvoie les données sur un rappel * @param integer $id Numéro du rappel * @return array Données du rappel ................................................................................ /** * Liste des rappels envoyés à un membre * @param integer $id Numéro du membre * @return array Liste des rappels */ public function listForMember($id) { return DB::getInstance()->simpleStatementFetch('SELECT re.*, c.intitule, c.montant FROM rappels_envoyes AS re INNER JOIN cotisations AS c ON c.id = re.id_cotisation WHERE re.id_membre = ? ORDER BY re.date DESC;', \SQLITE3_ASSOC, (int)$id); } /** * Liste des rappels pour une cotisation donnée * @param integer $id Numéro de la cotisation * @param integer $page Numéro de page de liste * @return array Liste des rappels */ public function listForCotisation($id, $page = 1) { $begin = ($page - 1) * self::ITEMS_PER_PAGE; return DB::getInstance()->simpleStatementFetch('SELECT * FROM rappels_envoyes WHERE id_rappel IN (SELECT id FROM rappels WHERE id_cotisation = ?) ORDER BY date DESC;', \SQLITE3_ASSOC, (int)$id); } /** * Nombre de rappels pour une cotisation donnée * @param integer $id Numéro de la cotisation * @return integer Nombre de rappels envoyés */ ................................................................................ * @param integer $page Numéro de page de liste * @return array Liste des rappels envoyés */ public function listForRappel($id, $page = 1) { $begin = ($page - 1) * self::ITEMS_PER_PAGE; return DB::getInstance()->simpleStatementFetch('SELECT * FROM rappels_envoyes WHERE id_rappel = ? ORDER BY date DESC LIMIT ?,?;', \SQLITE3_ASSOC, (int)$id, (int)$begin, self::ITEMS_PER_PAGE); } /** * Nombre de rappels envoyés pour un rappel automatique * @param integer $id Numéro du rappel * @return integer Nombre de rappels envoyés pour ce rappel */ public function countForRappel($id) { return DB::getInstance()->firstColumn('SELECT COUNT(*) FROM rappels_envoyes WHERE id_rappel = ?;', (int)$id); } } |
| | | | | | | | |
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 ... 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 ... 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
*/ public function add($data) { $db = DB::getInstance(); $this->_checkFields($data); $db->insert('rappels_envoyes', $data); return $db->lastInsertRowId(); } /** * Supprimer un rappel enregistré * @param integer $id Numéro du rappel * @return boolean TRUE en cas de succès */ public function delete($id) { $db = DB::getInstance(); $db->delete('rappels_envoyes', $db->where('id', (int) $id)); return true; } /** * Renvoie les données sur un rappel * @param integer $id Numéro du rappel * @return array Données du rappel ................................................................................ /** * Liste des rappels envoyés à un membre * @param integer $id Numéro du membre * @return array Liste des rappels */ public function listForMember($id) { return DB::getInstance()->get('SELECT re.*, c.intitule, c.montant FROM rappels_envoyes AS re INNER JOIN cotisations AS c ON c.id = re.id_cotisation WHERE re.id_membre = ? ORDER BY re.date DESC;', (int)$id); } /** * Liste des rappels pour une cotisation donnée * @param integer $id Numéro de la cotisation * @param integer $page Numéro de page de liste * @return array Liste des rappels */ public function listForCotisation($id, $page = 1) { $begin = ($page - 1) * self::ITEMS_PER_PAGE; return DB::getInstance()->get('SELECT * FROM rappels_envoyes WHERE id_rappel IN (SELECT id FROM rappels WHERE id_cotisation = ?) ORDER BY date DESC;', (int)$id); } /** * Nombre de rappels pour une cotisation donnée * @param integer $id Numéro de la cotisation * @return integer Nombre de rappels envoyés */ ................................................................................ * @param integer $page Numéro de page de liste * @return array Liste des rappels envoyés */ public function listForRappel($id, $page = 1) { $begin = ($page - 1) * self::ITEMS_PER_PAGE; return DB::getInstance()->get('SELECT * FROM rappels_envoyes WHERE id_rappel = ? ORDER BY date DESC LIMIT ?,?;', (int)$id, (int)$begin, self::ITEMS_PER_PAGE); } /** * Nombre de rappels envoyés pour un rappel automatique * @param integer $id Numéro du rappel * @return integer Nombre de rappels envoyés pour ce rappel */ public function countForRappel($id) { return DB::getInstance()->firstColumn('SELECT COUNT(*) FROM rappels_envoyes WHERE id_rappel = ?;', (int)$id); } } |