mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 01:06:46 +00:00
Move fields to configuration.
This commit is contained in:
@@ -75,26 +75,7 @@ class TransactionJournalFactory
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->errorOnHash = false;
|
$this->errorOnHash = false;
|
||||||
// TODO move valid meta fields to config.
|
$this->fields = config('firefly.journal_meta_fields');
|
||||||
$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->currencyRepository = app(CurrencyRepositoryInterface::class);
|
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
|
||||||
$this->typeRepository = app(TransactionTypeRepositoryInterface::class);
|
$this->typeRepository = app(TransactionTypeRepositoryInterface::class);
|
||||||
$this->billRepository = app(BillRepositoryInterface::class);
|
$this->billRepository = app(BillRepositoryInterface::class);
|
||||||
@@ -197,7 +178,7 @@ class TransactionJournalFactory
|
|||||||
$set = [
|
$set = [
|
||||||
'journal' => $journal,
|
'journal' => $journal,
|
||||||
'name' => $field,
|
'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']));
|
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']);
|
$type = $this->typeRepository->findTransactionType(null, $row['type']);
|
||||||
$carbon = $row['date'] ?? today(config('app.timezone'));
|
$carbon = $row['date'] ?? today(config('app.timezone'));
|
||||||
$order = $row['order'] ?? 0;
|
$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']);
|
$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;
|
$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 */
|
/** Manipulate basic fields */
|
||||||
$carbon->setTimezone(config('app.timezone'));
|
$carbon->setTimezone(config('app.timezone'));
|
||||||
@@ -263,11 +244,12 @@ class TransactionJournalFactory
|
|||||||
return null;
|
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 */
|
/** create or get source and destination accounts */
|
||||||
$sourceInfo = [
|
$sourceInfo = [
|
||||||
'id' => (int) $row['source_id'],
|
'id' => (int)$row['source_id'],
|
||||||
'name' => $row['source_name'],
|
'name' => $row['source_name'],
|
||||||
'iban' => $row['source_iban'],
|
'iban' => $row['source_iban'],
|
||||||
'number' => $row['source_number'],
|
'number' => $row['source_number'],
|
||||||
@@ -276,7 +258,7 @@ class TransactionJournalFactory
|
|||||||
];
|
];
|
||||||
|
|
||||||
$destInfo = [
|
$destInfo = [
|
||||||
'id' => (int) $row['destination_id'],
|
'id' => (int)$row['destination_id'],
|
||||||
'name' => $row['destination_name'],
|
'name' => $row['destination_name'],
|
||||||
'iban' => $row['destination_iban'],
|
'iban' => $row['destination_iban'],
|
||||||
'number' => $row['destination_number'],
|
'number' => $row['destination_number'],
|
||||||
@@ -320,7 +302,7 @@ class TransactionJournalFactory
|
|||||||
$transactionFactory->setForeignCurrency($foreignCurrency);
|
$transactionFactory->setForeignCurrency($foreignCurrency);
|
||||||
$transactionFactory->setReconciled($row['reconciled'] ?? false);
|
$transactionFactory->setReconciled($row['reconciled'] ?? false);
|
||||||
try {
|
try {
|
||||||
$negative = $transactionFactory->createNegative((string) $row['amount'], (string) $row['foreign_amount']);
|
$negative = $transactionFactory->createNegative((string)$row['amount'], (string)$row['foreign_amount']);
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
Log::error('Exception creating negative transaction.');
|
Log::error('Exception creating negative transaction.');
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
@@ -339,7 +321,7 @@ class TransactionJournalFactory
|
|||||||
$transactionFactory->setForeignCurrency($foreignCurrency);
|
$transactionFactory->setForeignCurrency($foreignCurrency);
|
||||||
$transactionFactory->setReconciled($row['reconciled'] ?? false);
|
$transactionFactory->setReconciled($row['reconciled'] ?? false);
|
||||||
try {
|
try {
|
||||||
$transactionFactory->createPositive((string) $row['amount'], (string) $row['foreign_amount']);
|
$transactionFactory->createPositive((string)$row['amount'], (string)$row['foreign_amount']);
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
Log::error('Exception creating positive transaction.');
|
Log::error('Exception creating positive transaction.');
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
@@ -352,7 +334,6 @@ class TransactionJournalFactory
|
|||||||
|
|
||||||
|
|
||||||
// verify that journal has two transactions. Otherwise, delete and cancel.
|
// 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->completed = true;
|
||||||
$journal->save();
|
$journal->save();
|
||||||
|
|
||||||
@@ -520,7 +501,7 @@ class TransactionJournalFactory
|
|||||||
$json = json_encode($dataRow, JSON_THROW_ON_ERROR, 512);
|
$json = json_encode($dataRow, JSON_THROW_ON_ERROR, 512);
|
||||||
if (false === $json) {
|
if (false === $json) {
|
||||||
// @codeCoverageIgnoreStart
|
// @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);
|
Log::error(sprintf('Could not hash the original row! %s', json_last_error_msg()), $dataRow);
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
@@ -556,7 +537,7 @@ class TransactionJournalFactory
|
|||||||
return;
|
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) {
|
if (null !== $piggyBank) {
|
||||||
$this->piggyEventFactory->create($journal, $piggyBank);
|
$this->piggyEventFactory->create($journal, $piggyBank);
|
||||||
@@ -579,8 +560,8 @@ class TransactionJournalFactory
|
|||||||
$this->accountValidator->setTransactionType($transactionType);
|
$this->accountValidator->setTransactionType($transactionType);
|
||||||
|
|
||||||
// validate source account.
|
// validate source account.
|
||||||
$sourceId = $data['source_id'] ? (int) $data['source_id'] : null;
|
$sourceId = $data['source_id'] ? (int)$data['source_id'] : null;
|
||||||
$sourceName = $data['source_name'] ? (string) $data['source_name'] : null;
|
$sourceName = $data['source_name'] ? (string)$data['source_name'] : null;
|
||||||
$validSource = $this->accountValidator->validateSource($sourceId, $sourceName, null);
|
$validSource = $this->accountValidator->validateSource($sourceId, $sourceName, null);
|
||||||
|
|
||||||
// do something with result:
|
// do something with result:
|
||||||
@@ -589,8 +570,8 @@ class TransactionJournalFactory
|
|||||||
}
|
}
|
||||||
Log::debug('Source seems valid.');
|
Log::debug('Source seems valid.');
|
||||||
// validate destination account
|
// validate destination account
|
||||||
$destinationId = $data['destination_id'] ? (int) $data['destination_id'] : null;
|
$destinationId = $data['destination_id'] ? (int)$data['destination_id'] : null;
|
||||||
$destinationName = $data['destination_name'] ? (string) $data['destination_name'] : null;
|
$destinationName = $data['destination_name'] ? (string)$data['destination_name'] : null;
|
||||||
$validDestination = $this->accountValidator->validateDestination($destinationId, $destinationName, null);
|
$validDestination = $this->accountValidator->validateDestination($destinationId, $destinationName, null);
|
||||||
// do something with result:
|
// do something with result:
|
||||||
if (false === $validDestination) {
|
if (false === $validDestination) {
|
||||||
|
Reference in New Issue
Block a user