Overview
Comment:Implement: edition of accounts in charts
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 48540772ec5801619710e349308dee834280f767
User & Date: bohwaz on 2020-10-14 17:09:17
Other Links: branch diff | manifest | tags
Context
2020-10-14
18:14
Implement: add account to chart check-in: 6d7d326267 user: bohwaz tags: dev
17:09
Implement: edition of accounts in charts check-in: 48540772ec user: bohwaz tags: dev
15:06
Fix: balance sheet and accounts that can be either assets or liabilities check-in: babf7c84fc user: bohwaz tags: dev
Changes

Modified src/include/data/1.0.0_migration.sql from [6311bd5a68] to [75112da8f5].

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

INSERT INTO acc_charts (id, country, code, label) VALUES (1, 'FR', 'PCGA1999', 'Plan comptable associatif 1999');

--.read plan_comptable_1999.sql
--.read plan_comptable_2020.sql

-- Migration comptes de code comme identifiant à ID unique

INSERT INTO acc_accounts (id, id_chart, code, label, position, user)
	SELECT NULL, 1, id, libelle, position, CASE WHEN plan_comptable = 1 THEN 0 ELSE 1 END FROM compta_comptes;

-- Migrations projets vers comptes analytiques
INSERT INTO acc_accounts (id_chart, code, label, position, user, type)
	VALUES (1, '99', 'Projets', 0, 1, 6);

INSERT INTO acc_accounts (id_chart, code, label, position, user, type)
	SELECT 1, '99' || substr('0000' || id, -4), libelle, 0, 1, 6 FROM compta_projets;

-- Suppression des positions "actif ou passif" et "charge ou produit"
UPDATE acc_accounts SET position = 0 WHERE position = 12;

