mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-14 08:11:20 +00:00
Code clean up and reformat.
This commit is contained in:
@@ -34,16 +34,23 @@ class Account extends Ardent
|
||||
* @var array
|
||||
*/
|
||||
public static $rules
|
||||
= [
|
||||
'name' => ['required', 'between:1,100', 'alphabasic'],
|
||||
'user_id' => 'required|exists:users,id',
|
||||
'account_type_id' => 'required|exists:account_types,id',
|
||||
'active' => 'required|boolean'
|
||||
= ['name' => ['required', 'between:1,100', 'alphabasic'], 'user_id' => 'required|exists:users,id',
|
||||
'account_type_id' => 'required|exists:account_types,id', 'active' => 'required|boolean'
|
||||
|
||||
];
|
||||
|
||||
protected $fillable = ['name', 'user_id', 'account_type_id', 'active'];
|
||||
|
||||
/**
|
||||
* Account type.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function accountType()
|
||||
{
|
||||
return $this->belongsTo('AccountType');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an accounts current balance.
|
||||
*
|
||||
@@ -56,43 +63,12 @@ class Account extends Ardent
|
||||
$date = is_null($date) ? new \Carbon\Carbon : $date;
|
||||
|
||||
return floatval(
|
||||
$this->transactions()
|
||||
->leftJoin(
|
||||
$this->transactions()->leftJoin(
|
||||
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
|
||||
)
|
||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount')
|
||||
)->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function balanceBeforeJournal(TransactionJournal $journal)
|
||||
{
|
||||
return floatval(
|
||||
$this->transactions()
|
||||
->leftJoin(
|
||||
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
|
||||
)
|
||||
->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d'))
|
||||
->where('transaction_journals.created_at', '<=', $journal->created_at->format('Y-m-d H:i:s'))
|
||||
->where('transaction_journals.id', '!=', $journal->id)
|
||||
->sum('transactions.amount')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Account type.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function accountType()
|
||||
{
|
||||
return $this->belongsTo('AccountType');
|
||||
}
|
||||
|
||||
/**
|
||||
* Transactions.
|
||||
*
|
||||
@@ -103,6 +79,22 @@ class Account extends Ardent
|
||||
return $this->hasMany('Transaction');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function balanceBeforeJournal(TransactionJournal $journal)
|
||||
{
|
||||
return floatval(
|
||||
$this->transactions()->leftJoin(
|
||||
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
|
||||
)->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d'))->where(
|
||||
'transaction_journals.created_at', '<=', $journal->created_at->format('Y-m-d H:i:s')
|
||||
)->where('transaction_journals.id', '!=', $journal->id)->sum('transactions.amount')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
@@ -123,16 +115,6 @@ class Account extends Ardent
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* User
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('User');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder $query
|
||||
* @param array $types
|
||||
@@ -146,5 +128,15 @@ class Account extends Ardent
|
||||
$query->whereIn('account_types.type', $types);
|
||||
}
|
||||
|
||||
/**
|
||||
* User
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('User');
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -12,11 +12,7 @@ class AccountMeta extends Ardent
|
||||
* @var array
|
||||
*/
|
||||
public static $rules
|
||||
= [
|
||||
'account_id' => 'numeric|required|exists:accounts,id',
|
||||
'name' => 'required|between:1,250',
|
||||
'data' => 'required'
|
||||
];
|
||||
= ['account_id' => 'numeric|required|exists:accounts,id', 'name' => 'required|between:1,250', 'data' => 'required'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
|
@@ -20,9 +20,7 @@ use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
class AccountType extends Eloquent
|
||||
{
|
||||
public static $rules
|
||||
= [
|
||||
'type' => ['required', 'between:1,50', 'alphabasic'],
|
||||
'editable' => 'required|boolean',
|
||||
= ['type' => ['required', 'between:1,50', 'alphabasic'], 'editable' => 'required|boolean',
|
||||
|
||||
];
|
||||
|
||||
|
@@ -25,15 +25,11 @@ class Component extends SingleTableInheritanceEntity
|
||||
{
|
||||
|
||||
public static $rules
|
||||
= [
|
||||
'user_id' => 'exists:users,id|required',
|
||||
'name' => ['required', 'between:1,100','min:1', 'alphabasic'],
|
||||
'class' => 'required',
|
||||
];
|
||||
protected $table = 'components';
|
||||
= ['user_id' => 'exists:users,id|required', 'name' => ['required', 'between:1,100', 'min:1', 'alphabasic'],
|
||||
'class' => 'required',];
|
||||
protected $fillable = ['name', 'user_id'];
|
||||
protected $subclassField = 'class';
|
||||
protected $fillable = ['name','user_id'];
|
||||
|
||||
protected $table = 'components';
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
|
@@ -23,14 +23,19 @@ use LaravelBook\Ardent\Ardent as Ardent;
|
||||
class Importmap extends Ardent
|
||||
{
|
||||
public static $rules
|
||||
= [
|
||||
'user_id' => 'required|exists:users,id',
|
||||
'file' => 'required',
|
||||
'totaljobs' => 'numeric|required|min:0',
|
||||
'jobsdone' => 'numeric|required|min:0',
|
||||
= ['user_id' => 'required|exists:users,id', 'file' => 'required', 'totaljobs' => 'numeric|required|min:0', 'jobsdone' => 'numeric|required|min:0',
|
||||
|
||||
];
|
||||
|
||||
public function pct()
|
||||
{
|
||||
if ($this->jobsdone == 0 || $this->totaljobs == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return round((($this->jobsdone / $this->totaljobs) * 100), 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User
|
||||
*
|
||||
@@ -40,13 +45,4 @@ class Importmap extends Ardent
|
||||
{
|
||||
return $this->belongsTo('User');
|
||||
}
|
||||
|
||||
public function pct()
|
||||
{
|
||||
if ($this->jobsdone == 0 || $this->totaljobs == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return round((($this->jobsdone / $this->totaljobs) * 100), 1);
|
||||
}
|
||||
}
|
||||
}
|
@@ -31,12 +31,8 @@ class Limit extends Ardent
|
||||
{
|
||||
|
||||
public static $rules
|
||||
= [
|
||||
'component_id' => 'required|exists:components,id',
|
||||
'startdate' => 'required|date',
|
||||
'amount' => 'numeric|required|min:0.01',
|
||||
'repeats' => 'required|boolean',
|
||||
'repeat_freq' => 'required|in:daily,weekly,monthly,quarterly,half-year,yearly'
|
||||
= ['component_id' => 'required|exists:components,id', 'startdate' => 'required|date', 'amount' => 'numeric|required|min:0.01',
|
||||
'repeats' => 'required|boolean', 'repeat_freq' => 'required|in:daily,weekly,monthly,quarterly,half-year,yearly'
|
||||
|
||||
];
|
||||
|
||||
@@ -90,8 +86,8 @@ class Limit extends Ardent
|
||||
}
|
||||
$end->subDay();
|
||||
$count = $this->limitrepetitions()->where('startdate', $start->format('Y-m-d'))->where('enddate', $end->format('Y-m-d'))->count();
|
||||
\Log::debug('All: '.$this->limitrepetitions()->count().' (#'.$this->id.')');
|
||||
\Log::debug('Found ' . $count.' limit-reps for limit #' . $this->id.' with start '.$start->format('Y-m-d') .' and end ' . $end->format('Y-m-d'));
|
||||
\Log::debug('All: ' . $this->limitrepetitions()->count() . ' (#' . $this->id . ')');
|
||||
\Log::debug('Found ' . $count . ' limit-reps for limit #' . $this->id . ' with start ' . $start->format('Y-m-d') . ' and end ' . $end->format('Y-m-d'));
|
||||
|
||||
if ($count == 0) {
|
||||
|
||||
@@ -113,7 +109,8 @@ class Limit extends Ardent
|
||||
if (isset($repetition->id)) {
|
||||
\Event::fire('limits.repetition', [$repetition]);
|
||||
}
|
||||
} else if($count == 1) {
|
||||
} else {
|
||||
if ($count == 1) {
|
||||
// update this one:
|
||||
$repetition = $this->limitrepetitions()->where('startdate', $start->format('Y-m-d'))->where('enddate', $end->format('Y-m-d'))->first();
|
||||
$repetition->amount = $this->amount;
|
||||
@@ -121,6 +118,7 @@ class Limit extends Ardent
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
|
@@ -25,12 +25,7 @@ use LaravelBook\Ardent\Ardent as Ardent;
|
||||
class LimitRepetition extends Ardent
|
||||
{
|
||||
public static $rules
|
||||
= [
|
||||
'limit_id' => 'required|exists:limits,id',
|
||||
'startdate' => 'required|date',
|
||||
'enddate' => 'required|date',
|
||||
'amount' => 'numeric|required|min:0.01',
|
||||
];
|
||||
= ['limit_id' => 'required|exists:limits,id', 'startdate' => 'required|date', 'enddate' => 'required|date', 'amount' => 'numeric|required|min:0.01',];
|
||||
|
||||
/**
|
||||
* @return array
|
||||
@@ -40,20 +35,6 @@ class LimitRepetition extends Ardent
|
||||
return ['created_at', 'updated_at', 'startdate', 'enddate'];
|
||||
}
|
||||
|
||||
public function spentInRepetition() {
|
||||
$sum = \DB::table('transactions')
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->leftJoin('component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('components', 'components.id', '=', 'component_transaction_journal.component_id')
|
||||
->leftJoin('limits', 'limits.component_id', '=', 'components.id')
|
||||
->leftJoin('limit_repetitions', 'limit_repetitions.limit_id', '=', 'limits.id')
|
||||
->where('transaction_journals.date', '>=', $this->startdate->format('Y-m-d'))
|
||||
->where('transaction_journals.date', '<=', $this->enddate->format('Y-m-d'))
|
||||
->where('transactions.amount', '>', 0)
|
||||
->where('limit_repetitions.id', '=', $this->id)->sum('transactions.amount');
|
||||
return floatval($sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* How much money is left in this?
|
||||
*/
|
||||
@@ -63,6 +44,21 @@ class LimitRepetition extends Ardent
|
||||
|
||||
}
|
||||
|
||||
public function spentInRepetition()
|
||||
{
|
||||
$sum = \DB::table('transactions')->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->leftJoin(
|
||||
'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'
|
||||
)->leftJoin('components', 'components.id', '=', 'component_transaction_journal.component_id')->leftJoin(
|
||||
'limits', 'limits.component_id', '=', 'components.id'
|
||||
)->leftJoin('limit_repetitions', 'limit_repetitions.limit_id', '=', 'limits.id')->where(
|
||||
'transaction_journals.date', '>=', $this->startdate->format('Y-m-d')
|
||||
)->where('transaction_journals.date', '<=', $this->enddate->format('Y-m-d'))->where('transactions.amount', '>', 0)->where(
|
||||
'limit_repetitions.id', '=', $this->id
|
||||
)->sum('transactions.amount');
|
||||
|
||||
return floatval($sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
@@ -45,8 +45,7 @@ use LaravelBook\Ardent\Ardent as Ardent;
|
||||
class Piggybank extends Ardent
|
||||
{
|
||||
public static $rules
|
||||
= [
|
||||
'account_id' => 'required|exists:accounts,id', // link to Account
|
||||
= ['account_id' => 'required|exists:accounts,id', // link to Account
|
||||
'name' => 'required|between:1,255', // name
|
||||
'targetamount' => 'required|min:0', // amount you want to save
|
||||
'startdate' => 'date', // when you started
|
||||
@@ -57,25 +56,11 @@ class Piggybank extends Ardent
|
||||
'rep_times' => 'min:1|max:100', // how many times do you want to save this amount? eg. 3 times
|
||||
'reminder' => 'in:day,week,month,year', // want a reminder to put money in this?
|
||||
'reminder_skip' => 'required|min:0|max:100', // every week? every 2 months?
|
||||
'remind_me' => 'required|boolean',
|
||||
'order' => 'required:min:1', // not yet used.
|
||||
'remind_me' => 'required|boolean', 'order' => 'required:min:1', // not yet used.
|
||||
];
|
||||
public $fillable
|
||||
= [
|
||||
'account_id',
|
||||
'name',
|
||||
'targetamount',
|
||||
'startdate',
|
||||
'targetdate',
|
||||
'repeats',
|
||||
'rep_length',
|
||||
'rep_every',
|
||||
'rep_times',
|
||||
'reminder',
|
||||
'reminder_skip',
|
||||
'remind_me',
|
||||
'order'
|
||||
];
|
||||
= ['account_id', 'name', 'targetamount', 'startdate', 'targetdate', 'repeats', 'rep_length', 'rep_every', 'rep_times', 'reminder', 'reminder_skip',
|
||||
'remind_me', 'order'];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
@@ -98,14 +83,6 @@ class Piggybank extends Ardent
|
||||
return $rep;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDates()
|
||||
{
|
||||
return ['created_at', 'updated_at', 'targetdate', 'startdate'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the PiggyBankRepetition that's currently relevant / active
|
||||
*
|
||||
@@ -113,8 +90,7 @@ class Piggybank extends Ardent
|
||||
*/
|
||||
public function currentRelevantRep()
|
||||
{
|
||||
$query = $this->piggybankrepetitions()
|
||||
->where(
|
||||
$query = $this->piggybankrepetitions()->where(
|
||||
function ($q) {
|
||||
|
||||
$q->where(
|
||||
@@ -123,8 +99,7 @@ class Piggybank extends Ardent
|
||||
$q->whereNull('startdate');
|
||||
$q->orWhere('startdate', '<=', $today->format('Y-m-d'));
|
||||
}
|
||||
)
|
||||
->where(
|
||||
)->where(
|
||||
function ($q) {
|
||||
$today = new Carbon;
|
||||
$q->whereNull('targetdate');
|
||||
@@ -154,6 +129,14 @@ class Piggybank extends Ardent
|
||||
return $this->hasMany('PiggybankRepetition');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDates()
|
||||
{
|
||||
return ['created_at', 'updated_at', 'targetdate', 'startdate'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
@@ -171,8 +154,7 @@ class Piggybank extends Ardent
|
||||
*/
|
||||
public function repetitionForDate(Carbon $date)
|
||||
{
|
||||
$query = $this->piggybankrepetitions()
|
||||
->where(
|
||||
$query = $this->piggybankrepetitions()->where(
|
||||
function ($q) use ($date) {
|
||||
|
||||
$q->where(
|
||||
@@ -180,8 +162,7 @@ class Piggybank extends Ardent
|
||||
$q->whereNull('startdate');
|
||||
$q->orWhere('startdate', '<=', $date->format('Y-m-d'));
|
||||
}
|
||||
)
|
||||
->where(
|
||||
)->where(
|
||||
function ($q) use ($date) {
|
||||
$q->whereNull('targetdate');
|
||||
$q->orWhere('targetdate', '>=', $date->format('Y-m-d'));
|
||||
|
@@ -23,11 +23,7 @@ class PiggybankEvent extends Ardent
|
||||
{
|
||||
|
||||
public static $rules
|
||||
= [
|
||||
'piggybank_id' => 'required|exists:piggybanks,id',
|
||||
'date' => 'required|date',
|
||||
'amount' => 'required|numeric'
|
||||
];
|
||||
= ['piggybank_id' => 'required|exists:piggybanks,id', 'date' => 'required|date', 'amount' => 'required|numeric'];
|
||||
|
||||
/**
|
||||
* @return array
|
||||
|
@@ -23,12 +23,7 @@ use LaravelBook\Ardent\Ardent as Ardent;
|
||||
class PiggybankRepetition extends Ardent
|
||||
{
|
||||
public static $rules
|
||||
= [
|
||||
'piggybank_id' => 'required|exists:piggybanks,id',
|
||||
'targetdate' => 'date',
|
||||
'startdate' => 'date',
|
||||
'currentamount' => 'required|numeric'
|
||||
];
|
||||
= ['piggybank_id' => 'required|exists:piggybanks,id', 'targetdate' => 'date', 'startdate' => 'date', 'currentamount' => 'required|numeric'];
|
||||
|
||||
/**
|
||||
* @return array
|
||||
|
@@ -22,27 +22,7 @@ use LaravelBook\Ardent\Ardent;
|
||||
class Preference extends Ardent
|
||||
{
|
||||
public static $rules
|
||||
= [
|
||||
'user_id' => 'required|exists:users,id',
|
||||
'name' => 'required|between:1,255',
|
||||
'data' => 'required'
|
||||
];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('User');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
public function setDataAttribute($value)
|
||||
{
|
||||
$this->attributes['data'] = json_encode($value);
|
||||
}
|
||||
= ['user_id' => 'required|exists:users,id', 'name' => 'required|between:1,255', 'data' => 'required'];
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
@@ -54,4 +34,20 @@ class Preference extends Ardent
|
||||
return json_decode($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
public function setDataAttribute($value)
|
||||
{
|
||||
$this->attributes['data'] = json_encode($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('User');
|
||||
}
|
||||
|
||||
}
|
@@ -37,20 +37,11 @@ class RecurringTransaction extends Ardent
|
||||
{
|
||||
|
||||
public static $rules
|
||||
= [
|
||||
'user_id' => 'required|exists:users,id',
|
||||
'name' => 'required|between:1,255',
|
||||
'match' => 'required',
|
||||
'amount_max' => 'required|between:0,65536',
|
||||
'amount_min' => 'required|between:0,65536',
|
||||
'date' => 'required|date',
|
||||
'active' => 'required|between:0,1',
|
||||
'automatch' => 'required|between:0,1',
|
||||
'repeat_freq' => 'required|in:daily,weekly,monthly,quarterly,half-year,yearly',
|
||||
'skip' => 'required|between:0,31',
|
||||
];
|
||||
= ['user_id' => 'required|exists:users,id', 'name' => 'required|between:1,255', 'match' => 'required', 'amount_max' => 'required|between:0,65536',
|
||||
'amount_min' => 'required|between:0,65536', 'date' => 'required|date', 'active' => 'required|between:0,1', 'automatch' => 'required|between:0,1',
|
||||
'repeat_freq' => 'required|in:daily,weekly,monthly,quarterly,half-year,yearly', 'skip' => 'required|between:0,31',];
|
||||
|
||||
protected $fillable = ['user_id','name','match','amount_min','amount_max','date','repeat_freq','skip','active','automatch'];
|
||||
protected $fillable = ['user_id', 'name', 'match', 'amount_min', 'amount_max', 'date', 'repeat_freq', 'skip', 'active', 'automatch'];
|
||||
|
||||
/**
|
||||
* @return array
|
||||
|
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use LaravelBook\Ardent\Ardent;
|
||||
|
||||
|
||||
|
@@ -41,13 +41,9 @@ use LaravelBook\Ardent\Builder;
|
||||
class Transaction extends Ardent
|
||||
{
|
||||
public static $rules
|
||||
= [
|
||||
'account_id' => 'numeric|required|exists:accounts,id',
|
||||
'piggybank_id' => 'numeric|exists:piggybanks,id',
|
||||
'transaction_journal_id' => 'numeric|required|exists:transaction_journals,id',
|
||||
'description' => 'between:1,255',
|
||||
'amount' => 'required|between:-65536,65536|not_in:0,0.00',
|
||||
];
|
||||
= ['account_id' => 'numeric|required|exists:accounts,id', 'piggybank_id' => 'numeric|exists:piggybanks,id',
|
||||
'transaction_journal_id' => 'numeric|required|exists:transaction_journals,id', 'description' => 'between:1,255',
|
||||
'amount' => 'required|between:-65536,65536|not_in:0,0.00',];
|
||||
|
||||
|
||||
/**
|
||||
@@ -58,36 +54,6 @@ class Transaction extends Ardent
|
||||
return $this->belongsTo('Account');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Piggybank $piggybank
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function connectPiggybank(\Piggybank $piggybank = null)
|
||||
{
|
||||
throw new NotImplementedException;
|
||||
// if (is_null($piggybank)) {
|
||||
// return true;
|
||||
// }
|
||||
// /** @var \Firefly\Storage\Piggybank\PiggybankRepositoryInterface $piggyRepository */
|
||||
// $piggyRepository = \App::make('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
|
||||
// if ($this->account_id == $piggybank->account_id) {
|
||||
// $this->piggybank()->associate($piggybank);
|
||||
// $this->save();
|
||||
// \Event::fire('piggybanks.createRelatedTransfer', [$piggybank, $this->transactionJournal, $this]);
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function piggybank()
|
||||
{
|
||||
return $this->belongsTo('Piggybank');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
@@ -112,6 +78,36 @@ class Transaction extends Ardent
|
||||
return $this->belongsToMany('Component');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Piggybank $piggybank
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function connectPiggybank(\Piggybank $piggybank = null)
|
||||
{
|
||||
throw new NotImplementedException;
|
||||
// if (is_null($piggybank)) {
|
||||
// return true;
|
||||
// }
|
||||
// /** @var \Firefly\Storage\Piggybank\PiggybankRepositoryInterface $piggyRepository */
|
||||
// $piggyRepository = \App::make('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
|
||||
// if ($this->account_id == $piggybank->account_id) {
|
||||
// $this->piggybank()->associate($piggybank);
|
||||
// $this->save();
|
||||
// \Event::fire('piggybanks.createRelatedTransfer', [$piggybank, $this->transactionJournal, $this]);
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function piggybank()
|
||||
{
|
||||
return $this->belongsTo('Piggybank');
|
||||
}
|
||||
|
||||
public function scopeAccountIs(Builder $query, Account $account)
|
||||
{
|
||||
$query->where('transactions.account_id', $account->id);
|
||||
@@ -121,8 +117,7 @@ class Transaction extends Ardent
|
||||
{
|
||||
if (is_null($this->joinedJournals)) {
|
||||
$query->leftJoin(
|
||||
'transaction_journals', 'transaction_journals.id', '=',
|
||||
'transactions.transaction_journal_id'
|
||||
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
|
||||
);
|
||||
$this->joinedJournals = true;
|
||||
}
|
||||
@@ -133,8 +128,7 @@ class Transaction extends Ardent
|
||||
{
|
||||
if (is_null($this->joinedJournals)) {
|
||||
$query->leftJoin(
|
||||
'transaction_journals', 'transaction_journals.id', '=',
|
||||
'transactions.transaction_journal_id'
|
||||
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
|
||||
);
|
||||
$this->joinedJournals = true;
|
||||
}
|
||||
@@ -155,15 +149,13 @@ class Transaction extends Ardent
|
||||
{
|
||||
if (is_null($this->joinedJournals)) {
|
||||
$query->leftJoin(
|
||||
'transaction_journals', 'transaction_journals.id', '=',
|
||||
'transactions.transaction_journal_id'
|
||||
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
|
||||
);
|
||||
$this->joinedJournals = true;
|
||||
}
|
||||
if (is_null($this->joinedTransactionTypes)) {
|
||||
$query->leftJoin(
|
||||
'transaction_types', 'transaction_types.id', '=',
|
||||
'transaction_journals.transaction_type_id'
|
||||
'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'
|
||||
);
|
||||
$this->joinedTransactionTypes = true;
|
||||
}
|
||||
|
@@ -51,13 +51,8 @@ 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'
|
||||
];
|
||||
= ['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'];
|
||||
|
||||
|
||||
/**
|
||||
@@ -99,15 +94,8 @@ class TransactionJournal extends Ardent
|
||||
return floatval($t->amount);
|
||||
}
|
||||
}
|
||||
return -0.01;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function recurringTransaction()
|
||||
{
|
||||
return $this->belongsTo('RecurringTransaction');
|
||||
return -0.01;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,6 +106,14 @@ class TransactionJournal extends Ardent
|
||||
return ['created_at', 'updated_at', 'date'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function recurringTransaction()
|
||||
{
|
||||
return $this->belongsTo('RecurringTransaction');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder $query
|
||||
* @param Account $account
|
||||
@@ -158,25 +154,11 @@ class TransactionJournal extends Ardent
|
||||
$query->orderBy('date', 'DESC')->orderBy('transaction_journals.id', 'DESC');
|
||||
}
|
||||
|
||||
public function scopeMoreThan(Builder $query, $amount)
|
||||
{
|
||||
if (is_null($this->joinedTransactions)) {
|
||||
$query->leftJoin(
|
||||
'transactions', 'transactions.transaction_journal_id', '=',
|
||||
'transaction_journals.id'
|
||||
);
|
||||
$this->joinedTransactions = true;
|
||||
}
|
||||
|
||||
$query->where('transactions.amount', '>=', $amount);
|
||||
}
|
||||
|
||||
public function scopeLessThan(Builder $query, $amount)
|
||||
{
|
||||
if (is_null($this->joinedTransactions)) {
|
||||
$query->leftJoin(
|
||||
'transactions', 'transactions.transaction_journal_id', '=',
|
||||
'transaction_journals.id'
|
||||
'transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id'
|
||||
);
|
||||
$this->joinedTransactions = true;
|
||||
}
|
||||
@@ -184,6 +166,18 @@ class TransactionJournal extends Ardent
|
||||
$query->where('transactions.amount', '<=', $amount);
|
||||
}
|
||||
|
||||
public function scopeMoreThan(Builder $query, $amount)
|
||||
{
|
||||
if (is_null($this->joinedTransactions)) {
|
||||
$query->leftJoin(
|
||||
'transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id'
|
||||
);
|
||||
$this->joinedTransactions = true;
|
||||
}
|
||||
|
||||
$query->where('transactions.amount', '>=', $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $query
|
||||
* @param Carbon $date
|
||||
@@ -199,8 +193,7 @@ class TransactionJournal extends Ardent
|
||||
{
|
||||
if (is_null($this->joinedTransactionTypes)) {
|
||||
$query->leftJoin(
|
||||
'transaction_types', 'transaction_types.id', '=',
|
||||
'transaction_journals.transaction_type_id'
|
||||
'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'
|
||||
);
|
||||
$this->joinedTransactionTypes = true;
|
||||
}
|
||||
|
@@ -40,24 +40,20 @@ class User extends Ardent implements UserInterface, RemindableInterface
|
||||
|
||||
|
||||
public static $rules
|
||||
= [
|
||||
'email' => 'required|email|unique:users,email',
|
||||
'migrated' => 'required|boolean',
|
||||
'password' => 'required|between:60,60',
|
||||
'reset' => 'between:32,32',
|
||||
];
|
||||
/**
|
||||
* The database table used by the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'users';
|
||||
= ['email' => 'required|email|unique:users,email', 'migrated' => 'required|boolean', 'password' => 'required|between:60,60',
|
||||
'reset' => 'between:32,32',];
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['remember_token'];
|
||||
/**
|
||||
* The database table used by the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'users';
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
@@ -91,6 +87,11 @@ class User extends Ardent implements UserInterface, RemindableInterface
|
||||
return $this->hasMany('Component');
|
||||
}
|
||||
|
||||
public function piggybanks()
|
||||
{
|
||||
return $this->hasManyThrough('Piggybank', 'Account');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
@@ -115,11 +116,6 @@ class User extends Ardent implements UserInterface, RemindableInterface
|
||||
$this->attributes['password'] = Hash::make($value);
|
||||
}
|
||||
|
||||
public function piggybanks()
|
||||
{
|
||||
return $this->hasManyThrough('Piggybank', 'Account');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
|
Reference in New Issue
Block a user