Merge branch 'develop' of github.com:firefly-iii/firefly-iii into develop

This commit is contained in:
James Cole 2020-08-05 18:39:33 +02:00
commit dfa60ec703
4 changed files with 77 additions and 66 deletions

View File

@ -62,7 +62,7 @@ class TransactionGroupTwig extends AbstractExtension
{ {
return new TwigFunction( return new TwigFunction(
'groupAmount', 'groupAmount',
static function (array $array): string { function (array $array): string {
$sums = $array['sums']; $sums = $array['sums'];
$return = []; $return = [];
$first = reset($array['transactions']); $first = reset($array['transactions']);
@ -77,15 +77,16 @@ class TransactionGroupTwig extends AbstractExtension
foreach ($sums as $sum) { foreach ($sums as $sum) {
$amount = $sum['amount']; $amount = $sum['amount'];
// do multiplication thing. $sourceType = $first['source_account_type'] ?? 'invalid';
if ($type !== TransactionType::WITHDRAWAL) { $amount = $this->signAmount($amount, $type, $sourceType);
$amount = bcmul($amount, '-1');
}
$return[] = app('amount')->formatFlat($sum['currency_symbol'], (int)$sum['currency_decimal_places'], $amount, $colored); $return[] = app('amount')->formatFlat($sum['currency_symbol'], (int)$sum['currency_decimal_places'], $amount, $colored);
} }
$result = implode(', ', $return);
return implode(', ', $return); if ($type === TransactionType::TRANSFER) {
$result = sprintf('<span class="text-info">%s</span>', $result);
}
return $result;
}, },
['is_safe' => ['html']] ['is_safe' => ['html']]
); );
@ -194,7 +195,6 @@ class TransactionGroupTwig extends AbstractExtension
return new TwigFunction( return new TwigFunction(
'journalObjectAmount', 'journalObjectAmount',
function (TransactionJournal $journal): string { function (TransactionJournal $journal): string {
// if is not a withdrawal, amount positive.
$result = $this->normalJournalObjectAmount($journal); $result = $this->normalJournalObjectAmount($journal);
// now append foreign amount, if any. // now append foreign amount, if any.
if ($this->journalObjectHasForeign($journal)) { if ($this->journalObjectHasForeign($journal)) {
@ -220,9 +220,10 @@ class TransactionGroupTwig extends AbstractExtension
$type = $array['transaction_type_type'] ?? TransactionType::WITHDRAWAL; $type = $array['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
$amount = $array['foreign_amount'] ?? '0'; $amount = $array['foreign_amount'] ?? '0';
$colored = true; $colored = true;
if ($type !== TransactionType::WITHDRAWAL) {
$amount = bcmul($amount, '-1'); $sourceType = $array['source_account_type'] ?? 'invalid';
} $amount = $this->signAmount($amount, $type, $sourceType);
if ($type === TransactionType::TRANSFER) { if ($type === TransactionType::TRANSFER) {
$colored = false; $colored = false;
} }
@ -249,9 +250,10 @@ class TransactionGroupTwig extends AbstractExtension
$currency = $first->foreignCurrency; $currency = $first->foreignCurrency;
$amount = $first->foreign_amount ?? '0'; $amount = $first->foreign_amount ?? '0';
$colored = true; $colored = true;
if ($type !== TransactionType::WITHDRAWAL) { $sourceType = $first->account()->first()->accountType()->first()->type;
$amount = bcmul($amount, '-1');
} $amount = $this->signAmount($amount, $type, $sourceType);
if ($type === TransactionType::TRANSFER) { if ($type === TransactionType::TRANSFER) {
$colored = false; $colored = false;
} }
@ -275,20 +277,8 @@ class TransactionGroupTwig extends AbstractExtension
$type = $array['transaction_type_type'] ?? TransactionType::WITHDRAWAL; $type = $array['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
$amount = $array['amount'] ?? '0'; $amount = $array['amount'] ?? '0';
$colored = true; $colored = true;
// withdrawals are negative $sourceType = $array['source_account_type'] ?? 'invalid';
if ($type !== TransactionType::WITHDRAWAL) { $amount = $this->signAmount($amount, $type, $sourceType);
$amount = bcmul($amount, '-1');
}
$destinationType = $array['destination_account_type'] ?? 'invalid';
// opening balance and it goes to initial balance? its expense.
if ($type === TransactionType::OPENING_BALANCE && AccountType::INITIAL_BALANCE === $destinationType) {
$amount = bcmul($amount, '-1');
}
// reconciliation and it goes to reconciliation?
if ($type === TransactionType::RECONCILIATION && AccountType::RECONCILIATION === $destinationType) {
$amount = bcmul($amount, '-1');
}
if ($type === TransactionType::TRANSFER) { if ($type === TransactionType::TRANSFER) {
$colored = false; $colored = false;
@ -316,9 +306,10 @@ class TransactionGroupTwig extends AbstractExtension
$currency = $journal->transactionCurrency; $currency = $journal->transactionCurrency;
$amount = $first->amount ?? '0'; $amount = $first->amount ?? '0';
$colored = true; $colored = true;
if ($type !== TransactionType::WITHDRAWAL) { $sourceType = $first->account()->first()->accountType()->first()->type;
$amount = bcmul($amount, '-1');
} $amount = $this->signAmount($amount, $type, $sourceType);
if ($type === TransactionType::TRANSFER) { if ($type === TransactionType::TRANSFER) {
$colored = false; $colored = false;
} }
@ -341,4 +332,24 @@ class TransactionGroupTwig extends AbstractExtension
return null !== $first->foreign_amount; return null !== $first->foreign_amount;
} }
private function signAmount( string $amount, string $transactionType, string $sourceType ): string {
// withdrawals stay negative
if ($transactionType !== TransactionType::WITHDRAWAL) {
$amount = bcmul($amount, '-1');
}
// opening balance and it comes from initial balance? its expense.
if ($transactionType === TransactionType::OPENING_BALANCE && AccountType::INITIAL_BALANCE !== $sourceType) {
$amount = bcmul($amount, '-1');
}
// reconciliation and it comes from reconciliation?
if ($transactionType === TransactionType::RECONCILIATION && AccountType::RECONCILIATION !== $sourceType) {
$amount = bcmul($amount, '-1');
}
return $amount;
}
} }

60
composer.lock generated
View File

@ -1532,16 +1532,16 @@
}, },
{ {
"name": "laravel/framework", "name": "laravel/framework",
"version": "v7.22.4", "version": "v7.23.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/framework.git", "url": "https://github.com/laravel/framework.git",
"reference": "30e851a2b3a2af73fba0b7f4fa22b04260db98e7" "reference": "17cbce101f2fc78e61a6135861823563c7cfb50b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/30e851a2b3a2af73fba0b7f4fa22b04260db98e7", "url": "https://api.github.com/repos/laravel/framework/zipball/17cbce101f2fc78e61a6135861823563c7cfb50b",
"reference": "30e851a2b3a2af73fba0b7f4fa22b04260db98e7", "reference": "17cbce101f2fc78e61a6135861823563c7cfb50b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1685,7 +1685,7 @@
"framework", "framework",
"laravel" "laravel"
], ],
"time": "2020-07-27T18:25:06+00:00" "time": "2020-08-04T14:36:37+00:00"
}, },
{ {
"name": "laravel/passport", "name": "laravel/passport",
@ -2500,16 +2500,16 @@
}, },
{ {
"name": "nesbot/carbon", "name": "nesbot/carbon",
"version": "2.37.0", "version": "2.38.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/briannesbitt/Carbon.git", "url": "https://github.com/briannesbitt/Carbon.git",
"reference": "1f61206de973d67f36ce50f041c792ddac663c3e" "reference": "d8f6a6a91d1eb9304527b040500f61923e97674b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/1f61206de973d67f36ce50f041c792ddac663c3e", "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/d8f6a6a91d1eb9304527b040500f61923e97674b",
"reference": "1f61206de973d67f36ce50f041c792ddac663c3e", "reference": "d8f6a6a91d1eb9304527b040500f61923e97674b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2524,7 +2524,7 @@
"kylekatarnls/multi-tester": "^2.0", "kylekatarnls/multi-tester": "^2.0",
"phpmd/phpmd": "^2.8", "phpmd/phpmd": "^2.8",
"phpstan/extension-installer": "^1.0", "phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.30", "phpstan/phpstan": "^0.12.35",
"phpunit/phpunit": "^7.5 || ^8.0", "phpunit/phpunit": "^7.5 || ^8.0",
"squizlabs/php_codesniffer": "^3.4" "squizlabs/php_codesniffer": "^3.4"
}, },
@ -2585,7 +2585,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2020-07-28T06:04:54+00:00" "time": "2020-08-04T19:12:46+00:00"
}, },
{ {
"name": "nyholm/psr7", "name": "nyholm/psr7",
@ -4782,7 +4782,7 @@
}, },
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git", "url": "https://github.com/symfony/polyfill-ctype.git",
@ -4858,7 +4858,7 @@
}, },
{ {
"name": "symfony/polyfill-iconv", "name": "symfony/polyfill-iconv",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-iconv.git", "url": "https://github.com/symfony/polyfill-iconv.git",
@ -4935,7 +4935,7 @@
}, },
{ {
"name": "symfony/polyfill-intl-grapheme", "name": "symfony/polyfill-intl-grapheme",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-intl-grapheme.git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git",
@ -5013,16 +5013,16 @@
}, },
{ {
"name": "symfony/polyfill-intl-idn", "name": "symfony/polyfill-intl-idn",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-intl-idn.git", "url": "https://github.com/symfony/polyfill-intl-idn.git",
"reference": "bc6549d068d0160e0f10f7a5a23c7d1406b95ebe" "reference": "5dcab1bc7146cf8c1beaa4502a3d9be344334251"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/bc6549d068d0160e0f10f7a5a23c7d1406b95ebe", "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/5dcab1bc7146cf8c1beaa4502a3d9be344334251",
"reference": "bc6549d068d0160e0f10f7a5a23c7d1406b95ebe", "reference": "5dcab1bc7146cf8c1beaa4502a3d9be344334251",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -5094,11 +5094,11 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2020-07-14T12:35:20+00:00" "time": "2020-08-04T06:02:08+00:00"
}, },
{ {
"name": "symfony/polyfill-intl-normalizer", "name": "symfony/polyfill-intl-normalizer",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-intl-normalizer.git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git",
@ -5179,7 +5179,7 @@
}, },
{ {
"name": "symfony/polyfill-mbstring", "name": "symfony/polyfill-mbstring",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git", "url": "https://github.com/symfony/polyfill-mbstring.git",
@ -5256,7 +5256,7 @@
}, },
{ {
"name": "symfony/polyfill-php70", "name": "symfony/polyfill-php70",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-php70.git", "url": "https://github.com/symfony/polyfill-php70.git",
@ -5333,7 +5333,7 @@
}, },
{ {
"name": "symfony/polyfill-php72", "name": "symfony/polyfill-php72",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-php72.git", "url": "https://github.com/symfony/polyfill-php72.git",
@ -5406,7 +5406,7 @@
}, },
{ {
"name": "symfony/polyfill-php73", "name": "symfony/polyfill-php73",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-php73.git", "url": "https://github.com/symfony/polyfill-php73.git",
@ -5482,7 +5482,7 @@
}, },
{ {
"name": "symfony/polyfill-php80", "name": "symfony/polyfill-php80",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-php80.git", "url": "https://github.com/symfony/polyfill-php80.git",
@ -8691,16 +8691,16 @@
}, },
{ {
"name": "phpstan/phpstan", "name": "phpstan/phpstan",
"version": "0.12.34", "version": "0.12.35",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpstan.git", "url": "https://github.com/phpstan/phpstan.git",
"reference": "ad75388d71fb0b4a954f71a852fd989915a51cb7" "reference": "5230eb31d546e4df7aa725894d17436cb8afd5df"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/ad75388d71fb0b4a954f71a852fd989915a51cb7", "url": "https://api.github.com/repos/phpstan/phpstan/zipball/5230eb31d546e4df7aa725894d17436cb8afd5df",
"reference": "ad75388d71fb0b4a954f71a852fd989915a51cb7", "reference": "5230eb31d546e4df7aa725894d17436cb8afd5df",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -8743,7 +8743,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2020-07-30T15:31:10+00:00" "time": "2020-08-04T09:48:39+00:00"
}, },
{ {
"name": "phpstan/phpstan-deprecation-rules", "name": "phpstan/phpstan-deprecation-rules",

View File

@ -1910,9 +1910,9 @@
"dev": true "dev": true
}, },
"bootstrap": { "bootstrap": {
"version": "4.5.0", "version": "4.5.1",
"resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.5.0.tgz", "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.5.1.tgz",
"integrity": "sha512-Z93QoXvodoVslA+PWNdk23Hze4RBYIkpb5h8I2HY2Tu2h7A0LpAgLcyrhrSUyo2/Oxm2l1fRZPs1e5hnxnliXA==" "integrity": "sha512-bxUooHBSbvefnIZfjD0LE8nfdPKrtiFy2sgrxQwUZ0UpFzpjVbVMUxaGIoo9XWT4B2LG1HX6UQg0UMOakT0prQ=="
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",

View File

@ -25,7 +25,7 @@
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^5.14.0", "@fortawesome/fontawesome-free": "^5.14.0",
"@popperjs/core": "^2.4.4", "@popperjs/core": "^2.4.4",
"bootstrap": "^4.5.0", "bootstrap": "^4.5.1",
"chart.js": "^2.9.3", "chart.js": "^2.9.3",
"icheck-bootstrap": "^3.0.1", "icheck-bootstrap": "^3.0.1",
"jquery": "^3.5.1", "jquery": "^3.5.1",