/**
  * @return Account|null
  */
 public function convert()
 {
     // is mapped? Then it's easy!
     if (isset($this->mapped[$this->index][$this->value])) {
         $account = Auth::user()->accounts()->find($this->mapped[$this->index][$this->value]);
         return $account;
     }
     if (strlen($this->value) > 0) {
         // find or create new account:
         $account = $this->findAccount();
         $accountType = AccountType::where('type', 'Asset account')->first();
         if (is_null($account)) {
             // create it if doesn't exist.
             $account = Account::firstOrCreateEncrypted(['name' => $this->value, 'iban' => $this->value, 'user_id' => Auth::user()->id, 'account_type_id' => $accountType->id, 'active' => 1]);
         }
         return $account;
     }
     return null;
 }
 /**
  * @return Account|null
  */
 public function convert()
 {
     // is mapped? Then it's easy!
     if (isset($this->mapped[$this->index][$this->value])) {
         $account = Auth::user()->accounts()->find($this->mapped[$this->index][$this->value]);
         return $account;
     }
     // find or create new account:
     $accountType = AccountType::where('type', 'Asset account')->first();
     $set = Auth::user()->accounts()->accountTypeIn(['Asset account', 'Default account'])->get();
     /** @var Account $entry */
     foreach ($set as $entry) {
         if ($entry->name == $this->value) {
             return $entry;
         }
     }
     // create it if doesnt exist.
     $account = Account::firstOrCreateEncrypted(['name' => $this->value, 'iban' => '', 'user_id' => Auth::user()->id, 'account_type_id' => $accountType->id, 'active' => 1]);
     return $account;
 }
 /**
  * @param array $data
  *
  * @return array
  */
 private function storeWithdrawalAccounts(array $data) : array
 {
     $sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first(['accounts.*']);
     if (strlen($data['destination_account_name']) > 0) {
         $destinationType = AccountType::where('type', 'Expense account')->first();
         $destinationAccount = Account::firstOrCreateEncrypted(['user_id' => $data['user'], 'account_type_id' => $destinationType->id, 'name' => $data['destination_account_name'], 'active' => 1]);
         return [$sourceAccount, $destinationAccount];
     }
     $destinationType = AccountType::where('type', 'Cash account')->first();
     $destinationAccount = Account::firstOrCreateEncrypted(['user_id' => $data['user'], 'account_type_id' => $destinationType->id, 'name' => 'Cash account', 'active' => 1]);
     return [$sourceAccount, $destinationAccount];
 }
Esempio n. 4
0
 /**
  *
  * @return AccountType
  */
 protected function getAccountType()
 {
     return AccountType::where('type', 'Asset account')->first();
 }
Esempio n. 5
0
 /**
  * @param array $data
  *
  * @return array
  */
 protected function storeDepositAccounts(array $data)
 {
     $toAccount = Account::find($data['account_id']);
     if (strlen($data['revenue_account']) > 0) {
         $fromType = AccountType::where('type', 'Revenue account')->first();
         $fromAccount = Account::firstOrCreateEncrypted(['user_id' => $data['user'], 'account_type_id' => $fromType->id, 'name' => $data['revenue_account'], 'active' => 1]);
     } else {
         $toType = AccountType::where('type', 'Cash account')->first();
         $fromAccount = Account::firstOrCreateEncrypted(['user_id' => $data['user'], 'account_type_id' => $toType->id, 'name' => 'Cash account', 'active' => 1]);
     }
     return [$fromAccount, $toAccount];
 }
 /**
  *
  * @return AccountType
  */
 protected function getAccountType()
 {
     // opposing account type:
     if ($this->data['amount'] < 0) {
         // create expense account:
         return AccountType::where('type', 'Expense account')->first();
     } else {
         // create revenue account:
         return AccountType::where('type', 'Revenue account')->first();
     }
 }