mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Some code cleanup and I sneaked in a chart optimisation.
This commit is contained in:
@@ -33,26 +33,25 @@ class Expense
|
||||
*/
|
||||
public function addOrCreateExpense(TransactionJournal $entry)
|
||||
{
|
||||
|
||||
$accountId = $entry->account_id;
|
||||
$amount = strval(round($entry->journalAmount, 2));
|
||||
if (bccomp('0', $amount) === -1) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
}
|
||||
|
||||
if (!$this->expenses->has($accountId)) {
|
||||
$newObject = new stdClass;
|
||||
$newObject->amount = $amount;
|
||||
$newObject->name = Crypt::decrypt($entry->account_name);
|
||||
$newObject->count = 1;
|
||||
$newObject->id = $accountId;
|
||||
$this->expenses->put($accountId, $newObject);
|
||||
} else {
|
||||
$existing = $this->expenses->get($accountId);
|
||||
$existing->amount = bcadd($existing->amount, $amount);
|
||||
$existing->count++;
|
||||
$this->expenses->put($accountId, $existing);
|
||||
$object = new stdClass;
|
||||
$object->amount = $amount;
|
||||
$object->name = Crypt::decrypt($entry->account_name);
|
||||
$object->count = 1;
|
||||
$object->id = $accountId;
|
||||
|
||||
// overrule some properties:
|
||||
if ($this->expenses->has($accountId)) {
|
||||
$object = $this->expenses->get($accountId);
|
||||
$object->amount = bcadd($object->amount, $amount);
|
||||
$object->count++;
|
||||
}
|
||||
$this->expenses->put($accountId, $object);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,8 +59,6 @@ class Expense
|
||||
*/
|
||||
public function addToTotal(string $add)
|
||||
{
|
||||
|
||||
|
||||
$add = strval(round($add, 2));
|
||||
if (bccomp('0', $add) === -1) {
|
||||
$add = bcmul($add, '-1');
|
||||
|
@@ -34,21 +34,21 @@ class Income
|
||||
*/
|
||||
public function addOrCreateIncome(TransactionJournal $entry)
|
||||
{
|
||||
|
||||
$accountId = $entry->account_id;
|
||||
if (!$this->incomes->has($accountId)) {
|
||||
$newObject = new stdClass;
|
||||
$newObject->amount = strval(round($entry->journalAmount, 2));
|
||||
$newObject->name = Crypt::decrypt($entry->account_name);
|
||||
$newObject->count = 1;
|
||||
$newObject->id = $accountId;
|
||||
$this->incomes->put($accountId, $newObject);
|
||||
} else {
|
||||
$existing = $this->incomes->get($accountId);
|
||||
$existing->amount = bcadd($existing->amount, $entry->journalAmount);
|
||||
$existing->count++;
|
||||
$this->incomes->put($accountId, $existing);
|
||||
|
||||
$object = new stdClass;
|
||||
$object->amount = strval(round($entry->journalAmount, 2));
|
||||
$object->name = Crypt::decrypt($entry->account_name);
|
||||
$object->count = 1;
|
||||
$object->id = $accountId;
|
||||
|
||||
// overrule some properties:
|
||||
if ($this->incomes->has($accountId)) {
|
||||
$object = $this->incomes->get($accountId);
|
||||
$object->amount = bcadd($object->amount, $entry->journalAmount);
|
||||
$object->count++;
|
||||
}
|
||||
$this->incomes->put($accountId, $object);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -20,15 +20,9 @@ class AccountId extends BasicConverter implements ConverterInterface
|
||||
{
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||
|
||||
// is mapped? Then it's easy!
|
||||
if (isset($this->mapped[$this->index][$this->value])) {
|
||||
/** @var Account $account */
|
||||
$account = $repository->find($this->mapped[$this->index][$this->value]);
|
||||
} else {
|
||||
/** @var Account $account */
|
||||
$account = $repository->find($this->value);
|
||||
}
|
||||
$account = isset($this->mapped[$this->index][$this->value])
|
||||
? $repository->find($this->mapped[$this->index][$this->value])
|
||||
: $repository->find($this->value);
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
@@ -156,8 +156,8 @@ var defaultColumnOptions = {
|
||||
callback: function (tickValue, index, ticks) {
|
||||
"use strict";
|
||||
return accounting.formatMoney(tickValue);
|
||||
|
||||
}
|
||||
},
|
||||
beginAtZero: true
|
||||
}
|
||||
}]
|
||||
},
|
||||
|
Reference in New Issue
Block a user