. */ declare(strict_types=1); namespace FireflyIII\Services\Internal\Update; use Exception; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Factory\AccountMetaFactory; use FireflyIII\Models\Account; use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountType; use FireflyIII\Services\Internal\Support\AccountServiceTrait; use Log; /** * Class AccountUpdateService */ class AccountUpdateService { use AccountServiceTrait; /** * Update account data. * * @param Account $account * @param array $data * * @return Account * @throws FireflyException * @throws Exception */ public function update(Account $account, array $data): Account { // update the account itself: $account->name = $data['name']; $account->active = $data['active']; $account->virtual_balance = trim($data['virtualBalance']) === '' ? '0' : $data['virtualBalance']; $account->iban = $data['iban']; $account->save(); // update all meta data: $this->updateMetaData($account, $data); // has valid initial balance (IB) data? if ($this->validIBData($data)) { // then do update! $this->updateIB($account, $data); } // if not, delete it when exist. if (!$this->validIBData($data)) { $this->deleteIB($account); } // update note: if (isset($data['notes']) && null !== $data['notes']) { $this->updateNote($account, strval($data['notes'])); } return $account; } }