Various optimisations.

This commit is contained in:
James Cole
2015-07-06 22:23:34 +02:00
parent d67db74ca2
commit 2d4b148b2c
19 changed files with 66 additions and 68 deletions

View File

@@ -566,7 +566,6 @@ class AccountRepository implements AccountRepositoryInterface
);
$journal->save();
if ($data['openingBalance'] < 0) {
$firstAccount = $opposing;
$secondAccount = $account;
@@ -578,26 +577,11 @@ class AccountRepository implements AccountRepositoryInterface
$firstAmount = $data['openingBalance'];
$secondAmount = $data['openingBalance'] * -1;
}
$one = new Transaction(['account_id' => $firstAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $firstAmount]);
$one->save();// first transaction: from
// first transaction: from
$one = new Transaction(
[
'account_id' => $firstAccount->id,
'transaction_journal_id' => $journal->id,
'amount' => $firstAmount
]
);
$one->save();
// second transaction: to
$two = new Transaction(
[
'account_id' => $secondAccount->id,
'transaction_journal_id' => $journal->id,
'amount' => $secondAmount
]
);
$two->save();
$two = new Transaction(['account_id' => $secondAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $secondAmount]);
$two->save(); // second transaction: to
return $journal;
@@ -606,6 +590,8 @@ class AccountRepository implements AccountRepositoryInterface
/**
* @param Account $account
* @param array $data
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function updateMetadata(Account $account, array $data)
{

View File

@@ -115,14 +115,14 @@ class JournalRepository implements JournalRepositoryInterface
}
/**
* @param $id
* @param int $journalId
* @param Carbon $date
*
* @return TransactionJournal
*/
public function getWithDate($id, Carbon $date)
public function getWithDate($journalId, Carbon $date)
{
return Auth::user()->transactionjournals()->where('id', $id)->where('date', $date->format('Y-m-d 00:00:00'))->first();
return Auth::user()->transactionjournals()->where('id', $journalId)->where('date', $date->format('Y-m-d 00:00:00'))->first();
}
/**

View File

@@ -62,12 +62,12 @@ interface JournalRepositoryInterface
public function getTransactionType($type);
/**
* @param $id
* @param int $journalId
* @param Carbon $date
*
* @return TransactionJournal
*/
public function getWithDate($id, Carbon $date);
public function getWithDate($journalId, Carbon $date);
/**
* @param TransactionJournal $journal