From bc0ef11a8cacdfe5a07508cfd6dd8756b3fa33e3 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 11 Aug 2017 05:36:05 +0200 Subject: [PATCH 1/7] Add copyright markers. --- app/Console/Commands/UseEncryption.php | 10 ++++++++++ app/Mail/RegisteredUser.php | 10 ++++++++++ app/Mail/RequestedNewPassword.php | 10 ++++++++++ public/browserconfig.xml | 9 +++++++++ public/safari-pinned-tab.svg | 9 +++++++++ tests/CreatesApplication.php | 10 ++++++++++ tests/TestCase.php | 10 ++++++++++ tests/Unit/ExampleTest.php | 10 ++++++++++ 8 files changed, 78 insertions(+) diff --git a/app/Console/Commands/UseEncryption.php b/app/Console/Commands/UseEncryption.php index d3c3e178c0..8cf70208b9 100644 --- a/app/Console/Commands/UseEncryption.php +++ b/app/Console/Commands/UseEncryption.php @@ -1,10 +1,20 @@ + + diff --git a/public/safari-pinned-tab.svg b/public/safari-pinned-tab.svg index b433d7b8ed..b7b99c70e8 100644 --- a/public/safari-pinned-tab.svg +++ b/public/safari-pinned-tab.svg @@ -1,4 +1,13 @@ + + Date: Fri, 11 Aug 2017 05:42:15 +0200 Subject: [PATCH 2/7] Small code cleanup. --- app/Http/Controllers/Auth/RegisterController.php | 2 +- app/Http/Controllers/CategoryController.php | 2 -- app/Http/Controllers/Transaction/SingleController.php | 4 ++-- app/Http/Controllers/TransactionController.php | 2 -- public/js/ff/charts.js | 2 +- public/js/ff/export/index.js | 3 +-- tests/Feature/Controllers/TagControllerTest.php | 1 - tests/Unit/Helpers/MetaPieChartTest.php | 7 ++----- 8 files changed, 7 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 6d2822d398..b91b436c0c 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -53,7 +53,7 @@ class RegisterController extends Controller } /** - * @param Request $request + * @param UserRegistrationRequest|Request $request * * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View */ diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index a4592a5ce0..240e2e18ed 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -227,8 +227,6 @@ class CategoryController extends Controller $subTitleIcon = 'fa-bar-chart'; $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; diff --git a/app/Http/Controllers/Transaction/SingleController.php b/app/Http/Controllers/Transaction/SingleController.php index b3e23c25a8..b8baff5568 100644 --- a/app/Http/Controllers/Transaction/SingleController.php +++ b/app/Http/Controllers/Transaction/SingleController.php @@ -199,10 +199,10 @@ class SingleController extends Controller } /** - * @param JournalRepositoryInterface $repository - * @param TransactionJournal $transactionJournal + * @param TransactionJournal $transactionJournal * * @return \Illuminate\Http\RedirectResponse + * @internal param JournalRepositoryInterface $repository */ public function destroy(TransactionJournal $transactionJournal) { diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 1dcf3fe2de..059a1e3fb7 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -72,8 +72,6 @@ class TransactionController extends Controller $types = config('firefly.transactionTypesByWhat.' . $what); $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; diff --git a/public/js/ff/charts.js b/public/js/ff/charts.js index 9e545d8f57..5ef0380c10 100644 --- a/public/js/ff/charts.js +++ b/public/js/ff/charts.js @@ -7,7 +7,7 @@ * * See the LICENSE file for details. */ -/** global: Chart, defaultChartOptions, accounting, defaultPieOptions, noDataForChart, noDataForChart */ +/** global: Chart, defaultChartOptions, accounting, defaultPieOptions, noDataForChart */ var allCharts = {}; /* diff --git a/public/js/ff/export/index.js b/public/js/ff/export/index.js index c04d89f2cc..4dd745a078 100644 --- a/public/js/ff/export/index.js +++ b/public/js/ff/export/index.js @@ -78,8 +78,7 @@ function showDownload() { function showError(text) { "use strict"; - $('#export-error').show(); - $('#export-error').find('p').text(text); + $('#export-error').show().find('p').text(text); } function callExport() { diff --git a/tests/Feature/Controllers/TagControllerTest.php b/tests/Feature/Controllers/TagControllerTest.php index 83f33af1c5..bb8ac8fecd 100644 --- a/tests/Feature/Controllers/TagControllerTest.php +++ b/tests/Feature/Controllers/TagControllerTest.php @@ -83,7 +83,6 @@ class TagControllerTest extends TestCase public function testEdit() { // mock stuff - $repository = $this->mock(TagRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); diff --git a/tests/Unit/Helpers/MetaPieChartTest.php b/tests/Unit/Helpers/MetaPieChartTest.php index 02286b0654..e575db4ed3 100644 --- a/tests/Unit/Helpers/MetaPieChartTest.php +++ b/tests/Unit/Helpers/MetaPieChartTest.php @@ -22,9 +22,6 @@ use FireflyIII\Models\Account; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionType; use FireflyIII\Repositories\Account\AccountRepositoryInterface; -use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; -use FireflyIII\Repositories\Category\CategoryRepositoryInterface; -use FireflyIII\Repositories\Tag\TagRepositoryInterface; use Illuminate\Support\Collection; use Tests\TestCase; @@ -62,7 +59,7 @@ class MetaPieChartTest extends TestCase $collector->shouldReceive('getJournals')->andReturn($collection); // mock all repositories: - $accountRepos = $this->mock(AccountRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('find')->withArgs([1])->andReturn($accounts[1]); @@ -122,7 +119,7 @@ class MetaPieChartTest extends TestCase $collector->shouldReceive('getJournals')->andReturn($others)->once(); // mock all repositories: - $accountRepos = $this->mock(AccountRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('find')->withArgs([1])->andReturn($accounts[1]); From 31de86c9eb8bba576ebfe75b037fb18f78e653d6 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 12 Aug 2017 06:40:17 +0200 Subject: [PATCH 3/7] Improve error reporting #752 --- app/Import/FileProcessor/CsvProcessor.php | 49 ++++++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/app/Import/FileProcessor/CsvProcessor.php b/app/Import/FileProcessor/CsvProcessor.php index 5be25f5ed1..b10549c703 100644 --- a/app/Import/FileProcessor/CsvProcessor.php +++ b/app/Import/FileProcessor/CsvProcessor.php @@ -151,6 +151,43 @@ class CsvProcessor implements FileProcessorInterface return $results; } + /** + * Will return string representation of JSON error code. + * + * @param int $jsonError + * + * @return string + */ + private function getJsonError(int $jsonError): string + { + switch ($jsonError) { + default: + return 'Unknown JSON error'; + case JSON_ERROR_NONE: + return 'No JSON error'; + case JSON_ERROR_DEPTH: + return 'JSON_ERROR_DEPTH'; + case JSON_ERROR_STATE_MISMATCH: + return 'JSON_ERROR_STATE_MISMATCH'; + case JSON_ERROR_CTRL_CHAR: + return 'JSON_ERROR_CTRL_CHAR'; + case JSON_ERROR_SYNTAX: + return 'JSON_ERROR_SYNTAX'; + case JSON_ERROR_UTF8: + return 'JSON_ERROR_UTF8'; + case JSON_ERROR_RECURSION: + return 'JSON_ERROR_RECURSION'; + case JSON_ERROR_INF_OR_NAN: + return 'JSON_ERROR_INF_OR_NAN'; + case JSON_ERROR_UNSUPPORTED_TYPE: + return 'JSON_ERROR_UNSUPPORTED_TYPE'; + case JSON_ERROR_INVALID_PROPERTY_NAME: + return 'JSON_ERROR_INVALID_PROPERTY_NAME'; + case JSON_ERROR_UTF16: + return 'JSON_ERROR_UTF16'; + } + } + /** * Take a row, build import journal by annotating each value and storing it in the import journal. * @@ -158,14 +195,22 @@ class CsvProcessor implements FileProcessorInterface * @param array $row * * @return ImportJournal + * @throws FireflyException */ private function importRow(int $index, array $row): ImportJournal { Log::debug(sprintf('Now at row %d', $index)); - $row = $this->specifics($row); + $row = $this->specifics($row); + $json = json_encode($row); + $jsonError = json_last_error(); + + if ($json === false) { + throw new FireflyException(sprintf('Error while encoding JSON: %s', $this->getJsonError($jsonError))); + } + $journal = new ImportJournal; $journal->setUser($this->job->user); - $journal->setHash(hash('sha256', json_encode($row))); + $journal->setHash(hash('sha256', $json)); foreach ($row as $rowIndex => $value) { $value = trim($value); From 716af4ed93239aa54804fad539bde6e0c8507896 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 12 Aug 2017 06:41:14 +0200 Subject: [PATCH 4/7] Text for #748 --- resources/lang/en_US/firefly.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 961659547d..0c5228923e 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -519,6 +519,7 @@ return [ 'update_amount' => 'Update amount', 'update_budget' => 'Update budget', 'update_budget_amount_range' => 'Update (expected) available amount between :start and :end', + 'budget_period_navigator' => 'Period navigator', // bills: 'matching_on' => 'Matching on', From 2e6d1f36420ff1781af9ffb56cf01fe597f6dc9d Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 12 Aug 2017 06:44:00 +0200 Subject: [PATCH 5/7] Clarifies #751 --- app/Export/Entry/Entry.php | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/app/Export/Entry/Entry.php b/app/Export/Entry/Entry.php index 13be79458e..81ef189d36 100644 --- a/app/Export/Entry/Entry.php +++ b/app/Export/Entry/Entry.php @@ -45,11 +45,11 @@ final class Entry public $transaction_type; - public $source_account_id; - public $source_account_name; + public $asset_account_id; + public $asset_account_name; - public $destination_account_id; - public $destination_account_name; + public $opposing_account_id; + public $opposing_account_name; public $budget_id; public $budget_name; @@ -71,21 +71,21 @@ final class Entry */ public static function fromObject($object): Entry { - $entry = new self; - $entry->journal_id = $object->transaction_journal_id; - $entry->description = Steam::decrypt(intval($object->journal_encrypted), $object->journal_description); - $entry->amount = $object->amount; - $entry->date = $object->date; - $entry->transaction_type = $object->transaction_type; - $entry->currency_code = $object->transaction_currency_code; - $entry->source_account_id = $object->account_id; - $entry->source_account_name = Steam::decrypt(intval($object->account_name_encrypted), $object->account_name); - $entry->destination_account_id = $object->opposing_account_id; - $entry->destination_account_name = Steam::decrypt(intval($object->opposing_account_encrypted), $object->opposing_account_name); - $entry->category_id = $object->category_id ?? ''; - $entry->category_name = $object->category_name ?? ''; - $entry->budget_id = $object->budget_id ?? ''; - $entry->budget_name = $object->budget_name ?? ''; + $entry = new self; + $entry->journal_id = $object->transaction_journal_id; + $entry->description = Steam::decrypt(intval($object->journal_encrypted), $object->journal_description); + $entry->amount = $object->amount; + $entry->date = $object->date; + $entry->transaction_type = $object->transaction_type; + $entry->currency_code = $object->transaction_currency_code; + $entry->asset_account_id = $object->account_id; + $entry->asset_account_name = Steam::decrypt(intval($object->account_name_encrypted), $object->account_name); + $entry->opposing_account_id = $object->opposing_account_id; + $entry->opposing_account_name = Steam::decrypt(intval($object->opposing_account_encrypted), $object->opposing_account_name); + $entry->category_id = $object->category_id ?? ''; + $entry->category_name = $object->category_name ?? ''; + $entry->budget_id = $object->budget_id ?? ''; + $entry->budget_name = $object->budget_name ?? ''; // update description when transaction description is different: if (!is_null($object->description) && $object->description !== $entry->description) { From f51e48f282afaa9b0ef996a82109145379c701a0 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 12 Aug 2017 06:55:35 +0200 Subject: [PATCH 6/7] Add link to split withdrawal --- resources/views/transactions/show.twig | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/resources/views/transactions/show.twig b/resources/views/transactions/show.twig index a6a7fc8876..5fb3fee0c3 100644 --- a/resources/views/transactions/show.twig +++ b/resources/views/transactions/show.twig @@ -221,7 +221,7 @@
{% if journal.transactionType.type != "Withdrawal" %}

- + {{ ('convert_'~journal.transactionType.type~'_to_withdrawal')|_ }} @@ -229,7 +229,7 @@ {% endif %} {% if journal.transactionType.type != "Deposit" %}

- + {{ ('convert_'~journal.transactionType.type~'_to_deposit')|_ }} @@ -238,21 +238,24 @@ {% if journal.transactionType.type != "Transfer" %}

- + {{ ('convert_'~journal.transactionType.type~'_to_transfer')|_ }}

{% endif %} - {% if transactions|length == 1 %}

- + {{ ('clone_'~journal.transactionType.type|lower)|_ }}

- {% endif %} - +

+ + + {{ ('split_this_'~what)|_ }} + +

{% endif %} From 72b08384adbe33823b43bc378d87966380d0f43e Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 12 Aug 2017 06:55:46 +0200 Subject: [PATCH 7/7] Code for #749 --- public/js/ff/transactions/split/edit.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/public/js/ff/transactions/split/edit.js b/public/js/ff/transactions/split/edit.js index d9e7e22ed9..dbe9cfba98 100644 --- a/public/js/ff/transactions/split/edit.js +++ b/public/js/ff/transactions/split/edit.js @@ -220,18 +220,24 @@ function resetDivSplits() { function calculateSum() { "use strict"; + var left = originalSum * -1; var sum = 0; var set = $('input[name$="][amount]"]'); for (var i = 0; i < set.length; i++) { var current = $(set[i]); sum += (current.val() === "" ? 0 : parseFloat(current.val())); + left += (current.val() === "" ? 0 : parseFloat(current.val())); } sum = Math.round(sum * 100) / 100; + left = Math.round(left * 100) / 100; $('.amount-warning').remove(); if (sum !== originalSum) { var holder = $('#journal_amount_holder'); var par = holder.find('p.form-control-static'); $('').text(' (' + accounting.formatMoney(sum) + ')').addClass('text-danger amount-warning').appendTo(par); + // also add what's left to divide (or vice versa) + $('').text(' (' + accounting.formatMoney(left) + ')').addClass('text-danger amount-warning').appendTo(par); } + } \ No newline at end of file