/**
  * @param $value
  * @param $parameters
  *
  * @return bool
  */
 protected function validateByAccountTypeString($value, $parameters)
 {
     $search = Config::get('firefly.accountTypeByIdentifier.' . $this->data['what']);
     $type = AccountType::whereType($search)->first();
     $ignore = isset($parameters[0]) ? intval($parameters[0]) : 0;
     $set = Auth::user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get();
     /** @var Account $entry */
     foreach ($set as $entry) {
         if ($entry->name == $value) {
             return false;
         }
     }
     return true;
 }
Esempio n. 2
0
 /**
  *
  */
 public function createRevenueAccounts()
 {
     $user = User::whereEmail('*****@*****.**')->first();
     $revenueType = AccountType::whereType('Revenue account')->first();
     Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Employer', 'active' => 1]);
     Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'IRS', 'active' => 1]);
     Account::create(['user_id' => $user->id, 'account_type_id' => $revenueType->id, 'name' => 'Second job employer', 'active' => 1]);
 }
Esempio n. 3
0
 /**
  * @param array $data
  *
  * @return Account
  */
 protected function storeAccount(array $data)
 {
     $type = Config::get('firefly.accountTypeByIdentifier.' . $data['accountType']);
     $accountType = AccountType::whereType($type)->first();
     $newAccount = new Account(['user_id' => $data['user'], 'account_type_id' => $accountType->id, 'name' => $data['name'], 'virtual_balance' => $data['virtualBalance'], 'active' => $data['active'] === true ? true : false, 'iban' => $data['iban']]);
     if (!$newAccount->isValid()) {
         // does the account already exist?
         $searchData = ['user_id' => $data['user'], 'account_type_id' => $accountType->id, 'virtual_balance' => $data['virtualBalance'], 'name' => $data['name'], 'iban' => $data['iban']];
         $existingAccount = Account::firstOrNullEncrypted($searchData);
         if (!$existingAccount) {
             Log::error('Account create error: ' . $newAccount->getErrors()->toJson());
             abort(500);
             // @codeCoverageIgnoreStart
         }
         // @codeCoverageIgnoreEnd
         $newAccount = $existingAccount;
     }
     $newAccount->save();
     return $newAccount;
 }