2014-06-29 15:12:33 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
2014-07-03 14:31:32 -05:00
|
|
|
class TransactionJournal extends Elegant
|
|
|
|
{
|
2014-06-29 15:12:33 -05:00
|
|
|
|
2014-07-03 14:31:32 -05:00
|
|
|
public static $rules
|
|
|
|
= [
|
|
|
|
'transaction_type_id' => 'required|exists:transaction_types,id',
|
|
|
|
'transaction_currency_id' => 'required|exists:transaction_currencies,id',
|
|
|
|
'description' => 'between:1,255',
|
|
|
|
'date' => 'date',
|
2014-07-05 09:19:15 -05:00
|
|
|
'completed' => 'required|between:0,1'
|
2014-07-03 14:31:32 -05:00
|
|
|
];
|
|
|
|
|
2014-07-09 06:35:33 -05:00
|
|
|
public static $factory
|
|
|
|
= [
|
|
|
|
'transaction_type_id' => 'factory|TransactionType',
|
|
|
|
'transaction_currency_id' => 'factory|TransactionCurrency',
|
|
|
|
'description' => 'string',
|
|
|
|
'completed' => '1',
|
|
|
|
'date' => 'date|Y-m-d'
|
|
|
|
];
|
|
|
|
|
2014-07-03 14:31:32 -05:00
|
|
|
public function transactionType()
|
|
|
|
{
|
2014-06-29 15:12:33 -05:00
|
|
|
return $this->belongsTo('TransactionType');
|
|
|
|
}
|
2014-07-03 14:31:32 -05:00
|
|
|
|
|
|
|
public function transactionCurrency()
|
|
|
|
{
|
2014-06-29 15:12:33 -05:00
|
|
|
return $this->belongsTo('TransactionCurrency');
|
|
|
|
}
|
|
|
|
|
2014-07-03 14:31:32 -05:00
|
|
|
public function transactions()
|
|
|
|
{
|
2014-06-29 15:12:33 -05:00
|
|
|
return $this->hasMany('Transaction');
|
|
|
|
}
|
|
|
|
|
2014-07-05 12:44:26 -05:00
|
|
|
public function components()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany('Component');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function budgets()
|
|
|
|
{
|
2014-07-09 06:35:33 -05:00
|
|
|
return $this->belongsToMany(
|
|
|
|
'Budget', 'component_transaction_journal', 'transaction_journal_id', 'component_id'
|
|
|
|
);
|
2014-07-05 12:44:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function categories()
|
|
|
|
{
|
2014-07-09 06:35:33 -05:00
|
|
|
return $this->belongsToMany(
|
|
|
|
'Category', 'component_transaction_journal', 'transaction_journal_id', 'component_id'
|
|
|
|
);
|
2014-07-05 12:44:26 -05:00
|
|
|
}
|
|
|
|
|
2014-07-03 14:31:32 -05:00
|
|
|
public function getDates()
|
|
|
|
{
|
|
|
|
return array('created_at', 'updated_at', 'date');
|
|
|
|
}
|
|
|
|
|
2014-07-09 06:35:33 -05:00
|
|
|
public function scopeAfter($query, \Carbon\Carbon $date)
|
|
|
|
{
|
|
|
|
return $query->where('date', '>=', $date->format('Y-m-d'));
|
2014-07-09 05:56:06 -05:00
|
|
|
}
|
2014-07-09 06:35:33 -05:00
|
|
|
|
|
|
|
public function scopeBefore($query, \Carbon\Carbon $date)
|
|
|
|
{
|
|
|
|
return $query->where('date', '<=', $date->format('Y-m-d'));
|
2014-07-09 05:56:06 -05:00
|
|
|
}
|
|
|
|
|
2014-06-29 15:12:33 -05:00
|
|
|
}
|