mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix for transactions.
This commit is contained in:
@@ -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 SCRI $repository
|
||||||
* @param Category $category
|
* @param Category $category
|
||||||
@@ -435,60 +491,4 @@ class CategoryController extends Controller
|
|||||||
return $data;
|
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)
|
->before($end)
|
||||||
->after($start)
|
->after($start)
|
||||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
|
->having('transaction_count', '=', 1)
|
||||||
->transactionTypes($types);
|
->transactionTypes($types);
|
||||||
|
|
||||||
if (count($accountIds) > 0) {
|
if (count($accountIds) > 0) {
|
||||||
$query->whereIn('transactions.account_id', $accountIds);
|
$query->whereIn('transactions.account_id', $accountIds);
|
||||||
}
|
}
|
||||||
@@ -293,6 +295,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
|||||||
$single = $query->first(
|
$single = $query->first(
|
||||||
[
|
[
|
||||||
DB::raw('SUM(`transactions`.`amount`) as `sum`'),
|
DB::raw('SUM(`transactions`.`amount`) as `sum`'),
|
||||||
|
DB::raw('COUNT(`transactions`.`id`) as `transaction_count`'),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
if (!is_null($single)) {
|
if (!is_null($single)) {
|
||||||
|
Reference in New Issue
Block a user