Some cleaning up.

This commit is contained in:
James Cole 2015-09-25 20:40:24 +02:00
parent 466e81d56a
commit cdc0e3cfd8
10 changed files with 27 additions and 53 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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

View File

@ -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');
}
}

View File

@ -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);

View File

@ -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>';

View File

@ -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) }}