Overview
Comment:Fix [3eb74d23ce1656cf9b0a8a29cd33a80f793630f0]: transfer old fees to new year if possible, or alert that some manual operation needs to be done
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable | 1.0.3
Files: files | file ages | folders
SHA1: 4ae6254acdf9e2412bb5d436d6c0f377915ff561
User & Date: bohwaz on 2021-01-19 14:14:11
Other Links: manifest | tags
Context
2021-01-22
13:07
Fix some labels check-in: 0214816b6e user: bohwaz tags: trunk
2021-01-19
17:07
Merge back trunk changes check-in: 9317cae869 user: bohwaz tags: dev
14:14
Fix [3eb74d23ce1656cf9b0a8a29cd33a80f793630f0]: transfer old fees to new year if possible, or alert that some manual operation needs to be done check-in: 4ae6254acd user: bohwaz tags: trunk, stable, 1.0.3
13:35
Add SQL view in config to see what's going on check-in: 18f1a92627 user: bohwaz tags: trunk, stable
Changes

Modified src/VERSION from [687727ca1c] to [e5906c31c0].

1
1.0.2
|
1
1.0.3

Added src/include/data/1.0.3_migration.sql version [9ded2b030d].





>
>
1
2
-- Fix services connected to old closed year
UPDATE services_fees SET id_year = NULL, id_account = NULL WHERE id_year IN (SELECT id FROM acc_years WHERE closed = 1);

Modified src/include/lib/Garradin/Services/Fees.php from [a0a1d5ede0] to [5a3f0428c1].

2
3
4
5
6
7
8

9
10
11
12
13
14
15
..
17
18
19
20
21
22
23














24
25
26
27
28
29
30

namespace Garradin\Services;

use Garradin\Config;
use Garradin\DB;
use Garradin\Membres\Categories;
use Garradin\Entities\Services\Fee;

use KD2\DB\EntityManager;

class Fees
{
	protected $service_id;

