Finetune user feedback during import and add a tag to collect transactions.

This commit is contained in:
James Cole
2016-08-14 11:31:09 +02:00
parent 70b63e1736
commit 98c4ac955a
8 changed files with 75 additions and 14 deletions

View File

@@ -13,10 +13,12 @@ namespace FireflyIII\Import;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\ImportJob;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionJournalMeta;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
@@ -31,6 +33,8 @@ class ImportStorage
/** @var Collection */
public $entries;
/** @var Tag */
public $importTag;
/** @var ImportJob */
public $job;
/** @var User */
@@ -68,13 +72,14 @@ class ImportStorage
*/
public function store(): Collection
{
$collection = new Collection;
// create a tag to join the transactions.
$this->importTag = $this->createImportTag();
$collection = new Collection;
Log::notice(sprintf('Started storing %d entry(ies).', $this->entries->count()));
foreach ($this->entries as $index => $entry) {
Log::debug(sprintf('--- import store start for row %d ---', $index));
$result = $this->storeSingle($index, $entry);
$this->job->addStepsDone(1);
sleep(1);
$collection->put($index, $result);
}
Log::notice(sprintf('Finished storing %d entry(ies).', $collection->count()));
@@ -98,6 +103,27 @@ class ImportStorage
return new TransactionJournal;
}
/**
* @return Tag
*/
private function createImportTag(): Tag
{
/** @var TagRepositoryInterface $repository */
$repository = app(TagRepositoryInterface::class);
$data = [
'tag' => trans('firefly.import_with_key', ['key' => $this->job->key]),
'date' => null,
'description' => null,
'latitude' => null,
'longitude' => null,
'zoomLevel' => null,
'tagMode' => 'nothing',
];
$tag = $repository->store($data);
return $tag;
}
/**
* @param float $amount
*
@@ -303,6 +329,9 @@ class ImportStorage
$journal->completed = 1;
$journal->save();
// attach import tag.
$journal->tags()->save($this->importTag);
// now attach budget and so on.
$this->storeBudget($journal, $entry);
$this->storeCategory($journal, $entry);