Add new “earned in period” method. #524

This commit is contained in:
James Cole 2017-01-05 08:39:46 +01:00
parent d48cc69898
commit 4d49701203
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
2 changed files with 29 additions and 0 deletions

View File

@ -74,6 +74,25 @@ class CategoryRepository implements CategoryRepositoryInterface
}
/**
* @param Collection $categories
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return string
*/
public function earnedInPeriodCollector(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): string
{
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class, [$this->user]);
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAccounts($accounts)->setCategories($categories);
$set = $collector->getJournals();
$sum = strval($set->sum('transaction_amount'));
return $sum;
}
/**
* @param Collection $accounts
* @param Carbon $start

View File

@ -41,6 +41,16 @@ interface CategoryRepositoryInterface
*/
public function earnedInPeriod(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): string;
/**
* @param Collection $categories
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return string
*/
public function earnedInPeriodCollector(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): string;
/**
* @param Collection $accounts
* @param Carbon $start