Lots of new code for importer and some preferences.

This commit is contained in:
James Cole
2016-07-24 18:47:55 +02:00
parent 87c0f1d86e
commit 1392275b81
41 changed files with 1562 additions and 369 deletions

View File

@@ -23,7 +23,6 @@ use FireflyIII\User;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
use Log;
/**
* Class BudgetRepository
@@ -86,6 +85,26 @@ class BudgetRepository implements BudgetRepositoryInterface
return $budget;
}
/**
* Find a budget.
*
* @param string $name
*
* @return Budget
*/
public function findByName(string $name): Budget
{
$budgets = $this->user->budgets()->get();
/** @var Budget $budget */
foreach ($budgets as $budget) {
if ($budget->name === $name) {
return $budget;
}
}
return new Budget;
}
/**
* This method returns the oldest journal or transaction date known to this budget.
* Will cache result.
@@ -499,5 +518,4 @@ class BudgetRepository implements BudgetRepositoryInterface
return $limit;
}
}

View File

@@ -24,6 +24,11 @@ use Illuminate\Support\Collection;
interface BudgetRepositoryInterface
{
/**
* @return bool
*/
public function cleanupBudgets(): bool;
/**
* @param Budget $budget
*
@@ -40,6 +45,15 @@ interface BudgetRepositoryInterface
*/
public function find(int $budgetId): Budget;
/**
* Find a budget.
*
* @param string $name
*
* @return Budget
*/
public function findByName(string $name): Budget;
/**
* This method returns the oldest journal or transaction date known to this budget.
* Will cache result.
@@ -92,15 +106,6 @@ interface BudgetRepositoryInterface
*/
public function journalsInPeriodWithoutBudget(Collection $accounts, Carbon $start, Carbon $end): Collection;
/**
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return string
*/
public function spentInPeriodWithoutBudget(Collection $accounts, Carbon $start, Carbon $end): string;
/**
* @param Collection $budgets
* @param Collection $accounts
@@ -112,9 +117,13 @@ interface BudgetRepositoryInterface
public function spentInPeriod(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end) : string;
/**
* @return bool
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return string
*/
public function cleanupBudgets(): bool;
public function spentInPeriodWithoutBudget(Collection $accounts, Carbon $start, Carbon $end): string;
/**
* @param array $data

View File

@@ -101,6 +101,25 @@ class CategoryRepository implements CategoryRepositoryInterface
return $category;
}
/**
* Find a category
*
* @param string $name
*
* @return Category
*/
public function findByName(string $name) : Category
{
$categories = $this->user->categories()->get();
foreach ($categories as $category) {
if ($category->name === $name) {
return $category;
}
}
return new Category;
}
/**
* @param Category $category
* @param Collection $accounts
@@ -554,4 +573,5 @@ class CategoryRepository implements CategoryRepositoryInterface
return $sum;
}
}

View File

@@ -59,6 +59,15 @@ interface CategoryRepositoryInterface
*/
public function find(int $categoryId) : Category;
/**
* Find a category
*
* @param string $name
*
* @return Category
*/
public function findByName(string $name) : Category;
/**
* @param Category $category
* @param Collection $accounts
@@ -94,15 +103,6 @@ interface CategoryRepositoryInterface
*/
public function journalsInPeriod(Collection $categories, Collection $accounts, array $types, Carbon $start, Carbon $end): Collection;
/**
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return string
*/
public function spentInPeriodWithoutCategory(Collection $accounts, Carbon $start, Carbon $end) : string;
/**
* @param Collection $accounts
* @param array $types
@@ -133,6 +133,15 @@ interface CategoryRepositoryInterface
*/
public function spentInPeriod(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): string;
/**
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return string
*/
public function spentInPeriodWithoutCategory(Collection $accounts, Carbon $start, Carbon $end) : string;
/**
* @param array $data
*

View File

@@ -82,6 +82,39 @@ class TagRepository implements TagRepositoryInterface
return true;
}
/**
* @param int $tagId
*
* @return Tag
*/
public function find(int $tagId) : Tag
{
$tag = $this->user->tags()->find($tagId);
if (is_null($tag)) {
$tag = new Tag;
}
return $tag;
}
/**
* @param string $tag
*
* @return Tag
*/
public function findByTag(string $tag) : Tag
{
$tags = $this->user->tags()->get();
/** @var Tag $tag */
foreach ($tags as $tag) {
if ($tag->tag === $tag) {
return $tag;
}
}
return new Tag;
}
/**
* @return Collection
*/

View File

@@ -42,6 +42,20 @@ interface TagRepositoryInterface
*/
public function destroy(Tag $tag): bool;
/**
* @param string $tag
*
* @return Tag
*/
public function findByTag(string $tag) : Tag;
/**
* @param int $tagId
*
* @return Tag
*/
public function find(int $tagId) : Tag;
/**
* This method returns all the user's tags.
*