Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Add location to account.
James Cole021d421c6f86
diff --git a/app/Factory/AccountFactory.php b/app/Factory/AccountFactory.phpindex 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.phpindex 790f186f09..a95043b6d9 100644--- a/app/Http/Controllers/Account/ShowController.php+++ b/app/Http/Controllers/Account/ShowController.php@@ -99,7 +99,7 @@ class ShowController extends Controllerif ($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.phpindex 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.jsindex 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 © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',+ 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.phpindex 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.twigindex 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') }}</div></div>@@ -77,6 +77,43 @@</form>{% endblock %}{% block scripts %}+ <!-- location script -->+ <script type="text/javascript">+ // pre-set latitude:+ {% if old('tag_position_latitude') %}+ var tag_position_latitude = "{{ old('tag_position_latitude') }}";+ {% else %}+ var tag_position_latitude = "52.3167";+ {% endif %}++ // pre-set longitude+ {% if old('tag_position_longitude') %}+ var tag_position_longitude = "{{ old('tag_position_longitude') }}";+ {% else %}+ var tag_position_longitude = "5.5500";+ {% endif %}++ // pre-set zoom level+ {% if old('tag_position_zoomlevel') %}+ var tag_position_zoomlevel = "{{ old('tag_position_zoomlevel') }}";+ {% else %}+ var tag_position_zoomlevel = "6";+ {% endif %}++ // must draw a tag?+ {% if old('tag_position_latitude') and old('tag_position_longitude') and old('tag_position_zoomlevel') %}+ var tag_position_set_tag = true;+ {% else %}+ var tag_position_set_tag = false;+ {% endif %}++ // token for Mapbox:+ var mapboxToken = "{{ config('firefly.mapbox_api_key') }}";++ </script>+ <script src="v1/lib/leaflet/leaflet.js?v={{ FF_VERSION }}"></script>++<script type="text/javascript" src="v1/js/lib/modernizr-custom.js?v={{ FF_VERSION }}"></script><script type="text/javascript" src="v1/js/lib/jquery-ui.min.js?v={{ FF_VERSION }}"></script><script type="text/javascript" src="v1/js/ff/accounts/create.js?v={{ FF_VERSION }}"></script>@@ -85,4 +122,5 @@{% block styles %}<link href="v1/css/jquery-ui/jquery-ui.structure.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet" media="all"><link href="v1/css/jquery-ui/jquery-ui.theme.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet" media="all">+ <link rel="stylesheet" href="v1/lib/leaflet/leaflet.css?v={{ FF_VERSION }}"/>{% endblock %}diff --git a/resources/views/v1/accounts/show.twig b/resources/views/v1/accounts/show.twigindex d40fcb0ce1..e1c26b45eb 100644--- a/resources/views/v1/accounts/show.twig+++ b/resources/views/v1/accounts/show.twig@@ -85,9 +85,22 @@</div></div>{% endif %}- {% if account.notes.count == 1 %}- <div class="row">- <div class="col-lg-12">++ <div class="row">+ <div class="col-lg-6">+ <div class="box">+ <div class="box-header with-border">+ <h3 class="box-title">{{ 'location'|_ }}</h3>+ </div>+ <div class="box-body">+ {% if(location) %}+ <div id="location_map" style="width:100%;height:300px;"></div>+ {% endif %}+ </div>+ </div>+ </div>+ {% if account.notes.count == 1 %}+ <div class="col-lg-6"><div class="box"><div class="box-header with-border"><h3 class="box-title">{{ 'notes'|_ }}</h3>@@ -97,8 +110,8 @@</div></div></div>- </div>- {% endif %}+ {% endif %}+ </div><div class="row"><div class="{% if periods|length > 0 %}col-lg-10 col-md-8 col-sm-12{% else %}col-lg-12 col-md-12 col-sm-12{% 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 %}</script>+ {% if location %}+ <script src="v1/lib/leaflet/leaflet.js?v={{ FF_VERSION }}"></script>+ {% endif %}<script type="text/javascript" src="v1/js/lib/Chart.bundle.min.js?v={{ FF_VERSION }}"></script><script type="text/javascript" src="v1/js/lib/chartjs-plugin-annotation.min.js?v={{ FF_VERSION }}"></script><script type="text/javascript" src="v1/js/ff/charts.defaults.js?v={{ FF_VERSION }}"></script>@@ -173,3 +200,9 @@{# required for groups.twig #}<script type="text/javascript" src="v1/js/ff/list/groups.js?v={{ FF_VERSION }}"></script>{% endblock %}++{% block styles %}+ {% if location %}+ <link rel="stylesheet" href="v1/lib/leaflet/leaflet.css?v={{ FF_VERSION }}"/>+ {% endif %}+{% endblock %}