mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-19 02:52:44 +00:00
Fix #1198
This commit is contained in:
@@ -22,8 +22,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
use Steam;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class SplitJournalFormRequest.
|
* Class SplitJournalFormRequest.
|
||||||
*/
|
*/
|
||||||
@@ -77,13 +75,14 @@ class SplitJournalFormRequest extends Request
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$foreignAmount = $transaction['foreign_amount'] ?? null;
|
$foreignAmount = $transaction['foreign_amount'] ?? null;
|
||||||
|
$foreignCurrencyId = intval($transaction['foreign_currency_id'] ?? 0);
|
||||||
$set = [
|
$set = [
|
||||||
'source_id' => $sourceId,
|
'source_id' => $sourceId,
|
||||||
'source_name' => $sourceName,
|
'source_name' => $sourceName,
|
||||||
'destination_id' => $destinationId,
|
'destination_id' => $destinationId,
|
||||||
'destination_name' => $destinationName,
|
'destination_name' => $destinationName,
|
||||||
'foreign_amount' => $foreignAmount,
|
'foreign_amount' => $foreignAmount,
|
||||||
'foreign_currency_id' => null,
|
'foreign_currency_id' => $foreignCurrencyId,
|
||||||
'foreign_currency_code' => null,
|
'foreign_currency_code' => null,
|
||||||
'reconciled' => false,
|
'reconciled' => false,
|
||||||
'identifier' => $index,
|
'identifier' => $index,
|
||||||
|
@@ -258,6 +258,8 @@ trait TransactionServiceTrait
|
|||||||
protected function setForeignCurrency(Transaction $transaction, ?TransactionCurrency $currency): void
|
protected function setForeignCurrency(Transaction $transaction, ?TransactionCurrency $currency): void
|
||||||
{
|
{
|
||||||
if (is_null($currency)) {
|
if (is_null($currency)) {
|
||||||
|
$transaction->foreign_currency_id = null;
|
||||||
|
$transaction->save();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$transaction->foreign_currency_id = $currency->id;
|
$transaction->foreign_currency_id = $currency->id;
|
||||||
|
@@ -107,11 +107,11 @@ class TransactionUpdateService
|
|||||||
// set foreign currency
|
// set foreign currency
|
||||||
$foreign = $this->findCurrency($data['foreign_currency_id'], $data['foreign_currency_code']);
|
$foreign = $this->findCurrency($data['foreign_currency_id'], $data['foreign_currency_code']);
|
||||||
// set foreign amount:
|
// set foreign amount:
|
||||||
if (!is_null($data['foreign_amount'])) {
|
if (!is_null($data['foreign_amount']) && !is_null($foreign)) {
|
||||||
$this->setForeignCurrency($transaction, $foreign);
|
$this->setForeignCurrency($transaction, $foreign);
|
||||||
$this->setForeignAmount($transaction, $foreignAmount);
|
$this->setForeignAmount($transaction, $foreignAmount);
|
||||||
}
|
}
|
||||||
if (is_null($data['foreign_amount'])) {
|
if (is_null($data['foreign_amount']) || is_null($foreign)) {
|
||||||
$this->setForeignCurrency($transaction, null);
|
$this->setForeignCurrency($transaction, null);
|
||||||
$this->setForeignAmount($transaction, null);
|
$this->setForeignAmount($transaction, null);
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,7 @@ use FireflyIII\Models\Transaction as TransactionModel;
|
|||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use Lang;
|
use Lang;
|
||||||
|
use Log;
|
||||||
use Twig_Extension;
|
use Twig_Extension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -223,6 +224,7 @@ class Transaction extends Twig_Extension
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* TODO improve code
|
||||||
* @param TransactionModel $transaction
|
* @param TransactionModel $transaction
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
@@ -249,14 +251,19 @@ class Transaction extends Twig_Extension
|
|||||||
// if the amount is negative, find the opposing account and use that one:
|
// if the amount is negative, find the opposing account and use that one:
|
||||||
$journalId = $transaction->journal_id;
|
$journalId = $transaction->journal_id;
|
||||||
/** @var TransactionModel $other */
|
/** @var TransactionModel $other */
|
||||||
$other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id)
|
$other = TransactionModel
|
||||||
->where('amount', '=', bcmul($transaction->transaction_amount, '-1'))->where(
|
::where('transaction_journal_id', $journalId)
|
||||||
'identifier',
|
->where('transactions.id', '!=', $transaction->id)
|
||||||
$transaction->identifier
|
->where('amount', '=', bcmul($transaction->transaction_amount, '-1'))
|
||||||
)
|
->where('identifier', $transaction->identifier)
|
||||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||||
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
|
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
|
||||||
|
if (is_null($other)) {
|
||||||
|
Log::error(sprintf('Cannot find other transaction for journal #%d', $journalId));
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
$name = app('steam')->tryDecrypt($other->name);
|
$name = app('steam')->tryDecrypt($other->name);
|
||||||
$transactionId = $other->account_id;
|
$transactionId = $other->account_id;
|
||||||
$type = $other->type;
|
$type = $other->type;
|
||||||
|
Reference in New Issue
Block a user