mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-17 09:51:40 +00:00
New code.
This commit is contained in:
@@ -87,6 +87,19 @@ class TransactionJournal extends Model
|
||||
return $this->hasMany('FireflyIII\Models\PiggyBankEvent');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EloquentBuilder $query
|
||||
* @param Account $account
|
||||
*/
|
||||
public function scopeAccountIs(EloquentBuilder $query, Account $account)
|
||||
{
|
||||
if (!isset($this->joinedTransactions)) {
|
||||
$query->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id');
|
||||
$this->joinedTransactions = true;
|
||||
}
|
||||
$query->where('transactions.account_id', $account->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EloquentBuilder $query
|
||||
* @param Carbon $date
|
||||
@@ -125,6 +138,17 @@ class TransactionJournal extends Model
|
||||
$query->where('transactions.amount', '<=', $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EloquentBuilder $query
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopeOnDate(EloquentBuilder $query, Carbon $date)
|
||||
{
|
||||
return $query->where('date', '=', $date->format('Y-m-d'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EloquentBuilder $query
|
||||
* @param array $types
|
||||
@@ -140,6 +164,21 @@ class TransactionJournal extends Model
|
||||
$query->whereIn('transaction_types.type', $types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically includes the 'with' parameters to get relevant related
|
||||
* objects.
|
||||
*
|
||||
* @param EloquentBuilder $query
|
||||
*/
|
||||
public function scopeWithRelevantData(EloquentBuilder $query)
|
||||
{
|
||||
$query->with(
|
||||
['transactions' => function (HasMany $q) {
|
||||
$q->orderBy('amount', 'ASC');
|
||||
}, 'transactiontype', 'transactioncurrency', 'budgets', 'categories', 'transactions.account.accounttype', 'bill', 'budgets', 'categories']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
@@ -173,21 +212,6 @@ class TransactionJournal extends Model
|
||||
return $this->belongsToMany('FireflyIII\Models\TransactionGroup');
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically includes the 'with' parameters to get relevant related
|
||||
* objects.
|
||||
*
|
||||
* @param EloquentBuilder $query
|
||||
*/
|
||||
public function scopeWithRelevantData(EloquentBuilder $query)
|
||||
{
|
||||
$query->with(
|
||||
['transactions' => function (HasMany $q) {
|
||||
$q->orderBy('amount', 'ASC');
|
||||
}, 'transactiontype', 'transactioncurrency','budgets', 'categories', 'transactions.account.accounttype', 'bill', 'budgets', 'categories']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
@@ -204,17 +228,4 @@ class TransactionJournal extends Model
|
||||
return $this->belongsTo('FireflyIII\User');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EloquentBuilder $query
|
||||
* @param Account $account
|
||||
*/
|
||||
public function scopeAccountIs(EloquentBuilder $query, Account $account)
|
||||
{
|
||||
if (!isset($this->joinedTransactions)) {
|
||||
$query->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id');
|
||||
$this->joinedTransactions = true;
|
||||
}
|
||||
$query->where('transactions.account_id', $account->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user