Overview
SHA1:8b5dae64589210594c9aa12b275d3cd07f9ecd0d
Date: 2017-10-02 23:03:05
User: bohwaz
Comment:Permettre de supprimer un exercice vide, même clôturé
Timelines: family | ancestors | descendants | both | dev
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2017-10-03
22:44
[c41b7b9b10] Dossiers nécessaires (user: bohwaz, tags: dev)
2017-10-02
23:03
[8b5dae6458] Permettre de supprimer un exercice vide, même clôturé (user: bohwaz, tags: dev)
00:48
[9211225bb1] Correction recherche de membre (user: bohwaz, tags: dev)
Changes

Modified src/include/lib/Garradin/Compta/Exercices.php from [353bdea756] to [08a6fdce95].

250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268




269
270

271
272
273
274
275
276
277
278
    }
    
    public function delete($id)
    {
        $db = DB::getInstance();

        // Ne pas supprimer un compte qui est utilisé !
        if ($db->firstColumn('SELECT 1 FROM compta_journal WHERE id_exercice = ? LIMIT 1;', $id))
        {
            throw new UserException('Cet exercice ne peut être supprimé car des opérations comptables y sont liées.');
        }

        $db->delete('compta_exercices', 'id = ?', (int)$id);

        return true;
    }

    public function get($id)
    {




        $db = DB::getInstance();
        return $db->first('SELECT *, strftime(\'%s\', debut) AS debut,

            strftime(\'%s\', fin) AS fin FROM compta_exercices WHERE id = ?;', (int)$id);
    }

    public function getCurrent()
    {
        $db = DB::getInstance();
        return $db->first('SELECT *, strftime(\'%s\', debut) AS debut, strftime(\'%s\', fin) AS fin FROM compta_exercices
            WHERE cloture = 0 LIMIT 1;');







|









|

>
>
>
>


>
|







250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
    }
    
    public function delete($id)
    {
        $db = DB::getInstance();

        // Ne pas supprimer un compte qui est utilisé !
        if ($db->test('compta_journal', $db->where('id_exercice', $id)))
        {
            throw new UserException('Cet exercice ne peut être supprimé car des opérations comptables y sont liées.');
        }

        $db->delete('compta_exercices', 'id = ?', (int)$id);

        return true;
    }

    public function get($id, $with_count = false)
    {
        $with_count = $with_count
            ? ', (SELECT COUNT(*) FROM compta_journal WHERE id_exercice = compta_exercices.id) AS nb_operations'
            : '';

        $db = DB::getInstance();
        return $db->first('SELECT *, strftime(\'%s\', debut) AS debut,
            strftime(\'%s\', fin) AS fin ' . $with_count . '
            FROM compta_exercices WHERE id = ?;', (int)$id);
    }

    public function getCurrent()
    {
        $db = DB::getInstance();
        return $db->first('SELECT *, strftime(\'%s\', debut) AS debut, strftime(\'%s\', fin) AS fin FROM compta_exercices
            WHERE cloture = 0 LIMIT 1;');

Modified src/templates/admin/compta/exercices/index.tpl from [f3468b4928] to [cfdf80b4cf].

1
2
3
4
5
6
7
8
9
10
..
25
26
27
28
29
30
31


32
33
34
35
36
37
38
39
40
41
42
43
{include file="admin/_head.tpl" title="Exercices" current="compta/exercices"}

{if !$current}
<ul class="actions">
    <li><strong><a href="{$www_url}admin/compta/exercices/ajouter.php">Commencer un nouvel exercice</a></strong></li>
</ul>
{/if}

{if !empty($liste)}
    <dl class="catList">
................................................................................
        </dd>
        {if $session->canAccess('compta', Garradin\Membres::DROIT_ADMIN)}
        <dd class="actions">
            {if !$exercice.cloture}
            <a class="icn" href="{$www_url}admin/compta/exercices/modifier.php?id={$exercice.id}" title="Modifier">✎</a>
            <a class="icn" href="{$www_url}admin/compta/exercices/supprimer.php?id={$exercice.id}" title="Supprimer">✘</a>
            <a class="icn" href="{$www_url}admin/compta/exercices/cloturer.php?id={$exercice.id}" title="Clôturer cet exercice">🔒</a>


            {/if}
        </dd>
        {/if}
    {/foreach}
    </dl>
{else}
    <p class="alert">
        Il n'y a pas d'exercice en cours.
    </p>
{/if}

{include file="admin/_foot.tpl"}


|







 







>
>












1
2
3
4
5
6
7
8
9
10
..
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{include file="admin/_head.tpl" title="Exercices" current="compta/exercices"}

{if !$current_exercice}
<ul class="actions">
    <li><strong><a href="{$www_url}admin/compta/exercices/ajouter.php">Commencer un nouvel exercice</a></strong></li>
</ul>
{/if}

{if !empty($liste)}
    <dl class="catList">
................................................................................
        </dd>
        {if $session->canAccess('compta', Garradin\Membres::DROIT_ADMIN)}
        <dd class="actions">
            {if !$exercice.cloture}
            <a class="icn" href="{$www_url}admin/compta/exercices/modifier.php?id={$exercice.id}" title="Modifier">✎</a>
            <a class="icn" href="{$www_url}admin/compta/exercices/supprimer.php?id={$exercice.id}" title="Supprimer">✘</a>
            <a class="icn" href="{$www_url}admin/compta/exercices/cloturer.php?id={$exercice.id}" title="Clôturer cet exercice">🔒</a>
            {elseif $exercice.cloture && $exercice.nb_operations == 0}
            <a class="icn" href="{$www_url}admin/compta/exercices/supprimer.php?id={$exercice.id}" title="Supprimer">✘</a>
            {/if}
        </dd>
        {/if}
    {/foreach}
    </dl>
{else}
    <p class="alert">
        Il n'y a pas d'exercice en cours.
    </p>
{/if}

{include file="admin/_foot.tpl"}

Modified src/www/admin/compta/exercices/index.php from [b850cf88e1] to [631399af3f].

2
3
4
5
6
7
8
9
10
11
namespace Garradin;

require_once __DIR__ . '/../_inc.php';

$e = new Compta\Exercices;

$tpl->assign('liste', $e->getList());
$tpl->assign('current', $e->getCurrent());

$tpl->display('admin/compta/exercices/index.tpl');







|


2
3
4
5
6
7
8
9
10
11
namespace Garradin;

require_once __DIR__ . '/../_inc.php';

$e = new Compta\Exercices;

$tpl->assign('liste', $e->getList());
$tpl->assign('current_exercice', $e->getCurrent());

$tpl->display('admin/compta/exercices/index.tpl');

Modified src/www/admin/compta/exercices/supprimer.php from [5b9eced062] to [a021784f75].

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

require_once __DIR__ . '/../_inc.php';

$session->requireAccess('compta', Membres::DROIT_ADMIN);

$e = new Compta\Exercices;

$exercice = $e->get((int)qg('id'));

if (!$exercice)
{
	throw new UserException('Exercice inconnu.');
}

if ($exercice->cloture)
{
    throw new UserException('Impossible de supprimer un exercice clôturé.');
}

if (f('delete'))
{
    if ($form->check('compta_supprimer_exercice_'.$exercice->id))







|






|







3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

require_once __DIR__ . '/../_inc.php';

$session->requireAccess('compta', Membres::DROIT_ADMIN);

$e = new Compta\Exercices;

$exercice = $e->get((int)qg('id'), true);

if (!$exercice)
{
	throw new UserException('Exercice inconnu.');
}

if ($exercice->cloture && $exercice->nb_operations > 0)
{
    throw new UserException('Impossible de supprimer un exercice clôturé.');
}

if (f('delete'))
{
    if ($form->check('compta_supprimer_exercice_'.$exercice->id))