Skip to content

Firefly III: a personal finances manager

Add new “earned in period” method. #524

James Cole4d49701203d1
diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php
index 0b69ad69e3..dab725a385 100644
--- a/app/Repositories/Category/CategoryRepository.php
+++ b/app/Repositories/Category/CategoryRepository.php
@@ -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
diff --git a/app/Repositories/Category/CategoryRepositoryInterface.php b/app/Repositories/Category/CategoryRepositoryInterface.php
index 0fd3ef1399..96dd7fd02b 100644
--- a/app/Repositories/Category/CategoryRepositoryInterface.php
+++ b/app/Repositories/Category/CategoryRepositoryInterface.php
@@ -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