mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
This should fix #308
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
This commit is contained in:
parent
6c5cd705c0
commit
c3ccc4ccdf
@ -81,20 +81,19 @@ class CurrencyController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|View
|
||||
*/
|
||||
public function delete(CurrencyRepositoryInterface $repository, TransactionCurrency $currency)
|
||||
public function delete(TransactionCurrency $currency)
|
||||
{
|
||||
|
||||
if ($repository->countJournals($currency) > 0) {
|
||||
if (!$this->canDeleteCurrency($currency)) {
|
||||
Session::flash('error', trans('firefly.cannot_delete_currency', ['name' => $currency->name]));
|
||||
|
||||
return redirect(route('currency.index'));
|
||||
}
|
||||
|
||||
|
||||
// put previous url in session
|
||||
Session::put('currency.delete.url', URL::previous());
|
||||
Session::flash('gaEventCategory', 'currency');
|
||||
@ -106,15 +105,14 @@ class CurrencyController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function destroy(CurrencyRepositoryInterface $repository, TransactionCurrency $currency)
|
||||
public function destroy(TransactionCurrency $currency)
|
||||
{
|
||||
if ($repository->countJournals($currency) > 0) {
|
||||
if (!$this->canDeleteCurrency($currency)) {
|
||||
Session::flash('error', trans('firefly.cannot_delete_currency', ['name' => $currency->name]));
|
||||
|
||||
return redirect(route('currency.index'));
|
||||
@ -229,4 +227,39 @@ class CurrencyController extends Controller
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function canDeleteCurrency(TransactionCurrency $currency): bool
|
||||
{
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
|
||||
// has transactions still
|
||||
if ($repository->countJournals($currency) > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// is the only currency left
|
||||
if ($repository->get()->count() === 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// is the default currency for the user or the system
|
||||
$defaultCode = Preferences::get('currencyPreference', env('DEFAULT_CURRENCY', 'EUR'))->data;
|
||||
if ($currency->code === $defaultCode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// is the default currency for the system
|
||||
$defaultSystemCode = env('DEFAULT_CURRENCY', 'EUR');
|
||||
if ($currency->code === $defaultSystemCode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// can be deleted
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ return [
|
||||
'store_currency' => 'Store new currency',
|
||||
'update_currency' => 'Update currency',
|
||||
'new_default_currency' => ':name is now the default currency.',
|
||||
'cannot_delete_currency' => 'Cannot delete :name because there are still transactions attached to it!',
|
||||
'cannot_delete_currency' => 'Cannot delete :name because it is still in use.',
|
||||
'deleted_currency' => 'Currency :name deleted',
|
||||
'created_currency' => 'Currency :name created',
|
||||
'updated_currency' => 'Currency :name updated',
|
||||
|
Loading…
Reference in New Issue
Block a user