2015-02-27 09:48:33 -06:00
|
|
|
<?php namespace FireflyIII\Models;
|
|
|
|
|
2016-01-09 09:09:26 -06:00
|
|
|
use Auth;
|
2015-03-30 13:08:27 -05:00
|
|
|
use Crypt;
|
2015-02-27 09:48:33 -06:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2016-04-06 02:27:45 -05:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2016-01-09 09:09:26 -06:00
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
2015-02-27 09:48:33 -06:00
|
|
|
|
|
|
|
/**
|
2016-01-01 14:49:27 -06:00
|
|
|
* FireflyIII\Models\Bill
|
2015-02-27 09:48:33 -06:00
|
|
|
*
|
2016-01-28 15:06:16 -06:00
|
|
|
* @property integer $id
|
|
|
|
* @property \Carbon\Carbon $created_at
|
|
|
|
* @property \Carbon\Carbon $updated_at
|
|
|
|
* @property integer $user_id
|
|
|
|
* @property string $name
|
|
|
|
* @property string $match
|
|
|
|
* @property float $amount_min
|
|
|
|
* @property float $amount_max
|
|
|
|
* @property \Carbon\Carbon $date
|
|
|
|
* @property boolean $active
|
|
|
|
* @property boolean $automatch
|
|
|
|
* @property string $repeat_freq
|
|
|
|
* @property integer $skip
|
|
|
|
* @property boolean $name_encrypted
|
|
|
|
* @property boolean $match_encrypted
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|TransactionJournal[] $transactionjournals
|
|
|
|
* @property-read \FireflyIII\User $user
|
|
|
|
* @property \Carbon\Carbon $nextExpectedMatch
|
|
|
|
* @property \Carbon\Carbon $lastFoundMatch
|
2016-03-29 08:55:14 -05:00
|
|
|
* @property bool $paidInPeriod
|
2016-03-29 09:16:14 -05:00
|
|
|
* @property string $lastPaidAmount
|
2016-03-12 00:36:23 -06:00
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereId($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereCreatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereUpdatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereUserId($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereName($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereMatch($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereAmountMin($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereAmountMax($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereDate($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereActive($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereAutomatch($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereRepeatFreq($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereSkip($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereNameEncrypted($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereMatchEncrypted($value)
|
|
|
|
* @mixin \Eloquent
|
2015-02-27 09:48:33 -06:00
|
|
|
*/
|
|
|
|
class Bill extends Model
|
|
|
|
{
|
|
|
|
|
2016-03-29 08:55:14 -05:00
|
|
|
protected $dates = ['created_at', 'updated_at', 'date'];
|
2015-03-30 13:08:27 -05:00
|
|
|
protected $fillable
|
2016-03-29 09:16:14 -05:00
|
|
|
= ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip',
|
|
|
|
'automatch', 'active',];
|
2015-05-23 10:11:16 -05:00
|
|
|
protected $hidden = ['amount_min_encrypted', 'amount_max_encrypted', 'name_encrypted', 'match_encrypted'];
|
2016-03-29 08:55:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Bill $value
|
|
|
|
*
|
|
|
|
* @return Bill
|
|
|
|
*/
|
|
|
|
public static function routeBinder(Bill $value)
|
|
|
|
{
|
|
|
|
if (Auth::check()) {
|
|
|
|
if ($value->user_id == Auth::user()->id) {
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new NotFoundHttpException;
|
|
|
|
}
|
2015-02-27 09:48:33 -06:00
|
|
|
|
2015-03-30 13:08:27 -05:00
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getMatchAttribute($value)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (intval($this->match_encrypted) == 1) {
|
|
|
|
return Crypt::decrypt($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getNameAttribute($value)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (intval($this->name_encrypted) == 1) {
|
|
|
|
return Crypt::decrypt($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2015-05-23 00:47:36 -05:00
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
*/
|
|
|
|
public function setAmountMaxAttribute($value)
|
|
|
|
{
|
2015-05-24 01:00:40 -05:00
|
|
|
$this->attributes['amount_max'] = strval(round($value, 2));
|
2015-05-23 00:47:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
*/
|
|
|
|
public function setAmountMinAttribute($value)
|
|
|
|
{
|
2015-05-24 01:00:40 -05:00
|
|
|
$this->attributes['amount_min'] = strval(round($value, 2));
|
2015-05-23 00:47:36 -05:00
|
|
|
}
|
|
|
|
|
2015-03-30 13:08:27 -05:00
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
*/
|
|
|
|
public function setMatchAttribute($value)
|
|
|
|
{
|
|
|
|
$this->attributes['match'] = Crypt::encrypt($value);
|
|
|
|
$this->attributes['match_encrypted'] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
*/
|
|
|
|
public function setNameAttribute($value)
|
|
|
|
{
|
|
|
|
$this->attributes['name'] = Crypt::encrypt($value);
|
|
|
|
$this->attributes['name_encrypted'] = true;
|
|
|
|
}
|
|
|
|
|
2015-02-27 09:48:33 -06:00
|
|
|
/**
|
2016-04-06 02:27:45 -05:00
|
|
|
* @return HasMany
|
2015-02-27 09:48:33 -06:00
|
|
|
*/
|
2016-04-06 02:27:45 -05:00
|
|
|
public function transactionjournals(): HasMany
|
2015-02-27 09:48:33 -06:00
|
|
|
{
|
|
|
|
return $this->hasMany('FireflyIII\Models\TransactionJournal');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-04-06 02:27:45 -05:00
|
|
|
* @return BelongsTo
|
2015-02-27 09:48:33 -06:00
|
|
|
*/
|
2016-04-06 02:27:45 -05:00
|
|
|
public function user(): BelongsTo
|
2015-02-27 09:48:33 -06:00
|
|
|
{
|
|
|
|
return $this->belongsTo('FireflyIII\User');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|