New stuff for the rule thing.

This commit is contained in:
James Cole 2016-01-12 20:36:47 +01:00
parent da7eb615db
commit 06d11c9133
5 changed files with 123 additions and 30 deletions

View File

@ -9,30 +9,32 @@
namespace FireflyIII\Models;
use Crypt;
use Illuminate\Database\Eloquent\Model;
/**
* Class Rule
*
* @package FireflyIII\Models
* @property integer $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property string $deleted_at
* @property integer $user_id
* @property integer $rule_group_id
* @property integer $order
* @property string $title
* @property string $description
* @property boolean $active
* @property boolean $stop_processing
* @property-read \FireflyIII\User $user
* @property-read \FireflyIII\Models\RuleGroup $ruleGroup
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\RuleAction[] $ruleActions
* @property integer $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property string $deleted_at
* @property integer $user_id
* @property integer $rule_group_id
* @property integer $order
* @property string $title
* @property string $description
* @property boolean $active
* @property boolean $stop_processing
* @property-read \FireflyIII\User $user
* @property-read \FireflyIII\Models\RuleGroup $ruleGroup
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\RuleAction[] $ruleActions
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\RuleTrigger[] $ruleTriggers
*/
class Rule extends Model
{
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/

View File

@ -12,16 +12,14 @@ namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model;
/**
* Class RuleTrigger
* FireflyIII\Models\RuleTrigger
*
* @package FireflyIII\Models
* @property integer $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property integer $rule_id
* @property integer $order
* @property string $title
* @property string $trigger_field
* @property string $trigger_type
* @property string $trigger_value
* @property boolean $active

View File

@ -98,7 +98,7 @@ return [
'Revenue account' => 'revenue',
'Cash account' => 'cash',
],
'languages' => [
'languages' => [
'en_US' => ['name_locale' => 'English', 'name_english' => 'English', 'complete' => true],
'nl_NL' => ['name_locale' => 'Nederlands', 'name_english' => 'Dutch', 'complete' => true],
'pt_BR' => ['name_locale' => 'Português do Brasil', 'name_english' => 'Portugese (Brazil)', 'complete' => false],
@ -147,4 +147,47 @@ return [
'pt_BR' => '%B %e, %Y',
],
'bindables' => [
// models
'account' => 'FireflyIII\Models\Account',
'attachment' => 'FireflyIII\Models\Attachment',
'bill' => 'FireflyIII\Models\Bill',
'budget' => 'FireflyIII\Models\Budget',
'category' => 'FireflyIII\Models\Category',
'currency' => 'FireflyIII\Models\TransactionCurrency',
'limitrepetition' => 'FireflyIII\Models\LimitRepetition',
'piggyBank' => 'FireflyIII\Models\PiggyBank',
'tj' => 'FireflyIII\Models\TransactionJournal',
'tag' => 'FireflyIII\Models\Tag',
// lists
'accountList' => 'FireflyIII\Support\Binder\AccountList',
'budgetList' => 'FireflyIII\Support\Binder\BudgetList',
'categoryList' => 'FireflyIII\Support\Binder\CategoryList',
// others
'start_date' => 'FireflyIII\Support\Binder\Date',
'end_date' => 'FireflyIII\Support\Binder\Date'
],
'rule-triggers' => [
'from_account_starts' => 'FireflyIII\Rules\Triggers',
'from_account_ends' => 'FireflyIII\Rules\Triggers',
'from_account_is' => 'FireflyIII\Rules\Triggers',
'from_account_contains' => 'FireflyIII\Rules\Triggers',
'to_account_starts' => 'FireflyIII\Rules\Triggers',
'to_account_ends' => 'FireflyIII\Rules\Triggers',
'to_account_is' => 'FireflyIII\Rules\Triggers',
'to_account_contains' => 'FireflyIII\Rules\Triggers',
'transaction_type' => 'FireflyIII\Rules\Triggers',
'amount_less' => 'FireflyIII\Rules\Triggers',
'amount_exactly' => 'FireflyIII\Rules\Triggers',
'amount_exactly_not' => 'FireflyIII\Rules\Triggers',
'amount_more' => 'FireflyIII\Rules\Triggers',
'description_starts' => 'FireflyIII\Rules\Triggers',
'description_ends' => 'FireflyIII\Rules\Triggers',
'description_contains' => 'FireflyIII\Rules\Triggers',
'description_is' => 'FireflyIII\Rules\Triggers',
],
];

View File

@ -30,8 +30,8 @@ class ChangesForV370 extends Migration
$table->softDeletes();
$table->integer('user_id')->unsigned();
$table->unsignedSmallInteger('order');
$table->string('title', 2048);
$table->mediumText('description');
$table->string('title', 255);
$table->text('description');
$table->unsignedTinyInteger('active')->default(1);
// connect rule groups to users
@ -52,8 +52,8 @@ class ChangesForV370 extends Migration
$table->integer('user_id')->unsigned();
$table->integer('rule_group_id')->unsigned();
$table->unsignedSmallInteger('order');
$table->string('title', 2048);
$table->mediumText('description');
$table->string('title', 255);
$table->text('description');
$table->unsignedTinyInteger('active')->default(1);
$table->unsignedTinyInteger('stop_processing')->default(0);
@ -78,9 +78,8 @@ class ChangesForV370 extends Migration
$table->unsignedSmallInteger('order');
$table->string('title', 2048);
$table->string('trigger_field', 2048);
$table->string('trigger_type', 1024);
$table->string('trigger_value', 2048);
$table->string('trigger_type', 50);
$table->string('trigger_value', 255);
$table->unsignedTinyInteger('active')->default(1);
$table->unsignedTinyInteger('stop_processing')->default(0);
@ -88,7 +87,7 @@ class ChangesForV370 extends Migration
// order must be unique for rule triggers:
$table->unique(['rule_id', 'order']);
// connect rule tiggers to rules
// connect rule triggers to rules
$table->foreign('rule_id')->references('id')->on('rules')->onDelete('cascade');
}
);
@ -104,9 +103,9 @@ class ChangesForV370 extends Migration
$table->unsignedTinyInteger('active')->default(1);
$table->unsignedTinyInteger('stop_processing')->default(0);
$table->string('action_field', 2048);
$table->string('action', 1024);
$table->string('action_value', 2048);
$table->string('action_field', 50);
$table->string('action', 50);
$table->string('action_value', 255);
// connect rule actions to rules
$table->foreign('rule_id')->references('id')->on('rules')->onDelete('cascade');

View File

@ -10,6 +10,9 @@ use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Role;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\RuleTrigger;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
@ -33,6 +36,52 @@ class TestDataSeeder extends Seeder
public function __construct()
{
}
public function createRules()
{
// basic rules group. user should always have one
$ruleGroup = new RuleGroup;
$ruleGroup->user()->associate($this->user);
$ruleGroup->order = 1;
$ruleGroup->title = 'Default rules';
$ruleGroup->description = 'All your rules not in a particular group.';
$ruleGroup->active = 1;
$ruleGroup->save();
// a normal rule: saves transactions where description contains "groceries"
// and from account is "MyBank Checking Account"
// send it to Groceries/Groceries
$rule = new Rule;
$rule->user()->associate($this->user);
$rule->ruleGroup()->associate($ruleGroup);
$rule->order = 1;
$rule->title = 'A strange rule for testing.';
$rule->description = 'This rule triggers on transactions with the description "David Bowie" and puts them in the category "Blackstar".';
$rule->active = 1;
$rule->stop_processing = 0;
$rule->save();
// trigger for this rule:
$ruleTrigger = new RuleTrigger;
$ruleTrigger->rule()->associate($rule);
$ruleTrigger->order = 1;
$ruleTrigger->title = 'Groceries';
$ruleTrigger->trigger_type = 'description_contains';
$ruleTrigger->trigger_value = 'groceries';
$ruleTrigger->active = 1;
$ruleTrigger->stop_processing = 0;
// actions for this rule.
// TODO a rule that triggers on something, just like the previous one, but it has "stop_processing" set to 1.
// TODO a rule that triggers on that same thing, but it will not file, because the previous rule made FF skip it.
// TODO rule with specific actions.
// TODO rule with actions and one action has stop_processing and other actions are not processed. Somewhere in test?
}
/**
@ -49,6 +98,8 @@ class TestDataSeeder extends Seeder
$this->createBills();
$this->createPiggybanks();
$this->createRules();
// preference to only see account #1 on frontpage.
$this->createPreferences();
@ -649,7 +700,7 @@ class TestDataSeeder extends Seeder
$fromAccount = $this->findAccount('MyBank Checking Account');
$stores = ['Albert Heijn', 'PLUS', 'Bakker'];
$descriptions = ['Groceries', 'Bought some food', 'Got groceries'];
$descriptions = ['Groceries', 'Bought some groceries', 'Got groceries'];
$category = Category::firstOrCreateEncrypted(['name' => 'Daily groceries', 'user_id' => $this->user->id]);
$budget = Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $this->user->id]);