Removed some foreach() routines that are no longer necessary now that getAmountAttribute() exists.

This commit is contained in:
James Cole 2015-04-09 20:58:57 +02:00
parent 5124ce0302
commit 587b94153d
4 changed files with 4 additions and 38 deletions

View File

@ -51,14 +51,7 @@ class ConnectJournalToPiggyBank
return;
}
Log::debug('Found a piggy bank');
$amount = 0;
/** @var Transaction $transaction */
foreach ($journal->transactions()->get() as $transaction) {
if ($transaction->account_id === $piggyBank->account_id) {
// this transaction is the relevant one.
$amount = floatval($transaction->amount);
}
}
$amount = $journal->amount;
Log::debug('Amount: ' . $amount);
if ($amount == 0) {
return;

View File

@ -45,17 +45,8 @@ class UpdateJournalConnection
if (is_null($repetition)) {
return;
}
$amount = 0;
/** @var Transaction $transaction */
foreach ($journal->transactions()->get() as $transaction) {
if ($transaction->account_id === $piggyBank->account_id) {
// this transaction is the relevant one.
$amount = floatval($transaction->amount);
}
}
// update current repetition:
$diff = $amount - $event->amount;
$amount = $journal->amount;
$diff = $amount - $event->amount;// update current repetition
$repetition->currentamount += $diff;
$repetition->save();

View File

@ -40,19 +40,7 @@ class RelatedController extends Controller
$unique = array_unique($ids);
$journals = new Collection;
if (count($unique) > 0) {
$journals = Auth::user()->transactionjournals()->whereIn('id', $unique)->get();
$journals->each(
function (TransactionJournal $journal) {
/** @var Transaction $t */
foreach ($journal->transactions()->get() as $t) {
if ($t->amount > 0) {
$journal->amount = $t->amount;
}
}
}
);
}
$parent = $journal;

View File

@ -149,13 +149,7 @@ class TransactionController extends Controller
$preFilled['piggy_bank_id'] = $journal->piggyBankEvents()->orderBy('date', 'DESC')->first()->piggy_bank_id;
}
$preFilled['amount'] = 0;
/** @var Transaction $t */
foreach ($transactions as $t) {
if (floatval($t->amount) > 0) {
$preFilled['amount'] = floatval($t->amount);
}
}
$preFilled['amount'] = $journal->amount;
$preFilled['account_id'] = $repository->getAssetAccount($journal);
$preFilled['expense_account'] = $transactions[0]->account->name;
$preFilled['revenue_account'] = $transactions[1]->account->name;