Overview
Comment:Handle when opening balance is done between years with different charts
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 57aea9fdd9e2a7259f33b7ace06eac16564402f2
User & Date: bohwaz on 2020-10-17 15:49:54
Other Links: branch diff | manifest | tags
Context
2020-10-17
15:55
Try to match accounts between old and new chart check-in: e95ce263c4 user: bohwaz tags: dev
15:49
Handle when opening balance is done between years with different charts check-in: 57aea9fdd9 user: bohwaz tags: dev
09:42
Implement pie charts check-in: 0fa6b07811 user: bohwaz tags: dev
Changes

Modified src/templates/acc/years/balance.tpl from [221b5a0e74] to [df93e835da].

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
		<legend>Exercice&nbsp;: «&nbsp;{$year.label}&nbsp;» du {$year.start_date|date_fr:'d/m/Y'} au {$year.end_date|date_fr:'d/m/Y'}</legend>
		<p class="help">
			Renseigner ici les soldes d'ouverture (débiteur ou créditeur) des comptes.
		</p>

		{if null === $previous_year}
		<dl>
			<dt><label for="f_from_year">Reprendre les soldes de fermeture de l'exercice suivant</label></dt>
			<dd>
				<select id="f_from_year" name="from_year">
					<option value="">-- Aucun</option>
					{foreach from=$years item="year"}
					<option value="{$year.id}">{$year.label} — {$year.start_date|date_fr:'d/m/Y'} au {$year.end_date|date_fr:'d/m/Y'}</option>
					{/foreach}
				</select>
			</dd>
		</dl>
		{else}
		<table class="list transaction-lines">
			<thead>
				<tr>




					<th>Compte</th>

					<td>Débit</td>
					<td>Crédit</td>
					<td></td>
				</tr>
			</thead>
			<tbody>
			{foreach from=$lines key="k" item="line"}
				<tr>



					<th>
						{input type="list" target="acc/accounts/selector.php" name="lines[account][]" default=$line.account_selected}
					</th>
					<td>{input type="money" name="lines[debit][]" default=$line.debit size=5}</td>
					<td>{input type="money" name="lines[credit][]" default=$line.credit size=5}</td>
					<td>{button label="Enlever la ligne" shape="minus" min="1" name="remove_line"}</td>
				</tr>







|













>
>
>
>
|
>








>
>
>







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
52
53
54
55
56
57
58
59
		<legend>Exercice&nbsp;: «&nbsp;{$year.label}&nbsp;» du {$year.start_date|date_fr:'d/m/Y'} au {$year.end_date|date_fr:'d/m/Y'}</legend>
		<p class="help">
			Renseigner ici les soldes d'ouverture (débiteur ou créditeur) des comptes.
		</p>

		{if null === $previous_year}
		<dl>
			<dt><label for="f_from_year">Reprendre les soldes de fermeture d'un exercice clôtu</label></dt>
			<dd>
				<select id="f_from_year" name="from_year">
					<option value="">-- Aucun</option>
					{foreach from=$years item="year"}
					<option value="{$year.id}">{$year.label} — {$year.start_date|date_fr:'d/m/Y'} au {$year.end_date|date_fr:'d/m/Y'}</option>
					{/foreach}
				</select>
			</dd>
		</dl>
		{else}
		<table class="list transaction-lines">
			<thead>
				<tr>
					{if $chart_change}
						<td>Ancien compte</td>
						<th>Nouveau compte</th>
					{else}
						<th>Compte</th>
					{/if}
					<td>Débit</td>
					<td>Crédit</td>
					<td></td>
				</tr>
			</thead>
			<tbody>
			{foreach from=$lines key="k" item="line"}
				<tr>
					{if $chart_change}
						<td>{$line.code} — {$line.label}</td>
					{/if}
					<th>
						{input type="list" target="acc/accounts/selector.php" name="lines[account][]" default=$line.account_selected}
					</th>
					<td>{input type="money" name="lines[debit][]" default=$line.debit size=5}</td>
					<td>{input type="money" name="lines[credit][]" default=$line.credit size=5}</td>
					<td>{button label="Enlever la ligne" shape="minus" min="1" name="remove_line"}</td>
				</tr>
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
	</fieldset>

	<p class="submit">
		{if null === $previous_year}
			<input type="submit" name="next" value="Continuer &rarr;" />
		{else}
			{csrf_field key="acc_years_balance_%s"|args:$year.id}
			<input type="hidden" name="from_year" value="{$previous_year}" />
			<input type="submit" name="save" value="Sauvegarder &rarr;" />

			{literal}
			<script type="text/javascript" defer="defer" async="async">
			g.script('scripts/accounting.js', () => { initTransactionForm(); });
			</script>
			{/literal}







|







72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
	</fieldset>

	<p class="submit">
		{if null === $previous_year}
			<input type="submit" name="next" value="Continuer &rarr;" />
		{else}
			{csrf_field key="acc_years_balance_%s"|args:$year.id}
			<input type="hidden" name="from_year" value="{$previous_year.id}" />
			<input type="submit" name="save" value="Sauvegarder &rarr;" />

			{literal}
			<script type="text/javascript" defer="defer" async="async">
			g.script('scripts/accounting.js', () => { initTransactionForm(); });
			</script>
			{/literal}

Modified src/www/admin/acc/years/balance.php from [a6c1b6d337] to [7581d7619c].

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
	catch (UserException $e)
	{
		$form->addError($e->getMessage());
	}
}

$previous_year = null;

$lines = [[]];
$lines_accounts = [[]];
$years = Years::listClosed();

if (!count($years)) {
	$previous_year = 0;
}
elseif (null !== f('from_year')) {
	$previous_year = (int)f('from_year');

}






if ($previous_year) {
	$lines = Reports::getClosingSumsWithAccounts(['year' => $previous_year]);





	foreach ($lines as $k => &$line) {
		$line->credit = $line->sum > 0 ? $line->sum : 0;
		$line->debit = $line->sum < 0 ? abs($line->sum) : 0;


		$line->account_selected = [$line->id => sprintf('%s — %s', $line->code, $line->label)];

	}

	unset($line);
}

$tpl->assign('lines', $lines);
$tpl->assign('years', $years);
$tpl->assign('previous_year', $previous_year);
$tpl->assign('year', $year);

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







>









>
|
>
>
|
>
>
>

|
>
>
>
>




>
>
|
>





|
<
<
<


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



76
77
	catch (UserException $e)
	{
		$form->addError($e->getMessage());
	}
}

$previous_year = null;
$chart_change = false;
$lines = [[]];
$lines_accounts = [[]];
$years = Years::listClosed();

if (!count($years)) {
	$previous_year = 0;
}
elseif (null !== f('from_year')) {
	$previous_year = (int)f('from_year');
	$previous_year = Years::get($previous_year);

	if (!$previous_year) {
		throw new UserException('Année précédente invalide');
	}
}


if ($previous_year) {
	$lines = Reports::getClosingSumsWithAccounts(['year' => $previous_year->id()]);

	if ($previous_year->id_chart != $year->id_chart) {
		$chart_change = true;
	}

	foreach ($lines as $k => &$line) {
		$line->credit = $line->sum > 0 ? $line->sum : 0;
		$line->debit = $line->sum < 0 ? abs($line->sum) : 0;

		if (!$chart_change) {
			$line->account_selected = [$line->id => sprintf('%s — %s', $line->code, $line->label)];
		}
	}

	unset($line);
}

$tpl->assign(compact('lines', 'years', 'chart_change', 'previous_year', 'year'));




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