firefly-iii/app/models/TransactionJournal.php

127 lines
3.0 KiB
PHP
Raw Normal View History

<?php
use LaravelBook\Ardent\Ardent;
class TransactionJournal extends Ardent
{
public static $rules
= [
'transaction_type_id' => 'required|exists:transaction_types,id',
'transaction_currency_id' => 'required|exists:transaction_currencies,id',
'description' => 'required|between:1,255',
'date' => 'required|date',
'completed' => 'required|between:0,1'
];
2014-08-10 11:22:42 -05:00
/**
* @return array
*/
2014-07-22 23:57:51 -05:00
public static function factory()
{
$date = new \Carbon\Carbon;
2014-07-30 00:14:00 -05:00
2014-07-22 23:57:51 -05:00
return [
'transaction_type_id' => 'factory|TransactionType',
'transaction_currency_id' => 'factory|TransactionCurrency',
'description' => 'string',
'completed' => '1',
'user_id' => 'factory|User',
2014-07-22 23:57:51 -05:00
'date' => $date
];
2014-07-22 23:57:51 -05:00
}
2014-08-10 11:22:42 -05:00
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
2014-08-10 11:22:42 -05:00
*/
public function budgets()
{
return $this->belongsToMany(
'Budget', 'component_transaction_journal', 'transaction_journal_id', 'component_id'
);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function categories()
{
return $this->belongsToMany(
'Category', 'component_transaction_journal', 'transaction_journal_id', 'component_id'
);
}
2014-08-10 11:22:42 -05:00
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
2014-08-10 11:22:42 -05:00
*/
public function components()
{
return $this->belongsToMany('Component');
}
2014-08-10 11:22:42 -05:00
/**
* @return array
2014-08-10 11:22:42 -05:00
*/
public function getDates()
{
return ['created_at', 'updated_at', 'date'];
}
2014-08-10 11:22:42 -05:00
/**
* @param $query
* @param \Carbon\Carbon $date
*
* @return mixed
2014-08-10 11:22:42 -05:00
*/
public function scopeAfter($query, \Carbon\Carbon $date)
{
return $query->where('date', '>=', $date->format('Y-m-d'));
}
2014-08-10 11:22:42 -05:00
/**
* @param $query
* @param \Carbon\Carbon $date
*
* @return mixed
2014-08-10 11:22:42 -05:00
*/
public function scopeBefore($query, \Carbon\Carbon $date)
{
return $query->where('date', '<=', $date->format('Y-m-d'));
}
2014-08-10 11:22:42 -05:00
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
2014-08-10 11:22:42 -05:00
*/
public function transactionCurrency()
{
return $this->belongsTo('TransactionCurrency');
}
2014-08-10 11:22:42 -05:00
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
2014-08-10 11:22:42 -05:00
*/
public function transactionType()
{
return $this->belongsTo('TransactionType');
}
2014-08-10 11:22:42 -05:00
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
2014-08-10 11:22:42 -05:00
*/
public function transactions()
{
return $this->hasMany('Transaction');
2014-07-09 05:56:06 -05:00
}
2014-08-10 11:22:42 -05:00
/**
* User
2014-08-10 11:22:42 -05:00
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
2014-08-10 11:22:42 -05:00
*/
public function user()
{
return $this->belongsTo('User');
2014-07-09 05:56:06 -05:00
}
}