/** * */ public function createAccount() { $user = FactoryMuffin::create('FireflyIII\\User'); $this->be($user); if (is_null($this->account)) { $this->account = FactoryMuffin::create('FireflyIII\\Models\\Account'); $this->account->user_id = $user->id; $this->account->save(); } }
/** * @param Account $account * @param array $data * * @return Account */ public function update(Account $account, array $data) { // update the account: $account->name = $data['name']; $account->active = $data['active'] == '1' ? true : false; $account->virtual_balance = $data['virtualBalance']; $account->iban = $data['iban']; $account->save(); $this->updateMetadata($account, $data); $openingBalance = $this->openingBalanceTransaction($account); // if has openingbalance? if ($data['openingBalance'] != 0) { // if opening balance, do an update: if ($openingBalance) { // update existing opening balance. $this->updateInitialBalance($account, $openingBalance, $data); } else { // create new opening balance. $type = $data['openingBalance'] < 0 ? 'expense' : 'revenue'; $opposingData = ['user' => $data['user'], 'accountType' => $type, 'name' => $data['name'] . ' initial balance', 'active' => false, 'iban' => '', 'virtualBalance' => 0]; $opposing = $this->storeAccount($opposingData); if (!is_null($opposing)) { $this->storeInitialBalance($account, $opposing, $data); } } } else { if ($openingBalance) { // opening balance is zero, should we delete it? $openingBalance->delete(); // delete existing opening balance. } } return $account; }
/** * @param Account $account * @param string $type * * @return Account */ public function updateAccountType(Account $account, string $type) : Account { $type = AccountType::whereType($type)->first(); if (!is_null($type)) { $account->accountType()->associate($type); $account->save(); } return $this->find($account->id); }