This commit is contained in:
James Cole
2015-09-25 16:00:14 +02:00
parent a838dc163d
commit 45293fbd42
11 changed files with 228 additions and 16 deletions

View File

@@ -309,7 +309,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
$cache->addProperty($category->id);
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('spentInPeriod');
$cache->addProperty('earnedInPeriod');
if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore
@@ -323,4 +323,36 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
return $sum;
}
/**
* @param Category $category
* @param int $page
*
* @return Collection
*/
public function getJournalsInRange(Category $category, $page, Carbon $start, Carbon $end)
{
$offset = $page > 0 ? $page * 50 : 0;
return $category->transactionJournals()
->after($start)
->before($end)
->withRelevantData()->take(50)->offset($offset)
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC')
->get(
['transaction_journals.*']
);
}
/**
* @param Category $category
*
* @return int
*/
public function countJournalsInRange(Category $category, Carbon $start, Carbon $end)
{
return $category->transactionJournals()->before($end)->after($start)->count();
}
}

View File

@@ -20,6 +20,13 @@ interface CategoryRepositoryInterface
*/
public function countJournals(Category $category);
/**
* @param Category $category
*
* @return int
*/
public function countJournalsInRange(Category $category, Carbon $start, Carbon $end);
/**
* @param Category $category
*
@@ -57,6 +64,14 @@ interface CategoryRepositoryInterface
*/
public function getJournals(Category $category, $page);
/**
* @param Category $category
* @param int $page
*
* @return Collection
*/
public function getJournalsInRange(Category $category, $page, Carbon $start, Carbon $end);
/**
* This method returns the sum of the journals in the category, optionally
* limited by a start or end date.