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