mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-10 12:24:50 +00:00
Clean up code and comments.
This commit is contained in:
@@ -74,60 +74,6 @@ trait ConvertsExchangeRates
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a sum of entries, get the exchange rate to the native currency of
|
||||
* the user.
|
||||
* @param array $entries
|
||||
* @return array
|
||||
*/
|
||||
public function cerSum(array $entries): array
|
||||
{
|
||||
if (null === $this->enabled) {
|
||||
$this->getPreference();
|
||||
}
|
||||
|
||||
// if false, return the same array without conversion info
|
||||
if (false === $this->enabled) {
|
||||
$return = [];
|
||||
/** @var array $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$entry['converted'] = false;
|
||||
$return[] = $entry;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/** @var TransactionCurrency $native */
|
||||
$native = app('amount')->getDefaultCurrency();
|
||||
$return = [];
|
||||
/** @var array $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$currency = $this->getCurrency((int)$entry['id']);
|
||||
if ($currency->id !== $native->id) {
|
||||
$amount = $this->convertAmount($entry['sum'], $currency, $native);
|
||||
$entry['converted'] = true;
|
||||
$entry['native_sum'] = $amount;
|
||||
$entry['native_id'] = (string)$native->id;
|
||||
$entry['native_name'] = $native->name;
|
||||
$entry['native_symbol'] = $native->symbol;
|
||||
$entry['native_code'] = $native->code;
|
||||
$entry['native_decimal_places'] = $native->decimal_places;
|
||||
}
|
||||
if ($currency->id === $native->id) {
|
||||
$entry['converted'] = false;
|
||||
$entry['native_sum'] = $entry['sum'];
|
||||
$entry['native_id'] = (string)$native->id;
|
||||
$entry['native_name'] = $native->name;
|
||||
$entry['native_symbol'] = $native->symbol;
|
||||
$entry['native_code'] = $native->code;
|
||||
$entry['native_decimal_places'] = $native->decimal_places;
|
||||
}
|
||||
$return[] = $entry;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@@ -149,15 +95,6 @@ trait ConvertsExchangeRates
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function convertAmount(string $amount, TransactionCurrency $from, TransactionCurrency $to, ?Carbon $date = null): string
|
||||
{
|
||||
Log::debug(sprintf('Converting %s from %s to %s', $amount, $from->code, $to->code));
|
||||
$date = $date ?? today(config('app.timezone'));
|
||||
$rate = $this->getRate($from, $to, $date);
|
||||
|
||||
return bcmul($amount, $rate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $from
|
||||
* @param TransactionCurrency $to
|
||||
@@ -260,4 +197,67 @@ trait ConvertsExchangeRates
|
||||
Log::debug(sprintf('No rate for %s to EUR.', $currency->code));
|
||||
return '0';
|
||||
}
|
||||
|
||||
/**
|
||||
* For a sum of entries, get the exchange rate to the native currency of
|
||||
* the user.
|
||||
* @param array $entries
|
||||
* @return array
|
||||
*/
|
||||
public function cerSum(array $entries): array
|
||||
{
|
||||
if (null === $this->enabled) {
|
||||
$this->getPreference();
|
||||
}
|
||||
|
||||
// if false, return the same array without conversion info
|
||||
if (false === $this->enabled) {
|
||||
$return = [];
|
||||
/** @var array $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$entry['converted'] = false;
|
||||
$return[] = $entry;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/** @var TransactionCurrency $native */
|
||||
$native = app('amount')->getDefaultCurrency();
|
||||
$return = [];
|
||||
/** @var array $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$currency = $this->getCurrency((int)$entry['id']);
|
||||
if ($currency->id !== $native->id) {
|
||||
$amount = $this->convertAmount($entry['sum'], $currency, $native);
|
||||
$entry['converted'] = true;
|
||||
$entry['native_sum'] = $amount;
|
||||
$entry['native_id'] = (string)$native->id;
|
||||
$entry['native_name'] = $native->name;
|
||||
$entry['native_symbol'] = $native->symbol;
|
||||
$entry['native_code'] = $native->code;
|
||||
$entry['native_decimal_places'] = $native->decimal_places;
|
||||
}
|
||||
if ($currency->id === $native->id) {
|
||||
$entry['converted'] = false;
|
||||
$entry['native_sum'] = $entry['sum'];
|
||||
$entry['native_id'] = (string)$native->id;
|
||||
$entry['native_name'] = $native->name;
|
||||
$entry['native_symbol'] = $native->symbol;
|
||||
$entry['native_code'] = $native->code;
|
||||
$entry['native_decimal_places'] = $native->decimal_places;
|
||||
}
|
||||
$return[] = $entry;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
private function convertAmount(string $amount, TransactionCurrency $from, TransactionCurrency $to, ?Carbon $date = null): string
|
||||
{
|
||||
Log::debug(sprintf('Converting %s from %s to %s', $amount, $from->code, $to->code));
|
||||
$date = $date ?? today(config('app.timezone'));
|
||||
$rate = $this->getRate($from, $to, $date);
|
||||
|
||||
return bcmul($amount, $rate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,6 @@ trait ModelInformation
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
*
|
||||
* @return string[]
|
||||
*
|
||||
@@ -95,7 +94,6 @@ trait ModelInformation
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* @return array
|
||||
*/
|
||||
protected function getRoles(): array
|
||||
|
||||
@@ -200,7 +200,6 @@ trait PeriodOverview
|
||||
* @param array $journals
|
||||
*
|
||||
* @return array
|
||||
|
||||
*/
|
||||
private function filterTransferredIn(Account $account, array $journals): array
|
||||
{
|
||||
@@ -219,7 +218,6 @@ trait PeriodOverview
|
||||
* @param array $journals
|
||||
*
|
||||
* @return array
|
||||
|
||||
*/
|
||||
private function groupByCurrency(array $journals): array
|
||||
{
|
||||
|
||||
@@ -24,7 +24,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Exceptions\ValidationException;
|
||||
use FireflyIII\Helpers\Help\HelpInterface;
|
||||
use FireflyIII\Http\Requests\RuleFormRequest;
|
||||
@@ -219,7 +218,6 @@ trait RequestInformation
|
||||
* @param array $data
|
||||
*
|
||||
* @return ValidatorContract
|
||||
|
||||
*/
|
||||
final protected function validator(array $data): ValidatorContract
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user