Scan bills when editing and creating journals.

This commit is contained in:
James Cole 2015-03-01 08:15:24 +01:00
parent d1cf683f57
commit 0d0df5f143
4 changed files with 29 additions and 19 deletions

View File

@ -1,18 +1,20 @@
<?php namespace FireflyIII\Providers;
use App;
use Auth;
use FireflyIII\Models\Account;
use FireflyIII\Models\Bill;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\LimitRepetition;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankRepetition;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Support\Facades\Navigation;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
/**
* Class EventServiceProvider
*
@ -57,6 +59,21 @@ class EventServiceProvider extends ServiceProvider
}
);
TransactionJournal::saved(
function (TransactionJournal $journal) {
/** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */
$repository = App::make('FireflyIII\Repositories\Bill\BillRepositoryInterface');
$list = $journal->user->bills()->where('active', 1)->where('automatch', 1)->get();
/** @var Bill $bill */
foreach ($list as $bill) {
$repository->scan($bill, $journal);
}
}
);
Account::deleted(
function (Account $account) {
@ -68,14 +85,16 @@ class EventServiceProvider extends ServiceProvider
}
);
PiggyBank::created(function(PiggyBank $piggyBank) {
PiggyBank::created(
function (PiggyBank $piggyBank) {
$repetition = new PiggyBankRepetition;
$repetition->piggyBank()->associate($piggyBank);
$repetition->startdate = $piggyBank->startdate;
$repetition->targetdate = $piggyBank->targetdate;
$repetition->currentamount = 0;
$repetition->save();
});
}
);
BudgetLimit::saved(
function (BudgetLimit $budgetLimit) {

View File

@ -36,7 +36,7 @@ class CreateAccountsTable extends Migration
$table->softDeletes();
$table->integer('user_id')->unsigned();
$table->integer('account_type_id')->unsigned();
$table->string('name', 1024);
$table->string('name', 100);
$table->boolean('active');
// connect accounts to users

View File

@ -15,12 +15,6 @@ class ChangesForV332 extends Migration {
*/
public function up()
{
Schema::table(
'transaction_journals', function (Blueprint $table) {
$table->boolean('encrypted');
}
);
Schema::table(
'accounts', function (Blueprint $table) {

View File

@ -279,7 +279,6 @@ class TestDataSeeder extends Seeder
);
// and some events!
PiggyBankEvent::create(['piggy_bank_id' => $newCamera->id, 'date' => $this->som, 'amount' => 100]);
//PiggyBankRepetition::create(['piggy_bank_id' => $newCamera->id, 'startdate' => $this->som, 'targetdate' => null, 'currentamount' => 100]);
$newClothes = PiggyBank::create(
@ -301,7 +300,6 @@ class TestDataSeeder extends Seeder
);
PiggyBankEvent::create(['piggy_bank_id' => $newClothes->id, 'date' => $this->som, 'amount' => 100]);
//PiggyBankRepetition::create(['piggy_bank_id' => $newClothes->id, 'startdate' => $this->som, 'targetdate' => $end, 'currentamount' => 100]);
// weekly reminder piggy bank
$weekly = PiggyBank::create(
@ -321,7 +319,6 @@ class TestDataSeeder extends Seeder
'order' => 0,
]
);
//PiggyBankRepetition::create(['piggy_bank_id' => $weekly->id, 'startdate' => $this->som, 'targetdate' => $next, 'currentamount' => 0]);
}
/**
@ -374,10 +371,10 @@ class TestDataSeeder extends Seeder
'order' => 0,
]
);
PiggyBankRepetition::create(['piggy_bank_id' => $recurring->id, 'startdate' => $this->som, 'targetdate' => $this->eom, 'currentamount' => 0]);
PiggyBankRepetition::create(
['piggy_bank_id' => $recurring->id, 'startdate' => $this->nsom, 'targetdate' => $this->neom, 'currentamount' => 0]
);
// PiggyBankRepetition::create(['piggy_bank_id' => $recurring->id, 'startdate' => $this->som, 'targetdate' => $this->eom, 'currentamount' => 0]);
// PiggyBankRepetition::create(
// ['piggy_bank_id' => $recurring->id, 'startdate' => $this->nsom, 'targetdate' => $this->neom, 'currentamount' => 0]
// );
Reminder::create(
['user_id' => $user->id, 'startdate' => $this->som, 'enddate' => $this->neom, 'active' => 1, 'notnow' => 0,
'remindersable_id' => $recurring->id, 'remindersable_type' => 'PiggyBank']