Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Simplify code.
James Colecf540bf173fa
diff --git a/app/Services/Internal/Update/AccountUpdateService.php b/app/Services/Internal/Update/AccountUpdateService.phpindex ae7967bc65..ae8c43b479 100644--- a/app/Services/Internal/Update/AccountUpdateService.php+++ b/app/Services/Internal/Update/AccountUpdateService.php@@ -86,8 +86,31 @@ class AccountUpdateService$this->updateMetaData($account, $data);// update, delete or create location:+ $this->updateLocation($account, $data);++ // update opening balance.+ $this->updateOpeningBalance($account, $data);++ // update note:+ if (isset($data['notes']) && null !== $data['notes']) {+ $this->updateNote($account, (string)$data['notes']);+ }++ // update preferences if inactive:+ $this->updatePreferences($account, $data);++ return $account;+ }++ /**+ * @param Account $account+ * @param array $data+ */+ private function updateLocation(Account $account, array $data): void {$updateLocation = $data['update_location'] ?? false;++// location must be updated?if (true === $updateLocation) {// if all set to NULL, delete@@ -109,33 +132,6 @@ class AccountUpdateService$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.-- if (in_array($type->type, $this->canHaveVirtual, true)) {- // check if is submitted as empty, that makes it valid:--- if ($this->validOBData($data) && !$this->isEmptyOBData($data)) {- $this->updateOBGroup($account, $data);- }-- if (!$this->validOBData($data) && $this->isEmptyOBData($data)) {- $this->deleteOBGroup($account);- }- }-- // update note:- if (isset($data['notes']) && null !== $data['notes']) {- $this->updateNote($account, (string)$data['notes']);- }-- // update preferences if inactive:- $this->updatePreferences($account, $data);-- return $account;}/**@@ -205,13 +201,40 @@ class AccountUpdateServiceif (null !== $preference) {$removeAccountId = (int)$account->id;$array = $preference->data;+ Log::debug('Current list of accounts: ', $array);+ Log::debug(sprintf('Going to remove account #%d', $removeAccountId));$filtered = array_filter($array, function ($accountId) use ($removeAccountId) {return (int)$accountId !== $removeAccountId;});+ Log::debug('Left with accounts', array_values($filtered));app('preferences')->setForUser($account->user, 'frontpageAccounts', array_values($filtered));}}}++ /**+ * @param Account $account+ * @param array $data+ */+ private function updateOpeningBalance(Account $account, array $data): void+ {++ // has valid initial balance (IB) data?+ $type = $account->accountType;+ // if it can have a virtual balance, it can also have an opening balance.++ if (in_array($type->type, $this->canHaveVirtual, true)) {++ // check if is submitted as empty, that makes it valid:+ if ($this->validOBData($data) && !$this->isEmptyOBData($data)) {+ $this->updateOBGroup($account, $data);+ }++ if (!$this->validOBData($data) && $this->isEmptyOBData($data)) {+ $this->deleteOBGroup($account);+ }+ }+ }}