Can edit and set location for accounts.

This commit is contained in:
James Cole
2019-12-30 12:12:08 +01:00
parent 71f2cacdbd
commit 54b049e106
24 changed files with 15310 additions and 785 deletions

View File

@@ -25,6 +25,7 @@ namespace FireflyIII\Services\Internal\Update;
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;
@@ -99,6 +100,23 @@ class AccountUpdateService
// update all meta data:
$this->updateMetaData($account, $data);
// update, delete or create location:
$hasLocation = $data['has_location'] ?? false;
if (false === $hasLocation) {
$account->locations()->delete();
}
if (true === $hasLocation) {
$location = $this->accountRepository->getLocation($account);
if (null === $location) {
$location = new Location;
$location->locatable()->associate($account);
}
$location->latitude = $data['latitude'] ?? config('firefly.default_location.latitude');
$location->longitude = $data['longitude'] ?? config('firefly.default_location.longitude');
$location->zoom_level = $data['zoom_level'] ?? config('firefly.default_location.zoom_level');
$location->save();
}
// has valid initial balance (IB) data?
$type = $account->accountType;
// if it can have a virtual balance, it can also have an opening balance.