Exemplo n.º 1
0
 /**
  * @param TransactionJournal $journal
  * @param Tag                $tag
  *
  * @return boolean
  */
 protected function connectAdvancePayment(TransactionJournal $journal, Tag $tag)
 {
     /** @var TransactionType $transfer */
     $transfer = TransactionType::whereType('Transfer')->first();
     /** @var TransactionType $withdrawal */
     $withdrawal = TransactionType::whereType('Withdrawal')->first();
     /** @var TransactionType $deposit */
     $deposit = TransactionType::whereType('Deposit')->first();
     $withdrawals = $tag->transactionjournals()->where('transaction_type_id', $withdrawal->id)->count();
     $deposits = $tag->transactionjournals()->where('transaction_type_id', $deposit->id)->count();
     // advance payments cannot accept transfers:
     if ($journal->transaction_type_id == $transfer->id) {
         return false;
     }
     // the first transaction to be attached to this
     // tag is attached just like that:
     if ($withdrawals < 1 && $deposits < 1) {
         $journal->tags()->save($tag);
         $journal->save();
         return true;
     }
     // if withdrawal and already has a withdrawal, return false:
     if ($journal->transaction_type_id == $withdrawal->id && $withdrawals == 1) {
         return false;
     }
     // if already has transaction journals, must match ALL asset account id's:
     if ($deposits > 0 || $withdrawals == 1) {
         return $this->matchAll($journal, $tag);
     }
     // this statement is unreachable.
     return false;
     // @codeCoverageIgnore
 }