mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Last minute fixes for import routine.
This commit is contained in:
@@ -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 error
|
||||
throw 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;
|
||||
}
|
||||
|
@@ -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 ImportSupport
|
||||
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 Bill $bill
|
||||
|
@@ -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) : [],
|
||||
];
|
||||
|
Reference in New Issue
Block a user