mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Use note object instead of field #888
This commit is contained in:
		| @@ -14,6 +14,7 @@ namespace FireflyIII\Repositories\Journal; | ||||
|  | ||||
| use FireflyIII\Models\Budget; | ||||
| use FireflyIII\Models\Category; | ||||
| use FireflyIII\Models\Note; | ||||
| use FireflyIII\Models\Tag; | ||||
| use FireflyIII\Models\Transaction; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| @@ -195,4 +196,31 @@ trait CreateJournalsTrait | ||||
|  | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @param TransactionJournal $journal | ||||
|      * @param string             $note | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     protected function updateNote(TransactionJournal $journal, string $note): bool | ||||
|     { | ||||
|         if (strlen($note) === 0) { | ||||
|             $dbNote = $journal->notes()->first(); | ||||
|             if (!is_null($dbNote)) { | ||||
|                 $dbNote->delete(); | ||||
|             } | ||||
|  | ||||
|             return true; | ||||
|         } | ||||
|         $dbNote = $journal->notes()->first(); | ||||
|         if (is_null($dbNote)) { | ||||
|             $dbNote = new Note(); | ||||
|             $dbNote->noteable()->associate($journal); | ||||
|         } | ||||
|         $dbNote->text = trim($note); | ||||
|         $dbNote->save(); | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -34,7 +34,7 @@ class JournalRepository implements JournalRepositoryInterface | ||||
|     /** @var User */ | ||||
|     private $user; | ||||
|     /** @var array */ | ||||
|     private $validMetaFields = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date', 'internal_reference', 'notes']; | ||||
|     private $validMetaFields = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date', 'internal_reference']; | ||||
|  | ||||
|     /** | ||||
|      * @param TransactionJournal $journal | ||||
| @@ -235,6 +235,9 @@ class JournalRepository implements JournalRepositoryInterface | ||||
|             $this->saveTags($journal, $data['tags']); | ||||
|         } | ||||
|  | ||||
|         // update note: | ||||
|         $this->updateNote($journal, $data['notes']); | ||||
|  | ||||
|         foreach ($data as $key => $value) { | ||||
|             if (in_array($key, $this->validMetaFields)) { | ||||
|                 $journal->setMeta($key, $value); | ||||
| @@ -287,6 +290,9 @@ class JournalRepository implements JournalRepositoryInterface | ||||
|             $this->updateTags($journal, $data['tags']); | ||||
|         } | ||||
|  | ||||
|         // update note: | ||||
|         $this->updateNote($journal, $data['notes']); | ||||
|  | ||||
|         // update meta fields: | ||||
|         $result = $journal->save(); | ||||
|         if ($result) { | ||||
| @@ -324,6 +330,9 @@ class JournalRepository implements JournalRepositoryInterface | ||||
|         $journal->categories()->detach(); | ||||
|         $journal->budgets()->detach(); | ||||
|  | ||||
|         // update note: | ||||
|         $this->updateNote($journal, $data['notes']); | ||||
|  | ||||
|         // update meta fields: | ||||
|         $result = $journal->save(); | ||||
|         if ($result) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user