mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 12:11:19 +00:00
Various code cleanup.
This commit is contained in:
@@ -55,11 +55,11 @@ class Amount
|
||||
|
||||
// there are five possible positions for the "+" or "-" sign (if it is even used)
|
||||
// pos_a and pos_e could be the ( and ) symbol.
|
||||
$pos_a = ''; // before everything
|
||||
$pos_b = ''; // before currency symbol
|
||||
$pos_c = ''; // after currency symbol
|
||||
$pos_d = ''; // before amount
|
||||
$pos_e = ''; // after everything
|
||||
$posA = ''; // before everything
|
||||
$posB = ''; // before currency symbol
|
||||
$posC = ''; // after currency symbol
|
||||
$posD = ''; // before amount
|
||||
$posE = ''; // after everything
|
||||
|
||||
// format would be (currency before amount)
|
||||
// AB%sC_D%vE
|
||||
@@ -73,32 +73,32 @@ class Amount
|
||||
default:
|
||||
case 0:
|
||||
// ( and ) around the whole thing
|
||||
$pos_a = '(';
|
||||
$pos_e = ')';
|
||||
$posA = '(';
|
||||
$posE = ')';
|
||||
break;
|
||||
case 1:
|
||||
// The sign string precedes the quantity and currency_symbol
|
||||
$pos_a = $sign;
|
||||
$posA = $sign;
|
||||
break;
|
||||
case 2:
|
||||
// The sign string succeeds the quantity and currency_symbol
|
||||
$pos_e = $sign;
|
||||
$posE = $sign;
|
||||
break;
|
||||
case 3:
|
||||
// The sign string immediately precedes the currency_symbol
|
||||
$pos_b = $sign;
|
||||
$posB = $sign;
|
||||
break;
|
||||
case 4:
|
||||
// The sign string immediately succeeds the currency_symbol
|
||||
$pos_c = $sign;
|
||||
$posC = $sign;
|
||||
}
|
||||
|
||||
// default is amount before currency
|
||||
$format = $pos_a . $pos_d . '%v' . $space . $pos_b . '%s' . $pos_c . $pos_e;
|
||||
$format = $posA . $posD . '%v' . $space . $posB . '%s' . $posC . $posE;
|
||||
|
||||
if ($csPrecedes) {
|
||||
// alternative is currency before amount
|
||||
$format = $pos_a . $pos_b . '%s' . $pos_c . $space . $pos_d . '%v' . $pos_e;
|
||||
$format = $posA . $posB . '%s' . $posC . $space . $posD . '%v' . $posE;
|
||||
}
|
||||
|
||||
return $format;
|
||||
|
@@ -258,10 +258,10 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
if ($response->status_code !== 200) {
|
||||
throw new FireflyException(sprintf('Could not retrieve external IP: %d %s', $response->status_code, $response->body));
|
||||
}
|
||||
$ip = $response->body;
|
||||
Preferences::setForUser($this->user, 'external_ip', $ip);
|
||||
$serverIp = $response->body;
|
||||
Preferences::setForUser($this->user, 'external_ip', $serverIp);
|
||||
|
||||
return $ip;
|
||||
return $serverIp;
|
||||
}
|
||||
|
||||
return $preference->data;
|
||||
|
@@ -204,8 +204,8 @@ class Search implements SearchInterface
|
||||
// first "modifier" is always the text of the search:
|
||||
// check descr of journal:
|
||||
if (count($this->words) > 0
|
||||
&& !$this->strpos_arr(strtolower(strval($transaction->description)), $this->words)
|
||||
&& !$this->strpos_arr(strtolower(strval($transaction->transaction_description)), $this->words)
|
||||
&& !$this->strposArray(strtolower(strval($transaction->description)), $this->words)
|
||||
&& !$this->strposArray(strtolower(strval($transaction->transaction_description)), $this->words)
|
||||
) {
|
||||
Log::debug('Description does not match', $this->words);
|
||||
|
||||
@@ -230,7 +230,7 @@ class Search implements SearchInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function strpos_arr(string $haystack, array $needle)
|
||||
private function strposArray(string $haystack, array $needle)
|
||||
{
|
||||
if (strlen($haystack) === 0) {
|
||||
return false;
|
||||
|
@@ -119,16 +119,15 @@ class Transaction extends Twig_Extension
|
||||
return new Twig_SimpleFunction(
|
||||
'transactionDestinationAccount', function (TransactionModel $transaction): string {
|
||||
|
||||
$name = Steam::decrypt(intval($transaction->account_encrypted), $transaction->account_name);
|
||||
$id = intval($transaction->account_id);
|
||||
$type = $transaction->account_type;
|
||||
$name = Steam::decrypt(intval($transaction->account_encrypted), $transaction->account_name);
|
||||
$transactionId = intval($transaction->account_id);
|
||||
$type = $transaction->account_type;
|
||||
|
||||
// name is present in object, use that one:
|
||||
if (bccomp($transaction->transaction_amount, '0') === -1 && !is_null($transaction->opposing_account_id)) {
|
||||
|
||||
$name = $transaction->opposing_account_name;
|
||||
$id = intval($transaction->opposing_account_id);
|
||||
$type = $transaction->opposing_account_type;
|
||||
$name = $transaction->opposing_account_name;
|
||||
$transactionId = intval($transaction->opposing_account_id);
|
||||
$type = $transaction->opposing_account_type;
|
||||
}
|
||||
|
||||
// Find the opposing account and use that one:
|
||||
@@ -136,21 +135,23 @@ class Transaction extends Twig_Extension
|
||||
// if the amount is negative, find the opposing account and use that one:
|
||||
$journalId = $transaction->journal_id;
|
||||
/** @var TransactionModel $other */
|
||||
$other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id)
|
||||
->where('amount', '=', bcmul($transaction->transaction_amount, '-1'))->where('identifier', $transaction->identifier)
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
|
||||
$name = Steam::decrypt(intval($other->encrypted), $other->name);
|
||||
$id = $other->account_id;
|
||||
$type = $other->type;
|
||||
$other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id)
|
||||
->where('amount', '=', bcmul($transaction->transaction_amount, '-1'))->where(
|
||||
'identifier', $transaction->identifier
|
||||
)
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
|
||||
$name = Steam::decrypt(intval($other->encrypted), $other->name);
|
||||
$transactionId = $other->account_id;
|
||||
$type = $other->type;
|
||||
}
|
||||
|
||||
if ($type === AccountType::CASH) {
|
||||
return '<span class="text-success">(cash)</span>';
|
||||
}
|
||||
|
||||
return sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($name), route('accounts.show', [$id]));
|
||||
return sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($name), route('accounts.show', [$transactionId]));
|
||||
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
@@ -193,36 +194,37 @@ class Transaction extends Twig_Extension
|
||||
'transactionSourceAccount', function (TransactionModel $transaction): string {
|
||||
|
||||
// if the amount is negative, assume that the current account (the one in $transaction) is indeed the source account.
|
||||
$name = Steam::decrypt(intval($transaction->account_encrypted), $transaction->account_name);
|
||||
$id = intval($transaction->account_id);
|
||||
$type = $transaction->account_type;
|
||||
$name = Steam::decrypt(intval($transaction->account_encrypted), $transaction->account_name);
|
||||
$transactionId = intval($transaction->account_id);
|
||||
$type = $transaction->account_type;
|
||||
|
||||
// name is present in object, use that one:
|
||||
if (bccomp($transaction->transaction_amount, '0') === 1 && !is_null($transaction->opposing_account_id)) {
|
||||
|
||||
$name = $transaction->opposing_account_name;
|
||||
$id = intval($transaction->opposing_account_id);
|
||||
$type = $transaction->opposing_account_type;
|
||||
$name = $transaction->opposing_account_name;
|
||||
$transactionId = intval($transaction->opposing_account_id);
|
||||
$type = $transaction->opposing_account_type;
|
||||
}
|
||||
// Find the opposing account and use that one:
|
||||
if (bccomp($transaction->transaction_amount, '0') === 1 && is_null($transaction->opposing_account_id)) {
|
||||
$journalId = $transaction->journal_id;
|
||||
/** @var TransactionModel $other */
|
||||
$other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id)
|
||||
->where('amount', '=', bcmul($transaction->transaction_amount, '-1'))->where('identifier', $transaction->identifier)
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
|
||||
$name = Steam::decrypt(intval($other->encrypted), $other->name);
|
||||
$id = $other->account_id;
|
||||
$type = $other->type;
|
||||
$other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id)
|
||||
->where('amount', '=', bcmul($transaction->transaction_amount, '-1'))->where(
|
||||
'identifier', $transaction->identifier
|
||||
)
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
|
||||
$name = Steam::decrypt(intval($other->encrypted), $other->name);
|
||||
$transactionId = $other->account_id;
|
||||
$type = $other->type;
|
||||
}
|
||||
|
||||
if ($type === AccountType::CASH) {
|
||||
return '<span class="text-success">(cash)</span>';
|
||||
}
|
||||
|
||||
return sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($name), route('accounts.show', [$id]));
|
||||
return sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($name), route('accounts.show', [$transactionId]));
|
||||
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
|
Reference in New Issue
Block a user