Skip to content

Firefly III: a personal finances manager

Some cleaning up.

James Colecdc0e3cfd851
diff --git a/app/Handlers/Events/ConnectJournalToPiggyBank.php b/app/Handlers/Events/ConnectJournalToPiggyBank.php
index cc75dca89f..d4c9cef764 100644
--- a/app/Handlers/Events/ConnectJournalToPiggyBank.php
+++ b/app/Handlers/Events/ConnectJournalToPiggyBank.php
@@ -53,7 +53,7 @@ class ConnectJournalToPiggyBank
}
bcscale(2);
- $amount = $journal->actual_amount;
+ $amount = $journal->amount_positive;
// if piggy account matches source account, the amount is positive
if ($piggyBank->account_id == $journal->source_account->id) {
$amount = $amount * -1;
diff --git a/app/Helpers/Collection/Expense.php b/app/Helpers/Collection/Expense.php
index 22f189329f..e165feb365 100644
--- a/app/Helpers/Collection/Expense.php
+++ b/app/Helpers/Collection/Expense.php
@@ -36,7 +36,7 @@ class Expense
$accountId = $entry->account_id;
if (!$this->expenses->has($accountId)) {
$newObject = new stdClass;
- $newObject->amount = strval(round($entry->actual_amount, 2));
+ $newObject->amount = strval(round($entry->amount_positive, 2));
$newObject->name = $entry->name;
$newObject->count = 1;
$newObject->id = $accountId;
@@ -44,7 +44,7 @@ class Expense
} else {
bcscale(2);
$existing = $this->expenses->get($accountId);
- $existing->amount = bcadd($existing->amount, $entry->actual_amount);
+ $existing->amount = bcadd($existing->amount, $entry->amount_positive);
$existing->count++;
$this->expenses->put($accountId, $existing);
}
diff --git a/app/Helpers/Collection/Income.php b/app/Helpers/Collection/Income.php
index 5a80b7a9b1..9d1389dfcb 100644
--- a/app/Helpers/Collection/Income.php
+++ b/app/Helpers/Collection/Income.php
@@ -38,7 +38,7 @@ class Income
$accountId = $entry->account_id;
if (!$this->incomes->has($accountId)) {
$newObject = new stdClass;
- $newObject->amount = strval(round($entry->actual_amount, 2));
+ $newObject->amount = strval(round($entry->amount_positive, 2));
$newObject->name = $entry->name;
$newObject->count = 1;
$newObject->id = $accountId;
@@ -46,7 +46,7 @@ class Income
} else {
bcscale(2);
$existing = $this->incomes->get($accountId);
- $existing->amount = bcadd($existing->amount, $entry->actual_amount);
+ $existing->amount = bcadd($existing->amount, $entry->amount_positive);
$existing->count++;
$this->incomes->put($accountId, $existing);
}
diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php
index 8281b99629..97090de7da 100644
--- a/app/Helpers/Report/ReportHelper.php
+++ b/app/Helpers/Report/ReportHelper.php
@@ -350,7 +350,7 @@ class ReportHelper implements ReportHelperInterface
$object = new Expense;
$set = $this->query->expenseInPeriodCorrected($start, $end, $shared);
foreach ($set as $entry) {
- $object->addToTotal($entry->actual_amount);
+ $object->addToTotal($entry->amount_positive);
$object->addOrCreateExpense($entry);
}
@@ -371,7 +371,7 @@ class ReportHelper implements ReportHelperInterface
$object = new Income;
$set = $this->query->incomeInPeriodCorrected($start, $end, $shared);
foreach ($set as $entry) {
- $object->addToTotal($entry->actual_amount);
+ $object->addToTotal($entry->amount_positive);
$object->addOrCreateIncome($entry);
}
diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php
index aa53a87ba1..ef8c33d0dc 100644
--- a/app/Http/Controllers/TransactionController.php
+++ b/app/Http/Controllers/TransactionController.php
@@ -179,7 +179,7 @@ class TransactionController extends Controller
$preFilled['piggy_bank_id'] = $journal->piggyBankEvents()->orderBy('date', 'DESC')->first()->piggy_bank_id;
}
- $preFilled['amount'] = $journal->actual_amount;
+ $preFilled['amount'] = $journal->amount_positive;
if ($journal->transactionType->type == 'Withdrawal') {
$preFilled['account_id'] = $journal->source_account->id;
diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php
index a2b1fc3f8b..3248980fb3 100644
--- a/app/Models/TransactionJournal.php
+++ b/app/Models/TransactionJournal.php
@@ -69,6 +69,7 @@ use Watson\Validating\ValidatingTrait;
* @property string $name
* @property-read string $symbol
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Attachment[] $attachments
+ * @property-read mixed $amount_positive
*/
class TransactionJournal extends Model
{
@@ -120,7 +121,7 @@ class TransactionJournal extends Model
/**
* @return string
*/
- public function getActualAmountAttribute()
+ public function getAmountPositiveAttribute()
{
$amount = '0';
/** @var Transaction $t */
@@ -146,18 +147,11 @@ class TransactionJournal extends Model
}
bcscale(2);
- $set = $this->transactions->sortByDesc('amount');
- $amount = $set->first()->amount;
-
- if (intval($this->tag_count) === 1) {
- // get amount for single tag:
- $amount = $this->amountByTag($this->tags()->first(), $amount);
- }
-
- if (intval($this->tag_count) > 1) {
- // get amount for either tag.
- $amount = $this->amountByTags($amount);
-
+ $type = $this->transactionType->type;
+ $transaction = $this->transactions->sortByDesc('amount')->first();
+ $amount = $transaction->amount;
+ if ($type == 'Withdrawal') {
+ $amount = $amount * -1;
}
$cache->store($amount);
@@ -176,7 +170,7 @@ class TransactionJournal extends Model
if ($this->transactionType->type == 'Withdrawal') {
$others = $tag->transactionJournals()->transactionTypes(['Deposit'])->get();
foreach ($others as $other) {
- $amount = bcsub($amount, $other->actual_amount);
+ $amount = bcsub($amount, $other->amount_positive);
}
return $amount;
@@ -199,7 +193,7 @@ class TransactionJournal extends Model
if ($this->transactionType->type == 'Withdrawal') {
$transfer = $tag->transactionJournals()->transactionTypes(['Transfer'])->first();
if ($transfer) {
- $amount = bcsub($amount, $transfer->actual_amount);
+ $amount = bcsub($amount, $transfer->amount_positive);
return $amount;
}
@@ -260,22 +254,6 @@ class TransactionJournal extends Model
return $amount;
}
- /**
- * @return string
- */
- public function getCorrectAmountAttribute()
- {
-
- switch ($this->transactionType->type) {
- case 'Deposit':
- return $this->transactions()->where('amount', '>', 0)->first()->amount;
- case 'Withdrawal':
- return $this->transactions()->where('amount', '<', 0)->first()->amount;
- }
-
- return $this->transactions()->where('amount', '>', 0)->first()->amount;
- }
-
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\HasMany
diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php
index 3212a5121a..035f1079ed 100644
--- a/app/Repositories/Category/CategoryRepository.php
+++ b/app/Repositories/Category/CategoryRepository.php
@@ -200,7 +200,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
*/
public function spentOnDaySumCorrected(Category $category, Carbon $date)
{
- return $category->transactionjournals()->transactionTypes(['Withdrawal'])->onDate($date)->get(['transaction_journals.*'])->sum('correct_amount');
+ return $category->transactionjournals()->transactionTypes(['Withdrawal'])->onDate($date)->get(['transaction_journals.*'])->sum('amount');
}
/**
@@ -260,7 +260,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
$query->before($end);
}
- return $query->get(['transaction_journals.*'])->sum('correct_amount');
+ return $query->get(['transaction_journals.*'])->sum('amount');
}
@@ -286,7 +286,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
}
$sum = $category->transactionjournals()->transactionTypes(['Withdrawal'])->before($end)->after($start)->get(['transaction_journals.*'])->sum(
- 'correct_amount'
+ 'amount'
);
$cache->store($sum);
@@ -316,7 +316,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
}
$sum = $category->transactionjournals()->transactionTypes(['Deposit'])->before($end)->after($start)->get(['transaction_journals.*'])->sum(
- 'correct_amount'
+ 'amount'
);
$cache->store($sum);
@@ -367,6 +367,6 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
*/
public function earnedOnDaySumCorrected(Category $category, Carbon $date)
{
- return $category->transactionjournals()->transactionTypes(['Deposit'])->onDate($date)->get(['transaction_journals.*'])->sum('correct_amount');
+ return $category->transactionjournals()->transactionTypes(['Deposit'])->onDate($date)->get(['transaction_journals.*'])->sum('amount');
}
}
diff --git a/app/Repositories/Shared/ComponentRepository.php b/app/Repositories/Shared/ComponentRepository.php
index 632ce9db63..7edbb7bfb3 100644
--- a/app/Repositories/Shared/ComponentRepository.php
+++ b/app/Repositories/Shared/ComponentRepository.php
@@ -40,7 +40,7 @@ class ComponentRepository
if ($shared === true) { // shared is true: always ignore transfers between accounts!
$sum = $object->transactionjournals()->transactionTypes(['Withdrawal', 'Deposit', 'Opening balance'])->before($end)->after($start)
- ->get(['transaction_journals.*'])->sum('correct_amount');
+ ->get(['transaction_journals.*'])->sum('amount');
} else {
// do something else, SEE budgets.
// get all journals in this month where the asset account is NOT shared.
@@ -52,7 +52,7 @@ class ComponentRepository
'account_meta', function (JoinClause $join) {
$join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
}
- )->where('account_meta.data', '!=', '"sharedAsset"')->get(['transaction_journals.*'])->sum('correct_amount');
+ )->where('account_meta.data', '!=', '"sharedAsset"')->get(['transaction_journals.*'])->sum('amount');
}
$cache->store($sum);
diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.php
index 1be638061d..62c07048de 100644
--- a/app/Support/Twig/Journal.php
+++ b/app/Support/Twig/Journal.php
@@ -181,7 +181,7 @@ class Journal extends Twig_Extension
if ($tag->tagMode == 'balancingAct') {
// return tag formatted for a "balancing act", even if other
// tags are present.
- $amount = app('amount')->format($journal->actual_amount, false);
+ $amount = app('amount')->format($journal->amount_positive, false);
$string = '<a href="' . route('tags.show', [$tag->id]) . '" class="label label-success" title="' . $amount
. '"><i class="fa fa-fw fa-refresh"></i> ' . $tag->tag . '</a>';
diff --git a/resources/twig/list/journals.twig b/resources/twig/list/journals.twig
index f3cae8d9ca..ddc9c6e64c 100644
--- a/resources/twig/list/journals.twig
+++ b/resources/twig/list/journals.twig
@@ -40,7 +40,7 @@
<td colspan="7"><em>Invalid journal: Found {{ journal.transactions|length }} transaction(s)</em></td>
</tr>
{% else %}
- {% set _sum = _sum + journal.correct_amount %}
+ {% set _sum = _sum + journal.amount %}
<tr class="drag" data-date="{{ journal.date.format('Y-m-d') }}" data-id="{{ journal.id }}">
<td class="hidden-xs">
<div class="btn-group btn-group-xs">
@@ -64,11 +64,7 @@
</td>
<td>
- {% if not hideTags %}
- {{ relevantTags(journal)|raw }}
- {% else %}
- {{ journal.correct_amount|formatAmount }}
- {% endif %}
+ {{ journal.amount|formatAmount }}
</td>
<td class="hidden-sm hidden-xs">
{{ journal.date.formatLocalized(monthAndDayFormat) }}