Accounts can now have IBAN.

This commit is contained in:
James Cole 2015-07-03 12:51:14 +02:00
parent 4a20eef351
commit 1eb60ab100
12 changed files with 92 additions and 52 deletions

View File

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

View File

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

View File

@ -47,6 +47,9 @@ use Watson\Validating\ValidatingTrait;
* @property mixed piggyBalance * @property mixed piggyBalance
* @property mixed difference * @property mixed difference
* @property mixed percentage * @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 class Account extends Model
{ {
@ -143,6 +146,22 @@ class Account extends Model
return ['created_at', 'updated_at', 'deleted_at']; 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 * @param string $fieldName
@ -236,6 +255,16 @@ class Account extends Model
$query->where($joinName . '.data', json_encode($value)); $query->where($joinName . '.data', json_encode($value));
} }
/**
* @codeCoverageIgnore
*
* @param $value
*/
public function setIbanAttribute($value)
{
$this->attributes['iban'] = Crypt::encrypt($value);
}
/** /**
* @codeCoverageIgnore * @codeCoverageIgnore
* *

View File

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

View File

@ -1,39 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
* Class ChangesForV3451
*/
class ChangesForV3451 extends Migration
{
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table(
'accounts', function (Blueprint $table) {
$table->dropColumn('iban');
}
);
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table(
'accounts', function (Blueprint $table) {
$table->string('iban', 38)->nullable();
}
);
}
}

View File

@ -1,10 +1,27 @@
<?php <?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
* Class ChangesForV3462
*/
class ChangesForV3462 extends Migration class ChangesForV3462 extends Migration
{ {
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table(
'accounts', function (Blueprint $table) {
$table->dropColumn('iban');
}
);
}
/** /**
* Run the migrations. * Run the migrations.
* *
@ -13,16 +30,10 @@ class ChangesForV3462 extends Migration
public function up() public function up()
{ {
// add IBAN to accounts: // add IBAN to accounts:
Schema::table(
'accounts', function (Blueprint $table) {
$table->string('iban')->nullable();
} }
);
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
} }
} }

View File

@ -126,6 +126,7 @@ class TestDataSeeder extends Seeder
'name' => $name, 'name' => $name,
'active' => 1, 'active' => 1,
'encrypted' => 1, 'encrypted' => 1,
'iban' => 'GB82WEST12345698765432'
] ]
); );
foreach ($assetMeta[$index] as $name => $value) { foreach ($assetMeta[$index] as $name => $value) {

View File

@ -45,6 +45,7 @@ return [
'under' => 'Under', 'under' => 'Under',
'symbol' => 'Symbol', 'symbol' => 'Symbol',
'code' => 'Code', 'code' => 'Code',
'iban' => 'IBAN',
'store_new_withdrawal' => 'Store new withdrawal', 'store_new_withdrawal' => 'Store new withdrawal',
'store_new_deposit' => 'Store new deposit', 'store_new_deposit' => 'Store new deposit',

View File

@ -45,6 +45,7 @@ return [
'under' => 'Onder', 'under' => 'Onder',
'symbol' => 'Symbool', 'symbol' => 'Symbool',
'code' => 'Code', 'code' => 'Code',
'iban' => 'IBAN',
'store_new_withdrawal' => 'Nieuwe uitgave opslaan', 'store_new_withdrawal' => 'Nieuwe uitgave opslaan',
'store_new_deposit' => 'Nieuwe inkomsten opslaan', 'store_new_deposit' => 'Nieuwe inkomsten opslaan',

View File

@ -29,6 +29,7 @@
</div> </div>
<div class="box-body"> <div class="box-body">
{{ ExpandedForm.text('iban') }}
{{ ExpandedForm.balance('openingBalance') }} {{ ExpandedForm.balance('openingBalance') }}
{{ ExpandedForm.date('openingBalanceDate', phpdate('Y-m-d')) }} {{ ExpandedForm.date('openingBalanceDate', phpdate('Y-m-d')) }}
{{ ExpandedForm.select('accountRole', Config.get('firefly.accountRoles'),null,{'helpText' : 'Any extra options resulting from your choice can be set later.'}) }} {{ ExpandedForm.select('accountRole', Config.get('firefly.accountRoles'),null,{'helpText' : 'Any extra options resulting from your choice can be set later.'}) }}

View File

@ -27,6 +27,7 @@
<h3 class="box-title">{{ 'optionalFields'|_ }}</h3> <h3 class="box-title">{{ 'optionalFields'|_ }}</h3>
</div> </div>
<div class="box-body"> <div class="box-body">
{{ ExpandedForm.text('iban') }}
{% if account.accounttype.type == 'Default account' or account.accounttype.type == 'Asset account' %} {% if account.accounttype.type == 'Default account' or account.accounttype.type == 'Asset account' %}
{{ ExpandedForm.balance('openingBalance',null, {'currency' : openingBalance ? openingBalance.transactionCurrency : null}) }} {{ ExpandedForm.balance('openingBalance',null, {'currency' : openingBalance ? openingBalance.transactionCurrency : null}) }}
{{ ExpandedForm.date('openingBalanceDate') }} {{ ExpandedForm.date('openingBalanceDate') }}