mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Extra large code cleanup.
This commit is contained in:
parent
ac12a47071
commit
c4312c0b11
@ -141,7 +141,7 @@ class PiggyBankController extends Controller
|
||||
public function index(AccountRepositoryInterface $repository)
|
||||
{
|
||||
/** @var Collection $piggyBanks */
|
||||
$piggyBanks = Auth::user()->piggyBanks()->where('repeats', 0)->orderBy('order', 'ASC')->get();
|
||||
$piggyBanks = Auth::user()->piggyBanks()->orderBy('order', 'ASC')->get();
|
||||
|
||||
$accounts = [];
|
||||
/** @var PiggyBank $piggyBank */
|
||||
@ -298,7 +298,6 @@ class PiggyBankController extends Controller
|
||||
public function store(PiggyBankFormRequest $request, PiggyBankRepositoryInterface $repository)
|
||||
{
|
||||
$piggyBankData = [
|
||||
'repeats' => false,
|
||||
'name' => $request->get('name'),
|
||||
'startdate' => new Carbon,
|
||||
'account_id' => intval($request->get('account_id')),
|
||||
@ -330,7 +329,6 @@ class PiggyBankController extends Controller
|
||||
public function update(PiggyBank $piggyBank, PiggyBankRepositoryInterface $repository, PiggyBankFormRequest $request)
|
||||
{
|
||||
$piggyBankData = [
|
||||
'repeats' => false,
|
||||
'name' => $request->get('name'),
|
||||
'startdate' => is_null($piggyBank->startdate) ? $piggyBank->created_at : $piggyBank->startdate,
|
||||
'account_id' => intval($request->get('account_id')),
|
||||
|
@ -55,7 +55,6 @@ class PiggyBanks
|
||||
/** @var Collection $set */
|
||||
$set = $this->auth->user()->piggybanks()
|
||||
->leftJoin('piggy_bank_repetitions', 'piggy_banks.id', '=', 'piggy_bank_repetitions.piggy_bank_id')
|
||||
->where('piggy_banks.repeats', 0)
|
||||
->whereNull('piggy_bank_repetitions.id')
|
||||
->get(['piggy_banks.id', 'piggy_banks.startdate', 'piggy_banks.targetdate']);
|
||||
if ($set->count() > 0) {
|
||||
@ -70,68 +69,6 @@ class PiggyBanks
|
||||
}
|
||||
}
|
||||
unset($partialPiggy, $set, $repetition);
|
||||
|
||||
// get repeating piggy banks without a repetition for current time frame.
|
||||
/** @var Collection $set */
|
||||
$set = $this->auth->user()->piggybanks()->leftJoin(
|
||||
'piggy_bank_repetitions', function (JoinClause $join) {
|
||||
$join->on('piggy_bank_repetitions.piggy_bank_id', '=', 'piggy_banks.id')
|
||||
->where('piggy_bank_repetitions.targetdate', '>=', Session::get('start')->format('Y-m-d'))
|
||||
->where('piggy_bank_repetitions.startdate', '<=', Session::get('end')->format('Y-m-d'));
|
||||
}
|
||||
)
|
||||
->where('repeats', 1)
|
||||
->whereNull('piggy_bank_repetitions.id')
|
||||
->get(['piggy_banks.*']);
|
||||
|
||||
// these piggy banks are missing a repetition. start looping and create them!
|
||||
if ($set->count() > 0) {
|
||||
/** @var PiggyBank $piggyBank */
|
||||
foreach ($set as $piggyBank) {
|
||||
$start = clone $piggyBank->startdate;
|
||||
$end = clone $piggyBank->targetdate;
|
||||
$max = clone $piggyBank->targetdate;
|
||||
|
||||
// first loop: start date to target date.
|
||||
// then, continue looping until end is > today
|
||||
while ($start <= $max) {
|
||||
// first loop fixes this date. or should fix it.
|
||||
$max = new Carbon;
|
||||
|
||||
echo '[#' . $piggyBank->id . ', from: ' . $start->format('Y-m-d.') . ' to ' . $end->format('Y-m-d.') . ']';
|
||||
// create stuff. Or at least, try:
|
||||
$repetition = $piggyBank->piggyBankRepetitions()->onDates($start, $end)->first();
|
||||
if (!$repetition) {
|
||||
$repetition = new PiggyBankRepetition;
|
||||
$repetition->piggyBank()->associate($piggyBank);
|
||||
$repetition->startdate = $start;
|
||||
$repetition->targetdate = $end;
|
||||
$repetition->currentamount = 0;
|
||||
// it might exist, catch:
|
||||
$repetition->save();
|
||||
}
|
||||
|
||||
// start where end 'ended':
|
||||
$start = clone $end;
|
||||
// move end.
|
||||
$end = Navigation::addPeriod($end, $piggyBank->rep_length, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// first repetition: from original start to original target.
|
||||
$repetition = new PiggyBankRepetition;
|
||||
$repetition->piggyBank()->associate($piggyBank);
|
||||
$repetition->startdate = is_null($piggyBank->startdate) ? null : $piggyBank->startdate;
|
||||
$repetition->targetdate = is_null($piggyBank->targetdate) ? null : $piggyBank->targetdate;
|
||||
$repetition->currentamount = 0;
|
||||
// it might exist, catch:
|
||||
|
||||
// then, loop from original target up to now.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
@ -32,11 +32,14 @@ class AccountFormRequest extends Request
|
||||
$types = join(',', array_keys(Config::get('firefly.subTitlesByIdentifier')));
|
||||
|
||||
$nameRule = 'required|between:1,100|uniqueAccountForUser';
|
||||
$idRule = '';
|
||||
if (Account::find(Input::get('id'))) {
|
||||
$nameRule = 'required|between:1,100|belongsToUser:accounts|uniqueForUser:' . Input::get('id');
|
||||
$idRule = 'belongsToUser:accounts';
|
||||
$nameRule = 'required|between:1,100|uniqueAccountForUser:' . Input::get('id');
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $idRule,
|
||||
'name' => $nameRule,
|
||||
'openingBalance' => 'numeric',
|
||||
'openingBalanceDate' => 'date',
|
||||
|
@ -35,27 +35,14 @@ class PiggyBankFormRequest extends Request
|
||||
$nameRule = 'required|between:1,255';
|
||||
}
|
||||
|
||||
if (intval(Input::get('repeats')) == 1) {
|
||||
$targetDateRule = 'required|date|after:' . date('Y-m-d');
|
||||
// switch on rep_every, make sure it's not too far away.
|
||||
if (!is_null(Input::get('rep_length'))) {
|
||||
$end = Navigation::addPeriod(new Carbon, Input::get('rep_length'), 0);
|
||||
$targetDateRule .= '|before:' . $end->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$rules = [
|
||||
'repeats' => 'required|boolean',
|
||||
'name' => $nameRule,
|
||||
'account_id' => 'required|belongsToUser:accounts',
|
||||
'targetamount' => 'required|min:0.01',
|
||||
'amount_currency_id' => 'exists:transaction_currencies,id',
|
||||
'startdate' => 'date',
|
||||
'targetdate' => $targetDateRule,
|
||||
'rep_length' => 'in:day,week,quarter,month,year',
|
||||
'rep_every' => 'integer|min:0|max:31',
|
||||
'rep_times' => 'integer|min:0|max:99',
|
||||
'reminder' => 'in:day,week,quarter,month,year',
|
||||
'reminder_skip' => 'integer|min:0|max:99',
|
||||
'remind_me' => 'boolean|piggyBankReminder',
|
||||
|
@ -107,7 +107,7 @@ Route::bind(
|
||||
where('piggy_banks.id', $value)
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')
|
||||
->where('accounts.user_id', Auth::user()->id)
|
||||
->where('repeats', 0)->first(['piggy_banks.*']);
|
||||
->first(['piggy_banks.*']);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -15,6 +15,7 @@ class Account extends Model
|
||||
{
|
||||
use SoftDeletes, ValidatingTrait;
|
||||
|
||||
protected $fillable = ['user_id', 'account_type_id', 'name', 'active'];
|
||||
protected $rules
|
||||
= [
|
||||
'user_id' => 'required|exists:users,id',
|
||||
@ -23,41 +24,6 @@ class Account extends Model
|
||||
'active' => 'required|boolean'
|
||||
];
|
||||
|
||||
protected $fillable = ['user_id', 'account_type_id', 'name', 'active'];
|
||||
|
||||
/**
|
||||
* @param $fieldName
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getMeta($fieldName)
|
||||
{
|
||||
foreach ($this->accountMeta as $meta) {
|
||||
if ($meta->name == $fieldName) {
|
||||
return $meta->data;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNameAttribute($value)
|
||||
{
|
||||
if ($this->encrypted) {
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
return $value;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
@ -82,6 +48,33 @@ class Account extends Model
|
||||
return ['created_at', 'updated_at', 'deleted_at'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fieldName
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getMeta($fieldName)
|
||||
{
|
||||
foreach ($this->accountMeta as $meta) {
|
||||
if ($meta->name == $fieldName) {
|
||||
return $meta->data;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function piggyBanks()
|
||||
{
|
||||
return $this->hasMany('FireflyIII\Models\PiggyBank');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EloquentBuilder $query
|
||||
* @param array $types
|
||||
@ -95,6 +88,31 @@ class Account extends Model
|
||||
$query->whereIn('account_types.type', $types);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
public function setNameAttribute($value)
|
||||
{
|
||||
$this->attributes['name'] = Crypt::encrypt($value);
|
||||
$this->attributes['encrypted'] = true;
|
||||
}
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNameAttribute($value)
|
||||
{
|
||||
|
||||
if (intval($this->encrypted) == 1) {
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
return $value;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
@ -111,12 +129,4 @@ class Account extends Model
|
||||
return $this->belongsTo('FireflyIII\User');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function piggyBanks()
|
||||
{
|
||||
return $this->hasMany('FireflyIII\Models\PiggyBank');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php namespace FireflyIII\Models;
|
||||
|
||||
use Crypt;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
@ -10,7 +11,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class Bill extends Model
|
||||
{
|
||||
|
||||
protected $fillable = ['name', 'match', 'amount_min', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',];
|
||||
protected $fillable
|
||||
= ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',];
|
||||
|
||||
/**
|
||||
* @return array
|
||||
@ -20,6 +22,58 @@ class Bill extends Model
|
||||
return ['created_at', 'updated_at', 'date'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMatchAttribute($value)
|
||||
{
|
||||
|
||||
if (intval($this->match_encrypted) == 1) {
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
return $value;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNameAttribute($value)
|
||||
{
|
||||
|
||||
if (intval($this->name_encrypted) == 1) {
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
return $value;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Crypt;
|
||||
|
||||
/**
|
||||
* Class Budget
|
||||
@ -55,5 +56,30 @@ class Budget extends Model
|
||||
return $this->belongsTo('FireflyIII\User');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
public function setNameAttribute($value)
|
||||
{
|
||||
$this->attributes['name'] = Crypt::encrypt($value);
|
||||
$this->attributes['encrypted'] = true;
|
||||
}
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNameAttribute($value)
|
||||
{
|
||||
|
||||
if (intval($this->encrypted) == 1) {
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
return $value;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
use Crypt;
|
||||
/**
|
||||
* Class Category
|
||||
*
|
||||
@ -38,4 +38,29 @@ class Category extends Model
|
||||
return $this->belongsTo('FireflyIII\User');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
public function setNameAttribute($value)
|
||||
{
|
||||
$this->attributes['name'] = Crypt::encrypt($value);
|
||||
$this->attributes['encrypted'] = true;
|
||||
}
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNameAttribute($value)
|
||||
{
|
||||
|
||||
if (intval($this->encrypted) == 1) {
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
return $value;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
<?php namespace FireflyIII\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Log;
|
||||
|
||||
use Crypt;
|
||||
/**
|
||||
* Class PiggyBank
|
||||
*
|
||||
@ -15,8 +13,7 @@ class PiggyBank extends Model
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable
|
||||
= ['repeats', 'name', 'account_id', 'rep_every', 'rep_times', 'reminder_skip', 'targetamount', 'startdate', 'targetdate', 'reminder', 'remind_me',
|
||||
'rep_length'];
|
||||
= ['name', 'account_id', 'reminder_skip', 'targetamount', 'startdate', 'targetdate', 'reminder', 'remind_me'];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
@ -37,14 +34,10 @@ class PiggyBank extends Model
|
||||
return $this->currentRep;
|
||||
}
|
||||
// repeating piggy banks are no longer supported.
|
||||
if (intval($this->repeats) === 0) {
|
||||
$rep = $this->piggyBankRepetitions()->first(['piggy_bank_repetitions.*']);
|
||||
$this->currentRep = $rep;
|
||||
$rep = $this->piggyBankRepetitions()->first(['piggy_bank_repetitions.*']);
|
||||
$this->currentRep = $rep;
|
||||
|
||||
return $rep;
|
||||
} else {
|
||||
Log::error('Tried to work with a piggy bank with a repeats=1 value! (id is ' . $this->id . ')');
|
||||
}
|
||||
return $rep;
|
||||
|
||||
|
||||
}
|
||||
@ -90,4 +83,29 @@ class PiggyBank extends Model
|
||||
{
|
||||
return $this->morphMany('FireflyIII\Models\Reminder', 'remindersable');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
public function setNameAttribute($value)
|
||||
{
|
||||
$this->attributes['name'] = Crypt::encrypt($value);
|
||||
$this->attributes['encrypted'] = true;
|
||||
}
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNameAttribute($value)
|
||||
{
|
||||
|
||||
if (intval($this->encrypted) == 1) {
|
||||
return Crypt::decrypt($value);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
return $value;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use Crypt;
|
||||
/**
|
||||
* Class Reminder
|
||||
*
|
||||
@ -40,6 +40,9 @@ class Reminder extends Model
|
||||
*/
|
||||
public function getMetadataAttribute($value)
|
||||
{
|
||||
if (intval($this->encrypted) == 1) {
|
||||
return json_decode(Crypt::decrypt($value));
|
||||
}
|
||||
return json_decode($value);
|
||||
}
|
||||
|
||||
@ -86,7 +89,8 @@ class Reminder extends Model
|
||||
*/
|
||||
public function setMetadataAttribute($value)
|
||||
{
|
||||
$this->attributes['metadata'] = json_encode($value);
|
||||
$this->attributes['encrypted'] = true;
|
||||
$this->attributes['metadata'] = Crypt::encrypt(json_encode($value));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -153,9 +153,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
$piggyBank->targetdate = $data['targetdate'];
|
||||
$piggyBank->reminder = $data['reminder'];
|
||||
$piggyBank->startdate = $data['startdate'];
|
||||
$piggyBank->rep_length = isset($data['rep_length']) ? $data['rep_length'] : null;
|
||||
$piggyBank->rep_every = isset($data['rep_every']) ? $data['rep_every'] : null;
|
||||
$piggyBank->rep_times = isset($data['rep_times']) ? $data['rep_times'] : null;
|
||||
$piggyBank->remind_me = isset($data['remind_me']) && $data['remind_me'] == '1' ? 1 : 0;
|
||||
|
||||
$piggyBank->save();
|
||||
|
@ -2,14 +2,18 @@
|
||||
|
||||
namespace FireflyIII\Validation;
|
||||
|
||||
use App;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use DB;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Validation\Validator;
|
||||
use Input;
|
||||
use Navigation;
|
||||
use Crypt;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class FireflyValidator
|
||||
@ -28,6 +32,7 @@ class FireflyValidator extends Validator
|
||||
*/
|
||||
public function validateBelongsToUser($attribute, $value, $parameters)
|
||||
{
|
||||
|
||||
$count = DB::table($parameters[0])->where('user_id', Auth::user()->id)->where('id', $value)->count();
|
||||
if ($count == 1) {
|
||||
return true;
|
||||
@ -79,44 +84,105 @@ class FireflyValidator extends Validator
|
||||
*/
|
||||
public function validateUniqueAccountForUser($attribute, $value, $parameters)
|
||||
{
|
||||
// get account type from data, we must have this:
|
||||
$validTypes = array_keys(Config::get('firefly.subTitlesByIdentifier'));
|
||||
$type = null;
|
||||
|
||||
|
||||
$type = isset($this->data['what']) && in_array($this->data['what'], $validTypes) ? $this->data['what'] : null;
|
||||
// some fallback:
|
||||
if (is_null($type)) {
|
||||
$type = in_array(Input::get('what'), $validTypes) ? Input::get('what') : null;
|
||||
/**
|
||||
* Switch on different cases on which this method can respond:
|
||||
*/
|
||||
$hasWhat = isset($this->data['what']);
|
||||
$hasAccountId = isset($this->data['account_type_id']) && isset($this->data['name']);
|
||||
|
||||
if ($hasWhat) {
|
||||
|
||||
$search = Config::get('firefly.accountTypeByIdentifier.' . $this->data['what']);
|
||||
$type = AccountType::whereType($search)->first();
|
||||
// this field can be used to find the exact type, and continue.
|
||||
}
|
||||
// still null?
|
||||
if (is_null($type)) {
|
||||
// find by other field:
|
||||
$type = isset($this->data['account_type_id']) ? $this->data['account_type_id'] : 0;
|
||||
$dbType = AccountType::find($type);
|
||||
} else {
|
||||
$longType = Config::get('firefly.accountTypeByIdentifier.' . $type);
|
||||
$dbType = AccountType::whereType($longType)->first();
|
||||
if($hasAccountId) {
|
||||
$type = AccountType::find($this->data['account_type_id']);
|
||||
}
|
||||
|
||||
if (is_null($dbType)) {
|
||||
/**
|
||||
* Try to decrypt data just in case:
|
||||
*/
|
||||
try {
|
||||
$value = Crypt::decrypt($value);
|
||||
} catch(DecryptException $e) {}
|
||||
|
||||
|
||||
if (is_null($type)) {
|
||||
Log::error('Could not determine type of account to validate.');
|
||||
return false;
|
||||
}
|
||||
|
||||
// user id?
|
||||
$userId = Auth::check() ? Auth::user()->id : $this->data['user_id'];
|
||||
|
||||
$query = DB::table('accounts')->where('name', $value)->where('account_type_id', $dbType->id)->where('user_id', $userId);
|
||||
|
||||
if (isset($parameters[0])) {
|
||||
$query->where('id', '!=', $parameters[0]);
|
||||
}
|
||||
$count = $query->count();
|
||||
if ($count == 0) {
|
||||
|
||||
return true;
|
||||
// get all accounts with this type, and find the name.
|
||||
$userId = Auth::check() ? Auth::user()->id : 0;
|
||||
$set = Account::where('account_type_id', $type->id)->where('user_id', $userId)->get();
|
||||
/** @var Account $entry */
|
||||
foreach ($set as $entry) {
|
||||
if ($entry->name == $value) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
// exit;
|
||||
//
|
||||
//
|
||||
// // get account type from data, we must have this:
|
||||
// $validTypes = array_keys(Config::get('firefly.subTitlesByIdentifier'));
|
||||
// $dbType = null;
|
||||
// $type = isset($this->data['what']) && in_array($this->data['what'], $validTypes) ? $this->data['what'] : null;
|
||||
// // some fallback:
|
||||
// if (is_null($type)) {
|
||||
// $type = in_array(Input::get('what'), $validTypes) ? Input::get('what') : null;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// // still null?
|
||||
// if (is_null($type)) {
|
||||
// // find by other field:
|
||||
// $findType = isset($this->data['account_type_id']) ? $this->data['account_type_id'] : 0;
|
||||
// $dbType = AccountType::find($findType);
|
||||
// $type = $findType == 0 ? null : $findType;
|
||||
// }
|
||||
// // STILL null?
|
||||
//
|
||||
// if (is_null($type) && isset($this->data['id'])) {
|
||||
// // check ID thingie
|
||||
// $dbAccount = Account::find($this->data['id']);
|
||||
// if (!$dbAccount) {
|
||||
// Log::error('False because $dbAccount does not exist.');
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
// $dbType = AccountType::find($dbAccount->account_type_id);
|
||||
// } else {
|
||||
// $dbType = AccountType::whereType()
|
||||
// }
|
||||
//
|
||||
// if (is_null($dbType)) {
|
||||
// Log::error('False because $dbType is null.');
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// // user id?
|
||||
// $userId = Auth::check() ? Auth::user()->id : $this->data['user_id'];
|
||||
//
|
||||
// $query = DB::table('accounts')->where('name', $value)->where('account_type_id', $dbType->id)->where('user_id', $userId);
|
||||
//
|
||||
// if (isset($parameters[0])) {
|
||||
// $query->where('id', '!=', $parameters[0]);
|
||||
// }
|
||||
// $count = $query->count();
|
||||
// if ($count == 0) {
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\Component;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
@ -1,20 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* Class ChangesForV332
|
||||
*/
|
||||
class ChangesForV332 extends Migration {
|
||||
class ChangesForV332 extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
|
||||
Schema::table(
|
||||
'accounts', function (Blueprint $table) {
|
||||
@ -33,14 +44,4 @@ class ChangesForV332 extends Migration {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,33 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class ChangesForV333 extends Migration {
|
||||
class ChangesForV333 extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table(
|
||||
'transaction_journals', function (Blueprint $table) {
|
||||
$table->smallInteger('order',false,true)->default(0);
|
||||
$table->smallInteger('order', false, true)->default(0);
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class ChangesFor336 extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table(
|
||||
'budgets', function (Blueprint $table) {
|
||||
$table->smallInteger('active',false,true)->default(1);
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
}
|
184
database/migrations/2015_03_29_174140_changes_for_v336.php
Normal file
184
database/migrations/2015_03_29_174140_changes_for_v336.php
Normal file
@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* Class ChangesForV336
|
||||
*/
|
||||
class ChangesForV336 extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
|
||||
/**
|
||||
* ACCOUNTS
|
||||
*/
|
||||
// change field to be cryptable.
|
||||
Schema::table(
|
||||
'accounts', function (Blueprint $table) {
|
||||
// drop foreign key:
|
||||
$table->dropForeign('accounts_user_id_foreign');
|
||||
|
||||
// drop unique:
|
||||
$table->dropUnique('accounts_user_id_account_type_id_name_unique');
|
||||
}
|
||||
);
|
||||
|
||||
Schema::table(
|
||||
'accounts', function (Blueprint $table) {
|
||||
$table->text('name')->change();
|
||||
$table->foreign('user_id', 'account_user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* BUDGETS
|
||||
*/
|
||||
// add active/inactive and encrypt.
|
||||
Schema::table(
|
||||
'budgets', function (Blueprint $table) {
|
||||
$table->smallInteger('active', false, true)->default(1);
|
||||
$table->smallInteger('encrypted', false, true)->default(0);
|
||||
|
||||
// drop foreign key:
|
||||
$table->dropForeign('budgets_user_id_foreign');
|
||||
|
||||
// drop unique:
|
||||
$table->dropUnique('budgets_user_id_name_unique');
|
||||
|
||||
}
|
||||
);
|
||||
Schema::table(
|
||||
'budgets', function (Blueprint $table) {
|
||||
$table->text('name')->change();
|
||||
$table->foreign('user_id', 'budget_user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* BILLS
|
||||
*/
|
||||
// change field to be cryptable.
|
||||
Schema::table(
|
||||
'bills', function (Blueprint $table) {
|
||||
// drop foreign key:
|
||||
$table->dropForeign('bills_uid_for');
|
||||
|
||||
// drop unique:
|
||||
$table->dropUnique('uid_name_unique');
|
||||
}
|
||||
);
|
||||
|
||||
Schema::table(
|
||||
'bills', function (Blueprint $table) {
|
||||
// raw query:
|
||||
|
||||
DB::insert('ALTER TABLE `bills` CHANGE `name` `name` TEXT NOT NULL');
|
||||
DB::insert('ALTER TABLE `bills` CHANGE `match` `match` TEXT NOT NULL');
|
||||
$table->smallInteger('name_encrypted', false, true)->default(0);
|
||||
$table->smallInteger('match_encrypted', false, true)->default(0);
|
||||
$table->foreign('user_id', 'bill_user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* CATEGORIES
|
||||
*/
|
||||
Schema::table(
|
||||
'categories', function (Blueprint $table) {
|
||||
$table->smallInteger('encrypted', false, true)->default(0);
|
||||
|
||||
// drop foreign key:
|
||||
$table->dropForeign('categories_user_id_foreign');
|
||||
|
||||
// drop unique:
|
||||
$table->dropUnique('categories_user_id_name_unique');
|
||||
|
||||
}
|
||||
);
|
||||
Schema::table(
|
||||
'categories', function (Blueprint $table) {
|
||||
$table->text('name')->change();
|
||||
$table->foreign('user_id', 'category_user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* PIGGY BANKS
|
||||
*/
|
||||
Schema::table(
|
||||
'piggy_banks', function (Blueprint $table) {
|
||||
$table->smallInteger('encrypted', false, true)->default(0);
|
||||
|
||||
// drop foreign:
|
||||
$table->dropForeign('piggybanks_account_id_foreign');
|
||||
|
||||
// drop unique:
|
||||
$table->dropUnique('piggybanks_account_id_name_unique');
|
||||
|
||||
}
|
||||
);
|
||||
Schema::table(
|
||||
'piggy_banks', function (Blueprint $table) {
|
||||
DB::insert('ALTER TABLE `piggy_banks` CHANGE `name` `name` TEXT NOT NULL');
|
||||
$table->dropColumn(['repeats', 'rep_length', 'rep_every', 'rep_times']);
|
||||
|
||||
// create index again:
|
||||
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* REMINDERS
|
||||
*/
|
||||
Schema::table(
|
||||
'reminders', function (Blueprint $table) {
|
||||
$table->smallInteger('encrypted', false, true)->default(0);
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
// Schema::table(
|
||||
// 'categories', function (Blueprint $table) {
|
||||
// $table->smallInteger('encrypted', false, true)->default(0);
|
||||
// $table->text('name')->change();
|
||||
// }
|
||||
// );
|
||||
//
|
||||
// Schema::table(
|
||||
// 'piggy_banks', function (Blueprint $table) {
|
||||
// $table->smallInteger('encrypted', false, true)->default(0);
|
||||
// $table->text('name')->change();
|
||||
// $table->dropColumn(['repeats', 'rep_length', 'rep_every', 'rep_times']);
|
||||
// }
|
||||
// );
|
||||
// Schema::table(
|
||||
// 'reminders', function (Blueprint $table) {
|
||||
// $table->smallInteger('encrypted', false, true)->default(0);
|
||||
// }
|
||||
// );
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -257,10 +257,6 @@ class TestDataSeeder extends Seeder
|
||||
'targetamount' => 2000,
|
||||
'startdate' => $this->som,
|
||||
'targetdate' => null,
|
||||
'repeats' => 0,
|
||||
'rep_length' => null,
|
||||
'rep_every' => 0,
|
||||
'rep_times' => null,
|
||||
'reminder' => null,
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 0,
|
||||
@ -278,10 +274,6 @@ class TestDataSeeder extends Seeder
|
||||
'targetamount' => 2000,
|
||||
'startdate' => $this->som,
|
||||
'targetdate' => $end,
|
||||
'repeats' => 0,
|
||||
'rep_length' => null,
|
||||
'rep_every' => 0,
|
||||
'rep_times' => null,
|
||||
'reminder' => null,
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 0,
|
||||
@ -307,10 +299,6 @@ class TestDataSeeder extends Seeder
|
||||
'targetamount' => 1000,
|
||||
'startdate' => $this->som,
|
||||
'targetdate' => $nextYear,
|
||||
'repeats' => 0,
|
||||
'rep_length' => null,
|
||||
'rep_every' => 0,
|
||||
'rep_times' => null,
|
||||
'reminder' => $entry,
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 1,
|
||||
@ -324,10 +312,6 @@ class TestDataSeeder extends Seeder
|
||||
'targetamount' => 1000,
|
||||
'startdate' => $this->som,
|
||||
'targetdate' => null,
|
||||
'repeats' => 0,
|
||||
'rep_length' => null,
|
||||
'rep_every' => 0,
|
||||
'rep_times' => null,
|
||||
'reminder' => $entry,
|
||||
'reminder_skip' => 0,
|
||||
'remind_me' => 1,
|
||||
|
Loading…
Reference in New Issue
Block a user