Some code cleanup and I sneaked in a chart optimisation.

This commit is contained in:
James Cole
2016-04-26 22:21:34 +02:00
parent 5199377113
commit 66f2df9677
4 changed files with 30 additions and 39 deletions

View File

@@ -33,26 +33,25 @@ class Expense
*/ */
public function addOrCreateExpense(TransactionJournal $entry) public function addOrCreateExpense(TransactionJournal $entry)
{ {
$accountId = $entry->account_id; $accountId = $entry->account_id;
$amount = strval(round($entry->journalAmount, 2)); $amount = strval(round($entry->journalAmount, 2));
if (bccomp('0', $amount) === -1) { if (bccomp('0', $amount) === -1) {
$amount = bcmul($amount, '-1'); $amount = bcmul($amount, '-1');
} }
if (!$this->expenses->has($accountId)) { $object = new stdClass;
$newObject = new stdClass; $object->amount = $amount;
$newObject->amount = $amount; $object->name = Crypt::decrypt($entry->account_name);
$newObject->name = Crypt::decrypt($entry->account_name); $object->count = 1;
$newObject->count = 1; $object->id = $accountId;
$newObject->id = $accountId;
$this->expenses->put($accountId, $newObject); // overrule some properties:
} else { if ($this->expenses->has($accountId)) {
$existing = $this->expenses->get($accountId); $object = $this->expenses->get($accountId);
$existing->amount = bcadd($existing->amount, $amount); $object->amount = bcadd($object->amount, $amount);
$existing->count++; $object->count++;
$this->expenses->put($accountId, $existing);
} }
$this->expenses->put($accountId, $object);
} }
/** /**
@@ -60,8 +59,6 @@ class Expense
*/ */
public function addToTotal(string $add) public function addToTotal(string $add)
{ {
$add = strval(round($add, 2)); $add = strval(round($add, 2));
if (bccomp('0', $add) === -1) { if (bccomp('0', $add) === -1) {
$add = bcmul($add, '-1'); $add = bcmul($add, '-1');

View File

@@ -34,21 +34,21 @@ class Income
*/ */
public function addOrCreateIncome(TransactionJournal $entry) public function addOrCreateIncome(TransactionJournal $entry)
{ {
$accountId = $entry->account_id; $accountId = $entry->account_id;
if (!$this->incomes->has($accountId)) {
$newObject = new stdClass; $object = new stdClass;
$newObject->amount = strval(round($entry->journalAmount, 2)); $object->amount = strval(round($entry->journalAmount, 2));
$newObject->name = Crypt::decrypt($entry->account_name); $object->name = Crypt::decrypt($entry->account_name);
$newObject->count = 1; $object->count = 1;
$newObject->id = $accountId; $object->id = $accountId;
$this->incomes->put($accountId, $newObject);
} else { // overrule some properties:
$existing = $this->incomes->get($accountId); if ($this->incomes->has($accountId)) {
$existing->amount = bcadd($existing->amount, $entry->journalAmount); $object = $this->incomes->get($accountId);
$existing->count++; $object->amount = bcadd($object->amount, $entry->journalAmount);
$this->incomes->put($accountId, $existing); $object->count++;
} }
$this->incomes->put($accountId, $object);
} }
/** /**

View File

@@ -20,15 +20,9 @@ class AccountId extends BasicConverter implements ConverterInterface
{ {
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface'); $repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$account = isset($this->mapped[$this->index][$this->value])
// is mapped? Then it's easy! ? $repository->find($this->mapped[$this->index][$this->value])
if (isset($this->mapped[$this->index][$this->value])) { : $repository->find($this->value);
/** @var Account $account */
$account = $repository->find($this->mapped[$this->index][$this->value]);
} else {
/** @var Account $account */
$account = $repository->find($this->value);
}
return $account; return $account;
} }

View File

@@ -156,8 +156,8 @@ var defaultColumnOptions = {
callback: function (tickValue, index, ticks) { callback: function (tickValue, index, ticks) {
"use strict"; "use strict";
return accounting.formatMoney(tickValue); return accounting.formatMoney(tickValue);
},
} beginAtZero: true
} }
}] }]
}, },