Accounts can now have IBAN.

This commit is contained in:
James Cole
2015-07-03 12:51:14 +02:00
parent 854368a8f3
commit d8b65f62e7
12 changed files with 92 additions and 52 deletions

View File

@@ -199,6 +199,7 @@ class AccountController extends Controller
'virtualBalance' => floatval($request->input('virtualBalance')),
'active' => true,
'user' => Auth::user()->id,
'iban' => $request->input('iban'),
'accountRole' => $request->input('accountRole'),
'openingBalance' => floatval($request->input('openingBalance')),
'openingBalanceDate' => new Carbon((string)$request->input('openingBalanceDate')),
@@ -237,6 +238,7 @@ class AccountController extends Controller
'name' => $request->input('name'),
'active' => $request->input('active'),
'user' => Auth::user()->id,
'iban' => $request->input('iban'),
'accountRole' => $request->input('accountRole'),
'virtualBalance' => floatval($request->input('virtualBalance')),
'openingBalance' => floatval($request->input('openingBalance')),

View File

@@ -44,6 +44,7 @@ class AccountFormRequest extends Request
'id' => $idRule,
'name' => $nameRule,
'openingBalance' => 'numeric',
'iban' => 'iban',
'virtualBalance' => 'numeric',
'openingBalanceDate' => 'date',
'accountRole' => 'in:' . $accountRoles,

View File

@@ -47,6 +47,9 @@ use Watson\Validating\ValidatingTrait;
* @property mixed piggyBalance
* @property mixed difference
* @property mixed percentage
* @property string $iban
* @property-read mixed $name_for_editform
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereIban($value)
*/
class Account extends Model
{
@@ -143,6 +146,22 @@ class Account extends Model
return ['created_at', 'updated_at', 'deleted_at'];
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @return string
*/
public function getIbanAttribute($value)
{
if (is_null($value)) {
return null;
}
return Crypt::decrypt($value);
}
/**
*
* @param string $fieldName
@@ -236,6 +255,16 @@ class Account extends Model
$query->where($joinName . '.data', json_encode($value));
}
/**
* @codeCoverageIgnore
*
* @param $value
*/
public function setIbanAttribute($value)
{
$this->attributes['iban'] = Crypt::encrypt($value);
}
/**
* @codeCoverageIgnore
*

View File

@@ -401,6 +401,7 @@ class AccountRepository implements AccountRepositoryInterface
'virtualBalance' => 0,
'name' => $data['name'] . ' initial balance',
'active' => false,
'iban' => '',
];
$opposing = $this->storeAccount($opposingData);
$this->storeInitialBalance($newAccount, $opposing, $data);
@@ -431,6 +432,7 @@ class AccountRepository implements AccountRepositoryInterface
$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);
@@ -481,6 +483,7 @@ class AccountRepository implements AccountRepositoryInterface
'name' => $data['name'],
'virtual_balance' => $data['virtualBalance'],
'active' => $data['active'] === true ? true : false,
'iban' => $data['iban'],
]
);
@@ -490,7 +493,8 @@ class AccountRepository implements AccountRepositoryInterface
'user_id' => $data['user'],
'account_type_id' => $accountType->id,
'virtual_balance' => $data['virtualBalance'],
'name' => $data['name']
'name' => $data['name'],
'iban' => $data['iban'],
];
$existingAccount = Account::firstOrNullEncrypted($searchData);
if (!$existingAccount) {

View File

@@ -54,6 +54,33 @@ class FireflyValidator extends Validator
}
/**
* @param $attribute
* @param $value
* @param $parameters
*/
public function validateIban($attribute, $value, $parameters)
{
$value = strtoupper($value);
if (strlen($value) < 6) {
return false;
}
$search = [' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
$replace = ['', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31',
'32', '33', '34', '35'];
// take
$first = substr($value, 0, 4);
$last = substr($value, 4);
$iban = $last . $first;
$iban = str_replace($search, $replace, $iban);
$checksum = bcmod($iban, '97');
return (intval($checksum) === 1);
}
/**
* @param $attribute
* @param $value