Last minute fixes for import routine.

This commit is contained in:
James Cole
2017-08-13 08:49:45 +02:00
parent 287f37eba5
commit f9b5468481
3 changed files with 30 additions and 11 deletions

View File

@@ -15,7 +15,6 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Object\ImportJournal; use FireflyIII\Import\Object\ImportJournal;
use FireflyIII\Models\ImportJob; use FireflyIII\Models\ImportJob;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
@@ -140,7 +139,7 @@ class ImportStorage
'asset' => $assetAccount->name, 'asset' => $assetAccount->name,
'opposing' => $opposingAccount->name, 'opposing' => $opposingAccount->name,
]; ];
if ($this->isDoubleTransfer($parameters)) { if ($this->isDoubleTransfer($parameters) || $this->hashAlreadyImported($importJournal->hash)) {
$this->job->addStepsDone(3); $this->job->addStepsDone(3);
// throw error // throw error
throw new FireflyException('Detected a possible duplicate, skip this one.'); throw new FireflyException('Detected a possible duplicate, skip this one.');
@@ -187,12 +186,7 @@ class ImportStorage
$this->job->addStepsDone(1); $this->job->addStepsDone(1);
$this->journals->push($journal); $this->journals->push($journal);
Log::info( Log::info(sprintf('Imported new journal #%d: "%s", amount %s %s.', $journal->id, $journal->description, $journal->transactionCurrency->code, $amount));
sprintf(
'Imported new journal #%d with description "%s" and amount %s %s.', $journal->id, $journal->description, $journal->transactionCurrency->code,
$amount
)
);
return true; return true;
} }

View File

@@ -26,6 +26,7 @@ use FireflyIII\Models\Category;
use FireflyIII\Models\Rule; use FireflyIII\Models\Rule;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionJournalMeta;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Tag\TagRepositoryInterface; use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Rules\Processor; use FireflyIII\Rules\Processor;
@@ -47,7 +48,7 @@ trait ImportSupport
{ {
if ($this->rules->count() > 0) { if ($this->rules->count() > 0) {
$this->rules->each( $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)); Log::debug(sprintf('Going to apply rule #%d to journal %d.', $rule->id, $journal->id));
$processor = Processor::make($rule); $processor = Processor::make($rule);
$processor->handleTransactionJournal($journal); $processor->handleTransactionJournal($journal);
@@ -231,7 +232,7 @@ trait ImportSupport
// verify that opposing account is of the correct type: // verify that opposing account is of the correct type:
if ($account->accountType->type === AccountType::EXPENSE && $transactionType !== TransactionType::WITHDRAWAL) { 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); Log::error($message);
throw new FireflyException($message); throw new FireflyException($message);
} }
@@ -286,6 +287,28 @@ trait ImportSupport
return $array; return $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 TransactionJournal $journal
* @param Bill $bill * @param Bill $bill

View File

@@ -49,9 +49,11 @@ class Roles implements ConfigurationInterface
$end = $start + config('csv.example_rows'); $end = $start + config('csv.example_rows');
// set data: // set data:
$roles = $this->getRoles();
asort($roles);
$this->data = [ $this->data = [
'examples' => [], 'examples' => [],
'roles' => $this->getRoles(), 'roles' => $roles,
'total' => 0, 'total' => 0,
'headers' => $config['has-headers'] ? $reader->fetchOne(0) : [], 'headers' => $config['has-headers'] ? $reader->fetchOne(0) : [],
]; ];