Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CurrencyAccessor.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Utilities\Currency;
  3. use Akaunting\Money\Currency as ISOCurrencies;
  4. use App\Facades\Forex;
  5. use App\Models\Setting\Currency;
  6. use App\Services\CompanySettingsService;
  7. class CurrencyAccessor
  8. {
  9. public static function getForexSupportedCurrencies(): ?array
  10. {
  11. return Forex::getSupportedCurrencies();
  12. }
  13. public static function getSupportedCurrencies(): array
  14. {
  15. $forexSupportedCurrencies = self::getForexSupportedCurrencies();
  16. $allCurrencies = self::getAllCurrencies();
  17. if (empty($forexSupportedCurrencies)) {
  18. return array_keys($allCurrencies);
  19. }
  20. return array_intersect($forexSupportedCurrencies, array_keys($allCurrencies));
  21. }
  22. public static function getAllCurrencies(): array
  23. {
  24. return ISOCurrencies::getCurrencies();
  25. }
  26. public static function getAllCurrencyOptions(): array
  27. {
  28. $allCurrencies = self::getSupportedCurrencies();
  29. return array_combine($allCurrencies, $allCurrencies);
  30. }
  31. public static function getAvailableCurrencies(): array
  32. {
  33. $supportedCurrencies = self::getSupportedCurrencies();
  34. $storedCurrencies = Currency::query()
  35. ->pluck('code')
  36. ->toArray();
  37. $availableCurrencies = array_diff($supportedCurrencies, $storedCurrencies);
  38. return array_combine($availableCurrencies, $availableCurrencies);
  39. }
  40. public static function getDefaultCurrency(): ?string
  41. {
  42. $companyId = auth()->user()?->current_company_id;
  43. if ($companyId === null) {
  44. return 'USD';
  45. }
  46. return CompanySettingsService::getDefaultCurrency($companyId);
  47. }
  48. }