/** * @param $entry * * @return TransactionJournal */ private function storeJournal($entry) : TransactionJournal { $billId = is_null($entry->fields['bill']) || intval($entry->fields['bill']->id) === 0 ? null : intval($entry->fields['bill']->id); $journalData = ['user_id' => $entry->user->id, 'transaction_type_id' => $entry->fields['transaction-type']->id, 'bill_id' => $billId, 'transaction_currency_id' => $entry->fields['currency']->id, 'description' => $entry->fields['description'], 'date' => $entry->fields['date-transaction'], 'interest_date' => $entry->fields['date-interest'], 'book_date' => $entry->fields['date-book'], 'process_date' => $entry->fields['date-process'], 'completed' => 0]; /** @var TransactionJournal $journal */ $journal = TransactionJournal::create($journalData); foreach ($journal->getErrors()->all() as $err) { Log::error('Error when storing journal: ' . $err); } Log::debug('Created journal', ['id' => $journal->id]); // save hash as meta value: $meta = new TransactionJournalMeta(); $meta->name = 'originalImportHash'; $meta->data = $entry->hash; $meta->transactionJournal()->associate($journal); $meta->save(); return $journal; }
/** * @param string $name * @param $value * * @return TransactionJournalMeta */ public function setMeta(string $name, $value) : TransactionJournalMeta { if (is_null($value)) { $this->deleteMeta($name); return new TransactionJournalMeta(); } if ($value instanceof Carbon) { $value = $value->toW3cString(); } Log::debug(sprintf('Going to set "%s" with value "%s"', $name, json_encode($value))); $entry = $this->transactionJournalMeta()->where('name', $name)->first(); if (is_null($entry)) { $entry = new TransactionJournalMeta(); $entry->transactionJournal()->associate($this); $entry->name = $name; } $entry->data = $value; $entry->save(); Preferences::mark(); return $entry; }