mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 09:14:08 +00:00
Currency dropdowns now display the most-traded currencies (USD, EUR, GBP, JPY, CAD, AUD, CHF, CNY, INR, BRL) at the top, followed by the rest alphabetically. The install wizard defaults to USD instead of EUR and formats currency names as "USD - US Dollar" for consistency with the rest of the app.
30 lines
814 B
PHP
30 lines
814 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Currency;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
class CurrencyService
|
|
{
|
|
/**
|
|
* Retrieve all currencies with commonly-used currencies sorted first.
|
|
*
|
|
* @return Collection<int, Currency>
|
|
*/
|
|
public function getAllWithCommonFirst(): Collection
|
|
{
|
|
$currencies = Currency::query()->get();
|
|
|
|
$commonCodes = Currency::COMMON_CURRENCY_CODES;
|
|
|
|
$common = $currencies->filter(fn (Currency $c): bool => in_array($c->code, $commonCodes, true))
|
|
->sortBy(fn (Currency $c): int => array_search($c->code, $commonCodes));
|
|
|
|
$rest = $currencies->reject(fn (Currency $c): bool => in_array($c->code, $commonCodes, true))
|
|
->sortBy('name');
|
|
|
|
return $common->concat($rest)->values();
|
|
}
|
|
}
|