mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 18:02:34 +00:00
Fix some cases in loans
This commit is contained in:
@@ -72,11 +72,8 @@ class CreditRecalculateService
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->processWork();
|
|
||||||
|
|
||||||
|
|
||||||
Log::debug('Will now do CreditRecalculationService');
|
Log::debug('Will now do CreditRecalculationService');
|
||||||
// do something
|
$this->processWork();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,7 +108,7 @@ class CreditRecalculateService
|
|||||||
$transactions = $account->transactions()->get();
|
$transactions = $account->transactions()->get();
|
||||||
/** @var Transaction $transaction */
|
/** @var Transaction $transaction */
|
||||||
foreach ($transactions as $transaction) {
|
foreach ($transactions as $transaction) {
|
||||||
$leftOfDebt = $this->processTransaction($transaction, $leftOfDebt);
|
$leftOfDebt = $this->processTransaction($account, $transaction, $leftOfDebt);
|
||||||
}
|
}
|
||||||
$factory->crud($account, 'current_debt', $leftOfDebt);
|
$factory->crud($account, 'current_debt', $leftOfDebt);
|
||||||
|
|
||||||
@@ -242,13 +239,28 @@ class CreditRecalculateService
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function processTransaction(Transaction $transaction, string $amount): string
|
private function processTransaction(Account $account, Transaction $transaction, string $amount): string
|
||||||
{
|
{
|
||||||
|
Log::debug(sprintf('Now in %s(#%d, %s)', __METHOD__, $transaction->id, $amount));
|
||||||
$journal = $transaction->transactionJournal;
|
$journal = $transaction->transactionJournal;
|
||||||
$type = $journal->transactionType->type;
|
$type = $journal->transactionType->type;
|
||||||
|
|
||||||
|
Log::debug(sprintf('Type is "%s"', $type));
|
||||||
|
if (in_array($type, [TransactionType::WITHDRAWAL]) && (int)$account->id === (int)$transaction->account_id && 1 === bccomp($transaction->amount, '0')) {
|
||||||
|
Log::debug(sprintf('Transaction #%d is withdrawal into liability #%d, does not influence the amount left.', $account->id, $transaction->account_id));
|
||||||
|
|
||||||
|
return $amount;
|
||||||
|
}
|
||||||
|
if (in_array($type, [TransactionType::DEPOSIT]) && (int)$account->id === (int)$transaction->account_id && -1 === bccomp($transaction->amount, '0')) {
|
||||||
|
Log::debug(sprintf('Transaction #%d is deposit from liability #%d,does not influence the amount left.', $account->id, $transaction->account_id));
|
||||||
|
|
||||||
|
return $amount;
|
||||||
|
}
|
||||||
|
|
||||||
if (in_array($type, [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER], true)) {
|
if (in_array($type, [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER], true)) {
|
||||||
$amount = bcadd($amount, bcmul($transaction->amount, '-1'));
|
$amount = bcadd($amount, bcmul($transaction->amount, '-1'));
|
||||||
}
|
}
|
||||||
|
Log::debug(sprintf('Amount is now %s', $amount));
|
||||||
|
|
||||||
return $amount;
|
return $amount;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,11 +139,13 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td style=" {{ style|raw }}">
|
<td style=" {{ style|raw }}">
|
||||||
|
{# deposit #}
|
||||||
{% if transaction.transaction_type_type == 'Deposit' %}
|
{% if transaction.transaction_type_type == 'Deposit' %}
|
||||||
{{ formatAmountBySymbol(transaction.amount*-1, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
{{ formatAmountBySymbol(transaction.amount*-1, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
||||||
{% if null != transaction.foreign_amount %}
|
{% if null != transaction.foreign_amount %}
|
||||||
({{ formatAmountBySymbol(transaction.foreign_amount*-1, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
|
({{ formatAmountBySymbol(transaction.foreign_amount*-1, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{# transfer #}
|
||||||
{% elseif transaction.transaction_type_type == 'Transfer' %}
|
{% elseif transaction.transaction_type_type == 'Transfer' %}
|
||||||
<span class="text-info">
|
<span class="text-info">
|
||||||
{{ formatAmountBySymbol(transaction.amount*-1, transaction.currency_symbol, transaction.currency_decimal_places, false) }}
|
{{ formatAmountBySymbol(transaction.amount*-1, transaction.currency_symbol, transaction.currency_decimal_places, false) }}
|
||||||
@@ -151,6 +153,7 @@
|
|||||||
({{ formatAmountBySymbol(transaction.foreign_amount*-1, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places, false) }})
|
({{ formatAmountBySymbol(transaction.foreign_amount*-1, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places, false) }})
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
|
{# opening balance #}
|
||||||
{% elseif transaction.transaction_type_type == 'Opening balance' %}
|
{% elseif transaction.transaction_type_type == 'Opening balance' %}
|
||||||
{% if transaction.source_account_type == 'Initial balance account' %}
|
{% if transaction.source_account_type == 'Initial balance account' %}
|
||||||
{{ formatAmountBySymbol(transaction.amount*-1, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
{{ formatAmountBySymbol(transaction.amount*-1, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
||||||
@@ -163,6 +166,7 @@
|
|||||||
({{ formatAmountBySymbol(transaction.foreign_amount, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
|
({{ formatAmountBySymbol(transaction.foreign_amount, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{# reconciliation #}
|
||||||
{% elseif transaction.transaction_type_type == 'Reconciliation' %}
|
{% elseif transaction.transaction_type_type == 'Reconciliation' %}
|
||||||
{% if transaction.source_account_type == 'Reconciliation account' %}
|
{% if transaction.source_account_type == 'Reconciliation account' %}
|
||||||
{{ formatAmountBySymbol(transaction.amount*-1, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
{{ formatAmountBySymbol(transaction.amount*-1, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
||||||
@@ -175,6 +179,22 @@
|
|||||||
({{ formatAmountBySymbol(transaction.foreign_amount, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
|
({{ formatAmountBySymbol(transaction.foreign_amount, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{# liability credit #}
|
||||||
|
{% elseif transaction.transaction_type_type == 'Liability credit' %}
|
||||||
|
{% if transaction.source_account_type == 'Liability credit' %}
|
||||||
|
{{ formatAmountBySymbol(transaction.amount, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
||||||
|
{% if null != transaction.foreign_amount %}
|
||||||
|
({{ formatAmountBySymbol(transaction.foreign_amount, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
{{ formatAmountBySymbol(transaction.amount*-1, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
||||||
|
{% if null != transaction.foreign_amount %}
|
||||||
|
({{ formatAmountBySymbol(transaction.foreign_amount*-1, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
{# THE REST #}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ formatAmountBySymbol(transaction.amount, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
{{ formatAmountBySymbol(transaction.amount, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
||||||
{% if null != transaction.foreign_amount %}
|
{% if null != transaction.foreign_amount %}
|
||||||
|
|||||||
Reference in New Issue
Block a user