From 9c9fc2b5dc66c3c373205e6ea19ccf622d42fbdf Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 9 Jul 2015 18:33:09 +0200 Subject: [PATCH] Some fixes in csv importer. --- app/Helpers/Csv/Importer.php | 34 ++++++++++++++++++++++++++----- config/csv.php | 1 + database/seeds/TestDataSeeder.php | 3 ++- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/app/Helpers/Csv/Importer.php b/app/Helpers/Csv/Importer.php index 7cff6a7ed1..33912ed48d 100644 --- a/app/Helpers/Csv/Importer.php +++ b/app/Helpers/Csv/Importer.php @@ -88,6 +88,7 @@ class Importer foreach ($this->data->getReader() as $index => $row) { if ($this->parseRow($index)) { + Log::debug('--- Importing row ' . $index); $this->rows++; $result = $this->importRow($row); if (!($result === true)) { @@ -96,6 +97,7 @@ class Importer } else { $this->imported++; } + Log::debug('---'); } } } @@ -118,13 +120,14 @@ class Importer */ protected function importRow($row) { + $data = $this->getFiller(); // These fields are necessary to create a new transaction journal. Some are optional foreach ($row as $index => $value) { $role = isset($this->roles[$index]) ? $this->roles[$index] : '_ignore'; $class = Config::get('csv.roles.' . $role . '.converter'); $field = Config::get('csv.roles.' . $role . '.field'); - Log::debug('For column ' . $index . ' (role: ' . $role . ') : converter ' . $class . ' into field ' . $field); + Log::debug('Column #' . $index . ' (role: ' . $role . ') : converter ' . $class . ' stores its data into field ' . $field . ':'); /** @var ConverterInterface $converter */ $converter = app('FireflyIII\Helpers\Csv\Converter\\' . $class); @@ -135,7 +138,6 @@ class Importer $converter->setValue($value); $converter->setRole($role); $data[$field] = $converter->convert(); - } // move to class vars. $this->importData = $data; @@ -192,6 +194,7 @@ class Importer $specifix = app('FireflyIII\Helpers\Csv\Specifix\\' . $className); $specifix->setData($this->importData); $specifix->setRow($this->importRow); + Log::debug('Now post-process specifix named ' . $className . ':'); $this->importData = $specifix->fix(); } @@ -201,6 +204,7 @@ class Importer /** @var PostProcessorInterface $postProcessor */ $postProcessor = app('FireflyIII\Helpers\Csv\PostProcessing\\' . $className); $postProcessor->setData($this->importData); + Log::debug('Now post-process processor named ' . $className . ':'); $this->importData = $postProcessor->process(); } @@ -227,6 +231,10 @@ class Importer return 'Opposing account is null'; } + if (!($this->importData['asset-account-object'] instanceof Account)) { + return 'No asset account to import into.'; + } + return true; } @@ -242,9 +250,6 @@ class Importer $date = $this->importData['date-rent']; } - if (!($this->importData['asset-account-object'] instanceof Account)) { - return 'No asset account to import into.'; - } $transactionType = $this->getTransactionType(); // defaults to deposit $errors = new MessageBag; @@ -277,6 +282,25 @@ class Importer $this->saveCategory($journal); $this->saveTags($journal); + // some debug info: + $id = $journal->id; + $type = $journal->transactionType->type; + /** @var Account $asset */ + $asset = $this->importData['asset-account-object']; + /** @var Account $opposing */ + $opposing = $this->importData['opposing-account-object']; + + Log::info('Created journal #' . $id . ' of type ' . $type . '!'); + Log::info('Asset account ' . $asset->name . ' (#' . $asset->id . ') lost/gained: ' . $this->importData['amount']); + Log::info($opposing->accountType->type . ' ' . $opposing->name . ' (#' . $opposing->id . ') lost/gained: ' . bcmul($this->importData['amount'], -1)); + + //. + //' [' . $asset->name . ' (#' .$asset->id . ')] <--> ' . + //' [' . $this->importData['opposing-account-object']->name . ' (' . $this->importData['opposing-account-object']->accountType->type . ') (#' + //. $this->importData['opposing-account-object']->id . ')]' + // ); + // + return $journal; } diff --git a/config/csv.php b/config/csv.php index 2aec11f478..a88a006dba 100644 --- a/config/csv.php +++ b/config/csv.php @@ -10,6 +10,7 @@ return [ 'Currency', 'Bill', 'OpposingAccount', // must be after Amount! + 'AssetAccount', ], 'roles' => [ diff --git a/database/seeds/TestDataSeeder.php b/database/seeds/TestDataSeeder.php index cca8a151fd..ef76a0de0d 100644 --- a/database/seeds/TestDataSeeder.php +++ b/database/seeds/TestDataSeeder.php @@ -101,6 +101,7 @@ class TestDataSeeder extends Seeder protected function createAssetAccounts() { $assets = ['MyBank Checking Account', 'Savings', 'Shared', 'Creditcard', 'Emergencies', 'STE']; + $ibans = ['NL47JDYU6179706202', 'NL51WGBP5832453599', 'NL81RCQZ7160379858', 'NL19NRAP2367994221', 'NL40UKBK3619908726', 'NL38SRMN4325934708']; $assetMeta = [ [ 'accountRole' => 'defaultAsset', @@ -134,7 +135,7 @@ class TestDataSeeder extends Seeder 'name' => $name, 'active' => 1, 'encrypted' => 1, - 'iban' => 'GB82WEST12345698765432' + 'iban' => $ibans[$index], ] ); foreach ($assetMeta[$index] as $name => $value) {