Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Expand new charts.
James Cole1591b61b7784
diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.phpindex 6b1456a5fa..2189b5a22f 100644--- a/app/Http/Controllers/CategoryController.php+++ b/app/Http/Controllers/CategoryController.php@@ -181,8 +181,8 @@ class CategoryController extends Controller// get all spent and earned data:// get amount earned in period, grouped by day.- $spentArray = $repository->spentPerDay($category, $start, $end);- $earnedArray = $repository->earnedPerDay($category, $start, $end);+ $spentArray = $repository->spentPerDay($category, $start, $end, new Collection);+ $earnedArray = $repository->earnedPerDay($category, $start, $end, new Collection);if ($cache->has()) {$entries = $cache->get();diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.phpindex a7e9c9ae59..57a524d94b 100644--- a/app/Http/Controllers/Chart/CategoryController.php+++ b/app/Http/Controllers/Chart/CategoryController.php@@ -68,8 +68,8 @@ class CategoryController extends Controllerif ($cache->has()) {return Response::json($cache->get());}- $spentArray = $repository->spentPerDay($category, $start, $end);- $earnedArray = $repository->earnedPerDay($category, $start, $end);+ $spentArray = $repository->spentPerDay($category, $start, $end, new Collection);+ $earnedArray = $repository->earnedPerDay($category, $start, $end, new Collection);while ($start <= $end) {$currentEnd = Navigation::endOfPeriod($start, $range);@@ -417,8 +417,8 @@ class CategoryController extends Controller// get amount earned in period, grouped by day.// get amount spent in period, grouped by day.- $spentArray = $repository->spentPerDay($category, $start, $end);- $earnedArray = $repository->earnedPerDay($category, $start, $end);+ $spentArray = $repository->spentPerDay($category, $start, $end, new Collection);+ $earnedArray = $repository->earnedPerDay($category, $start, $end, new Collection);while ($start <= $end) {$str = $start->format('Y-m-d');@@ -470,8 +470,8 @@ class CategoryController extends Controller$currentStart = clone $current;$currentEnd = Navigation::endOfPeriod($currentStart, $viewRange);- $spent = strval(array_sum($repository->spentPerDay($category, $currentStart, $currentEnd)));- $earned = strval(array_sum($repository->earnedPerDay($category, $currentStart, $currentEnd)));+ $spent = strval(array_sum($repository->spentPerDay($category, $currentStart, $currentEnd, new Collection)));+ $earned = strval(array_sum($repository->earnedPerDay($category, $currentStart, $currentEnd, new Collection)));$entry = [$category->name,diff --git a/app/Repositories/Category/SingleCategoryRepository.php b/app/Repositories/Category/SingleCategoryRepository.phpindex 5fa7ffe2c2..8592cbb361 100644--- a/app/Repositories/Category/SingleCategoryRepository.php+++ b/app/Repositories/Category/SingleCategoryRepository.php@@ -76,25 +76,32 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate* Where yyyy-mm-dd is the date and <amount> is the money earned using DEPOSITS in the $category* from all the users $accounts.*- * @param Category $category- * @param Carbon $start- * @param Carbon $end+ * @param Category $category+ * @param Carbon $start+ * @param Carbon $end+ * @param Collection $accounts** @return array*/- public function earnedPerDay(Category $category, Carbon $start, Carbon $end): array+ public function earnedPerDay(Category $category, Carbon $start, Carbon $end, Collection $accounts): array{/** @var Collection $query */$query = $category->transactionjournals()+ ->expanded()->transactionTypes([TransactionType::DEPOSIT])- ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')- ->where('transactions.amount', '>', 0)->before($end)->after($start)- ->groupBy('date')->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`transactions`.`amount`) AS `sum`')]);+ ->groupBy('transaction_journals.date');++ if ($accounts->count() > 0) {+ $ids = $accounts->pluck('id')->toArray();+ $query->whereIn('destination_account.id', $ids);+ }++ $result = $query->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`destination`.`amount`) AS `sum`')]);$return = [];- foreach ($query->toArray() as $entry) {+ foreach ($result->toArray() as $entry) {$return[$entry['dateFormatted']] = $entry['sum'];}@@ -226,25 +233,33 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate* Where yyyy-mm-dd is the date and <amount> is the money spent using DEPOSITS in the $category* from all the users accounts.*- * @param Category $category- * @param Carbon $start- * @param Carbon $end+ * @param Category $category+ * @param Carbon $start+ * @param Carbon $end+ * @param Collection $accounts** @return array*/- public function spentPerDay(Category $category, Carbon $start, Carbon $end): array+ public function spentPerDay(Category $category, Carbon $start, Carbon $end, Collection $accounts): array{/** @var Collection $query */$query = $category->transactionjournals()+ ->expanded()->transactionTypes([TransactionType::WITHDRAWAL])- ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')- ->where('transactions.amount', '<', 0)->before($end)->after($start)- ->groupBy('date')->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`transactions`.`amount`) AS `sum`')]);+ ->groupBy('transaction_journals.date');++ if ($accounts->count() > 0) {+ $ids = $accounts->pluck('id')->toArray();+ $query->whereIn('source_account.id', $ids);+ }+++ $result = $query->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`transactions`.`amount`) AS `sum`')]);$return = [];- foreach ($query->toArray() as $entry) {+ foreach ($result->toArray() as $entry) {$return[$entry['dateFormatted']] = $entry['sum'];}diff --git a/app/Repositories/Category/SingleCategoryRepositoryInterface.php b/app/Repositories/Category/SingleCategoryRepositoryInterface.phpindex 011fc522a1..7e0e5c9110 100644--- a/app/Repositories/Category/SingleCategoryRepositoryInterface.php+++ b/app/Repositories/Category/SingleCategoryRepositoryInterface.php@@ -47,13 +47,14 @@ interface SingleCategoryRepositoryInterface* Where yyyy-mm-dd is the date and <amount> is the money earned using DEPOSITS in the $category* from all the users accounts.*- * @param Category $category- * @param Carbon $start- * @param Carbon $end+ * @param Category $category+ * @param Carbon $start+ * @param Carbon $end+ * @param Collection $accounts** @return array*/- public function earnedPerDay(Category $category, Carbon $start, Carbon $end): array;+ public function earnedPerDay(Category $category, Carbon $start, Carbon $end, Collection $accounts): array;/*** Find a category@@ -118,13 +119,14 @@ interface SingleCategoryRepositoryInterface* Where yyyy-mm-dd is the date and <amount> is the money spent using WITHDRAWALS in the $category* from all the users accounts.*- * @param Category $category- * @param Carbon $start- * @param Carbon $end+ * @param Category $category+ * @param Carbon $start+ * @param Carbon $end+ * @param Collection $accounts** @return array*/- public function spentPerDay(Category $category, Carbon $start, Carbon $end): array;+ public function spentPerDay(Category $category, Carbon $start, Carbon $end, Collection $accounts): array;/**