mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-26 02:40:43 -06:00
Fix for transactions.
This commit is contained in:
parent
3c1ff4d21f
commit
80350f8423
@ -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 Controller
|
||||
return $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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user