mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 20:16:22 +00:00
Small tweaks in charts.
This commit is contained in:
@@ -25,6 +25,44 @@ class CategoryController extends Controller
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show an overview for a category for all time, per month/week/year.
|
||||||
|
*
|
||||||
|
* @param GChart $chart
|
||||||
|
* @param CategoryRepositoryInterface $repository
|
||||||
|
* @param Category $category
|
||||||
|
*
|
||||||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
*/
|
||||||
|
public function all(GChart $chart, CategoryRepositoryInterface $repository, Category $category)
|
||||||
|
{
|
||||||
|
// oldest transaction in category:
|
||||||
|
$start = $repository->getFirstActivityDate($category);
|
||||||
|
$range = Preferences::get('viewRange', '1M')->data;
|
||||||
|
// jump to start of week / month / year / etc
|
||||||
|
$start = Navigation::startOfPeriod($start, $range);
|
||||||
|
|
||||||
|
$chart->addColumn(trans('firefly.period'), 'date');
|
||||||
|
$chart->addColumn(trans('firefly.spent'), 'number');
|
||||||
|
|
||||||
|
|
||||||
|
$end = new Carbon;
|
||||||
|
while ($start <= $end) {
|
||||||
|
|
||||||
|
$currentEnd = Navigation::endOfPeriod($start, $range);
|
||||||
|
$spent = $repository->spentInPeriod($category, $start, $currentEnd);
|
||||||
|
$chart->addRow(clone $start, $spent);
|
||||||
|
|
||||||
|
$start = Navigation::addPeriod($start, $range, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$chart->generate();
|
||||||
|
|
||||||
|
return Response::json($chart->getData());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show this month's category overview.
|
* Show this month's category overview.
|
||||||
*
|
*
|
||||||
@@ -81,44 +119,6 @@ class CategoryController extends Controller
|
|||||||
return Response::json($chart->getData());
|
return Response::json($chart->getData());
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show an overview for a category for all time, per month/week/year.
|
|
||||||
*
|
|
||||||
* @param GChart $chart
|
|
||||||
* @param CategoryRepositoryInterface $repository
|
|
||||||
* @param Category $category
|
|
||||||
*
|
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
|
||||||
*/
|
|
||||||
public function all(GChart $chart, CategoryRepositoryInterface $repository, Category $category)
|
|
||||||
{
|
|
||||||
// oldest transaction in category:
|
|
||||||
$start = $repository->getFirstActivityDate($category);
|
|
||||||
|
|
||||||
$range = Preferences::get('viewRange', '1M')->data;
|
|
||||||
// jump to start of week / month / year / etc
|
|
||||||
$start = Navigation::startOfPeriod($start, $range);
|
|
||||||
|
|
||||||
$chart->addColumn(trans('firefly.period'), 'date');
|
|
||||||
$chart->addColumn(trans('firefly.spent'), 'number');
|
|
||||||
|
|
||||||
$end = new Carbon;
|
|
||||||
while ($start <= $end) {
|
|
||||||
|
|
||||||
$currentEnd = Navigation::endOfPeriod($start, $range);
|
|
||||||
$spent = $repository->spentInPeriod($category, $start, $currentEnd);
|
|
||||||
$chart->addRow(clone $start, $spent);
|
|
||||||
|
|
||||||
$start = Navigation::addPeriod($start, $range, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
$chart->generate();
|
|
||||||
|
|
||||||
return Response::json($chart->getData());
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -172,12 +172,34 @@ class CategoryRepository implements CategoryRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function spentInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false)
|
public function spentInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false)
|
||||||
{
|
{
|
||||||
if($shared === false) {
|
if ($shared === true) {
|
||||||
// do something else, SEE budgets.
|
// shared is true.
|
||||||
$sum = floatval($category->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1;
|
// always ignore transfers between accounts!
|
||||||
|
$sum = floatval(
|
||||||
|
$category->transactionjournals()
|
||||||
|
->transactionTypes(['Withdrawal', 'Deposit'])
|
||||||
|
->before($end)->after($start)->lessThan(0)->sum('amount')
|
||||||
|
) * -1;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$sum = floatval($category->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1;
|
// do something else, SEE budgets.
|
||||||
|
// get all journals in this month where the asset account is NOT shared.
|
||||||
|
$sum = $category->transactionjournals()
|
||||||
|
->before($end)
|
||||||
|
->after($start)
|
||||||
|
->transactionTypes(['Withdrawal', 'Deposit'])
|
||||||
|
->lessThan(0)
|
||||||
|
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||||
|
->leftJoin(
|
||||||
|
'account_meta', function (JoinClause $join) {
|
||||||
|
$join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
|
||||||
|
}
|
||||||
|
)
|
||||||
|
->where('account_meta.data', '!=', '"sharedAsset"')
|
||||||
|
->sum('amount');
|
||||||
|
$sum = floatval($sum) * -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sum;
|
return $sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user