From ab70fd8bc58e13269e06e0f71286b97ef43cd81b Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 8 Nov 2020 18:26:40 +0100 Subject: [PATCH] Move fields to configuration. --- app/Factory/TransactionJournalFactory.php | 55 ++++++++--------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/app/Factory/TransactionJournalFactory.php b/app/Factory/TransactionJournalFactory.php index 2b4f61af63..1dc51b5db6 100644 --- a/app/Factory/TransactionJournalFactory.php +++ b/app/Factory/TransactionJournalFactory.php @@ -74,27 +74,8 @@ class TransactionJournalFactory */ public function __construct() { - $this->errorOnHash = false; - // TODO move valid meta fields to config. - $this->fields = [ - // sepa - 'sepa_cc', 'sepa_ct_op', 'sepa_ct_id', - 'sepa_db', 'sepa_country', 'sepa_ep', - 'sepa_ci', 'sepa_batch_id', 'external_uri', - - // dates - 'interest_date', 'book_date', 'process_date', - 'due_date', 'payment_date', 'invoice_date', - - // others - 'recurrence_id', 'internal_reference', 'bunq_payment_id', - 'import_hash', 'import_hash_v2', 'external_id', 'original_source', - - // recurring transactions - 'recurrence_total', 'recurrence_count', - ]; - - + $this->errorOnHash = false; + $this->fields = config('firefly.journal_meta_fields'); $this->currencyRepository = app(CurrencyRepositoryInterface::class); $this->typeRepository = app(TransactionTypeRepositoryInterface::class); $this->billRepository = app(BillRepositoryInterface::class); @@ -197,7 +178,7 @@ class TransactionJournalFactory $set = [ 'journal' => $journal, 'name' => $field, - 'data' => (string) ($data[$field] ?? ''), + 'data' => (string)($data[$field] ?? ''), ]; Log::debug(sprintf('Going to store meta-field "%s", with value "%s".', $set['name'], $set['data'])); @@ -244,11 +225,11 @@ class TransactionJournalFactory $type = $this->typeRepository->findTransactionType(null, $row['type']); $carbon = $row['date'] ?? today(config('app.timezone')); $order = $row['order'] ?? 0; - $currency = $this->currencyRepository->findCurrency((int) $row['currency_id'], $row['currency_code']); + $currency = $this->currencyRepository->findCurrency((int)$row['currency_id'], $row['currency_code']); $foreignCurrency = $this->currencyRepository->findCurrencyNull($row['foreign_currency_id'], $row['foreign_currency_code']); - $bill = $this->billRepository->findBill((int) $row['bill_id'], $row['bill_name']); + $bill = $this->billRepository->findBill((int)$row['bill_id'], $row['bill_name']); $billId = TransactionType::WITHDRAWAL === $type->type && null !== $bill ? $bill->id : null; - $description = app('steam')->cleanString((string) $row['description']); + $description = app('steam')->cleanString((string)$row['description']); /** Manipulate basic fields */ $carbon->setTimezone(config('app.timezone')); @@ -263,11 +244,12 @@ class TransactionJournalFactory return null; } - // TODO typeOverrule: the account validator may have another opinion on the transaction type. + // typeOverrule: the account validator may have another opinion on the transaction type. + // not sure what to do with this. /** create or get source and destination accounts */ $sourceInfo = [ - 'id' => (int) $row['source_id'], + 'id' => (int)$row['source_id'], 'name' => $row['source_name'], 'iban' => $row['source_iban'], 'number' => $row['source_number'], @@ -276,7 +258,7 @@ class TransactionJournalFactory ]; $destInfo = [ - 'id' => (int) $row['destination_id'], + 'id' => (int)$row['destination_id'], 'name' => $row['destination_name'], 'iban' => $row['destination_iban'], 'number' => $row['destination_number'], @@ -320,7 +302,7 @@ class TransactionJournalFactory $transactionFactory->setForeignCurrency($foreignCurrency); $transactionFactory->setReconciled($row['reconciled'] ?? false); try { - $negative = $transactionFactory->createNegative((string) $row['amount'], (string) $row['foreign_amount']); + $negative = $transactionFactory->createNegative((string)$row['amount'], (string)$row['foreign_amount']); } catch (FireflyException $e) { Log::error('Exception creating negative transaction.'); Log::error($e->getMessage()); @@ -339,7 +321,7 @@ class TransactionJournalFactory $transactionFactory->setForeignCurrency($foreignCurrency); $transactionFactory->setReconciled($row['reconciled'] ?? false); try { - $transactionFactory->createPositive((string) $row['amount'], (string) $row['foreign_amount']); + $transactionFactory->createPositive((string)$row['amount'], (string)$row['foreign_amount']); } catch (FireflyException $e) { Log::error('Exception creating positive transaction.'); Log::error($e->getMessage()); @@ -352,7 +334,6 @@ class TransactionJournalFactory // verify that journal has two transactions. Otherwise, delete and cancel. - // TODO this can't be faked so it can't be tested. $journal->completed = true; $journal->save(); @@ -520,7 +501,7 @@ class TransactionJournalFactory $json = json_encode($dataRow, JSON_THROW_ON_ERROR, 512); if (false === $json) { // @codeCoverageIgnoreStart - $json = json_encode((string) microtime(), JSON_THROW_ON_ERROR, 512); + $json = json_encode((string)microtime(), JSON_THROW_ON_ERROR, 512); Log::error(sprintf('Could not hash the original row! %s', json_last_error_msg()), $dataRow); // @codeCoverageIgnoreEnd } @@ -556,7 +537,7 @@ class TransactionJournalFactory return; } - $piggyBank = $this->piggyRepository->findPiggyBank((int) $data['piggy_bank_id'], $data['piggy_bank_name']); + $piggyBank = $this->piggyRepository->findPiggyBank((int)$data['piggy_bank_id'], $data['piggy_bank_name']); if (null !== $piggyBank) { $this->piggyEventFactory->create($journal, $piggyBank); @@ -579,8 +560,8 @@ class TransactionJournalFactory $this->accountValidator->setTransactionType($transactionType); // validate source account. - $sourceId = $data['source_id'] ? (int) $data['source_id'] : null; - $sourceName = $data['source_name'] ? (string) $data['source_name'] : null; + $sourceId = $data['source_id'] ? (int)$data['source_id'] : null; + $sourceName = $data['source_name'] ? (string)$data['source_name'] : null; $validSource = $this->accountValidator->validateSource($sourceId, $sourceName, null); // do something with result: @@ -589,8 +570,8 @@ class TransactionJournalFactory } Log::debug('Source seems valid.'); // validate destination account - $destinationId = $data['destination_id'] ? (int) $data['destination_id'] : null; - $destinationName = $data['destination_name'] ? (string) $data['destination_name'] : null; + $destinationId = $data['destination_id'] ? (int)$data['destination_id'] : null; + $destinationName = $data['destination_name'] ? (string)$data['destination_name'] : null; $validDestination = $this->accountValidator->validateDestination($destinationId, $destinationName, null); // do something with result: if (false === $validDestination) {