Overview
Comment: | Déplacement des entités, ajout de vérifications supplémentaires |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | dev |
Files: | files | file ages | folders |
SHA1: |
5a3f31fcb9d805244d7be6ef6ad46e07 |
User & Date: | bohwaz on 2020-01-21 13:27:48 |
Other Links: | branch diff | manifest | tags |
Context
2020-01-21
| ||
13:28 | Création de l'entité Exercice check-in: 24709246df user: bohwaz tags: dev | |
13:27 | Déplacement des entités, ajout de vérifications supplémentaires check-in: 5a3f31fcb9 user: bohwaz tags: dev | |
2020-01-20
| ||
00:14 | Adaptation au nouveau KD2\DB\SQLite3 check-in: 6ed70e24ff user: bohwaz tags: dev | |
Changes
Modified src/include/lib/Garradin/Compta/Comptes.php from [8e9c8fd0ed] to [0bf699eef0].
︙ | ︙ | |||
44 45 46 47 48 49 50 | if(is_null($plan)) { throw new UserException('Le fichier n\'est pas du JSON ou n\'a pas pu être décodé.'); } $db = DB::getInstance(); $db->begin(); | | | > | > > | > > | > > > > | > > | | < | | | > > | | < | | | 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 | if(is_null($plan)) { throw new UserException('Le fichier n\'est pas du JSON ou n\'a pas pu être décodé.'); } $db = DB::getInstance(); $db->begin(); $codes = []; foreach ($plan as $code=>$compte) { $codes[$code] = $db->firstColumn('SELECT id FROM compta_comptes WHERE code = ?;', $code); if (0 === $compte->parent) { $parent = null; } else { $parent = $db->firstColumn('SELECT id FROM compta_comptes WHERE code = ?;', $compte->parent); if (!$parent) { throw new UserException(sprintf('Le compte parent "%s" n\'existe pas', $compte->parent)); } } if ($codes[$code]) { $db->update('compta_comptes', [ 'parent' => $parent, 'libelle' => $compte->nom, 'position' => $compte->position, 'plan_comptable' => $reset || !empty($compte->plan_comptable) ? 1 : 0, ], 'code = :code AND id_exercice IS NULL', ['code' => $code]); } else { $db->insert('compta_comptes', [ 'code' => $code, 'parent' => $parent, 'libelle' => $compte->nom, 'position' => $compte->position, 'plan_comptable' => $reset || !empty($compte->plan_comptable) ? 1 : 0, 'id_exercice' => null, ]); $codes[$code] = $db->lastInsertRowId(); } } // Effacer les comptes du plan comptable s'ils ne sont pas utilisés ailleurs // et qu'ils ne sont pas dans le nouveau plan comptable qu'on vient d'importer $sql = 'DELETE FROM compta_comptes WHERE id_exercice IS NULL AND id NOT IN ( SELECT id FROM compta_comptes_bancaires UNION SELECT compte FROM compta_mouvements_lignes UNION SELECT compte FROM compta_categories) AND '. $db->where('code', 'NOT IN', array_keys($codes)); // Si on ne fait qu'importer une mise à jour du plan comptable, // ne supprimer que les comptes qui n'ont pas été créés par l'usager if (!$delete_all) { $sql .= ' AND ' . $db->where('plan_comptable', 1); } |
︙ | ︙ |
Modified src/include/lib/Garradin/Entities/Compta/Compte.php from [6715611975] to [ec757b0335].
1 2 | <?php | | | 1 2 3 4 5 6 7 8 9 10 | <?php namespace Garradin\Entities\Compta; use Garradin\Entity; use Garradin\DB; use Garradin\Utils; use Garradin\UserException; class Compte extends Entity |
︙ | ︙ |
Modified src/include/lib/Garradin/Entities/Compta/Ligne.php from [b6662c154e] to [820ffb3e7d].
1 2 | <?php | | | 1 2 3 4 5 6 7 8 9 10 | <?php namespace Garradin\Entities\Compta; use Garradin\Entity; use Garradin\ValidationException; class Ligne extends Entity { const TABLE = 'compta_mouvements_lignes'; |
︙ | ︙ |
Modified src/include/lib/Garradin/Entities/Compta/Mouvement.php from [b67e1a34c6] to [d018180264].
1 2 | <?php | | > | | | | | > | | | | | | | | | > | > | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 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 114 115 116 117 118 119 120 121 | <?php namespace Garradin\Entities\Compta; use Garradin\Entity; use Garradin\ValidationException; use Garradin\DB; use Garradin\Config; class Mouvement extends Entity { const TABLE = 'compta_mouvements'; protected $id; protected $libelle; protected $remarques; protected $numero_piece; protected $date; protected $moyen_paiement; protected $reference_paiement; protected $validation; protected $hash; protected $prev_hash; protected $id_exercice; protected $id_auteur; protected $id_categorie; protected $id_projet; protected $_types = [ 'libelle' => 'string', 'remarques' => '?string', 'numero_piece' => '?string', 'date' => 'date', 'moyen_paiement' => '?string', 'reference_paiement' => '?string', 'validation' => 'bool', 'hash' => '?string', 'prev_hash' => '?string', 'id_exercice' => '?int', 'id_auteur' => '?int', 'id_categorie' => '?int', 'id_projet' => '?int', ]; protected $_validation_rules = [ 'libelle' => 'required|string|max:200', 'remarques' => 'string|max:20000', 'numero_piece' => 'string|max:200', 'date' => 'required|date', 'moyen_paiement' => 'string|min:2|max:2|in_table:compta_moyens_paiement,code|required_with:id_categorie', 'reference_paiement' => 'string|max:200', 'validation' => 'bool', 'id_exercice' => 'integer|in_table:compta_exercices,id', 'id_auteur' => 'integer|in_table:membres,id', 'id_categorie' => 'integer|in_table:compta_categories,id', 'id_projet' => 'integer|in_table:compta_projets,id' ]; protected $lignes; public function getLignes() { if (null === $this->lignes && $this->exists()) { $db = DB::getInstance(); $this->lignes = $db->toObject($db->get('SELECT * FROM compta_mouvements_lignes WHERE id_mouvement = ? ORDER BY id;', $this->id), Ligne::class); } else { $this->lignes = []; } return $this->lignes; } /* public function getHash() { if (!$this->id_exercice) { throw new \LogicException('Il n\'est pas possible de hasher un mouvement qui n\'est pas associé à un exercice'); } static $keep_keys = [ 'libelle', 'remarques', 'numero_piece', 'date', 'moyen_paiement', 'reference_paiement', 'validation', 'prev_hash', ]; $hash = hash_init('sha256'); $values = $this->asArray(); $values = array_intersect_key($values, $keep_keys); hash_update($hash, implode(',', array_keys($values))); hash_update($hash, implode(',', $values)); foreach ($this->getLignes() as $ligne) { hash_update($hash, implode(',', [$ligne->compte, $ligne->debit, $ligne->credit])); } return hash_final($hash, false); } public function checkHash() { return hash_equals($this->getHash(), $this->hash); } */ public function add(Ligne $ligne) { $this->lignes[] = $ligne; } public function simple($montant, $moyen, $compte) |
︙ | ︙ | |||
85 86 87 88 89 90 91 | $from = $compte; $to = $categorie->compte; } return $this->transfer($montant, $from, $to); } | | | > > | > > > > > > > > > > | | < < < < > > | > | > > > > > > > > > > > > | 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 | $from = $compte; $to = $categorie->compte; } return $this->transfer($montant, $from, $to); } public function transfer(int $amount, int $from, int $to) { $ligne1 = new Ligne; $ligne1->compte = $from; $ligne1->debit = $amount; $ligne1->credit = 0; $ligne2 = new Ligne; $ligne1->compte = $to; $ligne1->debit = 0; $ligne1->credit = $amount; return $this->add($ligne1) && $this->add($ligne2); } public function save() { if ($this->validation && !isset($this->_modified['validation'])) { throw new ValidationException('Il n\'est pas possible de modifier un mouvement qui a été validé'); } if (!parent::save()) { return false; } foreach ($this->lignes as $ligne) { $ligne->id_mouvement = $this->id; $ligne->save(); } } public function delete() { if ($this->validation) { throw new ValidationException('Il n\'est pas possible de supprimer un mouvement qui a été validé'); } parent::delete(); } public function filterUserValue($key, $value) { $value = parent::filterUserValue($key, $value); if ($key == 'moyen_paiement') { $value = strtoupper($value); } return $value; } public function selfCheck() { parent::selfCheck(); $db = DB::getInstance(); $config = Config::getInstance(); // ID d'exercice obligatoire s'il existe déjà des exercices if (null === $this->id_exercice && $db->firstColumn('SELECT 1 FROM compta_exercices LIMIT 1;')) { throw new ValidationException('Aucun exercice spécifié.'); } if (null !== $this->id_exercice && !$db->test('compta_exercices', 'id = ? AND debut <= ? AND fin >= ?;', $this->id_exercice, $this->date, $this->date)) { throw new ValidationException('La date ne correspond pas à l\'exercice sélectionné.'); } $total = 0; $lignes = $this->getLignes(); foreach ($lignes as $ligne) { $total += $ligne->credit; $total -= $ligne->debit; } if (0 !== $total) { throw new ValidationException('Mouvement non équilibré : déséquilibre entre débits et crédits'); } } } |