mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-17 01:42:19 +00:00
Build account update service.
This commit is contained in:
43
app/Factory/AccountMetaFactory.php
Normal file
43
app/Factory/AccountMetaFactory.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* AccountMetaFactory.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Factory;
|
||||
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
|
||||
/**
|
||||
* Class AccountMetaFactory
|
||||
*/
|
||||
class AccountMetaFactory
|
||||
{
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return AccountMeta|null
|
||||
*/
|
||||
public function create(array $data): ?AccountMeta
|
||||
{
|
||||
return AccountMeta::create($data);
|
||||
}
|
||||
|
||||
}
|
@@ -62,13 +62,15 @@ class TransactionFactory
|
||||
*/
|
||||
public function create(array $data): Transaction
|
||||
{
|
||||
$currencyId = isset($data['currency']) ? $data['currency']->id : $data['currency_id'];
|
||||
|
||||
return Transaction::create(
|
||||
[
|
||||
'reconciled' => $data['reconciled'],
|
||||
'account_id' => $data['account']->id,
|
||||
'transaction_journal_id' => $data['transaction_journal']->id,
|
||||
'description' => $data['description'],
|
||||
'transaction_currency_id' => $data['currency']->id,
|
||||
'transaction_currency_id' => $currencyId,
|
||||
'amount' => $data['amount'],
|
||||
'foreign_amount' => $data['foreign_amount'],
|
||||
'foreign_currency_id' => null,
|
||||
|
@@ -85,7 +85,7 @@ class TransactionJournalFactory
|
||||
$this->connectTags($journal, $data);
|
||||
|
||||
// store note:
|
||||
$this->storeNote($journal, $data['notes']);
|
||||
$this->storeNote($journal, strval($data['notes']));
|
||||
|
||||
// store date meta fields (if present):
|
||||
$this->storeMeta($journal, $data, 'interest_date');
|
||||
@@ -154,6 +154,9 @@ class TransactionJournalFactory
|
||||
{
|
||||
$factory = app(TagFactory::class);
|
||||
$factory->setUser($journal->user);
|
||||
if (is_null($data['tags'])) {
|
||||
return;
|
||||
}
|
||||
foreach ($data['tags'] as $string) {
|
||||
$tag = $factory->findOrCreate($string);
|
||||
$journal->tags()->save($tag);
|
||||
@@ -187,7 +190,7 @@ class TransactionJournalFactory
|
||||
*/
|
||||
protected function storeMeta(TransactionJournal $journal, array $data, string $field): void
|
||||
{
|
||||
$value = $data[$field];
|
||||
$value = $data[$field] ?? null;
|
||||
if (!is_null($value)) {
|
||||
$set = [
|
||||
'journal' => $journal,
|
||||
|
Reference in New Issue
Block a user