Fix last minute issues.

This commit is contained in:
James Cole 2018-06-03 08:23:49 +02:00
parent b52bd59cea
commit c7af25ac38
3 changed files with 24 additions and 23 deletions

View File

@ -31,7 +31,6 @@ use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Preferences;
use View; use View;
/** /**
@ -109,7 +108,7 @@ class TagController extends Controller
$this->repository->destroy($tag); $this->repository->destroy($tag);
session()->flash('success', (string)trans('firefly.deleted_tag', ['tag' => $tagName])); session()->flash('success', (string)trans('firefly.deleted_tag', ['tag' => $tagName]));
Preferences::mark(); app('preferences')->mark();
return redirect($this->getPreviousUri('tags.delete.uri')); return redirect($this->getPreviousUri('tags.delete.uri'));
} }
@ -177,8 +176,8 @@ class TagController extends Controller
$subTitle = $tag->tag; $subTitle = $tag->tag;
$subTitleIcon = 'fa-tag'; $subTitleIcon = 'fa-tag';
$page = (int)$request->get('page'); $page = (int)$request->get('page');
$pageSize = (int)Preferences::get('listPageSize', 50)->data; $pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$range = Preferences::get('viewRange', '1M')->data; $range = app('preferences')->get('viewRange', '1M')->data;
$start = null; $start = null;
$end = null; $end = null;
$periods = new Collection; $periods = new Collection;
@ -193,7 +192,7 @@ class TagController extends Controller
} }
// prep for "specific date" view. // prep for "specific date" view.
if (\strlen($moment) > 0 && 'all' !== $moment) { if ('all' !== $moment && \strlen($moment) > 0) {
$start = new Carbon($moment); $start = new Carbon($moment);
$end = app('navigation')->endOfPeriod($start, $range); $end = app('navigation')->endOfPeriod($start, $range);
$subTitle = trans( $subTitle = trans(
@ -206,7 +205,7 @@ class TagController extends Controller
} }
// prep for current period // prep for current period
if (0 === \strlen($moment)) { if ('' === $moment) {
/** @var Carbon $start */ /** @var Carbon $start */
$start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range)); $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range));
/** @var Carbon $end */ /** @var Carbon $end */
@ -241,7 +240,7 @@ class TagController extends Controller
$this->repository->store($data); $this->repository->store($data);
session()->flash('success', (string)trans('firefly.created_tag', ['tag' => $data['tag']])); session()->flash('success', (string)trans('firefly.created_tag', ['tag' => $data['tag']]));
Preferences::mark(); app('preferences')->mark();
if (1 === (int)$request->get('create_another')) { if (1 === (int)$request->get('create_another')) {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
@ -266,7 +265,7 @@ class TagController extends Controller
$this->repository->update($tag, $data); $this->repository->update($tag, $data);
session()->flash('success', (string)trans('firefly.updated_tag', ['tag' => $data['tag']])); session()->flash('success', (string)trans('firefly.updated_tag', ['tag' => $data['tag']]));
Preferences::mark(); app('preferences')->mark();
if (1 === (int)$request->get('return_to_edit')) { if (1 === (int)$request->get('return_to_edit')) {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
@ -288,9 +287,10 @@ class TagController extends Controller
private function getPeriodOverview(Tag $tag): Collection private function getPeriodOverview(Tag $tag): Collection
{ {
// get first and last tag date from tag: // get first and last tag date from tag:
$range = Preferences::get('viewRange', '1M')->data; $range = app('preferences')->get('viewRange', '1M')->data;
$start = app('navigation')->startOfPeriod($this->repository->firstUseDate($tag), $range)->startOfMonth(); $end = app('navigation')->endOfX($this->repository->lastUseDate($tag), $range, null);
$end = app('navigation')->endOfPeriod($this->repository->lastUseDate($tag), $range)->endOfMonth(); $start = $this->repository->firstUseDate($tag);
// properties for entries with their amounts. // properties for entries with their amounts.
$cache = new CacheProperties; $cache = new CacheProperties;
@ -304,22 +304,23 @@ class TagController extends Controller
} }
$collection = new Collection; $collection = new Collection;
$currentEnd = clone $end;
// while end larger or equal to start // while end larger or equal to start
while ($end >= $start) { while ($currentEnd >= $start) {
$currentEnd = app('navigation')->endOfPeriod($end, $range); $currentStart = app('navigation')->startOfPeriod($currentEnd, $range);
// get expenses and what-not in this period and this tag. // get expenses and what-not in this period and this tag.
$arr = [ $arr = [
'string' => $end->format('Y-m-d'), 'string' => $end->format('Y-m-d'),
'name' => app('navigation')->periodShow($end, $range), 'name' => app('navigation')->periodShow($currentEnd, $range),
'date' => clone $end, 'date' => clone $end,
'spent' => $this->repository->spentInPeriod($tag, $end, $currentEnd), 'spent' => $this->repository->spentInPeriod($tag, $currentStart, $currentEnd),
'earned' => $this->repository->earnedInPeriod($tag, $end, $currentEnd), 'earned' => $this->repository->earnedInPeriod($tag, $currentStart, $currentEnd),
]; ];
$collection->push($arr); $collection->push($arr);
$end = app('navigation')->subtractPeriod($end, $range, 1); $currentEnd = clone $currentStart;
$currentEnd->subDay();
} }
$cache->store($collection); $cache->store($collection);

View File

@ -98,7 +98,7 @@ class RuleRepository implements RuleRepositoryInterface
public function getForImport(): Collection public function getForImport(): Collection
{ {
return Rule::distinct() return Rule::distinct()
->where('rules.user_id', $this->user->user_id) ->where('rules.user_id', $this->user->id)
->leftJoin('rule_groups', 'rule_groups.id', '=', 'rules.rule_group_id') ->leftJoin('rule_groups', 'rule_groups.id', '=', 'rules.rule_group_id')
->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id') ->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id')
->where('rule_groups.active', 1) ->where('rule_groups.active', 1)

View File

@ -156,10 +156,10 @@ class TagControllerTest extends TestCase
$collector = $this->mock(JournalCollectorInterface::class); $collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('spentInPeriod')->andReturn('-1')->times(3); $repository->shouldReceive('spentInPeriod')->andReturn('-1')->times(1);
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once(); $repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('lastUseDate')->andReturn(new Carbon)->once(); $repository->shouldReceive('lastUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('earnedInPeriod')->andReturn('1')->times(3); $repository->shouldReceive('earnedInPeriod')->andReturn('1')->times(1);
$repository->shouldReceive('sumsOfTag')->andReturn($amounts)->once(); $repository->shouldReceive('sumsOfTag')->andReturn($amounts)->once();
$collector->shouldReceive('removeFilter')->andReturnSelf()->once(); $collector->shouldReceive('removeFilter')->andReturnSelf()->once();
@ -225,10 +225,10 @@ class TagControllerTest extends TestCase
$collector = $this->mock(JournalCollectorInterface::class); $collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('spentInPeriod')->andReturn('-1')->times(3); $repository->shouldReceive('spentInPeriod')->andReturn('-1')->times(1);
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once(); $repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('lastUseDate')->andReturn(new Carbon)->once(); $repository->shouldReceive('lastUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('earnedInPeriod')->andReturn('1')->times(3); $repository->shouldReceive('earnedInPeriod')->andReturn('1')->times(1);
$collector->shouldReceive('removeFilter')->andReturnSelf()->once(); $collector->shouldReceive('removeFilter')->andReturnSelf()->once();
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once(); $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();