Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Update ING description for #1015
James Colebad889d45091
diff --git a/app/Import/FileProcessor/CsvProcessor.php b/app/Import/FileProcessor/CsvProcessor.phpindex 0b547eb026..9a21cfc9da 100644--- a/app/Import/FileProcessor/CsvProcessor.php+++ b/app/Import/FileProcessor/CsvProcessor.php@@ -169,9 +169,11 @@ class CsvProcessor implements FileProcessorInterface$delimiter = "\t";}$reader->setDelimiter($delimiter);- $start = $config['has-headers'] ? 1 : 0;- $results = $reader->setOffset($start)->fetch();- Log::debug(sprintf('Created a CSV reader starting at offset %d', $start));+ if($config['has-headers']) {+ $reader->setHeaderOffset(0);+ }+ $results = $reader->getRecords();+ Log::debug('Created a CSV reader.');return $results;}diff --git a/app/Import/Specifics/IngDescription.php b/app/Import/Specifics/IngDescription.phpindex 010b93801d..c34cf61cde 100644--- a/app/Import/Specifics/IngDescription.php+++ b/app/Import/Specifics/IngDescription.php@@ -60,7 +60,7 @@ class IngDescription implements SpecificInterface*/public function run(array $row): array{- $this->row = $row;+ $this->row = array_values($row);if (count($this->row) >= 8) { // check if the array is correctswitch ($this->row[4]) { // Get value for the mutation typecase 'GT': // InternetBankieren@@ -69,6 +69,8 @@ class IngDescription implements SpecificInterfacecase 'IC': // Incasso$this->removeIBANIngDescription();$this->removeNameIngDescription();+ // if "tegenrekening" empty, copy the description. Primitive, but it works.+ $this->copyDescriptionToOpposite();break;case 'BA': // Betaalautomaat$this->addNameIngDescription();@@ -113,9 +115,20 @@ class IngDescription implements SpecificInterface*/protected function removeNameIngDescription(){- // Try remove everything bevore the 'Omschrijving'+ // Try remove everything before the 'Omschrijving'$this->row[8] = preg_replace('/.+Omschrijving: /', '', $this->row[8]);return true;}++ /**+ *+ */+ private function copyDescriptionToOpposite(): void+ {+ $search = ['Naar Oranje Spaarrekening ', 'Afschrijvingen'];+ if (strlen($this->row[3]) === 0) {+ $this->row[3] = trim(str_ireplace($search, '', $this->row[8]));+ }+ }}diff --git a/app/Support/Import/Configuration/Csv/Map.php b/app/Support/Import/Configuration/Csv/Map.phpindex 7aa35f62b0..449124bbb8 100644--- a/app/Support/Import/Configuration/Csv/Map.php+++ b/app/Support/Import/Configuration/Csv/Map.php@@ -60,8 +60,10 @@ class Map implements ConfigurationInterface/** @var Reader $reader */$reader = Reader::createFromString($content);$reader->setDelimiter($this->configuration['delimiter']);- $offset = $this->configuration['has-headers'] ? 1 : 0;- $results = $reader->setOffset($offset)->fetch();+ if($this->configuration['has-headers']) {+ $reader->setHeaderOffset(0);+ }+ $results = $reader->getRecords();$this->validSpecifics = array_keys(config('csv.import_specifics'));$indexes = array_keys($this->data);$rowIndex = 0;diff --git a/app/Support/Import/Configuration/Csv/Roles.php b/app/Support/Import/Configuration/Csv/Roles.phpindex 97160b430e..f0d1f206c5 100644--- a/app/Support/Import/Configuration/Csv/Roles.php+++ b/app/Support/Import/Configuration/Csv/Roles.php@@ -26,6 +26,7 @@ use FireflyIII\Import\Specifics\SpecificInterface;use FireflyIII\Models\ImportJob;use FireflyIII\Support\Import\Configuration\ConfigurationInterface;use League\Csv\Reader;+use League\Csv\Statement;use Log;/**@@ -53,9 +54,10 @@ class Roles implements ConfigurationInterface// create CSV reader.$reader = Reader::createFromString($content);$reader->setDelimiter($config['delimiter']);- $start = $config['has-headers'] ? 1 : 0;- $end = $start + config('csv.example_rows');-+ if ($config['has-headers']) {+ $reader->setHeaderOffset(0);+ }+ $stmt = (new Statement)->limit(intval(config('csv.example_rows', 5)));// set data:$roles = $this->getRoles();asort($roles);@@ -66,13 +68,13 @@ class Roles implements ConfigurationInterface'headers' => $config['has-headers'] ? $reader->fetchOne(0) : [],];- while ($start < $end) {- $row = $reader->fetchOne($start);++ $records = $stmt->process($reader);+ foreach ($records as $row) {$row = $this->processSpecifics($row);$count = count($row);$this->data['total'] = $count > $this->data['total'] ? $count : $this->data['total'];$this->processRow($row);- ++$start;}$this->updateColumCount();