mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Initial user ability to set foreign currency
This commit is contained in:
@@ -15,6 +15,7 @@ use Amount;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -29,7 +30,6 @@ use Session;
|
||||
*/
|
||||
class JavascriptController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param CurrencyRepositoryInterface $currencyRepository
|
||||
@@ -50,7 +50,7 @@ class JavascriptController extends Controller
|
||||
$accountId = $account->id;
|
||||
$currency = intval($account->getMeta('currency_id'));
|
||||
$currency = $currency === 0 ? $default->id : $currency;
|
||||
$entry = ['preferredCurrency' => $currency];
|
||||
$entry = ['preferredCurrency' => $currency, 'name' => $account->name];
|
||||
$data['accounts'][$accountId] = $entry;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,27 @@ class JavascriptController extends Controller
|
||||
->header('Content-Type', 'text/javascript');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function currencies(CurrencyRepositoryInterface $repository)
|
||||
{
|
||||
$currencies = $repository->get();
|
||||
$data = ['currencies' => [],];
|
||||
/** @var TransactionCurrency $currency */
|
||||
foreach ($currencies as $currency) {
|
||||
$currencyId = $currency->id;
|
||||
$entry = ['name' => $currency->name, 'code' => $currency->code, 'symbol' => $currency->symbol];
|
||||
$data['currencies'][$currencyId] = $entry;
|
||||
}
|
||||
|
||||
return response()
|
||||
->view('javascript.currencies', $data, 200)
|
||||
->header('Content-Type', 'text/javascript');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
|
@@ -14,10 +14,12 @@ namespace FireflyIII\Http\Controllers\Json;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\CurrencyExchangeRate;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Services\Currency\ExchangeRateInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
use Response;
|
||||
|
||||
/**
|
||||
@@ -42,6 +44,7 @@ class ExchangeController extends Controller
|
||||
$rate = $repository->getExchangeRate($fromCurrency, $toCurrency, $date);
|
||||
$amount = null;
|
||||
if (is_null($rate->id)) {
|
||||
Log::debug(sprintf('No cached exchange rate in database for %s to %s on %s', $fromCurrency->code, $toCurrency->code, $date->format('Y-m-d')));
|
||||
$preferred = env('EXCHANGE_RATE_SERVICE', config('firefly.preferred_exchange_service'));
|
||||
$class = config('firefly.currency_exchange_services.' . $preferred);
|
||||
/** @var ExchangeRateInterface $object */
|
||||
@@ -53,7 +56,9 @@ class ExchangeController extends Controller
|
||||
$return['amount'] = null;
|
||||
if (!is_null($request->get('amount'))) {
|
||||
// assume amount is in "from" currency:
|
||||
$return['amount'] = bcmul($request->get('amount'), strval($rate->rate));
|
||||
$return['amount'] = bcmul($request->get('amount'), strval($rate->rate), 12);
|
||||
// round to toCurrency decimal places:
|
||||
$return['amount'] = round($return['amount'], $toCurrency->decimal_places);
|
||||
}
|
||||
|
||||
return Response::json($return);
|
||||
|
Reference in New Issue
Block a user