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!

View File

@@ -132,6 +132,17 @@ interface CurrencyRepositoryInterface
*/
public function findBySymbolNull(string $currencySymbol): ?TransactionCurrency;
/**
* 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;
/**
* Find by ID, return NULL if not found.
*

View File

@@ -0,0 +1,64 @@
<?php
/**
* TransactionTypeRepository.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Repositories\TransactionType;
use FireflyIII\Models\TransactionType;
/**
* Class TransactionTypeRepository
*/
class TransactionTypeRepository implements TransactionTypeRepositoryInterface
{
/**
* @param string $type
*
* @return TransactionType|null
*/
public function findByType(string $type): ?TransactionType
{
$search = ucfirst($type);
return TransactionType::whereType($search)->first();
}
/**
* @param TransactionType|null $type
* @param string|null $typeString
*
* @return TransactionType
*/
public function findTransactionType(?TransactionType $type, ?string $typeString): TransactionType
{
if (null !== $type) {
return $type;
}
$search = $this->findByType($typeString);
if (null === $search) {
$search = $this->findByType(TransactionType::WITHDRAWAL);
}
return $search;
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* TransactionTypeRepositoryInterface.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Repositories\TransactionType;
use FireflyIII\Models\TransactionType;
/**
* Interface TransactionTypeRepositoryInterface
*/
interface TransactionTypeRepositoryInterface
{
/**
* @param TransactionType|null $type
* @param string|null $typeString
*
* @return TransactionType
*/
public function findTransactionType(?TransactionType $type, ?string $typeString): TransactionType;
/**
* @param string $type
*
* @return TransactionType|null
*/
public function findByType(string $type): ?TransactionType;
}