Skip to content

Firefly III: a personal finances manager

Fixed some more reports and charts. [skip ci]

James Cole95ef691077d8
diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php
index 2b066f726d..deefb7d899 100644
--- a/app/Helpers/Report/ReportHelper.php
+++ b/app/Helpers/Report/ReportHelper.php
@@ -129,7 +129,7 @@ class ReportHelper implements ReportHelperInterface
$balanceEntry->setAccount($account);
// get spent:
- $spent = $this->query->spentInBudget($account, $budget, $start, $end); // I think shared is irrelevant.
+ $spent = $this->query->spentInBudgetCorrected($account, $budget, $start, $end); // I think shared is irrelevant.
$balanceEntry->setSpent($spent);
$line->addBalanceEntry($balanceEntry);
diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php
index 83efb2fbc6..26b056e449 100644
--- a/app/Helpers/Report/ReportQuery.php
+++ b/app/Helpers/Report/ReportQuery.php
@@ -300,6 +300,32 @@ class ReportQuery implements ReportQueryInterface
);
}
+ /**
+ * Covers tags
+ *
+ * @param Account $account
+ * @param Budget $budget
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return float
+ */
+ public function spentInBudgetCorrected(Account $account, Budget $budget, Carbon $start, Carbon $end)
+ {
+
+ return floatval(
+ Auth::user()->transactionjournals()
+ ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
+ ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
+ ->transactionTypes(['Withdrawal'])
+ ->where('transactions.account_id', $account->id)
+ ->before($end)
+ ->after($start)
+ ->where('budget_transaction_journal.budget_id', $budget->id)
+ ->get(['transaction_journals.*'])->sum('amount')
+ ) * -1;
+ }
+
/**
* @param Account $account
* @param Carbon $start
diff --git a/app/Helpers/Report/ReportQueryInterface.php b/app/Helpers/Report/ReportQueryInterface.php
index 7d9d2e33de..1ecf9f9f21 100644
--- a/app/Helpers/Report/ReportQueryInterface.php
+++ b/app/Helpers/Report/ReportQueryInterface.php
@@ -89,6 +89,18 @@ interface ReportQueryInterface
*/
public function spentInBudget(Account $account, Budget $budget, Carbon $start, Carbon $end);
+ /**
+ * Covers tags as well.
+ *
+ * @param Account $account
+ * @param Budget $budget
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return float
+ */
+ public function spentInBudgetCorrected(Account $account, Budget $budget, Carbon $start, Carbon $end);
+
/**
* @param Account $account
* @param Carbon $start
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php
index 0d2d4a648c..21c044f762 100644
--- a/app/Http/Controllers/Chart/CategoryController.php
+++ b/app/Http/Controllers/Chart/CategoryController.php
@@ -78,13 +78,10 @@ class CategoryController extends Controller
$start = Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth());
- $set = $repository->getCategoriesAndExpenses($start, $end);
+ $set = $repository->getCategoriesAndExpensesCorrected($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->addRow($entry['name'], floatval($entry['sum']));
}
$chart->generate();
diff --git a/app/Http/Middleware/Range.php b/app/Http/Middleware/Range.php
index 9faf2b4e00..ac0c05ac76 100644
--- a/app/Http/Middleware/Range.php
+++ b/app/Http/Middleware/Range.php
@@ -73,9 +73,9 @@ class Range
Session::put('first', Carbon::now()->startOfYear());
}
}
- $current = Carbon::now()->format('F Y');
- $next = Carbon::now()->endOfMonth()->addDay()->format('F Y');
- $prev = Carbon::now()->startOfMonth()->subDay()->format('F Y');
+ $current = Carbon::now()->formatLocalized('%B %Y');
+ $next = Carbon::now()->endOfMonth()->addDay()->formatLocalized('%B %Y');
+ $prev = Carbon::now()->startOfMonth()->subDay()->formatLocalized('%B %Y');
View::share('currentMonthName', $current);
View::share('previousMonthName', $prev);
View::share('nextMonthName', $next);
diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php
index 0de670911b..91c6c7f889 100644
--- a/app/Repositories/Category/CategoryRepository.php
+++ b/app/Repositories/Category/CategoryRepository.php
@@ -4,6 +4,7 @@ namespace FireflyIII\Repositories\Category;
use Auth;
use Carbon\Carbon;
+use Crypt;
use DB;
use FireflyIII\Models\Category;
use FireflyIII\Models\TransactionJournal;
@@ -87,6 +88,47 @@ class CategoryRepository implements CategoryRepositoryInterface
->get(['categories.id', 'categories.encrypted', 'categories.name', DB::Raw('SUM(`transactions`.`amount`) AS `sum`')]);
}
+ /**
+ *
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function getCategoriesAndExpensesCorrected($start, $end)
+ {
+ $set = Auth::user()->transactionjournals()
+ ->leftJoin(
+ 'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'
+ )
+ ->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id')
+ ->before($end)
+ ->where('categories.user_id', Auth::user()->id)
+ ->after($start)
+ ->transactionTypes(['Withdrawal'])
+ ->groupBy('categories.id')
+ ->get(['categories.id as category_id', 'categories.encrypted', 'categories.name', 'transaction_journals.*']);
+
+ $result = [];
+ foreach ($set as $entry) {
+ $categoryId = intval($entry->category_id);
+ if (isset($result[$categoryId])) {
+ $result[$categoryId]['sum'] += $entry->amount;
+ } else {
+ $isEncrypted = intval($entry->encrypted) == 1 ? true : false;
+ $name = strlen($entry->name) == 0 ? trans('firefly.noCategory') : $entry->name;
+ $name = $isEncrypted ? Crypt::decrypt($name) : $name;
+ $result[$categoryId] = [
+ 'name' => $name,
+ 'sum' => $entry->amount,
+ ];
+
+ }
+ }
+
+ return $result;
+ }
+
/**
* @param Category $category
*
@@ -220,10 +262,10 @@ class CategoryRepository implements CategoryRepositoryInterface
// shared is true.
// always ignore transfers between accounts!
$sum = floatval(
- $category->transactionjournals()
- ->transactionTypes(['Withdrawal'])
- ->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount')
- );
+ $category->transactionjournals()
+ ->transactionTypes(['Withdrawal'])
+ ->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount')
+ );
} else {
// do something else, SEE budgets.
@@ -260,6 +302,7 @@ class CategoryRepository implements CategoryRepositoryInterface
/**
* Corrected for tags
+ *
* @param Category $category
* @param Carbon $date
*
diff --git a/app/Repositories/Category/CategoryRepositoryInterface.php b/app/Repositories/Category/CategoryRepositoryInterface.php
index d5883dd51f..23425b5ff7 100644
--- a/app/Repositories/Category/CategoryRepositoryInterface.php
+++ b/app/Repositories/Category/CategoryRepositoryInterface.php
@@ -40,6 +40,16 @@ interface CategoryRepositoryInterface
*/
public function getCategoriesAndExpenses($start, $end);
+ /**
+ * Corrected for tags.
+ *
+ * @param Carbon $start
+ * @param Carbon $end
+ *
+ * @return Collection
+ */
+ public function getCategoriesAndExpensesCorrected($start, $end);
+
/**
* @param Category $category
*
diff --git a/resources/lang/en/firefly.php b/resources/lang/en/firefly.php
index f4150d4695..990dd4a344 100644
--- a/resources/lang/en/firefly.php
+++ b/resources/lang/en/firefly.php
@@ -108,6 +108,7 @@ return [
'splitByAccount' => 'Split by account',
'balancedByTransfersAndTags' => 'Balanced by transfers and tags',
+ 'coveredWithTags' => 'Covered with tags',
'leftUnbalanced' => 'Left unbalanced',
'expectedBalance' => 'Expected balance',
'outsideOfBudgets' => 'Outside of budgets',
diff --git a/resources/twig/list/journals-tiny.twig b/resources/twig/list/journals-tiny.twig
index db5f0b04a4..e2c24b72db 100644
--- a/resources/twig/list/journals-tiny.twig
+++ b/resources/twig/list/journals-tiny.twig
@@ -1,37 +1,19 @@
<div class="list-group">
{% for journal in transactions %}
+ {% if journal.amount != 0 %}
-<a class="list-group-item" title="{{journal.date.format('jS M Y')}}" href="{{route('transactions.show',journal.id)}}">
+ <a class="list-group-item" title="{{journal.date.format('jS M Y')}}" href="{{route('transactions.show',journal.id)}}">
- {% if not journal.type %}
- {% if journal.transactiontype.type == 'Withdrawal' %}
- <i class="fa fa-long-arrow-left fa-fw" title="{{ trans('list.withdrawal') }}"></i>
- {% endif %}
- {% if journal.transactiontype.type == 'Deposit' %}
- <i class="fa fa-long-arrow-right fa-fw" title="{{ trans('list.deposit') }}"></i>
- {% endif %}
- {% if journal.transactiontype.type == 'Transfer' %}
- <i class="fa fa-fw fa-exchange" title="{{ trans('list.transfer') }}"></i>
- {% endif %}
- {% else %}
- {% if journal.type == 'Withdrawal' %}
- <i class="fa fa-long-arrow-left fa-fw" title="{{ trans('list.withdrawal') }}"></i>
- {% endif %}
- {% if journal.type == 'Deposit' %}
- <i class="fa fa-long-arrow-right fa-fw" title="{{ trans('list.deposit') }}"></i>
- {% endif %}
- {% if journal.type == 'Transfer' %}
- <i class="fa fa-fw fa-exchange" title="{{ trans('list.transfer') }}"></i>
- {% endif %}
- {% endif %}
+ {{ journal|typeIcon }}
{{ journal.description }}
-<span class="pull-right small">
+ <span class="pull-right small">
{{ journal|formatJournal }}
-</span>
+ </span>
-</a>
+ </a>
+ {% endif %}
{% endfor %}
</div>