Added some correcting methods. [skip ci]

This commit is contained in:
James Cole
2015-05-20 06:50:15 +02:00
parent 9217c2f003
commit 42b49d0e4b
6 changed files with 174 additions and 4 deletions

View File

@@ -99,15 +99,22 @@ class TransactionJournal extends Model
/** @var Tag $tag */
$tag = $this->tags()->where('tagMode', 'advancePayment')->first();
if ($tag && $this->transactionType->type == 'Withdrawal') {
// loop other deposits, remove from our amount.
$others = $tag->transactionJournals()->transactionTypes(['Deposit'])->get();
foreach ($others as $other) {
$amount -= $other->amount;
$amount -= $other->actualAmount;
}
return $amount;
}
// if this journal is part of an advancePayment AND the journal is a deposit,
// then the journal amount is correcting a withdrawal, and the amount is zero:
if ($tag && $this->transactionType->type == 'Deposit') {
return 0;
}
return $amount;
}