mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 09:52:20 +00:00
Make sure update and edit work for location, API or not.
This commit is contained in:
@@ -81,7 +81,7 @@ class AccountStoreRequest extends Request
|
|||||||
'interest_period' => $this->string('interest_period'),
|
'interest_period' => $this->string('interest_period'),
|
||||||
];
|
];
|
||||||
// append Location information.
|
// append Location information.
|
||||||
$data = $this->appendLocationData($data);
|
$data = $this->appendLocationData($data, null);
|
||||||
|
|
||||||
if ('liability' === $data['account_type']) {
|
if ('liability' === $data['account_type']) {
|
||||||
$data['opening_balance'] = bcmul($this->string('liability_amount'), '-1');
|
$data['opening_balance'] = bcmul($this->string('liability_amount'), '-1');
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class AccountUpdateRequest extends Request
|
|||||||
'interest_period' => $this->nullableString('interest_period'),
|
'interest_period' => $this->nullableString('interest_period'),
|
||||||
];
|
];
|
||||||
|
|
||||||
$data = $this->appendLocationData($data);
|
$data = $this->appendLocationData($data, null);
|
||||||
|
|
||||||
if ('liability' === $data['account_type']) {
|
if ('liability' === $data['account_type']) {
|
||||||
$data['opening_balance'] = bcmul($this->nullableString('liability_amount'), '-1');
|
$data['opening_balance'] = bcmul($this->nullableString('liability_amount'), '-1');
|
||||||
|
|||||||
@@ -68,13 +68,9 @@ class AccountFormRequest extends Request
|
|||||||
'interest' => $this->string('interest'),
|
'interest' => $this->string('interest'),
|
||||||
'interest_period' => $this->string('interest_period'),
|
'interest_period' => $this->string('interest_period'),
|
||||||
'include_net_worth' => '1',
|
'include_net_worth' => '1',
|
||||||
|
|
||||||
// new: location
|
|
||||||
'longitude' => $this->string('location_longitude'),
|
|
||||||
'latitude' => $this->string('location_latitude'),
|
|
||||||
'zoom_level' => $this->integer('location_zoom_level'),
|
|
||||||
'has_location' => $this->boolean('location_has_location'),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$data = $this->appendLocationData($data, 'location');
|
||||||
if (false === $this->boolean('include_net_worth')) {
|
if (false === $this->boolean('include_net_worth')) {
|
||||||
$data['include_net_worth'] = '0';
|
$data['include_net_worth'] = '0';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -347,39 +347,55 @@ class Request extends FormRequest
|
|||||||
/**
|
/**
|
||||||
* Read the submitted Request data and add new or updated Location data to the array.
|
* Read the submitted Request data and add new or updated Location data to the array.
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @param string|null $prefix
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function appendLocationData(array $data): array
|
protected function appendLocationData(array $data, ?string $prefix): array
|
||||||
{
|
{
|
||||||
Log::debug('Now in appendLocationData()');
|
Log::debug(sprintf('Now in appendLocationData(%s)', $prefix), $data);
|
||||||
$data['store_location'] = false;
|
$data['store_location'] = false;
|
||||||
$data['update_location'] = false;
|
$data['update_location'] = false;
|
||||||
$data['longitude'] = null;
|
$data['longitude'] = null;
|
||||||
$data['latitude'] = null;
|
$data['latitude'] = null;
|
||||||
$data['zoom_level'] = null;
|
$data['zoom_level'] = null;
|
||||||
|
|
||||||
|
$longitudeKey = null === $prefix ? 'longitude' : sprintf('%s_longitude', $prefix);
|
||||||
|
$latitudeKey = null === $prefix ? 'latitude' : sprintf('%s_latitude', $prefix);
|
||||||
|
$zoomLevelKey = null === $prefix ? 'zoom_level' : sprintf('%s_zoom_level', $prefix);
|
||||||
|
|
||||||
// for a POST (store, all fields must be present and accounted for:
|
// for a POST (store, all fields must be present and accounted for:
|
||||||
if ('POST' === $this->method() && $this->has('longitude') && $this->has('latitude') && $this->has('zoom_level')) {
|
if (
|
||||||
|
('POST' === $this->method() && ($this->routeIs('accounts.store') || $this->routeIs('api.v1.accounts.store')))
|
||||||
|
&& ($this->has($longitudeKey) && $this->has($latitudeKey) && $this->has($zoomLevelKey))
|
||||||
|
) {
|
||||||
Log::debug('Method is POST and all fields present.');
|
Log::debug('Method is POST and all fields present.');
|
||||||
$data['store_location'] = true;
|
$data['store_location'] = true;
|
||||||
$data['longitude'] = '' === $this->string('longitude') ? null : $this->string('longitude');
|
$data['longitude'] = '' === $this->string($longitudeKey) ? null : $this->string($longitudeKey);
|
||||||
$data['latitude'] = '' === $this->string('latitude') ? null : $this->string('latitude');
|
$data['latitude'] = '' === $this->string($latitudeKey) ? null : $this->string($latitudeKey);
|
||||||
$data['zoom_level'] = '' === $this->string('zoom_level') ? null : $this->integer('zoom_level');
|
$data['zoom_level'] = '' === $this->string($zoomLevelKey) ? null : $this->integer($zoomLevelKey);
|
||||||
}
|
}
|
||||||
if ('PUT' === $this->method() && $this->has('longitude') && $this->has('latitude') && $this->has('zoom_level')) {
|
if (
|
||||||
|
($this->has($longitudeKey) && $this->has($latitudeKey) && $this->has($zoomLevelKey))
|
||||||
|
&& (
|
||||||
|
('PUT' === $this->method() && $this->routeIs('api.v1.accounts.update'))
|
||||||
|
|| ('POST' === $this->method() && $this->routeIs('accounts.update'))
|
||||||
|
)
|
||||||
|
) {
|
||||||
Log::debug('Method is PUT and all fields present.');
|
Log::debug('Method is PUT and all fields present.');
|
||||||
$data['update_location'] = true;
|
$data['update_location'] = true;
|
||||||
$data['longitude'] = '' === $this->string('longitude') ? null : $this->string('longitude');
|
$data['longitude'] = '' === $this->string($longitudeKey) ? null : $this->string($longitudeKey);
|
||||||
$data['latitude'] = '' === $this->string('latitude') ? null : $this->string('latitude');
|
$data['latitude'] = '' === $this->string($latitudeKey) ? null : $this->string($latitudeKey);
|
||||||
$data['zoom_level'] = '' === $this->string('zoom_level') ? null : $this->integer('zoom_level');
|
$data['zoom_level'] = '' === $this->string($zoomLevelKey) ? null : $this->integer($zoomLevelKey);
|
||||||
}
|
}
|
||||||
if (null === $data['longitude'] || null === $data['latitude'] || null === $data['zoom_level']) {
|
if (null === $data['longitude'] || null === $data['latitude'] || null === $data['zoom_level']) {
|
||||||
Log::debug('One of the fields is NULL, wont save.');
|
Log::debug('One of the fields is NULL, wont save.');
|
||||||
$data['store_location'] = false;
|
$data['store_location'] = false;
|
||||||
$data['update_location'] = false;
|
$data['update_location'] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::debug(sprintf('Returning longitude: "%s", latitude: "%s", zoom level: "%s"', $data['longitude'], $data['latitude'], $data['zoom_level']));
|
Log::debug(sprintf('Returning longitude: "%s", latitude: "%s", zoom level: "%s"', $data['longitude'], $data['latitude'], $data['zoom_level']));
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ class AccountUpdateService
|
|||||||
$this->updateMetaData($account, $data);
|
$this->updateMetaData($account, $data);
|
||||||
|
|
||||||
// update, delete or create location:
|
// update, delete or create location:
|
||||||
$updateLocation = $data['has_location'] ?? false;
|
$updateLocation = $data['update_location'] ?? false;
|
||||||
|
|
||||||
// location must be updated?
|
// location must be updated?
|
||||||
if (true === $updateLocation) {
|
if (true === $updateLocation) {
|
||||||
|
|||||||
@@ -72,6 +72,9 @@
|
|||||||
if (typeof marker !== 'undefined') {
|
if (typeof marker !== 'undefined') {
|
||||||
marker.remove();
|
marker.remove();
|
||||||
$('input[name="{{ haslocationvar }}"]').val('false');
|
$('input[name="{{ haslocationvar }}"]').val('false');
|
||||||
|
$('input[name="{{ latitudevar }}"]').val('');
|
||||||
|
$('input[name="{{ longitudevar }}"]').val('');
|
||||||
|
$('input[name="{{ zoomlevelvar }}"]').val('');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user