From 1cfa1faccc694449700e06ee52953f4e824a6593 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 30 Jul 2017 13:53:04 +0200 Subject: [PATCH] =?UTF-8?q?Remove=20all=20time=20jumps=20because=20they?= =?UTF-8?q?=E2=80=99re=20unclear=20and=20complex.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/AccountController.php | 38 ++------- app/Http/Controllers/BudgetController.php | 36 ++------ app/Http/Controllers/CategoryController.php | 84 +++++-------------- app/Http/Controllers/TagController.php | 36 ++------ .../Controllers/TransactionController.php | 34 ++------ app/Import/Converter/Amount.php | 2 + resources/lang/en_US/firefly.php | 1 - 7 files changed, 49 insertions(+), 182 deletions(-) diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index db8c7b7f9c..b1f35acc20 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -32,7 +32,6 @@ use Illuminate\Support\Collection; use Log; use Navigation; use Preferences; -use Session; use Steam; use View; @@ -292,37 +291,14 @@ class AccountController extends Controller $periods = $this->getPeriodOverview($account); } - $count = 0; - $loop = 0; - // grab journals, but be prepared to jump a period back to get the right ones: - Log::info('Now at loop start.'); - while ($count === 0 && $loop < 3) { - $loop++; - $collector = app(JournalCollectorInterface::class); - Log::info('Count is zero, search for journals.'); - $collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page); - if (!is_null($start)) { - $collector->setRange($start, $end); - } - $journals = $collector->getPaginatedJournals(); - $journals->setPath(route('accounts.show', [$account->id, $moment])); - $count = $journals->getCollection()->count(); - if ($count === 0 && $loop < 3) { - $start->subDay(); - $start = Navigation::startOfPeriod($start, $range); - $end = Navigation::endOfPeriod($start, $range); - Log::info(sprintf('Count is still zero, go back in time to "%s" and "%s"!', $start->format('Y-m-d'), $end->format('Y-m-d'))); - } + // grab journals: + $collector = app(JournalCollectorInterface::class); + $collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page); + if (!is_null($start)) { + $collector->setRange($start, $end); } - - if ($moment !== 'all' && $loop > 1) { - $fStart = $start->formatLocalized($this->monthAndDayFormat); - $fEnd = $end->formatLocalized($this->monthAndDayFormat); - $chartUri = route('chart.account.period', [$account->id, $start->format('Y-m-d')]); - $subTitle = trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]); - Session::flash('info', trans('firefly.jump_back_in_time')); - } - + $journals = $collector->getPaginatedJournals(); + $journals->setPath(route('accounts.show', [$account->id, $moment])); return view( 'accounts.show', diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index bd385094b1..3e051b8b83 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -34,7 +34,6 @@ use Log; use Navigation; use Preferences; use Response; -use Session; use View; /** @@ -297,35 +296,12 @@ class BudgetController extends Controller $page = intval($request->get('page')); $pageSize = intval(Preferences::get('transactionPageSize', 50)->data); - $count = 0; - $loop = 0; - // grab journals, but be prepared to jump a period back to get the right ones: - Log::info('Now at no-budget loop start.'); - while ($count === 0 && $loop < 3) { - $loop++; - Log::info(sprintf('Count is zero, search for journals between %s and %s.', $start->format('Y-m-d'), $end->format('Y-m-d'))); - /** @var JournalCollectorInterface $collector */ - $collector = app(JournalCollectorInterface::class); - $collector->setAllAssetAccounts()->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setLimit($pageSize)->setPage($page) - ->withoutBudget()->withOpposingAccount(); - $journals = $collector->getPaginatedJournals(); - $journals->setPath(route('budgets.no-budget')); - $count = $journals->getCollection()->count(); - if ($count === 0 && $loop < 3) { - $start->subDay(); - $start = Navigation::startOfPeriod($start, $range); - $end = Navigation::endOfPeriod($start, $range); - Log::info(sprintf('Count is still zero, go back in time to "%s" and "%s"!', $start->format('Y-m-d'), $end->format('Y-m-d'))); - } - } - - if ($moment !== 'all' && $loop > 1) { - $subTitle = trans( - 'firefly.without_budget_between', - ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] - ); - Session::flash('info', trans('firefly.jump_back_in_time')); - } + /** @var JournalCollectorInterface $collector */ + $collector = app(JournalCollectorInterface::class); + $collector->setAllAssetAccounts()->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setLimit($pageSize)->setPage($page) + ->withoutBudget()->withOpposingAccount(); + $journals = $collector->getPaginatedJournals(); + $journals->setPath(route('budgets.no-budget')); return view('budgets.no-budget', compact('journals', 'subTitle', 'moment', 'periods', 'start', 'end')); } diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 871112d16d..a4592a5ce0 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -29,7 +29,6 @@ use Illuminate\Support\Collection; use Log; use Navigation; use Preferences; -use Session; use Steam; use View; @@ -165,10 +164,12 @@ class CategoryController extends Controller public function noCategory(Request $request, JournalRepositoryInterface $repository, string $moment = '') { // default values: - $range = Preferences::get('viewRange', '1M')->data; - $start = null; - $end = null; - $periods = new Collection; + $range = Preferences::get('viewRange', '1M')->data; + $start = null; + $end = null; + $periods = new Collection; + $page = intval($request->get('page')); + $pageSize = intval(Preferences::get('transactionPageSize', 50)->data); // prep for "all" view. if ($moment === 'all') { @@ -200,38 +201,13 @@ class CategoryController extends Controller ); } - $page = intval($request->get('page')); - $pageSize = intval(Preferences::get('transactionPageSize', 50)->data); - $count = 0; - $loop = 0; - // grab journals, but be prepared to jump a period back to get the right ones: - Log::info('Now at no-cat loop start.'); - while ($count === 0 && $loop < 3) { - $loop++; - Log::info('Count is zero, search for journals.'); - /** @var JournalCollectorInterface $collector */ - $collector = app(JournalCollectorInterface::class); - $collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withoutCategory()->withOpposingAccount(); - $collector->removeFilter(InternalTransferFilter::class); - $journals = $collector->getPaginatedJournals(); - $journals->setPath(route('categories.no-category')); - $count = $journals->getCollection()->count(); - if ($count === 0 && $loop < 3) { - $start->subDay(); - $start = Navigation::startOfPeriod($start, $range); - $end = Navigation::endOfPeriod($start, $range); - Log::info(sprintf('Count is still zero, go back in time to "%s" and "%s"!', $start->format('Y-m-d'), $end->format('Y-m-d'))); - } - } - - if ($moment !== 'all' && $loop > 1) { - $subTitle = trans( - 'firefly.without_category_between', - ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] - ); - Session::flash('info', trans('firefly.jump_back_in_time')); - } + /** @var JournalCollectorInterface $collector */ + $collector = app(JournalCollectorInterface::class); + $collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withoutCategory()->withOpposingAccount(); + $collector->removeFilter(InternalTransferFilter::class); + $journals = $collector->getPaginatedJournals(); + $journals->setPath(route('categories.no-category')); return view('categories.no-category', compact('journals', 'subTitle', 'moment', 'periods', 'start', 'end')); } @@ -289,35 +265,15 @@ class CategoryController extends Controller 'end' => $end->formatLocalized($this->monthAndDayFormat)] ); } - // grab journals, but be prepared to jump a period back to get the right ones: - Log::info('Now at category loop start.'); - while ($count === 0 && $loop < 3) { - $loop++; - Log::info('Count is zero, search for journals.'); - /** @var JournalCollectorInterface $collector */ - $collector = app(JournalCollectorInterface::class); - $collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount() - ->setCategory($category)->withBudgetInformation()->withCategoryInformation(); - $collector->removeFilter(InternalTransferFilter::class); - $journals = $collector->getPaginatedJournals(); - $journals->setPath(route('categories.show', [$category->id])); - $count = $journals->getCollection()->count(); - if ($count === 0 && $loop < 3) { - $start->subDay(); - $start = Navigation::startOfPeriod($start, $range); - $end = Navigation::endOfPeriod($start, $range); - Log::info(sprintf('Count is still zero, go back in time to "%s" and "%s"!', $start->format('Y-m-d'), $end->format('Y-m-d'))); - } - } - if ($moment !== 'all' && $loop > 1) { - $subTitle = trans( - 'firefly.journals_in_period_for_category', - ['name' => $category->name, 'start' => $start->formatLocalized($this->monthAndDayFormat), - 'end' => $end->formatLocalized($this->monthAndDayFormat)] - ); - Session::flash('info', trans('firefly.jump_back_in_time')); - } + /** @var JournalCollectorInterface $collector */ + $collector = app(JournalCollectorInterface::class); + $collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount() + ->setCategory($category)->withBudgetInformation()->withCategoryInformation(); + $collector->removeFilter(InternalTransferFilter::class); + $journals = $collector->getPaginatedJournals(); + $journals->setPath(route('categories.show', [$category->id])); + return view('categories.show', compact('category', 'moment', 'journals', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end')); } diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index ce3189cf52..73c9cfdfdf 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -22,7 +22,6 @@ use FireflyIII\Repositories\Tag\TagRepositoryInterface; use FireflyIII\Support\CacheProperties; use Illuminate\Http\Request; use Illuminate\Support\Collection; -use Log; use Navigation; use Preferences; use Session; @@ -217,8 +216,6 @@ class TagController extends Controller $subTitleIcon = 'fa-tag'; $page = intval($request->get('page')); $pageSize = intval(Preferences::get('transactionPageSize', 50)->data); - $count = 0; - $loop = 0; $range = Preferences::get('viewRange', '1M')->data; $start = null; $end = null; @@ -260,33 +257,14 @@ class TagController extends Controller ['tag' => $tag->tag, 'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] ); } - // grab journals, but be prepared to jump a period back to get the right ones: - Log::info('Now at tag loop start.'); - while ($count === 0 && $loop < 3) { - $loop++; - Log::info(sprintf('Count is zero, search for journals between %s and %s (pagesize %d, page %d).', $start, $end, $pageSize, $page)); - /** @var JournalCollectorInterface $collector */ - $collector = app(JournalCollectorInterface::class); - $collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount() - ->setTag($tag)->withBudgetInformation()->withCategoryInformation()->removeFilter(InternalTransferFilter::class); - $journals = $collector->getPaginatedJournals(); - $journals->setPath($path); - $count = $journals->getCollection()->count(); - if ($count === 0 && $loop < 3) { - $start->subDay(); - $start = Navigation::startOfPeriod($start, $range); - $end = Navigation::endOfPeriod($start, $range); - Log::info(sprintf('Count is still zero, go back in time to "%s" and "%s"!', $start->format('Y-m-d'), $end->format('Y-m-d'))); - } - } - if ($moment !== 'all' && $loop > 1) { - $subTitle = trans( - 'firefly.journals_in_period_for_tag', - ['tag' => $tag->tag, 'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] - ); - Session::flash('info', trans('firefly.jump_back_in_time')); - } + /** @var JournalCollectorInterface $collector */ + $collector = app(JournalCollectorInterface::class); + $collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount() + ->setTag($tag)->withBudgetInformation()->withCategoryInformation()->removeFilter(InternalTransferFilter::class); + $journals = $collector->getPaginatedJournals(); + $journals->setPath($path); + return view('tags.show', compact('apiKey', 'tag', 'periods', 'subTitle', 'subTitleIcon', 'journals', 'sum', 'start', 'end', 'moment')); } diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index ddcdcfead8..1dcf3fe2de 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -27,7 +27,6 @@ use Log; use Navigation; use Preferences; use Response; -use Session; use Steam; use View; @@ -112,33 +111,14 @@ class TransactionController extends Controller ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] ); } - // grab journals, but be prepared to jump a period back to get the right ones: - Log::info('Now at transaction loop start.'); - while ($count === 0 && $loop < 3) { - $loop++; - Log::info('Count is zero, search for journals.'); - /** @var JournalCollectorInterface $collector */ - $collector = app(JournalCollectorInterface::class); - $collector->setAllAssetAccounts()->setRange($start, $end)->setTypes($types)->setLimit($pageSize)->setPage($page)->withOpposingAccount(); - $collector->removeFilter(InternalTransferFilter::class); - $journals = $collector->getPaginatedJournals(); - $journals->setPath($path); - $count = $journals->getCollection()->count(); - if ($count === 0 && $loop < 3) { - $start->subDay(); - $start = Navigation::startOfPeriod($start, $range); - $end = Navigation::endOfPeriod($start, $range); - Log::info(sprintf('Count is still zero, go back in time to "%s" and "%s"!', $start->format('Y-m-d'), $end->format('Y-m-d'))); - } - } - if ($moment !== 'all' && $loop > 1) { - $subTitle = trans( - 'firefly.title_' . $what . '_between', - ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] - ); - Session::flash('info', trans('firefly.jump_back_in_time')); - } + /** @var JournalCollectorInterface $collector */ + $collector = app(JournalCollectorInterface::class); + $collector->setAllAssetAccounts()->setRange($start, $end)->setTypes($types)->setLimit($pageSize)->setPage($page)->withOpposingAccount(); + $collector->removeFilter(InternalTransferFilter::class); + $journals = $collector->getPaginatedJournals(); + $journals->setPath($path); + return view('transactions.index', compact('subTitle', 'what', 'subTitleIcon', 'journals', 'periods', 'start', 'end', 'moment')); diff --git a/app/Import/Converter/Amount.php b/app/Import/Converter/Amount.php index 75f90a534d..160c8c05e6 100644 --- a/app/Import/Converter/Amount.php +++ b/app/Import/Converter/Amount.php @@ -29,6 +29,8 @@ class Amount implements ConverterInterface * @param $value * * @return string + * + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function convert($value): string { diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index dea2d1c6df..7ffead95b3 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -145,7 +145,6 @@ return [ 'exchange_rate_instructions' => 'Asset account "@name" only accepts transactions in @native_currency. If you wish to use @foreign_currency instead, make sure that the amount in @native_currency is known as well:', 'transfer_exchange_rate_instructions' => 'Source asset account "@source_name" only accepts transactions in @source_currency. Destination asset account "@dest_name" only accepts transactions in @dest_currency. You must provide the transferred amount correctly in both currencies.', 'transaction_data' => 'Transaction data', - 'jump_back_in_time' => 'The period you selected contains no transactions. Firefly III has skipped this empty period. The dates below may divert from what you have selected.', // search 'search' => 'Search',