Overview
Comment:Erreur plus explicite quand on essaye de modifier une écriture qui n'existe pas
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 1f94d65a20f8ba501e0d0b8b9d6e93d36de66d1e
User & Date: bohwaz on 2018-07-20 22:15:43
Other Links: branch diff | manifest | tags
Context
2018-08-02
22:52
Erreur plus explicite quand on essaye de modifier une écriture qui n'existe pas check-in: a0c15d9d73 user: bohwaz tags: trunk, stable
2018-07-26
13:07
Ajout queue d'envoi d'emails check-in: fa50a20dd3 user: bohwaz tags: dev
2018-07-20
22:16
Erreur plus explicite quand on essaye de modifier une écriture qui n'existe pas check-in: 116557af44 user: bohwaz tags: trunk, stable
22:15
Erreur plus explicite quand on essaye de modifier une écriture qui n'existe pas check-in: 1f94d65a20 user: bohwaz tags: dev
2018-07-14
20:23
Fix typo export CSV check-in: 54aa1c950e user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Compta/Import.php from [3ab8827a71] to [19a1972b2f].

216
217
218
219
220
221
222

223
224
225
226
227
228
229
230





231
232
233
234
235
236
237
			if ($cat)
			{
				$data['moyen_paiement']	=	$moyen;
				$data['numero_cheque']	=	$col('Numéro de chèque');
				$data['id_categorie']	=	$liste_cats[$cat];
			}


			if (empty($id))
			{
				$journal->add($data);
			}
			else
			{
				$journal->edit($id, $data);
			}





		}

		$db->commit();

		fclose($fp);
		return true;
	}







>








>
>
>
>
>







216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
			if ($cat)
			{
				$data['moyen_paiement']	=	$moyen;
				$data['numero_cheque']	=	$col('Numéro de chèque');
				$data['id_categorie']	=	$liste_cats[$cat];
			}

			try {
			if (empty($id))
			{
				$journal->add($data);
			}
			else
			{
				$journal->edit($id, $data);
			}
			}
			catch (UserException $e)
			{
				throw new UserException(sprintf('Ligne %s: %s', $line, $e->getMessage()));
			}
		}

		$db->commit();

		fclose($fp);
		return true;
	}

Modified src/include/lib/Garradin/Compta/Journal.php from [dbbae959c0] to [9b1778c3b4].

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    }

    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;
    }

    public function getSolde($id_compte, $inclure_sous_comptes = false)
    {
        $db = DB::getInstance();
        $exercice = $this->_getCurrentExercice();
        $compte = $inclure_sous_comptes







|
<
<
<
<
<
<
<







28
29
30
31
32
33
34
35







36
37
38
39
40
41
42
    }

    protected function _checkOpenExercice($id)
    {
        if (is_null($id))
            return true;

        return DB::getInstance()->test('compta_exercices', 'cloture = 0 AND id = ?', (int)$id);







    }

    public function getSolde($id_compte, $inclure_sous_comptes = false)
    {
        $db = DB::getInstance();
        $exercice = $this->_getCurrentExercice();
        $compte = $inclure_sous_comptes
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

        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));








>
>
>
>
>
>

|















>
>
>
>
>
>

|







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

        return $id;
    }

    public function edit($id, $data)
    {
        $db = DB::getInstance();

        // On ne peut éditer une opération qui n'existe pas
        if (!$db->test('compta_journal', 'id = ?', $id))
        {
            throw new UserException(sprintf('L\'opération n°%s n\'existe pas et ne peut donc être modifiée.', (int)$id));
        }

        // Vérification que l'on peut éditer cette opération
        if (!$this->_checkOpenExercice($db->firstColumn('SELECT id_exercice FROM compta_journal WHERE id = ?;', (int)$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();

        // On ne peut supprimer une opération qui n'existe pas
        if (!$db->test('compta_journal', 'id = ?', $id))
        {
            throw new UserException(sprintf('L\'opération n°%s n\'existe pas et ne peut donc être supprimée.', (int)$id));
        }

        // Vérification que l'on peut éditer cette opération
        if (!$this->_checkOpenExercice($db->firstColumn('SELECT id_exercice FROM compta_journal WHERE id = ?;', (int)$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));