Only show currencies in TransactionWizard component of which conversion rate is present
MODIFY
app/Http/Controllers/TransactionController.php
app/Http/Controllers/TransactionController.php
@@ -50,7 +50,7 @@ class TransactionController extends Controller
return view('transactions.create', [
'tags' => $tags,
- 'currencies' => $this->currencyRepository->getAll(),
+ 'currencies' => $this->currencyRepository->getIfConversionRatePresent(),
'defaultCurrencyId' => session('space')->currency_id,
'recurringsIntervals' => $this->recurringRepository->getSupportedIntervals()
]);

MODIFY
app/Repositories/CurrencyRepository.php
app/Repositories/CurrencyRepository.php
namespace App\Repositories;
use App\Models\Currency;
+use Illuminate\Database\Eloquent\Collection;
class CurrencyRepository
{
@@ -11,6 +12,18 @@ class CurrencyRepository
return Currency::all();
}
+ public function getIfConversionRatePresent(): Collection
+ {
+ $spaceCurrencyId = [session('space')->currency_id];
+
+ return Currency::select('currencies.*')
+ ->leftJoin('conversion_rates AS cr', 'cr.base_currency_id', '=', 'currencies.id')
+ ->where('cr.target_currency_id', $spaceCurrencyId)
+ ->orWhere('currencies.id', $spaceCurrencyId)
+ ->groupBy('currencies.id')
+ ->get();
+ }
+
public function getKeyValueArray(): array
{
$response = [];

Only show currencies in TransactionWizard component of which conversion rate is present