Some refactoring.

This commit is contained in:
James Cole
2016-05-14 13:51:33 +02:00
parent 5a6967cefd
commit 863227c55c
12 changed files with 240 additions and 260 deletions

View File

@@ -2,7 +2,6 @@
declare(strict_types = 1);
namespace FireflyIII\Helpers\Collection;
use Crypt;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Support\Collection;
use stdClass;
@@ -34,21 +33,29 @@ class Income
*/
public function addOrCreateIncome(TransactionJournal $entry)
{
$accountId = $entry->account_id;
// add each account individually:
$sources = TransactionJournal::sourceTransactionList($entry);
$object = new stdClass;
$object->amount = strval(round($entry->journalAmount, 2));
$object->name = Crypt::decrypt($entry->account_name);
$object->count = 1;
$object->id = $accountId;
foreach ($sources as $transaction) {
$amount = strval($transaction->amount);
$account = $transaction->account;
$amount = bcmul($amount, '-1');
// overrule some properties:
if ($this->incomes->has($accountId)) {
$object = $this->incomes->get($accountId);
$object->amount = bcadd($object->amount, $entry->journalAmount);
$object->count++;
$object = new stdClass;
$object->amount = $amount;
$object->name = $account->name;
$object->count = 1;
$object->id = $account->id;
// overrule some properties:
if ($this->incomes->has($account->id)) {
$object = $this->incomes->get($account->id);
$object->amount = bcadd($object->amount, $amount);
$object->count++;
}
$this->incomes->put($account->id, $object);
}
$this->incomes->put($accountId, $object);
}
/**