Move some stuff around.

This commit is contained in:
James Cole
2016-03-02 19:41:22 +01:00
parent 2fd476ada8
commit 5b949d6e00
4 changed files with 19 additions and 11 deletions

View File

@@ -144,6 +144,7 @@ class TransactionController extends Controller
// get journal again:
/** @var TransactionJournal $journal */
$journal = TransactionJournal::expanded()->where('transaction_journals.id', $journal->id)->first(TransactionJournal::QUERYFIELDS);
// TODO REMOVE this in favour of something static in TransactionJournal.
// cannot edit opening balance
if ($journal->isOpeningBalance()) {
throw new FireflyException('Cannot edit this transaction (#' . $journal->id . '). Edit the account instead!');

View File

@@ -3,6 +3,7 @@
use Auth;
use Carbon\Carbon;
use Crypt;
use FireflyIII\Support\Models\TransactionJournalSupport;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -58,7 +59,7 @@ use Watson\Validating\ValidatingTrait;
*
*/
class TransactionJournal extends BaseModel
class TransactionJournal extends TransactionJournalSupport
{
use SoftDeletes, ValidatingTrait;

View File

@@ -447,6 +447,7 @@ class BillRepository implements BillRepositoryInterface
// looks weird, but is useful:
/** @var TransactionJournal $journal */
$journal = TransactionJournal::expanded()->where('transaction_journals.id', $journal->id)->get(TransactionJournal::QUERYFIELDS)->first();
// TODO REMOVE this in favour of something static in TransactionJournal.
/*

View File

@@ -1,39 +1,44 @@
<?php
/**
* BaseModel.php
* TransactionJournalSupport.php
* Copyright (C) 2016 Sander Dorigo
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace FireflyIII\Models;
namespace FireflyIII\Support\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
/**
* Class BaseModel
* Class TransactionJournalSupport
*
* @package FireflyIII\Models
* @package FireflyIII\Support\Models
*/
class BaseModel extends Model
class TransactionJournalSupport extends Model
{
/**
* @param $query
* @param $table
* @param Builder $query
* @param string $table
*
* @return bool
*/
public static function isJoined($query, $table)
public static function isJoined(Builder $query, string $table):bool
{
$joins = $query->getQuery()->joins;
if($joins == null) {
if (is_null($joins)) {
return false;
}
foreach ($joins as $join) {
if ($join->table == $table) {
if ($join->table === $table) {
return true;
}
}
return false;
}
}