Some code cleanup and a better chart [skip ci]

This commit is contained in:
James Cole
2016-05-20 18:26:43 +02:00
parent 78afb771b1
commit a5d5f86aed
2 changed files with 16 additions and 10 deletions

View File

@@ -118,8 +118,8 @@ class ReportController extends Controller
while ($currentStart <= $end) { while ($currentStart <= $end) {
$currentEnd = Navigation::endOfPeriod($currentStart, '1M'); $currentEnd = Navigation::endOfPeriod($currentStart, '1M');
$date = $currentStart->format('Y-m'); $date = $currentStart->format('Y-m');
$spent = $repository->spentInPeriod($accounts, $currentStart, $currentEnd); $spent = $repository->expensesInPeriod($accounts, $currentStart, $currentEnd);
$earned = $repository->earnedInPeriod($accounts, $currentStart, $currentEnd); $earned = $repository->incomesInPeriod($accounts, $currentStart, $currentEnd);
$spentArray[$date] = bcmul($spent, '-1'); $spentArray[$date] = bcmul($spent, '-1');
$earnedArray[$date] = $earned; $earnedArray[$date] = $earned;
$currentStart = Navigation::addPeriod($currentStart, '1M', 0); $currentStart = Navigation::addPeriod($currentStart, '1M', 0);

View File

@@ -15,6 +15,7 @@ namespace FireflyIII\Support\Twig;
use Amount; use Amount;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\Budget as ModelBudget; use FireflyIII\Models\Budget as ModelBudget;
use FireflyIII\Models\Category;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
@@ -283,26 +284,29 @@ class Journal extends Twig_Extension
if ($cache->has()) { if ($cache->has()) {
return $cache->get(); return $cache->get();
} }
$categories = []; $categories = [];
// get all budgets: // get all categories for the journal itself (easy):
foreach ($journal->categories as $category) { foreach ($journal->categories as $category) {
$categories[] = '<a href="' . route('categories.show', [$category->id]) . '" title="' . e($category->name) . '">' . e($category->name) . '</a>'; $categories[] = '<a href="' . route('categories.show', [$category->id]) . '" title="' . e($category->name) . '">' . e($category->name) . '</a>';
} }
// and more! if (count($categories) === 0) {
foreach ($journal->transactions as $transaction) { $set = Category::distinct()->leftJoin('category_transaction', 'categories.id', '=', 'category_transaction.category_id')
foreach ($transaction->categories as $category) { ->leftJoin('transactions', 'category_transaction.transaction_id', '=', 'transactions.id')
->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('categories.user_ud', $journal->user_id)
->where('transaction_journals.id', $journal->id)
->get(['categories.*']);
/** @var Category $category */
foreach ($set as $category) {
$categories[] = '<a href="' . route('categories.show', [$category->id]) . '" title="' . e($category->name) . '">' . e($category->name) $categories[] = '<a href="' . route('categories.show', [$category->id]) . '" title="' . e($category->name) . '">' . e($category->name)
. '</a>'; . '</a>';
} }
} }
$string = join(', ', array_unique($categories)); $string = join(', ', array_unique($categories));
$cache->store($string); $cache->store($string);
return $string; return $string;
} }
); );
} }
@@ -370,6 +374,8 @@ class Journal extends Twig_Extension
} }
/** /**
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's 5.
*
* @return Twig_SimpleFilter * @return Twig_SimpleFilter
*/ */
protected function typeIcon(): Twig_SimpleFilter protected function typeIcon(): Twig_SimpleFilter