diff --git a/app/Import/Specifics/IngDescription.php b/app/Import/Specifics/IngDescription.php index 7d554388ea..35b3f63df1 100644 --- a/app/Import/Specifics/IngDescription.php +++ b/app/Import/Specifics/IngDescription.php @@ -70,18 +70,22 @@ class IngDescription implements SpecificInterface public function run(array $row): array { $this->row = array_values($row); + array_push($this->row); // New column for "Valutadatum" if (count($this->row) >= 8) { // check if the array is correct switch ($this->row[4]) { // Get value for the mutation type case 'GT': // InternetBankieren case 'OV': // Overschrijving case 'VZ': // Verzamelbetaling case 'IC': // Incasso - $this->removeIBANIngDescription(); - $this->removeNameIngDescription(); - // if "tegenrekening" empty, copy the description. Primitive, but it works. - $this->copyDescriptionToOpposite(); + case 'DV': // Divers + $this->removeIBANIngDescription(); // Remove "IBAN:", because it is already at "Tegenrekening" + $this->removeNameIngDescription(); // Remove "Naam:", because it is already at "Naam/ Omschrijving" + $this->removeIngDescription(); // Remove "Omschrijving", but not the value from description + $this->moveValutadatumDescription(); // Move "Valutadatum" from description to new column + $this->MoveSavingsAccount(); // Move savings account number and name break; case 'BA': // Betaalautomaat + $this->moveValutadatumDescription(); // Move "Valutadatum" from description to new column $this->addNameIngDescription(); break; } @@ -99,33 +103,60 @@ class IngDescription implements SpecificInterface $this->row[8] = $this->row[1] . ' ' . $this->row[8]; } + /** + * Remove "Omschrijving" (and NOT its value) from the description. + */ + protected function removeIngDescription(): void + { + $this->row[8] = preg_replace('/Omschrijving: /', '', $this->row[8]); + } + /** * Remove IBAN number out of the description * Default description of Description is: Naam: Omschrijving: IBAN: . */ protected function removeIBANIngDescription(): void { - // Try replace the iban number with nothing. The IBAN nr is found in the third row + // Try replace the iban number with nothing. The IBAN nr is found in the third column $this->row[8] = preg_replace('/\sIBAN:\s' . $this->row[3] . '/', '', $this->row[8]); } /** - * Remove name from the description (Remove everything before the description incl the word 'Omschrijving' ). + * Remove "Naam" (and its value) from the description. */ protected function removeNameIngDescription(): void { - // Try remove everything before the 'Omschrijving' - $this->row[8] = preg_replace('/.+Omschrijving: /', '', $this->row[8]); + $this->row[8] = preg_replace('/Naam:.*?([a-zA-Z\/]+:)/', '$1', $this->row[8]); } /** - * Copy description to name of opposite account. + * Move "Valutadatum" from the description to new column. */ - private function copyDescriptionToOpposite(): void + protected function moveValutadatumDescription(): void { - $search = ['Naar Oranje Spaarrekening ', 'Afschrijvingen']; + $matches = array(); + preg_match('/Valutadatum: ([0-9-]+)/', $this->row[8], $matches); + $this->row[9] = date("Ymd", strtotime($matches[1])); + $this->row[8] = preg_replace('/Valutadatum: [0-9-]+/', '', $this->row[8]); + } + + /** + * Move savings account number to column 1 and name to column 3. + */ + private function MoveSavingsAccount(): void + { + $matches = array(); if ('' === (string)$this->row[3]) { - $this->row[3] = trim(str_ireplace($search, '', $this->row[8])); + if (preg_match('/(Naar|Van) (.*rekening) ([0-9]+)/', $this->row[8], $matches)) { + $matches[3] = sprintf("%010d", $matches[3]); + $this->row[1] = $matches[2]; // Savings account name + $this->row[3] = $matches[3]; // Savings account number + $this->row[8] = preg_replace('/(Naar|Van) (.*rekening) ([0-9]+)/', '', $this->row[8]); // Remove the savings account content from description + } elseif (preg_match('/(Naar|Van) (.*rekening) ([0-9]+)/', $this->row[1], $matches)) { + $matches[3] = sprintf("%010d", $matches[3]); + $this->row[1] = $matches[2]; // Savings account name + $this->row[3] = $matches[3]; // Savings account number + } } } }