Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Small tweaks in charts.
James Cole512ce1597340
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.phpindex aa6b781c1e..5aa5ed4592 100644--- a/app/Http/Controllers/Chart/CategoryController.php+++ b/app/Http/Controllers/Chart/CategoryController.php@@ -26,92 +26,92 @@ class CategoryController extends Controller/**- * Show this month's category overview.+ * 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 frontpage(GChart $chart, CategoryRepositoryInterface $repository)+ public function all(GChart $chart, CategoryRepositoryInterface $repository, Category $category){- $chart->addColumn(trans('firefly.category'), 'string');+ // 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');- $start = Session::get('start', Carbon::now()->startOfMonth());- $end = Session::get('end', Carbon::now()->endOfMonth());- $set = $repository->getCategoriesAndExpenses($start, $end);- foreach ($set as $entry) {- $isEncrypted = intval($entry->encrypted) == 1 ? true : false;- $name = strlen($entry->name) == 0 ? trans('firefly.noCategory') : $entry->name;- $name = $isEncrypted ? Crypt::decrypt($name) : $name;- $chart->addRow($name, floatval($entry->sum));+ $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.+ ** @param GChart $chart* @param CategoryRepositoryInterface $repository- * @param Category $category** @return \Symfony\Component\HttpFoundation\Response*/- public function month(GChart $chart, CategoryRepositoryInterface $repository, Category $category)+ public function frontpage(GChart $chart, CategoryRepositoryInterface $repository){- $start = clone Session::get('start', Carbon::now()->startOfMonth());- $end = Session::get('end', Carbon::now()->endOfMonth());-- $chart->addColumn(trans('firefly.period'), 'date');+ $chart->addColumn(trans('firefly.category'), 'string');$chart->addColumn(trans('firefly.spent'), 'number');- while ($start <= $end) {- $spent = $repository->spentOnDaySum($category, $start);- $chart->addRow(clone $start, $spent);- $start->addDay();+ $start = Session::get('start', Carbon::now()->startOfMonth());+ $end = Session::get('end', Carbon::now()->endOfMonth());+ $set = $repository->getCategoriesAndExpenses($start, $end);++ foreach ($set as $entry) {+ $isEncrypted = intval($entry->encrypted) == 1 ? true : false;+ $name = strlen($entry->name) == 0 ? trans('firefly.noCategory') : $entry->name;+ $name = $isEncrypted ? Crypt::decrypt($name) : $name;+ $chart->addRow($name, floatval($entry->sum));}$chart->generate();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)+ public function month(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);+ $start = clone Session::get('start', Carbon::now()->startOfMonth());+ $end = Session::get('end', Carbon::now()->endOfMonth());$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);+ $spent = $repository->spentOnDaySum($category, $start);$chart->addRow(clone $start, $spent);-- $start = Navigation::addPeriod($start, $range, 0);+ $start->addDay();}$chart->generate();diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.phpindex b81b2b4dd5..55b6f43cb3 100644--- a/app/Repositories/Category/CategoryRepository.php+++ b/app/Repositories/Category/CategoryRepository.php@@ -172,12 +172,34 @@ class CategoryRepository implements CategoryRepositoryInterface*/public function spentInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false){- if($shared === false) {- // do something else, SEE budgets.- $sum = floatval($category->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1;+ if ($shared === true) {+ // shared is true.+ // always ignore transfers between accounts!+ $sum = floatval(+ $category->transactionjournals()+ ->transactionTypes(['Withdrawal', 'Deposit'])+ ->before($end)->after($start)->lessThan(0)->sum('amount')+ ) * -1;+} 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;}