Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Last minute fixes for import routine.
James Colef9b546848197
diff --git a/app/Import/Storage/ImportStorage.php b/app/Import/Storage/ImportStorage.phpindex ee2aceb74f..50980ad2a9 100644--- a/app/Import/Storage/ImportStorage.php+++ b/app/Import/Storage/ImportStorage.php@@ -15,7 +15,6 @@ use FireflyIII\Exceptions\FireflyException;use FireflyIII\Import\Object\ImportJournal;use FireflyIII\Models\ImportJob;use FireflyIII\Models\TransactionType;-use FireflyIII\Repositories\Tag\TagRepositoryInterface;use Illuminate\Support\Collection;use Log;@@ -140,7 +139,7 @@ class ImportStorage'asset' => $assetAccount->name,'opposing' => $opposingAccount->name,];- if ($this->isDoubleTransfer($parameters)) {+ if ($this->isDoubleTransfer($parameters) || $this->hashAlreadyImported($importJournal->hash)) {$this->job->addStepsDone(3);// throw errorthrow new FireflyException('Detected a possible duplicate, skip this one.');@@ -187,12 +186,7 @@ class ImportStorage$this->job->addStepsDone(1);$this->journals->push($journal);- Log::info(- sprintf(- 'Imported new journal #%d with description "%s" and amount %s %s.', $journal->id, $journal->description, $journal->transactionCurrency->code,- $amount- )- );+ Log::info(sprintf('Imported new journal #%d: "%s", amount %s %s.', $journal->id, $journal->description, $journal->transactionCurrency->code, $amount));return true;}diff --git a/app/Import/Storage/ImportSupport.php b/app/Import/Storage/ImportSupport.phpindex a18fdfaafd..38b444b98e 100644--- a/app/Import/Storage/ImportSupport.php+++ b/app/Import/Storage/ImportSupport.php@@ -26,6 +26,7 @@ use FireflyIII\Models\Category;use FireflyIII\Models\Rule;use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionJournal;+use FireflyIII\Models\TransactionJournalMeta;use FireflyIII\Models\TransactionType;use FireflyIII\Repositories\Tag\TagRepositoryInterface;use FireflyIII\Rules\Processor;@@ -47,7 +48,7 @@ trait ImportSupport{if ($this->rules->count() > 0) {$this->rules->each(- function (Rule $rule) use($journal) {+ function (Rule $rule) use ($journal) {Log::debug(sprintf('Going to apply rule #%d to journal %d.', $rule->id, $journal->id));$processor = Processor::make($rule);$processor->handleTransactionJournal($journal);@@ -231,7 +232,7 @@ trait ImportSupport// verify that opposing account is of the correct type:if ($account->accountType->type === AccountType::EXPENSE && $transactionType !== TransactionType::WITHDRAWAL) {- $message = sprintf('This row is imported as a %s but opposing is an expense account. This cannot be!', $transactionType);+ $message = 'This row is imported as a withdrawal but opposing is an expense account. This cannot be!';Log::error($message);throw new FireflyException($message);}@@ -286,6 +287,28 @@ trait ImportSupportreturn $array;}+ /**+ * Checks if the import journal has not been imported before.+ *+ * @param string $hash+ *+ * @return bool+ */+ private function hashAlreadyImported(string $hash): bool+ {+ $json = json_encode($hash);+ $entry = TransactionJournalMeta::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')+ ->where('data', $json)+ ->where('name', 'importHash')+ ->first();+ if (!is_null($entry)) {+ return true;+ }++ return false;++ }+/*** @param TransactionJournal $journal* @param Bill $billdiff --git a/app/Support/Import/Configuration/Csv/Roles.php b/app/Support/Import/Configuration/Csv/Roles.phpindex 64b3b165b7..bf8f5111ef 100644--- a/app/Support/Import/Configuration/Csv/Roles.php+++ b/app/Support/Import/Configuration/Csv/Roles.php@@ -49,9 +49,11 @@ class Roles implements ConfigurationInterface$end = $start + config('csv.example_rows');// set data:+ $roles = $this->getRoles();+ asort($roles);$this->data = ['examples' => [],- 'roles' => $this->getRoles(),+ 'roles' => $roles,'total' => 0,'headers' => $config['has-headers'] ? $reader->fetchOne(0) : [],];