/** * Define column roles and mapping. * * STEP THREE * * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View */ public function columnRoles() { $fields = ['csv-file', 'csv-date-format', 'csv-has-headers', 'csv-import-account']; if (!$this->wizard->sessionHasValues($fields)) { Session::flash('warning', 'Could not recover upload.'); return redirect(route('csv.index')); } $subTitle = trans('firefly.csv_define_column_roles'); $firstRow = $this->data->getReader()->fetchOne(); $count = count($firstRow); $headers = []; $example = $this->data->getReader()->fetchOne(1); $availableRoles = []; $roles = $this->data->getRoles(); $map = $this->data->getMap(); for ($i = 1; $i <= $count; $i++) { $headers[] = trans('firefly.csv_column') . ' #' . $i; } if ($this->data->hasHeaders()) { $headers = $firstRow; } foreach (Config::get('csv.roles') as $name => $role) { $availableRoles[$name] = trans('firefly.csv_column_' . $name); //$role['name']; } ksort($availableRoles); return view('csv.column-roles', compact('availableRoles', 'map', 'roles', 'headers', 'example', '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(); }