Skip to content

Firefly III: a personal finances manager

Accounts can now have IBAN.

James Cole1eb60ab10067
diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php
index be1a8545c8..f9dc21694b 100644
--- a/app/Http/Controllers/AccountController.php
+++ b/app/Http/Controllers/AccountController.php
@@ -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')),
diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php
index 83275c966d..a0ff4e9617 100644
--- a/app/Http/Requests/AccountFormRequest.php
+++ b/app/Http/Requests/AccountFormRequest.php
@@ -44,6 +44,7 @@ class AccountFormRequest extends Request
'id' => $idRule,
'name' => $nameRule,
'openingBalance' => 'numeric',
+ 'iban' => 'iban',
'virtualBalance' => 'numeric',
'openingBalanceDate' => 'date',
'accountRole' => 'in:' . $accountRoles,
diff --git a/app/Models/Account.php b/app/Models/Account.php
index a09825c266..9c061021d3 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -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
*
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php
index 8785c588ef..9ee8e6dca2 100644
--- a/app/Repositories/Account/AccountRepository.php
+++ b/app/Repositories/Account/AccountRepository.php
@@ -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) {
diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php
index 4e6e1397cb..6c177af69d 100644
--- a/app/Validation/FireflyValidator.php
+++ b/app/Validation/FireflyValidator.php
@@ -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
diff --git a/database/migrations/2015_06_23_050233_changes_for_v3451.php b/database/migrations/2015_06_23_050233_changes_for_v3451.php
deleted file mode 100644
index 72c6f799f2..0000000000
--- a/database/migrations/2015_06_23_050233_changes_for_v3451.php
+++ /dev/null
@@ -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();
- }
- );
-
- }
-}
diff --git a/database/migrations/2015_07_03_102450_changes_for_v3462.php b/database/migrations/2015_07_03_102450_changes_for_v3462.php
index 7dd6e4b833..930c8b0bab 100644
--- a/database/migrations/2015_07_03_102450_changes_for_v3462.php
+++ b/database/migrations/2015_07_03_102450_changes_for_v3462.php
@@ -1,28 +1,39 @@
<?php
-use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+/**
+ * Class ChangesForV3462
+ */
class ChangesForV3462 extends Migration
{
/**
- * Run the migrations.
+ * Reverse the migrations.
*
* @return void
*/
- public function up()
+ public function down()
{
- // add IBAN to accounts:
-
+ Schema::table(
+ 'accounts', function (Blueprint $table) {
+ $table->dropColumn('iban');
+ }
+ );
}
/**
- * Reverse the migrations.
+ * Run the migrations.
*
* @return void
*/
- public function down()
+ public function up()
{
- //
+ // add IBAN to accounts:
+ Schema::table(
+ 'accounts', function (Blueprint $table) {
+ $table->string('iban')->nullable();
+ }
+ );
}
}
diff --git a/database/seeds/TestDataSeeder.php b/database/seeds/TestDataSeeder.php
index 2ef6f90674..fedf19c97a 100644
--- a/database/seeds/TestDataSeeder.php
+++ b/database/seeds/TestDataSeeder.php
@@ -126,6 +126,7 @@ class TestDataSeeder extends Seeder
'name' => $name,
'active' => 1,
'encrypted' => 1,
+ 'iban' => 'GB82WEST12345698765432'
]
);
foreach ($assetMeta[$index] as $name => $value) {
diff --git a/resources/lang/en/form.php b/resources/lang/en/form.php
index 4fbb9a44f3..4edfa130f8 100644
--- a/resources/lang/en/form.php
+++ b/resources/lang/en/form.php
@@ -45,6 +45,7 @@ return [
'under' => 'Under',
'symbol' => 'Symbol',
'code' => 'Code',
+ 'iban' => 'IBAN',
'store_new_withdrawal' => 'Store new withdrawal',
'store_new_deposit' => 'Store new deposit',
diff --git a/resources/lang/nl/form.php b/resources/lang/nl/form.php
index 5ab0cd308b..f2ce23701f 100644
--- a/resources/lang/nl/form.php
+++ b/resources/lang/nl/form.php
@@ -45,6 +45,7 @@ return [
'under' => 'Onder',
'symbol' => 'Symbool',
'code' => 'Code',
+ 'iban' => 'IBAN',
'store_new_withdrawal' => 'Nieuwe uitgave opslaan',
'store_new_deposit' => 'Nieuwe inkomsten opslaan',
diff --git a/resources/twig/accounts/create.twig b/resources/twig/accounts/create.twig
index da6437d0e7..c52b5321ea 100644
--- a/resources/twig/accounts/create.twig
+++ b/resources/twig/accounts/create.twig
@@ -29,6 +29,7 @@
</div>
<div class="box-body">
+ {{ ExpandedForm.text('iban') }}
{{ ExpandedForm.balance('openingBalance') }}
{{ 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.'}) }}
diff --git a/resources/twig/accounts/edit.twig b/resources/twig/accounts/edit.twig
index 78d846f546..32e0c55972 100644
--- a/resources/twig/accounts/edit.twig
+++ b/resources/twig/accounts/edit.twig
@@ -27,6 +27,7 @@
<h3 class="box-title">{{ 'optionalFields'|_ }}</h3>
</div>
<div class="box-body">
+ {{ ExpandedForm.text('iban') }}
{% if account.accounttype.type == 'Default account' or account.accounttype.type == 'Asset account' %}
{{ ExpandedForm.balance('openingBalance',null, {'currency' : openingBalance ? openingBalance.transactionCurrency : null}) }}
{{ ExpandedForm.date('openingBalanceDate') }}