/**
  * Clean collection by filling in all the blanks.
  */
 public function clean() : Collection
 {
     Log::notice(sprintf('Started validating %d entry(ies).', $this->entries->count()));
     $newCollection = new Collection();
     /** @var ImportEntry $entry */
     foreach ($this->entries as $index => $entry) {
         Log::debug(sprintf('--- import validator start for row %d ---', $index));
         /*
          * X Adds the date (today) if no date is present.
          * X Determins the types of accounts involved (asset, expense, revenue).
          * X Determins the type of transaction (withdrawal, deposit, transfer).
          * - Determins the currency of the transaction.
          * X Adds a default description if there isn't one present.
          */
         $entry = $this->checkAmount($entry);
         $entry = $this->setDate($entry);
         $entry = $this->setAssetAccount($entry);
         $entry = $this->setOpposingAccount($entry);
         $entry = $this->cleanDescription($entry);
         $entry = $this->setTransactionType($entry);
         $entry = $this->setTransactionCurrency($entry);
         $newCollection->put($index, $entry);
         $this->job->addStepsDone(1);
     }
     Log::notice(sprintf('Finished validating %d entry(ies).', $newCollection->count()));
     return $newCollection;
 }
Exemplo n.º 2
0
 /**
  * Run the actual import
  *
  * @return Collection
  */
 public function createImportEntries() : Collection
 {
     $config = $this->job->configuration;
     $content = $this->job->uploadFileContents();
     // create CSV reader.
     $reader = Reader::createFromString($content);
     $reader->setDelimiter($config['delimiter']);
     $start = $config['has-headers'] ? 1 : 0;
     $results = $reader->fetch();
     Log::notice('Building importable objects from CSV file.');
     foreach ($results as $index => $row) {
         if ($index >= $start) {
             $line = $index + 1;
             Log::debug('----- import entry build start --');
             Log::debug(sprintf('Now going to import row %d.', $index));
             $importEntry = $this->importSingleRow($index, $row);
             $this->collection->put($line, $importEntry);
             /**
              * 1. Build import entry.
              * 2. Validate import entry.
              * 3. Store journal.
              * 4. Run rules.
              */
             $this->job->addTotalSteps(4);
             $this->job->addStepsDone(1);
         }
     }
     Log::debug(sprintf('Import collection contains %d entries', $this->collection->count()));
     Log::notice(sprintf('Built %d importable object(s) from your CSV file.', $this->collection->count()));
     return $this->collection;
 }
Exemplo n.º 3
0
 /**
  * @return Collection
  */
 public function store() : 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));
         // store entry:
         $journal = $this->storeSingle($index, $entry);
         $this->job->addStepsDone(1);
         // apply rules:
         $this->applyRules($journal);
         $this->job->addStepsDone(1);
         $collection->put($index, $journal);
     }
     Log::notice(sprintf('Finished storing %d entry(ies).', $collection->count()));
     return $collection;
 }