	public function __construct(int $id)
................................................................................
		$this->service_id = $id;
	}

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















	/**
	 * If $user_id is specified, then it will return a column 'user_amount' containing the amount that this specific user should pay
	 */
	static public function listAllByService(?int $user_id = null)
	{
		$db = DB::getInstance();







>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
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

namespace Garradin\Services;

use Garradin\Config;
use Garradin\DB;
use Garradin\Membres\Categories;
use Garradin\Entities\Services\Fee;
use Garradin\Entities\Accounting\Year;
use KD2\DB\EntityManager;

class Fees
{
	protected $service_id;

	public function __construct(int $id)
................................................................................
		$this->service_id = $id;
	}

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

	static public function updateYear(Year $old, Year $new): bool
	{
		$db = DB::getInstance();

		if ($new->id_chart == $old->id_chart) {
			$db->preparedQuery('UPDATE services_fees SET id_year = ? WHERE id_year = ?;', $new->id(), $old->id());
			return true;
		}
		else {
			$db->preparedQuery('UPDATE services_fees SET id_year = NULL, id_account = NULL WHERE id_year = ?;', $old->id());
			return false;
		}
	}

	/**
	 * If $user_id is specified, then it will return a column 'user_amount' containing the amount that this specific user should pay
	 */
	static public function listAllByService(?int $user_id = null)
	{
		$db = DB::getInstance();

Modified src/include/lib/Garradin/Upgrade.php from [5d06b1bc31] to [cdfba1b19b].

127
128
129
130
131
132
133








134
135
136
137
138
139
140
			if (version_compare($v, '1.0.1', '<'))
			{
				// Missing trigger
				$db->begin();
				$db->import(ROOT . '/include/data/1.0.1_migration.sql');
				$db->commit();
			}









			// Vérification de la cohérence des clés étrangères
			$db->foreignKeyCheck();

			Utils::clearCaches();

			$config->setVersion(garradin_version());







>
>
>
>
>
>
>
>







127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
			if (version_compare($v, '1.0.1', '<'))
			{
				// Missing trigger
				$db->begin();
				$db->import(ROOT . '/include/data/1.0.1_migration.sql');
				$db->commit();
			}

			if (version_compare($v, '1.0.3', '<'))
			{
				// Missing trigger
				$db->begin();
				$db->import(ROOT . '/include/data/1.0.3_migration.sql');
				$db->commit();
			}

			// Vérification de la cohérence des clés étrangères
			$db->foreignKeyCheck();

			Utils::clearCaches();

			$config->setVersion(garradin_version());

Modified src/templates/acc/years/index.tpl from [40b0f49623] to [fd39c3ba37].

17
18
19
20
21
22
23







24
25
26
27
28
29
30
<p class="block error">
	Il n'existe aucun exercice ouvert.
	{if $session->canAccess('compta', Membres::DROIT_ADMIN)}
		Merci d'en <a href="{$admin_url}acc/years/new.php">créer un nouveau</a> pour pouvoir saisir des écritures.
	{/if}
</p>
{/if}








{if !empty($list)}
	{if count($list) > 1}
	<section class="year-infos">
		<section class="graphs">
			<figure>
				<img src="{$admin_url}acc/reports/graph_plot_all.php?type=assets" alt="" />







>
>
>
>
>
>
>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<p class="block error">
	Il n'existe aucun exercice ouvert.
	{if $session->canAccess('compta', Membres::DROIT_ADMIN)}
		Merci d'en <a href="{$admin_url}acc/years/new.php">créer un nouveau</a> pour pouvoir saisir des écritures.
	{/if}
</p>
{/if}

{if $_GET.msg == 'UPDATE_FEES'}
<p class="block error">
	Des tarifs d'activité étaient associés à l'ancien exercice clôturé.
	Ces tarifs ont été déconnectés de la comptabilité à cause du changement de plan comptable, il vous faudra les reconnecter manuellement au nouvel exercice.
</p>
{/if}

{if !empty($list)}
	{if count($list) > 1}
	<section class="year-infos">
		<section class="graphs">
			<figure>
				<img src="{$admin_url}acc/reports/graph_plot_all.php?type=assets" alt="" />

Modified src/www/admin/acc/years/close.php from [e25c1f315a] to [440db77f6b].

19
20
21
22
23
24
25
26
27
28
29
30

$csrf_key = 'acc_years_close_' . $year->id();

$form->runIf('close', function () use ($year, $user, $session) {
	$year->close($user->id);
	$year->save();
	$session->set('acc_year', null);
}, $csrf_key, ADMIN_URL . 'acc/years/');

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

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







|




19
20
21
22
23
24
25
26
27
28
29
30

$csrf_key = 'acc_years_close_' . $year->id();

$form->runIf('close', function () use ($year, $user, $session) {
	$year->close($user->id);
	$year->save();
	$session->set('acc_year', null);
}, $csrf_key, ADMIN_URL . 'acc/years/new.php?from=' . $year->id());

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

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

Modified src/www/admin/acc/years/new.php from [52e738c176] to [bb5f6f537d].

1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16









17
18
19
20
21
22
23
<?php
namespace Garradin;

use Garradin\Accounting\Years;
use Garradin\Accounting\Charts;

use Garradin\Entities\Accounting\Year;

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

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

if (f('new') && $form->check('acc_years_new')) {
	try {
		$year = new Year;
		$year->importForm();
		$year->save();










		if (Years::countClosed()) {
			Utils::redirect(ADMIN_URL . 'acc/years/balance.php?id=' . $year->id());
		}
		else {
			Utils::redirect(ADMIN_URL . 'acc/years/');
		}





>











>
>
>
>
>
>
>
>
>







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

use Garradin\Accounting\Years;
use Garradin\Accounting\Charts;
use Garradin\Services\Fees;
use Garradin\Entities\Accounting\Year;

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

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

if (f('new') && $form->check('acc_years_new')) {
	try {
		$year = new Year;
		$year->importForm();
		$year->save();

		if ($old_id = qg('from')) {
			$old = Years::get((int) $old_id);
			$changed = Fees::updateYear($old, $year);

			if (!$changed) {
				Utils::redirect(ADMIN_URL . 'acc/years/?msg=UPDATE_FEES');
			}
		}

		if (Years::countClosed()) {
			Utils::redirect(ADMIN_URL . 'acc/years/balance.php?id=' . $year->id());
		}
		else {
			Utils::redirect(ADMIN_URL . 'acc/years/');
		}