Fixed the last issues. Now onto code complexity.

This commit is contained in:
James Cole 2015-07-06 18:48:17 +02:00
parent cd08484a13
commit 52df2edc8f
2 changed files with 12 additions and 6 deletions

View File

@ -389,7 +389,9 @@ class AccountRepository implements AccountRepositoryInterface
public function store(array $data) public function store(array $data)
{ {
$newAccount = $this->storeAccount($data); $newAccount = $this->storeAccount($data);
if (!is_null($newAccount)) {
$this->storeMetadata($newAccount, $data); $this->storeMetadata($newAccount, $data);
}
// continue with the opposing account: // continue with the opposing account:
@ -457,8 +459,10 @@ class AccountRepository implements AccountRepositoryInterface
'virtualBalance' => 0, 'virtualBalance' => 0,
]; ];
$opposing = $this->storeAccount($opposingData); $opposing = $this->storeAccount($opposingData);
if (!is_null($opposing)) {
$this->storeInitialBalance($account, $opposing, $data); $this->storeInitialBalance($account, $opposing, $data);
} }
}
} else { } else {
if ($openingBalance) { // opening balance is zero, should we delete it? if ($openingBalance) { // opening balance is zero, should we delete it?

View File

@ -143,10 +143,12 @@ class JournalRepository implements JournalRepositoryInterface
foreach ($array as $name) { foreach ($array as $name) {
if (strlen(trim($name)) > 0) { if (strlen(trim($name)) > 0) {
$tag = Tag::firstOrCreateEncrypted(['tag' => $name, 'user_id' => $journal->user_id]); $tag = Tag::firstOrCreateEncrypted(['tag' => $name, 'user_id' => $journal->user_id]);
if (!is_null($tag)) {
$tagRepository->connect($journal, $tag); $tagRepository->connect($journal, $tag);
} }
} }
} }
}
/** /**
* @param array $data * @param array $data
@ -186,19 +188,19 @@ class JournalRepository implements JournalRepositoryInterface
} }
// store accounts (depends on type) // store accounts (depends on type)
list($from, $to) = $this->storeAccounts($transactionType, $data); list($fromAccount, $toAccount) = $this->storeAccounts($transactionType, $data);
// store accompanying transactions. // store accompanying transactions.
Transaction::create( // first transaction. Transaction::create( // first transaction.
[ [
'account_id' => $from->id, 'account_id' => $fromAccount->id,
'transaction_journal_id' => $journal->id, 'transaction_journal_id' => $journal->id,
'amount' => $data['amount'] * -1 'amount' => $data['amount'] * -1
] ]
); );
Transaction::create( // second transaction. Transaction::create( // second transaction.
[ [
'account_id' => $to->id, 'account_id' => $toAccount->id,
'transaction_journal_id' => $journal->id, 'transaction_journal_id' => $journal->id,
'amount' => $data['amount'] 'amount' => $data['amount']
] ]