Overview
Comment:Removal of accounting transactions
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: a4353b8d3fa30f2973b18fed092dc6d2f5d74242
User & Date: bohwaz on 2020-09-16 15:19:41
Other Links: branch diff | manifest | tags
Context
2020-09-16
16:39
Use nav.tabs instead of ul.actions for submenus check-in: 0e113c6a6a user: bohwaz tags: dev
15:19
Removal of accounting transactions check-in: a4353b8d3f user: bohwaz tags: dev
15:18
Method to delete linked files check-in: e90ff81d47 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Accounting/Accounts.php from [c4161ad58e] to [1c715ecbe5].

13
14
15
16
17
18
19





20
21
22
23
24
25
26
	protected $em;

	public function __construct(int $chart_id)
	{
		$this->chart_id = $chart_id;
		$this->em = EntityManager::getInstance(Account::class);
	}






	public function getIdFromCode(string $code): int
	{
		return $this->em->col('SELECT id FROM @TABLE WHERE code = ?;', $code);
	}

	/**







>
>
>
>
>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
	protected $em;

	public function __construct(int $chart_id)
	{
		$this->chart_id = $chart_id;
		$this->em = EntityManager::getInstance(Account::class);
	}

	static public function get(int $id)
	{
		return EntityManager::findOneById(Account::class, $id);
	}

	public function getIdFromCode(string $code): int
	{
		return $this->em->col('SELECT id FROM @TABLE WHERE code = ?;', $code);
	}

	/**

Added src/include/lib/Garradin/Accounting/Transactions.php version [bc5e5f149a].





























>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php

namespace Garradin\Accounting;

use Garradin\Entities\Accounting\Transaction;
use KD2\DB\EntityManager;

class Transactions
{
	static public function get(int $id)
	{
		return EntityManager::findOneById(Transaction::class, $id);
	}
}

Modified src/include/lib/Garradin/Entities/Accounting/Transaction.php from [8c80beee08] to [54f7b43ca3].

1
2
3
4
5
6

7
8
9
10
11
12
13
...
107
108
109
110
111
112
113
114






115
116
117
118
119
120
121
...
126
127
128
129
130
131
132
133
134








135
136
137
138
139
140
141
<?php

namespace Garradin\Entities\Accounting;

use KD2\DB\EntityManager;
use Garradin\Entity;

use Garradin\Accounting\Accounts;
use Garradin\ValidationException;
use Garradin\DB;
use Garradin\Config;

class Transaction extends Entity
{
................................................................................
	{
		$this->_lines[] = $line;
	}

	public function save(): bool
	{
		if ($this->validated && !isset($this->_modified['validated'])) {
			throw new ValidationException('Il n\'est pas possible de modifier un mouvement qui a été validé');






		}

		if (!parent::save()) {
			return false;
		}

		foreach ($this->_lines as &$line)
................................................................................

		return true;
	}

	public function delete(): bool
	{
		if ($this->validated) {
			throw new ValidationException('Il n\'est pas possible de supprimer un mouvement qui a été validé');
		}









		return parent::delete();
	}

	public function selfCheck(): void
	{
		parent::selfCheck();






>







 







|
>
>
>
>
>
>







 







|

>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
...
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
...
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php

namespace Garradin\Entities\Accounting;

use KD2\DB\EntityManager;
use Garradin\Entity;
use Garradin\Fichiers;
use Garradin\Accounting\Accounts;
use Garradin\ValidationException;
use Garradin\DB;
use Garradin\Config;

class Transaction extends Entity
{
................................................................................
	{
		$this->_lines[] = $line;
	}

	public function save(): bool
	{
		if ($this->validated && !isset($this->_modified['validated'])) {
			throw new ValidationException('Il n\'est pas possible de modifier une écriture qui a été validé');
		}

		$db = DB::getInstance();

		if ($db->test(Year::TABLE, 'id = ? AND closed = 1', $this->id_year)) {
			throw new ValidationException('Il n\'est pas possible de modifier une écriture qui fait partie d\'un exercice clôturé');
		}

		if (!parent::save()) {
			return false;
		}

		foreach ($this->_lines as &$line)
................................................................................

		return true;
	}

	public function delete(): bool
	{
		if ($this->validated) {
			throw new ValidationException('Il n\'est pas possible de supprimer une écriture qui a été validée');
		}

		$db = DB::getInstance();

		if ($db->test(Year::TABLE, 'id = ? AND closed = 1', $this->id_year)) {
			throw new ValidationException('Il n\'est pas possible de supprimer une écriture qui fait partie d\'un exercice clôturé');
		}

		Fichiers::deleteLinkedFiles(Fichiers::LIEN_COMPTA, $this->id());

		return parent::delete();
	}

	public function selfCheck(): void
	{
		parent::selfCheck();

Modified src/templates/acc/transactions/delete.tpl from [f5372a2a85] to [5306fcce0b].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{include file="admin/_head.tpl" title="Supprimer une opération" current="compta/gestion"}

{form_errors}

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

    <fieldset>
        <legend>Supprimer cette opération ?</legend>
        <h3 class="warning">
            Êtes-vous sûr de vouloir supprimer l'opération n°{$operation.id}
            «&nbsp;{$operation.libelle}&nbsp;» du {$operation.date|date_fr:'d/m/Y'} ?
        </h3>
    </fieldset>

    <p class="submit">
        {csrf_field key="compta_supprimer_%d"|args:$operation.id}
        <input type="submit" name="delete" value="Supprimer &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
{include file="admin/_head.tpl" title="Supprimer l'écriture n°%d"|args:$transaction.id current="acc"}

{form_errors}

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

    <fieldset>
        <legend>Supprimer cette écriture ?</legend>
        <h3 class="warning">
            Êtes-vous sûr de vouloir supprimer l'opération n°{$transaction.id}
            «&nbsp;{$transaction.label}&nbsp;» du {$transaction.date|date_fr:'d/m/Y'} ?
        </h3>
    </fieldset>

    <p class="submit">
        {csrf_field key="acc_delete_%d"|args:$transaction.id}
        <input type="submit" name="delete" value="Supprimer &rarr;" />
    </p>

</form>

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

Modified src/templates/acc/transactions/details.tpl from [0439690d86] to [b320fd7a07].

1
2
3
4
5
6
7
8
9
10
{include file="admin/_head.tpl" title="Écriture n°%d"|args:$transaction.id current="acc"}

{if $session->canAccess('compta', Membres::DROIT_ADMIN)}
<ul class="actions">
	<li class="edit"><a href="edit.php?id={$transaction.id}">Modifier cette écriture</a></li>
	<li class="delete"><a href="delete.php?id={$transaction.id}">Supprimer cette écriture</a></li>
</ul>
{/if}

<dl class="describe">


|







1
2
3
4
5
6
7
8
9
10
{include file="admin/_head.tpl" title="Écriture n°%d"|args:$transaction.id current="acc"}

{if $session->canAccess('compta', Membres::DROIT_ADMIN) && !$transaction->validated && !$tr_year->closed}
<ul class="actions">
	<li class="edit"><a href="edit.php?id={$transaction.id}">Modifier cette écriture</a></li>
	<li class="delete"><a href="delete.php?id={$transaction.id}">Supprimer cette écriture</a></li>
</ul>
{/if}

<dl class="describe">

Modified src/www/admin/acc/transactions/delete.php from [0f0bd1e03f] to [b8196c91e9].

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;



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

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

$journal = new Compta\Journal;

$operation = $journal->get(qg('id'));

if (!$operation)
{
    throw new UserException("L'opération demandée n'existe pas.");
}

if (f('delete'))
{
    if ($form->check('compta_supprimer_' . $operation->id))
    {
        try
        {
            $journal->delete($operation->id);
            Utils::redirect(ADMIN_URL . 'compta/operations/');
        }
        catch (UserException $e)
        {
            $form->addError($e->getMessage());
        }
    }
}

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

$tpl->display('admin/compta/operations/supprimer.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
<?php

namespace Garradin;

use Garradin\Accounting\Transactions;

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

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

$transaction = Transactions::get((int) qg('id'));

if (!$transaction) {



    throw new UserException('Cette écriture n\'existe pas');
}

if (f('delete'))
{
    if ($form->check('acc_delete_' . $transaction->id))
    {
        try
        {
            $transaction->delete();
            Utils::redirect(ADMIN_URL . 'acc/');
        }
        catch (UserException $e)
        {
            $form->addError($e->getMessage());
        }
    }
}

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

$tpl->display('acc/transactions/delete.tpl');

Modified src/www/admin/acc/transactions/details.php from [a4e3c44122] to [ff2f396577].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
namespace Garradin;

use Garradin\Entities\Accounting\Transaction;
use KD2\DB\EntityManager as EM;

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

$transaction = EM::findOneById(Transaction::class, (int) qg('id'));

if (!$transaction) {
    throw new UserException('Cette écriture n\'existe pas');
}

$tpl->assign('files', Fichiers::listLinkedFiles(Fichiers::LIEN_COMPTA, $transaction->id()));
$tpl->assign('transaction', $transaction);
$tpl->assign('tr_year', $transaction->year());

$tpl->display('acc/transactions/details.tpl');



|
<



|










1
2
3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
namespace Garradin;

use Garradin\Accounting\Transactions;


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

$transaction = Transactions::get((int) qg('id'));

if (!$transaction) {
    throw new UserException('Cette écriture n\'existe pas');
}

$tpl->assign('files', Fichiers::listLinkedFiles(Fichiers::LIEN_COMPTA, $transaction->id()));
$tpl->assign('transaction', $transaction);
$tpl->assign('tr_year', $transaction->year());

$tpl->display('acc/transactions/details.tpl');