/** * * Map first if necessary, * * STEP FIVE. * * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View * @throws FireflyException */ public function map() { // Make sure all fields we need are accounted for. $fields = ['csv-file', 'csv-date-format', 'csv-has-headers', 'csv-map', 'csv-roles']; if (!$this->wizard->sessionHasValues($fields)) { Session::flash('warning', 'Could not recover upload.'); return redirect(route('csv.index')); } /* * The "options" array contains all options the user has * per column, where the key represents the column. * * For each key there is an array which in turn represents * all the options available: grouped by ID. * * options[column index] = [ * field id => field identifier. * ] */ try { $options = $this->wizard->showOptions($this->data->getMap()); } catch (FireflyException $e) { return view('error', ['message' => $e->getMessage()]); } // After these values are prepped, read the actual CSV file $reader = $this->data->getReader(); $map = $this->data->getMap(); $hasHeaders = $this->data->hasHeaders(); $values = $this->wizard->getMappableValues($reader, $map, $hasHeaders); $map = $this->data->getMap(); $mapped = $this->data->getMapped(); $subTitle = trans('firefly.csv_map_values'); return view('csv.map', compact('map', 'options', 'values', 'mapped', 'subTitle')); }
/** * @throws FireflyException */ public function run() { set_time_limit(0); $this->journals = new Collection(); $this->map = $this->data->getMap(); $this->roles = $this->data->getRoles(); $this->mapped = $this->data->getMapped(); $this->specifix = $this->data->getSpecifix(); foreach ($this->data->getReader() as $index => $row) { if ($this->parseRow($index)) { Log::debug('--- Importing row ' . $index); $this->rows++; $result = $this->importRow($row); if (!$result instanceof TransactionJournal) { Log::error('Caught error at row #' . $index . ': ' . $result); $this->errors[$index] = $result; } else { $this->imported++; $this->journals->push($result); } Log::debug('---'); } } // once all journals have been imported (or not) // fire the rules. $this->fireRules(); }