firefly-iii/app/Support/Http/Controllers/ModelInformation.php
2018-08-11 14:15:07 +02:00

65 lines
1.8 KiB
PHP

<?php
/**
* ModelInformation.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Http\Controllers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
/**
* Trait ModelInformation
*
*/
trait ModelInformation
{
/**
* Is transaction opening balance?
*
* @param TransactionJournal $journal
*
* @return bool
*/
protected function isOpeningBalance(TransactionJournal $journal): bool
{
return TransactionType::OPENING_BALANCE === $journal->transactionType->type;
}
/**
* Checks if journal is split.
*
* @param TransactionJournal $journal
*
* @return bool
*/
protected function isSplitJournal(TransactionJournal $journal): bool // validate objects
{
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
$repository->setUser($journal->user);
$count = $repository->countTransactions($journal);
return $count > 2;
}
}