Overview
Comment:Try to match accounts between old and new chart
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: e95ce263c45297e5bc2d5ea1b16185d260a17247
User & Date: bohwaz on 2020-10-17 15:55:42
Other Links: branch diff | manifest | tags
Context
2020-10-17
17:01
Add more graphs check-in: fa963fe834 user: bohwaz tags: dev
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
Changes

Modified src/include/lib/Garradin/Accounting/Accounts.php from [313a8ba3cd] to [d388bab2b8].

42
43
44
45
46
47
48





49
50
51
52
53
54
55
	 * Return all accounts from current chart
	 */
	public function listAll(): array
	{
		return $this->em->all('SELECT * FROM @TABLE WHERE id_chart = ? ORDER BY code COLLATE NOCASE;',
			$this->chart_id);
	}






	/**
	 * Return all accounts from current chart
	 */
	public function export(): \Generator
	{
		$res = $this->em->DB()->iterate($this->em->formatQuery('SELECT code, label, description, position, type FROM @TABLE WHERE id_chart = ? ORDER BY code COLLATE NOCASE;'),







>
>
>
>
>







42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
	 * Return all accounts from current chart
	 */
	public function listAll(): array
	{
		return $this->em->all('SELECT * FROM @TABLE WHERE id_chart = ? ORDER BY code COLLATE NOCASE;',
			$this->chart_id);
	}

	public function listForCodes(array $codes): array
	{
		return DB::getInstance()->getGrouped('SELECT code, id, label FROM acc_accounts WHERE id_chart = ?;', $this->chart_id);
	}

	/**
	 * Return all accounts from current chart
	 */
	public function export(): \Generator
	{
		$res = $this->em->DB()->iterate($this->em->formatQuery('SELECT code, label, description, position, type FROM @TABLE WHERE id_chart = ? ORDER BY code COLLATE NOCASE;'),

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

54
55
56
57
58
59
60







61
62
63
64
65
66
67









68
69
70
71
72
73
74
75
76
77


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');







>
>
>
>
>
>
>






|
>
>
>
>
>
>
>
>
>










54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93


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

	if ($previous_year->id_chart != $year->id_chart) {
		$chart_change = true;
		$codes = [];

		foreach ($lines as $line) {
			$codes[] = $line->code;
		}

		$matching_accounts = $year->accounts()->listForCodes($codes);
	}

	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) {
			if (array_key_exists($line->code, $matching_accounts)) {
				$acc = $matching_accounts[$line->code];
				$line->account_selected = [$acc->id => sprintf('%s — %s', $acc->code, $acc->label)];
			}
			else {
				$line->account_selected = null;
			}
		}
		else {
			$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');