Skip to content

Firefly III: a personal finances manager

This should fix #693.

James Coledd508dbc49ad
diff --git a/app/Import/Object/ImportCurrency.php b/app/Import/Object/ImportCurrency.php
index 8427f3ce5f..6791caba62 100644
--- a/app/Import/Object/ImportCurrency.php
+++ b/app/Import/Object/ImportCurrency.php
@@ -77,7 +77,7 @@ class ImportCurrency
'decimal_places' => 2,
];
if (is_null($data['code'])) {
- Log::info('Need at least a code to create currency, return nothing.');
+ Log::debug('Need at least a code to create currency, return nothing.');
return new TransactionCurrency();
}
diff --git a/app/Import/Object/ImportJournal.php b/app/Import/Object/ImportJournal.php
index a86cdffe5d..ce3af83147 100644
--- a/app/Import/Object/ImportJournal.php
+++ b/app/Import/Object/ImportJournal.php
@@ -19,6 +19,8 @@ use FireflyIII\Import\Converter\ConverterInterface;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\User;
use Illuminate\Support\Collection;
+use InvalidArgumentException;
+use Log;
use Steam;
/**
@@ -30,22 +32,26 @@ class ImportJournal
{
/** @var ImportAccount */
public $asset;
+ /** @var ImportBill */
+ public $bill;
/** @var ImportBudget */
public $budget;
+ /** @var ImportCategory */
+ public $category;
/** @var string */
public $description = '';
/** @var Collection */
public $errors;
/** @var string */
public $hash;
+ /** @var array */
+ public $metaDates = [];
+ /** @var string */
+ public $notes = '';
/** @var ImportAccount */
public $opposing;
/** @var string */
private $amount = '0';
- /** @var ImportBill */
- public $bill;
- /** @var ImportCategory */
- public $category;
/** @var ImportCurrency */
private $currency;
/** @var string */
@@ -54,16 +60,12 @@ class ImportJournal
private $externalId = '';
/** @var array */
private $modifiers = [];
- /** @var array */
- private $tags = [];
- /** @var string */
- public $notes = '';
+ /** @var array */
+ private $tags = [];
/** @var string */
private $transactionType = '';
/** @var User */
private $user;
- /** @var array */
- public $metaDates = [];
/**
* ImportEntry constructor.
@@ -133,7 +135,15 @@ class ImportJournal
*/
public function getDate(string $format): Carbon
{
- return Carbon::createFromFormat($format, $this->date);
+ $date = new Carbon;
+ try {
+ $date = Carbon::createFromFormat($format, $this->date);
+ } catch (InvalidArgumentException $e) {
+ // don't care, just log.
+ Log::error(sprintf('Import journal cannot parse date "%s" from value "%s" so will return current date instead.', $format, $this->date));
+ }
+
+ return $date;
}
/**
@@ -223,7 +233,7 @@ class ImportJournal
case 'sepa-ct-op':
case 'sepa-ct-id':
case 'sepa-db':
- $this->notes .= ' '.$array['value'];
+ $this->notes .= ' ' . $array['value'];
$this->notes = trim($this->notes);
break;
case 'external-id':
diff --git a/app/Import/Routine/ImportRoutine.php b/app/Import/Routine/ImportRoutine.php
index 62da476f86..6177f7a464 100644
--- a/app/Import/Routine/ImportRoutine.php
+++ b/app/Import/Routine/ImportRoutine.php
@@ -86,6 +86,7 @@ class ImportRoutine
Log::info(sprintf('Done with import job %s', $this->job->key));
+
return true;
}
diff --git a/app/Import/Storage/ImportStorage.php b/app/Import/Storage/ImportStorage.php
index d0eea39f5d..23d1ed9ad4 100644
--- a/app/Import/Storage/ImportStorage.php
+++ b/app/Import/Storage/ImportStorage.php
@@ -29,7 +29,6 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Rules\Processor;
use Illuminate\Support\Collection;
-use Illuminate\Support\MessageBag;
use Log;
use Steam;
@@ -107,6 +106,7 @@ class ImportStorage
$this->storeImportJournal($index, $object);
} catch (FireflyException $e) {
$this->errors->push($e->getMessage());
+ Log::error(sprintf('Cannot import row #%d because: %s', $index, $e->getMessage()));
}
}
@@ -351,6 +351,13 @@ class ImportStorage
$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
+ )
+ );
+
return true;
}
diff --git a/app/Support/Import/Configuration/Csv/Roles.php b/app/Support/Import/Configuration/Csv/Roles.php
index adb0707beb..ced9b88aa0 100644
--- a/app/Support/Import/Configuration/Csv/Roles.php
+++ b/app/Support/Import/Configuration/Csv/Roles.php
@@ -68,6 +68,18 @@ class Roles implements ConfigurationInterface
return $this->data;
}
+ /**
+ * @param ImportJob $job
+ *
+ * @return ConfigurationInterface
+ */
+ public function setJob(ImportJob $job): ConfigurationInterface
+ {
+ $this->job = $job;
+
+ return $this;
+ }
+
/**
* Store the result.
*
@@ -217,16 +229,20 @@ class Roles implements ConfigurationInterface
*/
private function setRolesComplete(): bool
{
- $config = $this->job->configuration;
- $count = $config['column-count'];
- $assigned = 0;
+ $config = $this->job->configuration;
+ $count = $config['column-count'];
+ $assigned = 0;
+ $hasAmount = false;
for ($i = 0; $i < $count; $i++) {
$role = $config['column-roles'][$i] ?? '_ignore';
if ($role !== '_ignore') {
$assigned++;
}
+ if ($role === 'amount') {
+ $hasAmount = true;
+ }
}
- if ($assigned > 0) {
+ if ($assigned > 0 && $hasAmount) {
$config['column-roles-complete'] = true;
$this->job->configuration = $config;
$this->job->save();
@@ -248,16 +264,4 @@ class Roles implements ConfigurationInterface
return true;
}
-
- /**
- * @param ImportJob $job
- *
- * @return ConfigurationInterface
- */
- public function setJob(ImportJob $job): ConfigurationInterface
- {
- $this->job = $job;
-
- return $this;
- }
}
\ No newline at end of file