This commit is contained in:
James Cole
2017-11-25 20:54:42 +01:00
parent 60abe2a3af
commit 0cf359b75f
11 changed files with 170 additions and 15 deletions

View File

@@ -25,6 +25,7 @@ namespace FireflyIII\Repositories\Bill;
use Carbon\Carbon;
use DB;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Note;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
@@ -536,6 +537,11 @@ class BillRepository implements BillRepositoryInterface
]
);
// update note:
if (isset($data['notes'])) {
$this->updateNote($bill, $data['notes']);
}
return $bill;
}
@@ -558,6 +564,11 @@ class BillRepository implements BillRepositoryInterface
$bill->active = $data['active'];
$bill->save();
// update note:
if (isset($data['notes']) && null !== $data['notes']) {
$this->updateNote($bill, strval($data['notes']));
}
return $bill;
}
@@ -598,4 +609,32 @@ class BillRepository implements BillRepositoryInterface
return $wordMatch;
}
/**
* @param Bill $bill
* @param string $note
*
* @return bool
*/
protected function updateNote(Bill $bill, string $note): bool
{
if (0 === strlen($note)) {
$dbNote = $bill->notes()->first();
if (null !== $dbNote) {
$dbNote->delete();
}
return true;
}
$dbNote = $bill->notes()->first();
if (null === $dbNote) {
$dbNote = new Note();
$dbNote->noteable()->associate($bill);
}
$dbNote->text = trim($note);
$dbNote->save();
return true;
}
}

View File

@@ -411,6 +411,7 @@ class JournalRepository implements JournalRepositoryInterface
return $journal;
}
/**
* Same as above but for transaction journal with multiple transactions.
*