Various improvements.

This commit is contained in:
James Cole
2019-03-08 05:47:51 +01:00
parent e6d7c0ddbd
commit 431cf08401
11 changed files with 813 additions and 430 deletions

View File

@@ -255,6 +255,41 @@ class CurrencyRepository implements CurrencyRepositoryInterface
return TransactionCurrency::whereSymbol($currencySymbol)->first();
}
/**
* Find by object, ID or code. Returns user default or system default.
*
* @param TransactionCurrency|null $currency
* @param int|null $currencyId
* @param string|null $currencyCode
*
* @return TransactionCurrency|null
*/
public function findCurrency(?TransactionCurrency $currency, ?int $currencyId, ?string $currencyCode): TransactionCurrency
{
$result = null;
if (null !== $currency) {
$result = $currency;
}
if (null === $result) {
$result = $this->find((int)$currencyId);
}
if (null === $result) {
$result = $this->findByCode((string)$currencyCode);
}
if (null === $result) {
$result = app('amount')->getDefaultCurrencyByUser($this->user);
}
if (null === $result) {
$result = $this->findByCode('EUR');
}
if (false === $result->enabled) {
$this->enable($result);
}
return $result;
}
/**
* Find by ID, return NULL if not found.
* Used in Import Currency!