-- Modification des valeurs de la position (qui n'est plus un champ binaire)
UPDATE acc_accounts SET position = 5 WHERE position = 8;

-- Mise à jour de la position pour les comptes de tiers qui peuvent varier actif ou passif
UPDATE acc_accounts SET position = 3 WHERE code IN (4010, 4110, 4210, 428, 438);







>

|








|







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

INSERT INTO acc_charts (id, country, code, label) VALUES (1, 'FR', 'PCGA1999', 'Plan comptable associatif 1999');

--.read plan_comptable_1999.sql
--.read plan_comptable_2020.sql

-- Migration comptes de code comme identifiant à ID unique
-- Inversement valeurs actif/passif
INSERT INTO acc_accounts (id, id_chart, code, label, position, user)
	SELECT NULL, 1, id, libelle, CASE WHEN position = 2 THEN 1 WHEN position = 1 THEN 2 ELSE position END, CASE WHEN plan_comptable = 1 THEN 0 ELSE 1 END FROM compta_comptes;

-- Migrations projets vers comptes analytiques
INSERT INTO acc_accounts (id_chart, code, label, position, user, type)
	VALUES (1, '99', 'Projets', 0, 1, 6);

INSERT INTO acc_accounts (id_chart, code, label, position, user, type)
	SELECT 1, '99' || substr('0000' || id, -4), libelle, 0, 1, 6 FROM compta_projets;

-- Suppression de la position "charge ou produit" qui n'a aucun sens
UPDATE acc_accounts SET position = 0 WHERE position = 12;

-- Modification des valeurs de la position (qui n'est plus un champ binaire)
UPDATE acc_accounts SET position = 5 WHERE position = 8;

-- Mise à jour de la position pour les comptes de tiers qui peuvent varier actif ou passif
UPDATE acc_accounts SET position = 3 WHERE code IN (4010, 4110, 4210, 428, 438);

Modified src/include/lib/Garradin/Entities/Accounting/Account.php from [d50de4a0ee] to [035f1d0b3a].

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use Garradin\Utils;
use Garradin\UserException;

class Account extends Entity
{
	const TABLE = 'acc_accounts';

	// Passif
	const LIABILITY = 1;

	// Actif
	const ASSET = 2;

	// Passif ou actif
	const LIABILITY_OR_ASSET = 3;

	// Produit
	const REVENUE = 4;








|
|

|
|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use Garradin\Utils;
use Garradin\UserException;

class Account extends Entity
{
	const TABLE = 'acc_accounts';

	// Actif
	const ASSET = 1;

	// Passif
	const LIABILITY = 2;

	// Passif ou actif
	const LIABILITY_OR_ASSET = 3;

	// Produit
	const REVENUE = 4;

87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
		'user'        => 'int',
	];

	protected $_form_rules = [
		'code'        => 'required|string|alpha_num|max:10',
		'label'       => 'required|string|max:200',
		'description' => 'string|max:2000',
		'position'    => 'required|integer',
		'type'        => 'numeric|min:0',
	];

	public function getJournal(int $year_id)
	{
		$db = DB::getInstance();
		$sql = 'SELECT l.debit, l.credit, t.id, t.date, t.reference, l.reference AS line_reference, t.label, l.label AS line_label, l.reconciled
			FROM acc_transactions_lines l







|
|







87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
		'user'        => 'int',
	];

	protected $_form_rules = [
		'code'        => 'required|string|alpha_num|max:10',
		'label'       => 'required|string|max:200',
		'description' => 'string|max:2000',
		'position'    => 'required|numeric|min:0',
		'type'        => 'required|numeric|min:0',
	];

	public function getJournal(int $year_id)
	{
		$db = DB::getInstance();
		$sql = 'SELECT l.debit, l.credit, t.id, t.date, t.reference, l.reference AS line_reference, t.label, l.label AS line_label, l.reconciled
			FROM acc_transactions_lines l

Modified src/include/lib/Garradin/Template.php from [7a56549b09] to [ad5ed56bcb].

217
218
219
220
221
222
223
224
225
226
227
228
229
230
231

		$attributes['id'] = 'f_' . $name;
		$attributes['name'] = $name;

		if ($type == 'radio' || $type == 'checkbox') {
			$attributes['id'] .= '_' . $value;

			if (isset($_POST[$name]) && $_POST[$name] == $value) {
				$attributes['checked'] = 'checked';
			}
		}
		elseif ($type == 'file') {
			$help = sprintf('Taille maximale : %s', Utils::format_bytes(Utils::getMaxUploadSize()));
		}
		elseif ($type == 'date') {







|







217
218
219
220
221
222
223
224
225
226
227
228
229
230
231

		$attributes['id'] = 'f_' . $name;
		$attributes['name'] = $name;

		if ($type == 'radio' || $type == 'checkbox') {
			$attributes['id'] .= '_' . $value;

			if ($current_value == $value) {
				$attributes['checked'] = 'checked';
			}
		}
		elseif ($type == 'file') {
			$help = sprintf('Taille maximale : %s', Utils::format_bytes(Utils::getMaxUploadSize()));
		}
		elseif ($type == 'date') {
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331



332
333
334
335




336

337

338
339
340
341
342
343
344
		// No label? then we only want the input without the widget
		if (empty($label)) {
			return $input;
		}

		$required_label = array_key_exists('required', $attributes) ? ' <b title="Champ obligatoire">(obligatoire)</b>' : '';

		$out = '<dt>';

		if ($type == 'radio' || $type == 'checkbox') {
			$out .= $input . ' ';
		}

		if ($type == 'file') {
			$input .= sprintf('<input type="hidden" name="MAX_FILE_SIZE" value="%d" id="f_maxsize" />', Utils::return_bytes(Utils::getMaxUploadSize()));
		}

		$out .= sprintf('<label for="%s">%s</label>%s</dt>', $attributes['id'], $this->escape($label), $required_label);




		if (isset($help)) {
			$out .= sprintf('<dd class="help">%s</dd>', $this->escape($help));
		}





		if ($type != 'radio' && $type != 'checkbox') {

			$out .= sprintf('<dd>%s</dd>', $input);

		}

		return $out;
	}

	protected function formField(array $params, $escape = true)
	{







<
<
<
<
<
<




|

>
>
>
|
|
|

>
>
>
>
|
>
|
>







313
314
315
316
317
318
319






320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
		// No label? then we only want the input without the widget
		if (empty($label)) {
			return $input;
		}

		$required_label = array_key_exists('required', $attributes) ? ' <b title="Champ obligatoire">(obligatoire)</b>' : '';







		if ($type == 'file') {
			$input .= sprintf('<input type="hidden" name="MAX_FILE_SIZE" value="%d" id="f_maxsize" />', Utils::return_bytes(Utils::getMaxUploadSize()));
		}

		$label = sprintf('<label for="%s">%s</label>%s', $attributes['id'], $this->escape($label), $required_label);

		if ($type == 'radio' || $type == 'checkbox') {
			$out = sprintf('<dd>%s %s', $input, $label);

			if (isset($help)) {
				$out .= sprintf(' <em class="help">(%s)</em>', $this->escape($help));
			}

			$out .= '</dd>';
		}
		else {
			$out = sprintf('<dt>%s</dt><dd>%s</dd>', $label, $input);

			if (isset($help)) {
				$out .= sprintf('<dd class="help">%s</dd>', $this->escape($help));
			}
		}

		return $out;
	}

	protected function formField(array $params, $escape = true)
	{

Modified src/templates/acc/charts/accounts/all.tpl from [1dd30710e2] to [ebdf897836].

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
			<td>
				{if $account.type}
					<?=Entities\Accounting\Account::TYPES_NAMES[$account->type]?>
				{/if}
			</td>
			<td class="actions">
				{if $session->canAccess('compta', Membres::DROIT_ADMIN)}
					{linkbutton shape="edit" label="Modifier" href="acc/accounts/edit.php?id=%d"|args:$account.id}
					{linkbutton shape="delete" label="Supprimer" href="acc/accounts/delete.php?id=%d"|args:$account.id}
				{/if}
			</td>
		</tr>
	{/foreach}
	</tbody>
</table>

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







|
|








11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
			<td>
				{if $account.type}
					<?=Entities\Accounting\Account::TYPES_NAMES[$account->type]?>
				{/if}
			</td>
			<td class="actions">
				{if $session->canAccess('compta', Membres::DROIT_ADMIN)}
					{linkbutton shape="edit" label="Modifier" href="acc/charts/accounts/edit.php?id=%d"|args:$account.id}
					{linkbutton shape="delete" label="Supprimer" href="acc/charts/accounts/delete.php?id=%d"|args:$account.id}
				{/if}
			</td>
		</tr>
	{/foreach}
	</tbody>
</table>

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

Added src/templates/acc/charts/accounts/edit.tpl version [3c53ed4ef4].











































































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

{form_errors}

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

	<fieldset>
		<legend>Modifier un compte</legend>
		<dl>
			{input type="select" label="Type de compte favori" name="type" source=$account required=true options=$types}
			<dd class="help">Le statut de compte favori est utilisé pour les écritures <em>«&nbsp;simplifiées&nbsp;»</em> (recettes, dépenses, dettes, créances, virements), pour la liste des comptes, et également pour proposer certaines fonctionnalités (rapprochement pour les comptes bancaires, règlement rapide de dette et créance, dépôt de chèques).</dd>
			<dd class="help">Un compte qui n'a pas de type favori ne pourra être utilisé que dans une saisie avancée, et ne sera visible que dans les rapports de l'exercice.</dd>

			<dt><label for="f_position_0">Position au bilan ou résultat</label> <b>(obligatoire)</b></dt>
			<dd class="help">La position permet d'indiquer dans quelle partie du bilan ou du résultat doit figurer le compte.</dd>
			<dd class="help">Les comptes inscrits en actif ou passif figureront dans le bilan, alors que ceux inscrits en produit ou charge figureront au compte de résultat.</dd>
			{input type="radio" label="Ne pas utiliser ce compte au bilan ni au résultat" name="position" value=0 source=$account}
			{input type="radio" label="Bilan : actif" name="position" value=1 source=$account help="ce que possède l'association : stocks, locaux, soldes bancaires, etc."}
			{input type="radio" label="Bilan : passif" name="position" value=2 source=$account help="ce que l'association doit : dettes, provisions, réserves, etc."}
			{input type="radio" label="Bilan : actif ou passif" name="position" value=3 source=$account help="le compte sera placé à l'actif si son solde est débiteur, ou au passif s'il est créditeur"}
			{input type="radio" label="Résultat : produit" name="position" value=4 source=$account help="recettes"}
			{input type="radio" label="Résultat : charge" name="position" value=5 source=$account help="dépenses"}

			{input type="text" label="Code" maxlength="10" name="code" source=$account required=true help="Le code du compte sert à trier le compte dans le plan comptable, attention à choisir un code qui correspond au plan comptable."}
			{input type="text" label="Libellé" name="label" source=$account required=true}
			{input type="textarea" label="Description" name="description" source=$account required=true}
		</dl>
	</fieldset>

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

</form>

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

Modified src/templates/acc/charts/accounts/index.tpl from [0ee487482f] to [472c3bf003].

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
	{foreach from=$accounts item="account"}
		<tr>
			<td class="num">{$account.code}</td>
			<th>{$account.label}</th>
			<td class="desc">{$account.description}</td>
			<td class="actions">
				{if $session->canAccess('compta', Membres::DROIT_ADMIN)}
					{linkbutton shape="edit" label="Modifier" href="acc/accounts/edit.php?id=%d"|args:$account.id}
					{linkbutton shape="delete" label="Supprimer" href="acc/accounts/delete.php?id=%d"|args:$account.id}
				{/if}
			</td>
		</tr>
	{/foreach}
	</tbody>
{/foreach}
</table>

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







|
|









10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
	{foreach from=$accounts item="account"}
		<tr>
			<td class="num">{$account.code}</td>
			<th>{$account.label}</th>
			<td class="desc">{$account.description}</td>
			<td class="actions">
				{if $session->canAccess('compta', Membres::DROIT_ADMIN)}
					{linkbutton shape="edit" label="Modifier" href="acc/charts/accounts/edit.php?id=%d"|args:$account.id}
					{linkbutton shape="delete" label="Supprimer" href="acc/charts/accounts/delete.php?id=%d"|args:$account.id}
				{/if}
			</td>
		</tr>
	{/foreach}
	</tbody>
{/foreach}
</table>

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

Added src/www/admin/acc/charts/accounts/delete.php version [6d0ff3b7ef].





























































































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

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

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

$id = qg('id');
$compte = $comptes->get($id);

if (!$compte)
{
    throw new UserException('Le compte demandé n\'existe pas.');
}

if (f('delete') && $form->check('compta_delete_compte_' . $compte->id))
{
    try
    {
        $comptes->delete($compte->id);
        Utils::redirect(ADMIN_URL . 'compta/comptes/?classe=' . substr($compte->id, 0, 1));
    }
    catch (UserException $e)
    {
        $form->addError($e->getMessage());
    }
}
elseif (f('disable') && $form->check('compta_disable_compte_' . $compte->id))
{
    try
    {
        $comptes->disable($compte->id);
        Utils::redirect(ADMIN_URL . 'compta/comptes/?classe='.substr($compte->id, 0, 1));
    }
    catch (UserException $e)
    {
        $form->addError($e->getMessage());
    }
}

$tpl->assign('can_delete', $comptes->canDelete($compte->id));
$tpl->assign('can_disable', $comptes->canDisable($compte->id));

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

$tpl->display('admin/compta/comptes/supprimer.tpl');

Added src/www/admin/acc/charts/accounts/edit.php version [a0164679cc].





















































































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

use Garradin\Accounting\Accounts;

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

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

$account = Accounts::get((int) qg('id'));

if (!$account) {
	throw new UserException("Le compte demandé n'existe pas.");
}

if (f('edit') && $form->check('acc_accounts_edit_' . $account->id()))
{
	try
	{
		$account->importForm();
		$account->save();

		$page = '';

		if (!$account->type) {
			$page = 'all.php';
		}

		Utils::redirect(sprintf('%sacc/charts/accounts/%s?id=%d', ADMIN_URL, $page, $account->id_chart));
	}
	catch (UserException $e)
	{
		$form->addError($e->getMessage());
	}
}

$types = $account::TYPES_NAMES;
$types[0] = '-- Pas un compte favori';

$tpl->assign(compact('types', 'account'));

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