2014-11-19 14:18:06 -06:00
|
|
|
<?php
|
|
|
|
namespace FireflyIII\Event;
|
|
|
|
|
|
|
|
|
|
|
|
use Illuminate\Events\Dispatcher;
|
|
|
|
|
2014-12-13 14:59:02 -06:00
|
|
|
/**
|
|
|
|
* Class TransactionJournal
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Event
|
|
|
|
*/
|
2014-11-19 14:18:06 -06:00
|
|
|
class TransactionJournal
|
|
|
|
{
|
|
|
|
|
2014-12-13 14:59:02 -06:00
|
|
|
/**
|
|
|
|
* @param \TransactionJournal $journal
|
|
|
|
*/
|
|
|
|
public function store(\TransactionJournal $journal)
|
2014-11-19 14:18:06 -06:00
|
|
|
{
|
2014-12-13 15:54:52 -06:00
|
|
|
/** @var \FireflyIII\Database\RecurringTransaction\RecurringTransaction $repository */
|
|
|
|
$repository = \App::make('FireflyIII\Database\RecurringTransaction\RecurringTransaction');
|
2014-11-19 14:18:06 -06:00
|
|
|
$set = $repository->get();
|
|
|
|
|
2014-11-20 04:36:53 -06:00
|
|
|
|
2014-11-19 14:18:06 -06:00
|
|
|
/** @var \RecurringTransaction $entry */
|
|
|
|
foreach ($set as $entry) {
|
|
|
|
$repository->scan($entry, $journal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Dispatcher $events
|
|
|
|
*/
|
|
|
|
public function subscribe(Dispatcher $events)
|
|
|
|
{
|
|
|
|
// triggers when others are updated.
|
|
|
|
$events->listen('transactionJournal.store', 'FireflyIII\Event\TransactionJournal@store');
|
|
|
|
$events->listen('transactionJournal.update', 'FireflyIII\Event\TransactionJournal@update');
|
|
|
|
}
|
2014-11-19 14:19:13 -06:00
|
|
|
|
2014-12-13 14:59:02 -06:00
|
|
|
/**
|
|
|
|
* @param \TransactionJournal $journal
|
|
|
|
*/
|
2014-11-19 14:19:13 -06:00
|
|
|
public function update(\TransactionJournal $journal)
|
|
|
|
{
|
2014-12-13 15:54:52 -06:00
|
|
|
/** @var \FireflyIII\Database\RecurringTransaction\RecurringTransaction $repository */
|
|
|
|
$repository = \App::make('FireflyIII\Database\RecurringTransaction\RecurringTransaction');
|
2014-11-19 14:19:13 -06:00
|
|
|
$set = $repository->get();
|
2014-11-20 04:36:53 -06:00
|
|
|
$journal->recurring_transaction_id = null;
|
|
|
|
$journal->save();
|
2014-11-19 14:19:13 -06:00
|
|
|
|
|
|
|
/** @var \RecurringTransaction $entry */
|
|
|
|
foreach ($set as $entry) {
|
|
|
|
$repository->scan($entry, $journal);
|
|
|
|
}
|
|
|
|
}
|
2014-11-19 14:18:06 -06:00
|
|
|
}
|