Esempio n. 1
0
 /**
  * @return array
  */
 public function rules()
 {
     $accountRoles = join(',', array_keys(Config::get('firefly.accountRoles')));
     $types = join(',', array_keys(Config::get('firefly.subTitlesByIdentifier')));
     $ccPaymentTypes = join(',', array_keys(Config::get('firefly.ccTypes')));
     $nameRule = 'required|min:1|uniqueAccountForUser';
     $idRule = '';
     if (Account::find(Input::get('id'))) {
         $idRule = 'belongsToUser:accounts';
         $nameRule = 'required|min:1|uniqueAccountForUser:'******'id');
     }
     return ['id' => $idRule, 'name' => $nameRule, 'openingBalance' => 'numeric', 'iban' => 'iban', 'virtualBalance' => 'numeric', 'openingBalanceDate' => 'date', 'accountRole' => 'in:' . $accountRoles, 'active' => 'boolean', 'ccType' => 'in:' . $ccPaymentTypes, 'ccMonthlyPaymentDate' => 'date', 'balance_currency_id' => 'exists:transaction_currencies,id', 'what' => 'in:' . $types];
 }
 /**
  * @param $value
  *
  * @return bool
  * @internal param $parameters
  *
  */
 protected function validateByAccountId($value)
 {
     /** @var Account $existingAccount */
     $existingAccount = Account::find($this->data['id']);
     $type = $existingAccount->accountType;
     $ignore = $existingAccount->id;
     $value = $this->tryDecrypt($value);
     $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. 3
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];
 }