Skip to content

Firefly III: a personal finances manager

Fix #1074

James Coled9dd00eb39fd
diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php
index 421425a835..bb9d6d0b04 100644
--- a/app/Http/Controllers/AccountController.php
+++ b/app/Http/Controllers/AccountController.php
@@ -29,6 +29,7 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Http\Requests\AccountFormRequest;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
+use FireflyIII\Models\Note;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -195,7 +196,15 @@ class AccountController extends Controller
'openingBalance' => $openingBalanceAmount,
'virtualBalance' => $account->virtual_balance,
'currency_id' => $currency->id,
+ 'notes' => '',
];
+ /** @var Note $note */
+ $note = $account->notes()->first();
+ if (null !== $note) {
+ $preFilled['notes'] = $note->text;
+ }
+
+
$request->session()->flash('preFilled', $preFilled);
return view(
diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php
index 9b640d7b08..efb721d45a 100644
--- a/app/Http/Requests/AccountFormRequest.php
+++ b/app/Http/Requests/AccountFormRequest.php
@@ -57,6 +57,7 @@ class AccountFormRequest extends Request
'openingBalanceDate' => $this->date('openingBalanceDate'),
'ccType' => $this->string('ccType'),
'ccMonthlyPaymentDate' => $this->string('ccMonthlyPaymentDate'),
+ 'notes' => $this->string('notes'),
];
}
diff --git a/app/Models/Account.php b/app/Models/Account.php
index 11a1061320..b04ec43d8e 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -345,6 +345,15 @@ class Account extends Model
$this->attributes['iban'] = Crypt::encrypt($value);
}
+ /**
+ * @codeCoverageIgnore
+ * Get all of the notes.
+ */
+ public function notes()
+ {
+ return $this->morphMany(Note::class, 'noteable');
+ }
+
/**
* @codeCoverageIgnore
*
diff --git a/app/Models/Bill.php b/app/Models/Bill.php
index b7dcb125cd..ec09d0fcc7 100644
--- a/app/Models/Bill.php
+++ b/app/Models/Bill.php
@@ -132,7 +132,7 @@ class Bill extends Model
*/
public function notes()
{
- return $this->morphMany('FireflyIII\Models\Note', 'noteable');
+ return $this->morphMany(Note::class, 'noteable');
}
/**
diff --git a/app/Models/Note.php b/app/Models/Note.php
index df8b0de9de..b9fa882cd5 100644
--- a/app/Models/Note.php
+++ b/app/Models/Note.php
@@ -57,8 +57,8 @@ class Note extends Model
/**
* @codeCoverageIgnore
- * Get all of the owning noteable models. Currently piggy bank and
- * transaction journal.
+ *
+ * Get all of the owning noteable models.
*/
public function noteable()
{
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php
index 3c404fdf88..291166d511 100644
--- a/app/Repositories/Account/AccountRepository.php
+++ b/app/Repositories/Account/AccountRepository.php
@@ -29,6 +29,7 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Category;
+use FireflyIII\Models\Note;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
@@ -176,6 +177,11 @@ class AccountRepository implements AccountRepositoryInterface
}
$this->deleteInitialBalance($newAccount);
+ // update note:
+ if (isset($data['notes'])) {
+ $this->updateNote($newAccount, $data['notes']);
+ }
+
return $newAccount;
}
@@ -199,6 +205,12 @@ class AccountRepository implements AccountRepositoryInterface
$this->updateInitialBalance($account, $data);
}
+ // update note:
+ if (isset($data['notes']) && null !== $data['notes']) {
+ $this->updateNote($account, strval($data['notes']));
+ }
+
+
return $account;
}
@@ -507,6 +519,33 @@ class AccountRepository implements AccountRepositoryInterface
}
}
+ /**
+ * @param Account $account
+ * @param string $note
+ *
+ * @return bool
+ */
+ protected function updateNote(Account $account, string $note): bool
+ {
+ if (0 === strlen($note)) {
+ $dbNote = $account->notes()->first();
+ if (null !== $dbNote) {
+ $dbNote->delete();
+ }
+
+ return true;
+ }
+ $dbNote = $account->notes()->first();
+ if (null === $dbNote) {
+ $dbNote = new Note();
+ $dbNote->noteable()->associate($account);
+ }
+ $dbNote->text = trim($note);
+ $dbNote->save();
+
+ return true;
+ }
+
/**
* @param Account $account
* @param TransactionJournal $journal
diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php
index 559caacafc..2325b3e52a 100644
--- a/resources/lang/en_US/firefly.php
+++ b/resources/lang/en_US/firefly.php
@@ -746,6 +746,7 @@ return [
'opt_group_savingAsset' => 'Savings accounts',
'opt_group_sharedAsset' => 'Shared asset accounts',
'opt_group_ccAsset' => 'Credit cards',
+ 'notes' => 'Notes',
// new user:
'welcome' => 'Welcome to Firefly!',
diff --git a/resources/views/accounts/create.twig b/resources/views/accounts/create.twig
index 50c35a5eae..3ad8c7dbc5 100644
--- a/resources/views/accounts/create.twig
+++ b/resources/views/accounts/create.twig
@@ -44,6 +44,7 @@
{{ ExpandedForm.select('accountRole', roles,null,{'helpText' : 'asset_account_role_help'|_}) }}
{{ ExpandedForm.nonSelectableBalance('virtualBalance') }}
{% endif %}
+ {{ ExpandedForm.textarea('notes',null,{helpText: trans('firefly.field_supports_markdown')}) }}
</div>
</div>
diff --git a/resources/views/accounts/edit.twig b/resources/views/accounts/edit.twig
index a3ed653d29..96f13de5a3 100644
--- a/resources/views/accounts/edit.twig
+++ b/resources/views/accounts/edit.twig
@@ -48,6 +48,7 @@
{{ ExpandedForm.nonSelectableBalance('virtualBalance',null, {'currency' : currency }) }}
{% endif %}
+ {{ ExpandedForm.textarea('notes',null,{helpText: trans('firefly.field_supports_markdown')}) }}
{{ ExpandedForm.checkbox('active','1') }}
</div>
</div>
diff --git a/resources/views/accounts/show.twig b/resources/views/accounts/show.twig
index 74fdaf1889..edf3a22fe5 100644
--- a/resources/views/accounts/show.twig
+++ b/resources/views/accounts/show.twig
@@ -70,6 +70,19 @@
</div>
</div>
</div>
+ {% if account.notes.count == 1 %}
+ <div class="row">
+ <div class="box">
+ <div class="box-header with-border">
+ <h3 class="box-title">{{ 'notes'|_ }}</h3>
+ </div>
+ <div class="box-body">
+ {{ account.notes.first.text|markdown }}
+ </div>
+ </div>
+ </div>
+ {% endif %}
+
{% if periods.count > 0 %}
<div class="row">
<div class="col-lg-offset-10 col-lg-2 col-md-offset-8 col-md-4 col-sm-12 col-xs-12">