Overview
Comment:Year editing now works
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: d8d509cc95b80548374a691b4f4d4d47e43870a2
User & Date: bohwaz on 2020-10-03 01:18:03
Other Links: branch diff | manifest | tags
Context
2020-10-03
15:42
Add opening balance, year closing, year edit, year creation, year removal check-in: fdf0caeabf user: bohwaz tags: dev
01:18
Year editing now works check-in: d8d509cc95 user: bohwaz tags: dev
00:53
Years list check-in: 4495da48a1 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Entities/Accounting/Year.php from [7550479a8a] to [9d5fb802e0].

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
        'end_date'   => 'date',
        'closed'     => 'int',
        'id_chart'   => 'int',
    ];

    protected $_form_rules = [
        'label'      => 'required|string|max:200',
        'start_date' => 'required|date|before:end_date',
        'end_date'   => 'required|date|after:start_date',
    ];

    public function selfCheck(): void
    {
        parent::selfCheck();
        $this->assert($this->start_date < $this->end_date, 'La date de fin doit être postérieure à la date de début');
        $this->assert($this->closed === 0 || $this->closed === 1);
        $this->assert($this->closed == 1 || !isset($this->_modified['closed']), 'Il est interdit de réouvrir un exercice clôturé');

        $db = DB::getInstance();

        $this->assert($this->id_chart !== null);

        // Vérifier qu'on ne crée pas 2 exercices qui se recoupent
        if ($this->exists()) {
            $this->assert(
                !$db->test(self::TABLE, 'id != :id AND ((start_date <= :start_date AND end_date >= :start_date) OR (start_date <= :end_date AND end_date >= :start_date))',
                    ['id' => $this->id(), 'start_date' => $this->start_date, 'end_date' => $this->end_date]),
                'La date de début ou de fin se recoupe avec un exercice existant.'
            );

            $this->assert(
                !$db->test(Transaction::TABLE, 'id_year = ? AND date < ?', $this->id(), $this->start_date),
                'Des mouvements de cet exercice ont une date antérieure à la date de début de l\'exercice.'
            );

            $this->assert(
                !$db->test(Transaction::TABLE, 'id_year = ? AND date > ?', $this->id(), $this->end_date),
                'Des mouvements de cet exercice ont une date postérieure à la date de fin de l\'exercice.'
            );
        }
        else {
            $this->assert(
                !$db->test(self::TABLE, '(start_date <= :start_date AND end_date >= :start_date) OR (start_date <= :end_date AND end_date >= :start_date)',
                    ['start_date' => $this->start_date, 'end_date' => $this->end_date]),
                'La date de début ou de fin se recoupe avec un exercice existant.'
            );
        }
    }

    public function close()
    {







|
|

















|




|




|






|







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
        'end_date'   => 'date',
        'closed'     => 'int',
        'id_chart'   => 'int',
    ];

    protected $_form_rules = [
        'label'      => 'required|string|max:200',
        'start_date' => 'required|date_format:d/m/Y',
        'end_date'   => 'required|date_format:d/m/Y',
    ];

    public function selfCheck(): void
    {
        parent::selfCheck();
        $this->assert($this->start_date < $this->end_date, 'La date de fin doit être postérieure à la date de début');
        $this->assert($this->closed === 0 || $this->closed === 1);
        $this->assert($this->closed == 1 || !isset($this->_modified['closed']), 'Il est interdit de réouvrir un exercice clôturé');

        $db = DB::getInstance();

        $this->assert($this->id_chart !== null);

        // Vérifier qu'on ne crée pas 2 exercices qui se recoupent
        if ($this->exists()) {
            $this->assert(
                !$db->test(self::TABLE, 'id != :id AND ((start_date <= :start_date AND end_date >= :start_date) OR (start_date <= :end_date AND end_date >= :start_date))',
                    ['id' => $this->id(), 'start_date' => $this->start_date->format('Y-m-d'), 'end_date' => $this->end_date->format('Y-m-d')]),
                'La date de début ou de fin se recoupe avec un exercice existant.'
            );

            $this->assert(
                !$db->test(Transaction::TABLE, 'id_year = ? AND date < ?', $this->id(), $this->start_date->format('Y-m-d')),
                'Des mouvements de cet exercice ont une date antérieure à la date de début de l\'exercice.'
            );

            $this->assert(
                !$db->test(Transaction::TABLE, 'id_year = ? AND date > ?', $this->id(), $this->end_date->format('Y-m-d')),
                'Des mouvements de cet exercice ont une date postérieure à la date de fin de l\'exercice.'
            );
        }
        else {
            $this->assert(
                !$db->test(self::TABLE, '(start_date <= :start_date AND end_date >= :start_date) OR (start_date <= :end_date AND end_date >= :start_date)',
                    ['start_date' => $this->start_date->format('Y-m-d'), 'end_date' => $this->end_date->format('Y-m-d')]),
                'La date de début ou de fin se recoupe avec un exercice existant.'
            );
        }
    }

    public function close()
    {

Name change from src/templates/acc/years/cloturer.tpl to src/templates/acc/years/close.tpl.

Name change from src/templates/acc/years/supprimer.tpl to src/templates/acc/years/delete.tpl.

Modified src/templates/acc/years/edit.tpl from [ea0aa3d194] to [c72072cf7d].

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
{include file="admin/_head.tpl" title="Modifier un exercice" current="compta/exercices" js=1}

{form_errors}

<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Modifier un exercice</legend>
        <dl>
            <dt><label for="f_libelle">Libellé</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
            <dd><input type="text" name="libelle" id="f_libelle" value="{form_field name=libelle data=$exercice}" required="required" /></dd>
            <dt><label for="f_debut">Début de l'exercice</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
            <dd><input type="date" name="debut" id="f_debut" value="{form_field name=debut default=$exercice.debut|date_fr:'Y-m-d'}" size="10" required="required" /></dd>
            <dt><label for="f_fin">Fin de l'exercice</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
            <dd><input type="date" name="fin" id="f_fin" value="{form_field name=fin default=$exercice.fin|date_fr:'Y-m-d'}" size="10" required="required" /></dd>
        </dl>
    </fieldset>

    <p class="submit">
        {csrf_field key="compta_modif_exercice_%s"|args:$exercice.id}
        <input type="submit" name="edit" value="Enregistrer &rarr;" />
    </p>

</form>

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





|
|
|
<
|
|
<
|
<
|
|

|
|
|
|




1
2
3
4
5
6
7
8
9

10
11

12

13
14
15
16
17
18
19
20
21
22
23
{include file="admin/_head.tpl" title="Modifier un exercice" current="acc/years" js=1}

{form_errors}

<form method="post" action="{$self_url}">

	<fieldset>
		<legend>Modifier un exercice</legend>
		<dl>

			{input type="text" label="Libellé" name="label" source=$year required=true}
			{input type="date" label="Début de l'exercice" name="start_date" source=$year required=true}

			{input type="date" label="Fin de l'exercice" name="end_date" source=$year required=true}

		</dl>
	</fieldset>

	<p class="submit">
		{csrf_field key="acc_years_edit_%s"|args:$year.id}
		<input type="submit" name="edit" value="Enregistrer &rarr;" />
	</p>

</form>

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

Name change from src/www/admin/acc/years/cloturer.php to src/www/admin/acc/years/close.php.

Name change from src/www/admin/acc/years/supprimer.php to src/www/admin/acc/years/delete.php.

Modified src/www/admin/acc/years/edit.php from [566d206828] to [43b8da34f3].

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
<?php
namespace Garradin;



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 modifier un exercice clôturé.');
}

