Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Merge remote-tracking branch 'upstream/develop' into fix-transfer-sign
Florian Dupret294cda7f3351
diff --cc app/Support/Twig/TransactionGroupTwig.phpindex 81329b4ccf,5c7c09679c..e23a0902fe--- a/app/Support/Twig/TransactionGroupTwig.php+++ b/app/Support/Twig/TransactionGroupTwig.php@@@ -277,15 -270,26 +277,21 @@@ class TransactionGroupTwig extends Abst** @return string*/- private function normalJournalArrayAmount(array $array): string+ private function normalJournalArrayAmount(array $journal, Account $account): string{- $type = $array['transaction_type_type'] ?? TransactionType::WITHDRAWAL;- $amount = $array['amount'] ?? '0';+ $type = $journal['transaction_type_type'] ?? TransactionType::WITHDRAWAL;+ $amount = $journal['amount'] ?? '0';$colored = true;+ $destinationType = $journal['destination_account_type'] ?? 'invalid';+ $sourceAccountId = $journal['source_account_id'];+ $amount = $this->signAmount($amount, $type, $destinationType, $sourceAccountId, $account->id);++ // withdrawals are negative+ if ($type !== TransactionType::WITHDRAWAL) {+ $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) {$colored = false;}@@@ -337,26 -341,4 +343,30 @@@return null !== $first->foreign_amount;}++ static function signAmount(string $amount, string $type, string $destinationType = null, int $sourceAccountId = null, int $displayedAccountId = null): string {++ // withdrawals stay negative+ if ($type !== TransactionType::WITHDRAWAL) {+ $amount = bcmul($amount, '-1');+ }+- // negative opening balance- if ($type === TransactionType::OPENING_BALANCE)- if (AccountType::INITIAL_BALANCE === $destinationType) {++ // opening balance and it goes to initial balance? its expense.++ if ($type === TransactionType::OPENING_BALANCE && AccountType::INITIAL_BALANCE === $destinationType) {+ $amount = bcmul($amount, '-1');+ }++ // transfers stay negative from source point of view+ if ($type === TransactionType::TRANSFER+ && !is_null($sourceAccountId) && $sourceAccountId === $displayedAccountId) {+ $amount = bcmul($amount, '-1');+ }+++ // reconciliation and it goes to reconciliation?++ if ($type === TransactionType::RECONCILIATION && AccountType::RECONCILIATION === $destinationType) {++ $amount = bcmul($amount, '-1');++ }+++ return $amount;+ }}