Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix for transactions.
James Cole80350f842392
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.phpindex 892464b254..1298c0ea0f 100644--- a/app/Http/Controllers/Chart/CategoryController.php+++ b/app/Http/Controllers/Chart/CategoryController.php@@ -270,6 +270,62 @@ class CategoryController extends Controller}+ /**+ * @param Category $category+ * @param string $reportType+ * @param Carbon $start+ * @param Carbon $end+ * @param Collection $accounts+ *+ * @return \Illuminate\Http\JsonResponse+ */+ public function period(Category $category, string $reportType, Carbon $start, Carbon $end, Collection $accounts)+ {+ // chart properties for cache:+ $cache = new CacheProperties();+ $cache->addProperty($start);+ $cache->addProperty($end);+ $cache->addProperty($reportType);+ $cache->addProperty($accounts);+ $cache->addProperty($category->id);+ $cache->addProperty('category');+ $cache->addProperty('period');+ if ($cache->has()) {+ return Response::json($cache->get());+ }++ /** @var SingleCategoryRepositoryInterface $repository */+ $repository = app('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface');+ // loop over period, add by users range:+ $current = clone $start;+ $viewRange = Preferences::get('viewRange', '1M')->data;+ $format = strval(trans('config.month'));+ $set = new Collection;+ while ($current < $end) {+ $currentStart = clone $current;+ $currentEnd = Navigation::endOfPeriod($currentStart, $viewRange);++ $spent = strval(array_sum($repository->spentPerDay($category, $currentStart, $currentEnd, $accounts)));+ $earned = strval(array_sum($repository->earnedPerDay($category, $currentStart, $currentEnd, $accounts)));++ $entry = [+ $category->name,+ $currentStart->formatLocalized($format),+ $spent,+ $earned,++ ];+ $set->push($entry);+ $currentEnd->addDay();+ $current = clone $currentEnd;+ }+ $data = $this->generator->period($set);+ $cache->store($data);++ return Response::json($data);++ }+/*** @param SCRI $repository* @param Category $category@@ -435,60 +491,4 @@ class CategoryController extends Controllerreturn $data;}- /**- * @param Category $category- * @param string $reportType- * @param Carbon $start- * @param Carbon $end- * @param Collection $accounts- *- * @return \Illuminate\Http\JsonResponse- */- public function period(Category $category, string $reportType, Carbon $start, Carbon $end, Collection $accounts)- {- // chart properties for cache:- $cache = new CacheProperties();- $cache->addProperty($start);- $cache->addProperty($end);- $cache->addProperty($reportType);- $cache->addProperty($accounts);- $cache->addProperty($category->id);- $cache->addProperty('category');- $cache->addProperty('period');- if ($cache->has()) {- return Response::json($cache->get());- }-- /** @var SingleCategoryRepositoryInterface $repository */- $repository = app('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface');- // loop over period, add by users range:- $current = clone $start;- $viewRange = Preferences::get('viewRange', '1M')->data;- $format = strval(trans('config.month'));- $set = new Collection;- while ($current < $end) {- $currentStart = clone $current;- $currentEnd = Navigation::endOfPeriod($currentStart, $viewRange);-- $spent = strval(array_sum($repository->spentPerDay($category, $currentStart, $currentEnd, $accounts)));- $earned = strval(array_sum($repository->earnedPerDay($category, $currentStart, $currentEnd, $accounts)));-- $entry = [- $category->name,- $currentStart->formatLocalized($format),- $spent,- $earned,-- ];- $set->push($entry);- $currentEnd->addDay();- $current = clone $currentEnd;- }- $data = $this->generator->period($set);- $cache->store($data);-- return Response::json($data);-- }-}diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.phpindex 0575a2b665..0b8209b76d 100644--- a/app/Repositories/Category/CategoryRepository.php+++ b/app/Repositories/Category/CategoryRepository.php@@ -284,7 +284,9 @@ class CategoryRepository implements CategoryRepositoryInterface->before($end)->after($start)->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')+ ->having('transaction_count', '=', 1)->transactionTypes($types);+if (count($accountIds) > 0) {$query->whereIn('transactions.account_id', $accountIds);}@@ -293,6 +295,7 @@ class CategoryRepository implements CategoryRepositoryInterface$single = $query->first([DB::raw('SUM(`transactions`.`amount`) as `sum`'),+ DB::raw('COUNT(`transactions`.`id`) as `transaction_count`'),]);if (!is_null($single)) {