mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-18 23:50:09 +00:00
First full implementation of new storage routine.
This commit is contained in:
@@ -86,6 +86,45 @@ class BillRepository implements BillRepositoryInterface
|
||||
return $this->user->bills()->find($billId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find bill by parameters.
|
||||
*
|
||||
* @param Bill|null $bill
|
||||
* @param int|null $billId
|
||||
* @param string|null $billName
|
||||
*
|
||||
* @return Bill|null
|
||||
*/
|
||||
public function findBill(?Bill $bill, ?int $billId, ?string $billName): ?Bill
|
||||
{
|
||||
Log::debug('Searching for bill information.');
|
||||
if ($bill instanceof Bill && $bill->user_id === $this->user->id) {
|
||||
Log::debug(sprintf('Bill object in parameters, will return Bill #%d', $bill->id));
|
||||
|
||||
return $bill;
|
||||
}
|
||||
|
||||
if (null !== $billId) {
|
||||
$searchResult = $this->find((int)$billId);
|
||||
if (null !== $searchResult) {
|
||||
Log::debug(sprintf('Found bill based on #%d, will return it.', $billId));
|
||||
|
||||
return $searchResult;
|
||||
}
|
||||
}
|
||||
if (null !== $billName) {
|
||||
$searchResult = $this->findByName((string)$billName);
|
||||
if (null !== $searchResult) {
|
||||
Log::debug(sprintf('Found bill based on "%s", will return it.', $billName));
|
||||
|
||||
return $searchResult;
|
||||
}
|
||||
}
|
||||
Log::debug('Found nothing');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a bill by name.
|
||||
*
|
||||
|
||||
@@ -49,6 +49,17 @@ interface BillRepositoryInterface
|
||||
*/
|
||||
public function find(int $billId): ?Bill;
|
||||
|
||||
/**
|
||||
* Find bill by parameters.
|
||||
*
|
||||
* @param Bill|null $bill
|
||||
* @param int|null $billId
|
||||
* @param string|null $billName
|
||||
*
|
||||
* @return Bill|null
|
||||
*/
|
||||
public function findBill(?Bill $bill, ?int $billId, ?string $billName): ?Bill;
|
||||
|
||||
/**
|
||||
* Find a bill by name.
|
||||
*
|
||||
|
||||
@@ -218,6 +218,55 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget|null $budget
|
||||
* @param int|null $budgetId
|
||||
* @param string|null $budgetName
|
||||
*
|
||||
* @return Budget|null
|
||||
*/
|
||||
public function findBudget(?Budget $budget, ?int $budgetId, ?string $budgetName): ?Budget
|
||||
{
|
||||
Log::debug('Now in findBudget()');
|
||||
$result = null;
|
||||
if (null !== $budget) {
|
||||
Log::debug(sprintf('Parameters contain budget #%d, will return this.', $budget->id));
|
||||
$result = $budget;
|
||||
}
|
||||
|
||||
if (null === $result) {
|
||||
Log::debug(sprintf('Searching for budget with ID #%d...', $budgetId));
|
||||
$result = $this->findNull((int)$budgetId);
|
||||
}
|
||||
if (null === $result) {
|
||||
Log::debug(sprintf('Searching for budget with name %s...', $budgetName));
|
||||
$result = $this->findByName((string)$budgetName);
|
||||
}
|
||||
if (null !== $result) {
|
||||
Log::debug(sprintf('Found budget #%d: %s', $result->id, $result->name));
|
||||
}
|
||||
Log::debug(sprintf('Found result is null? %s', var_export(null === $result, true)));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find budget by name.
|
||||
*
|
||||
* @param string|null $name
|
||||
*
|
||||
* @return Budget|null
|
||||
*/
|
||||
public function findByName(?string $name): ?Budget
|
||||
{
|
||||
if (null === $name) {
|
||||
return null;
|
||||
}
|
||||
$query = sprintf('%%%s%%', $name);
|
||||
|
||||
return $this->user->budgets()->where('name', 'LIKE', $query)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a budget or return NULL
|
||||
*
|
||||
@@ -399,6 +448,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
return $return;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* Returns all available budget objects.
|
||||
*
|
||||
@@ -439,8 +490,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
return bcdiv($total, (string)$days);
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
@@ -568,6 +617,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
return $set;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* Get all budgets with these ID's.
|
||||
*
|
||||
@@ -647,8 +698,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
return $this->user->budgets()->where('name', 'LIKE', $query)->get();
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
@@ -853,6 +902,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
return $return;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
@@ -915,8 +966,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
return $limit;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param array $data
|
||||
|
||||
@@ -35,6 +35,7 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface BudgetRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* A method that returns the amount of money budgeted per day for this budget,
|
||||
* on average.
|
||||
@@ -80,6 +81,24 @@ interface BudgetRepositoryInterface
|
||||
*/
|
||||
public function destroyBudgetLimit(BudgetLimit $budgetLimit): void;
|
||||
|
||||
/**
|
||||
* @param Budget|null $budget
|
||||
* @param int|null $budgetId
|
||||
* @param string|null $budgetName
|
||||
*
|
||||
* @return Budget|null
|
||||
*/
|
||||
public function findBudget(?Budget $budget, ?int $budgetId, ?string $budgetName): ?Budget;
|
||||
|
||||
/**
|
||||
* Find budget by name.
|
||||
*
|
||||
* @param string|null $name
|
||||
*
|
||||
* @return Budget|null
|
||||
*/
|
||||
public function findByName(?string $name): ?Budget;
|
||||
|
||||
/**
|
||||
* @param int|null $budgetId
|
||||
*
|
||||
|
||||
@@ -252,6 +252,42 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category|null $category
|
||||
* @param int|null $categoryId
|
||||
* @param string|null $categoryName
|
||||
*
|
||||
* @return Category|null
|
||||
*/
|
||||
public function findCategory(?Category $category, ?int $categoryId, ?string $categoryName): ?Category
|
||||
{
|
||||
Log::debug('Now in findCategory()');
|
||||
$result = null;
|
||||
if (null !== $category) {
|
||||
Log::debug(sprintf('Parameters contain category #%d, will return this.', $category->id));
|
||||
$result = $category;
|
||||
}
|
||||
|
||||
if (null === $result) {
|
||||
Log::debug(sprintf('Searching for category with ID #%d...', $categoryId));
|
||||
$result = $this->findNull((int)$categoryId);
|
||||
}
|
||||
if (null === $result) {
|
||||
Log::debug(sprintf('Searching for category with name %s...', $categoryName));
|
||||
$result = $this->findByName((string)$categoryName);
|
||||
if (null === $result && '' !== (string)$categoryName) {
|
||||
// create it!
|
||||
$result = $this->store(['name' => $categoryName]);
|
||||
}
|
||||
}
|
||||
if (null !== $result) {
|
||||
Log::debug(sprintf('Found category #%d: %s', $result->id, $result->name));
|
||||
}
|
||||
Log::debug(sprintf('Found category result is null? %s', var_export(null === $result, true)));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a category or return NULL
|
||||
*
|
||||
@@ -264,6 +300,8 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $this->user->categories()->find($categoryId);
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
@@ -292,8 +330,6 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $firstJournalDate;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* Get all categories with ID's.
|
||||
*
|
||||
@@ -306,6 +342,8 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $this->user->categories()->whereIn('id', $categoryIds)->get();
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* Returns a list of all the categories belonging to a user.
|
||||
*
|
||||
@@ -324,8 +362,6 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $set;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
@@ -401,6 +437,8 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $data;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
@@ -529,8 +567,6 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $result;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
*
|
||||
@@ -839,6 +875,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Carbon|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function getLastTransactionDate(Category $category, Collection $accounts): ?Carbon
|
||||
{
|
||||
|
||||
@@ -33,6 +33,15 @@ use Illuminate\Support\Collection;
|
||||
interface CategoryRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Category|null $category
|
||||
* @param int|null $categoryId
|
||||
* @param string|null $categoryName
|
||||
*
|
||||
* @return Category|null
|
||||
*/
|
||||
public function findCategory(?Category $category, ?int $categoryId, ?string $categoryName): ?Category;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
|
||||
@@ -266,24 +266,32 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
*/
|
||||
public function findCurrency(?TransactionCurrency $currency, ?int $currencyId, ?string $currencyCode): TransactionCurrency
|
||||
{
|
||||
Log::debug('Now in findCurrency()');
|
||||
$result = null;
|
||||
if (null !== $currency) {
|
||||
Log::debug(sprintf('Parameters contain %s, will return this.', $currency->code));
|
||||
$result = $currency;
|
||||
}
|
||||
|
||||
if (null === $result) {
|
||||
Log::debug(sprintf('Searching for currency with ID #%d...', $currencyId));
|
||||
$result = $this->find((int)$currencyId);
|
||||
}
|
||||
if (null === $result) {
|
||||
Log::debug(sprintf('Searching for currency with code %s...', $currencyCode));
|
||||
$result = $this->findByCode((string)$currencyCode);
|
||||
}
|
||||
if (null === $result) {
|
||||
Log::debug('Grabbing default currency for this user...');
|
||||
$result = app('amount')->getDefaultCurrencyByUser($this->user);
|
||||
}
|
||||
if (null === $result) {
|
||||
Log::debug('Grabbing EUR as fallback.');
|
||||
$result = $this->findByCode('EUR');
|
||||
}
|
||||
Log::debug(sprintf('Final result: %s', $result->code));
|
||||
if (false === $result->enabled) {
|
||||
Log::debug(sprintf('Also enabled currency %s', $result->code));
|
||||
$this->enable($result);
|
||||
}
|
||||
|
||||
|
||||
@@ -224,6 +224,43 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank|null $piggyBank
|
||||
* @param int|null $piggyBankId
|
||||
* @param string|null $piggyBankName
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
public function findPiggyBank(?PiggyBank $piggyBank, ?int $piggyBankId, ?string $piggyBankName): ?PiggyBank
|
||||
{
|
||||
Log::debug('Searching for piggy information.');
|
||||
if ($piggyBank instanceof PiggyBank && $piggyBank->account->user_id === $this->user->id) {
|
||||
Log::debug(sprintf('Piggy object in parameters, will return Piggy #%d', $piggyBank->id));
|
||||
|
||||
return $piggyBank;
|
||||
}
|
||||
|
||||
if (null !== $piggyBankId) {
|
||||
$searchResult = $this->findNull((int)$piggyBankId);
|
||||
if (null !== $searchResult) {
|
||||
Log::debug(sprintf('Found piggy based on #%d, will return it.', $piggyBankId));
|
||||
|
||||
return $searchResult;
|
||||
}
|
||||
}
|
||||
if (null !== $piggyBankName) {
|
||||
$searchResult = $this->findByName((string)$piggyBankName);
|
||||
if (null !== $searchResult) {
|
||||
Log::debug(sprintf('Found piggy based on "%s", will return it.', $piggyBankName));
|
||||
|
||||
return $searchResult;
|
||||
}
|
||||
}
|
||||
Log::debug('Found nothing');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current amount saved in piggy bank.
|
||||
*
|
||||
|
||||
@@ -35,7 +35,6 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface PiggyBankRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
@@ -117,6 +116,15 @@ interface PiggyBankRepositoryInterface
|
||||
*/
|
||||
public function findNull(int $piggyBankId): ?PiggyBank;
|
||||
|
||||
/**
|
||||
* @param PiggyBank|null $piggyBank
|
||||
* @param int|null $piggyBankId
|
||||
* @param string|null $piggyBankName
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
public function findPiggyBank(?PiggyBank $piggyBank, ?int $piggyBankId, ?string $piggyBankName): ?PiggyBank;
|
||||
|
||||
/**
|
||||
* Get current amount saved in piggy bank.
|
||||
*
|
||||
|
||||
@@ -24,7 +24,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Repositories\TransactionType;
|
||||
|
||||
use FireflyIII\Models\TransactionType;
|
||||
|
||||
use Log;
|
||||
/**
|
||||
* Class TransactionTypeRepository
|
||||
*/
|
||||
@@ -51,13 +51,17 @@ class TransactionTypeRepository implements TransactionTypeRepositoryInterface
|
||||
*/
|
||||
public function findTransactionType(?TransactionType $type, ?string $typeString): TransactionType
|
||||
{
|
||||
Log::debug('Now looking for a transaction type.');
|
||||
if (null !== $type) {
|
||||
Log::debug(sprintf('Found $type in parameters, its %s. Will return it.', $type->type));
|
||||
|
||||
return $type;
|
||||
}
|
||||
$search = $this->findByType($typeString);
|
||||
if (null === $search) {
|
||||
$search = $this->findByType(TransactionType::WITHDRAWAL);
|
||||
}
|
||||
Log::debug(sprintf('Tried to search for "%s", came up with "%s". Will return it.', $typeString, $search->type));
|
||||
|
||||
return $search;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user