Overview
Comment:Fix automatic appropriation when there's both a negative and a positive result
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable
Files: files | file ages | folders
SHA3-256: 2b9a663e6e89596ff06e08fe75e59631bd3a2a2a09f6cec5595dedf39c2fd048
User & Date: bohwaz on 2022-12-09 14:29:46
Other Links: manifest | tags
Context
2022-12-09
16:22
Fix skriv help check-in: c7afa191ac user: bohwaz tags: trunk, stable
14:29
Fix automatic appropriation when there's both a negative and a positive result check-in: 2b9a663e6e user: bohwaz tags: trunk, stable
14:13
Fix last sent in emails, where it failed in some cases check-in: d39cc2cbb7 user: bohwaz tags: trunk, stable
Changes

Modified src/include/lib/Garradin/Accounting/Years.php from [8d6a84de42] to [dd4bd35675].

78
79
80
81
82
83
84
85
86
87

88
89
90
91
92

93

94
95
96
97
98
99
100
	}

	static public function count()
	{
		return DB::getInstance()->count(Year::TABLE);
	}

	static public function list(bool $reverse = false)
	{
		$desc = $reverse ? 'DESC' : '';

		return DB::getInstance()->get(sprintf('SELECT y.*,
			(SELECT COUNT(*) FROM acc_transactions WHERE id_year = y.id) AS nb_transactions,
			c.label AS chart_name
			FROM acc_years y
			INNER JOIN acc_charts c ON c.id = y.id_chart

			ORDER BY end_date %s;', $desc));

	}

	static public function listLastTransactions(int $count, array $years): array
	{
		$out = [];

		foreach ($years as $year) {







|


>
|




>
|
>







78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
	}

	static public function count()
	{
		return DB::getInstance()->count(Year::TABLE);
	}

	static public function list(bool $reverse = false, ?int $except_id = null)
	{
		$desc = $reverse ? 'DESC' : '';
		$except = $except_id ? ' AND y.id != ' . (int)$except_id : '';
		$sql = sprintf('SELECT y.*,
			(SELECT COUNT(*) FROM acc_transactions WHERE id_year = y.id) AS nb_transactions,
			c.label AS chart_name
			FROM acc_years y
			INNER JOIN acc_charts c ON c.id = y.id_chart
			WHERE 1 %s
			ORDER BY end_date %s;', $except, $desc);
		return DB::getInstance()->get($sql);
	}

	static public function listLastTransactions(int $count, array $years): array
	{
		$out = [];

		foreach ($years as $year) {
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

		if (!empty($balances[Account::TYPE_NEGATIVE_RESULT])) {
			$account = $balances[Account::TYPE_NEGATIVE_RESULT];

			$line = Line::create($account->id, abs($account->balance), 0);
			$t->addLine($line);

			$sum += $account->balance;
		}

		if (!empty($balances[Account::TYPE_POSITIVE_RESULT])) {
			$account = $balances[Account::TYPE_POSITIVE_RESULT];

			$line = Line::create($account->id, 0, abs($account->balance));
			$t->addLine($line);

			$sum -= $account->balance;
		}

		if ($sum == 0) {
			return null;
		}

		if ($sum > 0) {







|








|







166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

		if (!empty($balances[Account::TYPE_NEGATIVE_RESULT])) {
			$account = $balances[Account::TYPE_NEGATIVE_RESULT];

			$line = Line::create($account->id, abs($account->balance), 0);
			$t->addLine($line);

			$sum += abs($account->balance);
		}

		if (!empty($balances[Account::TYPE_POSITIVE_RESULT])) {
			$account = $balances[Account::TYPE_POSITIVE_RESULT];

			$line = Line::create($account->id, 0, abs($account->balance));
			$t->addLine($line);

			$sum -= abs($account->balance);
		}

		if ($sum == 0) {
			return null;
		}

		if ($sum > 0) {

Modified src/www/admin/acc/years/balance.php from [c0bad0f7dd] to [a0744ba050].

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
}, $csrf_key);


$previous_year = null;
$year_selected = f('from_year') !== null;
$chart_change = false;
$lines = [[]];
$years = Years::list(true);

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







|







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
}, $csrf_key);


$previous_year = null;
$year_selected = f('from_year') !== null;
$chart_change = false;
$lines = [[]];
$years = Years::list(true, $year->id);

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