diff --git a/app/Factory/AccountFactory.php b/app/Factory/AccountFactory.php index eb41c9e171..cc1ce17b89 100644 --- a/app/Factory/AccountFactory.php +++ b/app/Factory/AccountFactory.php @@ -27,6 +27,7 @@ namespace FireflyIII\Factory; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; +use FireflyIII\Models\Location; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Services\Internal\Support\AccountServiceTrait; use FireflyIII\User; @@ -131,6 +132,17 @@ class AccountFactory } } $this->updateNote($return, $data['notes'] ?? ''); + + // store location + if (true === ($data['has_location'] ?? true) && null !== $return) { + $location = new Location; + $location->latitude = $data['latitude'] ?? 52.3167; + $location->longitude = $data['longitude'] ?? 5.55; + $location->zoom_level = $data['zoom_level'] ?? 6; + $location->locatable()->associate($return); + $location->save(); + } + } return $return; diff --git a/app/Http/Controllers/Account/ShowController.php b/app/Http/Controllers/Account/ShowController.php index 790f186f09..a95043b6d9 100644 --- a/app/Http/Controllers/Account/ShowController.php +++ b/app/Http/Controllers/Account/ShowController.php @@ -99,7 +99,7 @@ class ShowController extends Controller if ($end < $start) { [$start, $end] = [$end, $start]; // @codeCoverageIgnore } - + $location = $account->locations()->first(); $objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type)); $today = new Carbon; $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type)); @@ -128,7 +128,7 @@ class ShowController extends Controller 'accounts.show', compact( 'account', 'showAll', 'objectType', 'currency', 'today', 'periods', 'subTitleIcon', 'groups', 'subTitle', 'start', 'end', - 'chartUri' + 'chartUri', 'location' ) ); } diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php index a11ae83e92..662f271b16 100644 --- a/app/Http/Requests/AccountFormRequest.php +++ b/app/Http/Requests/AccountFormRequest.php @@ -67,6 +67,11 @@ class AccountFormRequest extends Request 'interest' => $this->string('interest'), 'interest_period' => $this->string('interest_period'), 'include_net_worth' => '1', + // new: location + 'longitude' => $this->float('location_longitude'), + 'latitude' => $this->float('location_latitude'), + 'zoom_level' => $this->integer('location_zoomlevel'), + 'has_location' => $this->boolean('location_has_tag'), ]; if (false === $this->boolean('include_net_worth')) { $data['include_net_worth'] = '0'; diff --git a/public/v1/js/ff/accounts/show.js b/public/v1/js/ff/accounts/show.js index 0ae59c2815..db9ef2a598 100644 --- a/public/v1/js/ff/accounts/show.js +++ b/public/v1/js/ff/accounts/show.js @@ -69,6 +69,30 @@ $(function () { ); } + if (doPlaceMarker === true) { + /* + Create new map: + */ + + // make map: + var mymap = L.map('location_map', { + zoomControl: false, + touchZoom: false, + doubleClickZoom: false, + scrollWheelZoom: false, + boxZoom: false, + dragging: false + }).setView([latitude, longitude], zoomLevel); + + L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', { + attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox', + maxZoom: 18, + id: 'mapbox.streets', + accessToken: mapboxToken + }).addTo(mymap); + L.marker([latitude, longitude]).addTo(mymap); + } + }); function sortStop(event, ui) { diff --git a/resources/lang/en_US/form.php b/resources/lang/en_US/form.php index 075832667b..6af86e4968 100644 --- a/resources/lang/en_US/form.php +++ b/resources/lang/en_US/form.php @@ -24,40 +24,41 @@ declare(strict_types=1); return [ // new user: - 'bank_name' => 'Bank name', - 'bank_balance' => 'Balance', - 'savings_balance' => 'Savings balance', - 'credit_card_limit' => 'Credit card limit', - 'automatch' => 'Match automatically', - 'skip' => 'Skip', - 'enabled' => 'Enabled', - 'name' => 'Name', - 'active' => 'Active', - 'amount_min' => 'Minimum amount', - 'amount_max' => 'Maximum amount', - 'match' => 'Matches on', - 'strict' => 'Strict mode', - 'repeat_freq' => 'Repeats', - 'update_channel' => 'Update channel', - 'journal_currency_id' => 'Currency', - 'currency_id' => 'Currency', - 'transaction_currency_id' => 'Currency', - 'external_ip' => 'Your server\'s external IP', - 'attachments' => 'Attachments', - 'journal_amount' => 'Amount', - 'journal_source_name' => 'Revenue account (source)', - 'keep_bill_id' => 'Bill', - 'journal_source_id' => 'Asset account (source)', - 'BIC' => 'BIC', - 'verify_password' => 'Verify password security', - 'source_account' => 'Source account', - 'destination_account' => 'Destination account', - 'journal_destination_id' => 'Asset account (destination)', - 'asset_destination_account' => 'Destination account', - 'include_net_worth' => 'Include in net worth', - 'asset_source_account' => 'Source account', - 'journal_description' => 'Description', - 'note' => 'Notes', + 'bank_name' => 'Bank name', + 'bank_balance' => 'Balance', + 'savings_balance' => 'Savings balance', + 'credit_card_limit' => 'Credit card limit', + 'automatch' => 'Match automatically', + 'skip' => 'Skip', + 'enabled' => 'Enabled', + 'name' => 'Name', + 'active' => 'Active', + 'amount_min' => 'Minimum amount', + 'amount_max' => 'Maximum amount', + 'match' => 'Matches on', + 'strict' => 'Strict mode', + 'repeat_freq' => 'Repeats', + 'location' => 'Location', + 'update_channel' => 'Update channel', + 'journal_currency_id' => 'Currency', + 'currency_id' => 'Currency', + 'transaction_currency_id' => 'Currency', + 'external_ip' => 'Your server\'s external IP', + 'attachments' => 'Attachments', + 'journal_amount' => 'Amount', + 'journal_source_name' => 'Revenue account (source)', + 'keep_bill_id' => 'Bill', + 'journal_source_id' => 'Asset account (source)', + 'BIC' => 'BIC', + 'verify_password' => 'Verify password security', + 'source_account' => 'Source account', + 'destination_account' => 'Destination account', + 'journal_destination_id' => 'Asset account (destination)', + 'asset_destination_account' => 'Destination account', + 'include_net_worth' => 'Include in net worth', + 'asset_source_account' => 'Source account', + 'journal_description' => 'Description', + 'note' => 'Notes', 'store_new_transaction' => 'Store new transaction', 'split_journal' => 'Split this transaction', 'split_journal_explanation' => 'Split this transaction in multiple parts', diff --git a/resources/views/v1/accounts/create.twig b/resources/views/v1/accounts/create.twig index d52a1f46f2..39acaa72a7 100644 --- a/resources/views/v1/accounts/create.twig +++ b/resources/views/v1/accounts/create.twig @@ -53,7 +53,7 @@ {# only correct way to do active checkbox #} {{ ExpandedForm.checkbox('include_net_worth', 1) }} {{ ExpandedForm.textarea('notes',null,{helpText: trans('firefly.field_supports_markdown')}) }} - + {{ ExpandedForm.location('location') }} @@ -77,6 +77,43 @@ {% endblock %} {% block scripts %} + + + + + @@ -85,4 +122,5 @@ {% block styles %} + {% endblock %} diff --git a/resources/views/v1/accounts/show.twig b/resources/views/v1/accounts/show.twig index d40fcb0ce1..e1c26b45eb 100644 --- a/resources/views/v1/accounts/show.twig +++ b/resources/views/v1/accounts/show.twig @@ -85,9 +85,22 @@ {% endif %} - {% if account.notes.count == 1 %} -
-
+ +
+
+
+
+

{{ 'location'|_ }}

+
+
+ {% if(location) %} +
+ {% endif %} +
+
+
+ {% if account.notes.count == 1 %} +

{{ 'notes'|_ }}

@@ -97,8 +110,8 @@
-
- {% endif %} + {% endif %} +
@@ -149,6 +162,17 @@ var chartUri = '{{ chartUri }}'; {% if not showAll %} showAll = false; + + // location stuff + {% if location %} + var latitude = {{ location.latitude|default("52.3167") }}; + var longitude = {{ location.longitude|default("5.5500") }}; + var zoomLevel = {{ location.zoom_level|default("6") }}; + var doPlaceMarker = true; + // token for Mapbox: + var mapboxToken = "{{ config('firefly.mapbox_api_key') }}"; + {% endif %} + // uri's for charts: var incomeCategoryUri = '{{ route('chart.account.income-category', [account.id, start.format('Ymd'), end.format('Ymd')]) }}'; @@ -162,6 +186,9 @@ {% endif %} + {% if location %} + + {% endif %} @@ -173,3 +200,9 @@ {# required for groups.twig #} {% endblock %} + +{% block styles %} + {% if location %} + + {% endif %} +{% endblock %}