mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-26 02:40:43 -06:00
New converters for #180 (Currency)
This commit is contained in:
parent
5e78cc02bd
commit
c14fa1021c
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Helpers\Csv\Converter;
|
||||
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class CurrencyCode
|
||||
@ -17,10 +18,14 @@ class CurrencyCode extends BasicConverter implements ConverterInterface
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
/** @var CurrencyRepositoryInterface $repository */
|
||||
$repository = app('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
|
||||
|
||||
|
||||
if (isset($this->mapped[$this->index][$this->value])) {
|
||||
$currency = TransactionCurrency::find($this->mapped[$this->index][$this->value]);
|
||||
$currency = $repository->find($this->mapped[$this->index][$this->value]);
|
||||
} else {
|
||||
$currency = TransactionCurrency::whereCode($this->value)->first();
|
||||
$currency = $repository->findByCode($this->value);
|
||||
}
|
||||
|
||||
return $currency;
|
||||
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Helpers\Csv\Converter;
|
||||
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class CurrencyId
|
||||
@ -17,10 +18,13 @@ class CurrencyId extends BasicConverter implements ConverterInterface
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
/** @var CurrencyRepositoryInterface $repository */
|
||||
$repository = app('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
|
||||
|
||||
if (isset($this->mapped[$this->index][$this->value])) {
|
||||
$currency = TransactionCurrency::find($this->mapped[$this->index][$this->value]);
|
||||
$currency = $repository->find($this->mapped[$this->index][$this->value]);
|
||||
} else {
|
||||
$currency = TransactionCurrency::find($this->value);
|
||||
$currency = $repository->find($this->value);
|
||||
}
|
||||
|
||||
return $currency;
|
||||
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Helpers\Csv\Converter;
|
||||
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class CurrencyName
|
||||
@ -17,10 +18,14 @@ class CurrencyName extends BasicConverter implements ConverterInterface
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
/** @var CurrencyRepositoryInterface $repository */
|
||||
$repository = app('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
|
||||
|
||||
if (isset($this->mapped[$this->index][$this->value])) {
|
||||
$currency = TransactionCurrency::find($this->mapped[$this->index][$this->value]);
|
||||
|
||||
$currency = $repository->find($this->mapped[$this->index][$this->value]);
|
||||
} else {
|
||||
$currency = TransactionCurrency::whereName($this->value)->first();
|
||||
$currency = $repository->findByName($this->value);
|
||||
}
|
||||
|
||||
return $currency;
|
||||
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Helpers\Csv\Converter;
|
||||
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class CurrencySymbol
|
||||
@ -17,10 +18,13 @@ class CurrencySymbol extends BasicConverter implements ConverterInterface
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
/** @var CurrencyRepositoryInterface $repository */
|
||||
$repository = app('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
|
||||
|
||||
if (isset($this->mapped[$this->index][$this->value])) {
|
||||
$currency = TransactionCurrency::find($this->mapped[$this->index][$this->value]);
|
||||
$currency = $repository->find($this->mapped[$this->index][$this->value]);
|
||||
} else {
|
||||
$currency = TransactionCurrency::whereSymbol($this->value)->first();
|
||||
$currency = $repository->findBySymbol($this->value);
|
||||
}
|
||||
|
||||
return $currency;
|
||||
|
@ -26,6 +26,75 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
return $currency->transactionJournals()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find by ID
|
||||
*
|
||||
* @param int $currencyId
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public function find(int $currencyId) : TransactionCurrency
|
||||
{
|
||||
$currency = TransactionCurrency::find($currencyId);
|
||||
if (is_null($currency)) {
|
||||
$currency = new TransactionCurrency;
|
||||
|
||||
}
|
||||
|
||||
return $currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find by currency code
|
||||
*
|
||||
* @param string $currencyCode
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public function findByCode(string $currencyCode) : TransactionCurrency
|
||||
{
|
||||
$currency = TransactionCurrency::whereCode($currencyCode)->first();
|
||||
if (is_null($currency)) {
|
||||
$currency = new TransactionCurrency;
|
||||
}
|
||||
|
||||
return $currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find by currency name
|
||||
*
|
||||
* @param string $currencyName
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public function findByName(string $currencyName) : TransactionCurrency
|
||||
{
|
||||
$preferred = TransactionCurrency::whereName($currencyName)->first();
|
||||
if (is_null($preferred)) {
|
||||
$preferred = new TransactionCurrency;
|
||||
}
|
||||
|
||||
return $preferred;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find by currency symbol
|
||||
*
|
||||
* @param string $currencySymbol
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public function findBySymbol(string $currencySymbol) : TransactionCurrency
|
||||
{
|
||||
$currency = TransactionCurrency::whereSymbol($currencySymbol)->first();
|
||||
if (is_null($currency)) {
|
||||
$currency = new TransactionCurrency;
|
||||
}
|
||||
|
||||
return $currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
|
@ -15,7 +15,6 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface CurrencyRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
@ -23,6 +22,42 @@ interface CurrencyRepositoryInterface
|
||||
*/
|
||||
public function countJournals(TransactionCurrency $currency);
|
||||
|
||||
/**
|
||||
* Find by ID
|
||||
*
|
||||
* @param int $currencyId
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public function find(int $currencyId) : TransactionCurrency;
|
||||
|
||||
/**
|
||||
* Find by currency code
|
||||
*
|
||||
* @param string $currencyCode
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public function findByCode(string $currencyCode) : TransactionCurrency;
|
||||
|
||||
/**
|
||||
* Find by currency name
|
||||
*
|
||||
* @param string $currencyName
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public function findByName(string $currencyName) : TransactionCurrency;
|
||||
|
||||
/**
|
||||
* Find by currency symbol
|
||||
*
|
||||
* @param string $currencySymbol
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public function findBySymbol(string $currencySymbol) : TransactionCurrency;
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user