This should fix #693.

This commit is contained in:
James Cole 2017-07-07 08:04:21 +02:00
parent 71eed45b77
commit dd508dbc49
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
5 changed files with 52 additions and 30 deletions

View File

@ -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();
}

View File

@ -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':

View File

@ -86,6 +86,7 @@ class ImportRoutine
Log::info(sprintf('Done with import job %s', $this->job->key));
return true;
}

View File

@ -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;
}

View File

@ -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;
}
}