if ($form('edit'))
{
    $form->check('compta_modif_exercice_' . $exercice->id, [
        'libelle' => 'required',
        'fin'     => 'required|date',
        'debut'   => 'required|date',
    ]);

    if (!$form->hasErrors())
    {
        try
        {
            $id = $e->edit($exercice->id, [
                'libelle'   =>  f('libelle'),
                'debut'     =>  f('debut'),
                'fin'       =>  f('fin'),
            ]);

            Utils::redirect(ADMIN_URL . 'compta/exercices/');
        }
        catch (UserException $e)
        {
            $form->addError($e->getMessage());
        }
    }
}

$tpl->assign('exercice', $exercice);

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


>
>





<
<
|

|
<



|
<
|


<
<
<
<
<
<
<
|
<
|
|
<
|
<
<
<
|

|
|
|
|
|
|
|
|
<
|

|
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
<?php
namespace Garradin;

use Garradin\Accounting\Years;

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

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



$year = Years::get((int)qg('id'));

if (!$year) {

	throw new UserException('Exercice inconnu.');
}

if ($year->closed) {

	throw new UserException('Impossible de modifier un exercice clôturé.');
}








if (f('edit') && $form->check('acc_years_edit_' . $year->id()))

{
	try {

		$year->importForm();



		$year->save();

		Utils::redirect(ADMIN_URL . 'acc/years/');
	}
	catch (UserException $e)
	{
		$form->addError($e->getMessage());
	}
}


$tpl->assign('year', $year);

$tpl->display('acc/years/edit.tpl');