Files
firefly-iii/app/Import/Specifics/IngDescription.php

133 lines
4.5 KiB
PHP
Raw Normal View History

2016-10-03 17:08:24 +00:00
<?php
/**
* IngDescription.php
2019-10-05 10:10:11 +02:00
* Copyright (c) 2019 https://github.com/tomwerf
2016-10-03 17:08:24 +00:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2017-10-21 08:40:00 +02:00
*
* This program is distributed in the hope that it will be useful,
2017-10-21 08:40:00 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2017-10-21 08:40:00 +02:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2016-10-03 17:08:24 +00:00
*/
declare(strict_types=1);
2016-10-03 17:08:24 +00:00
namespace FireflyIII\Import\Specifics;
/**
2017-11-15 12:25:49 +01:00
* Class IngDescription.
2016-10-03 17:08:24 +00:00
*
* Parses the description from CSV files for Ing bank accounts.
*
* With Mutation 'InternetBankieren', 'Overschrijving', 'Verzamelbetaling' and
* 'Incasso' the Name of Opposing account the Opposing IBAN number are in the
* Description. This class will remove them, and add Name in description by
* 'Betaalautomaat' so those are easily recognizable
2016-10-03 17:08:24 +00:00
*/
class IngDescription implements SpecificInterface
{
2018-07-22 15:08:56 +02:00
/** @var array The current row. */
2016-10-03 17:08:24 +00:00
public $row;
/**
2018-07-22 15:08:56 +02:00
* Description of the current specific.
*
2016-10-03 17:08:24 +00:00
* @return string
2018-07-22 15:08:56 +02:00
* @codeCoverageIgnore
2016-10-03 17:08:24 +00:00
*/
public static function getDescription(): string
{
return 'import.specific_ing_descr';
2016-10-03 17:08:24 +00:00
}
/**
2018-07-22 15:08:56 +02:00
* Name of the current specific.
*
2016-10-03 17:08:24 +00:00
* @return string
2018-07-22 15:08:56 +02:00
* @codeCoverageIgnore
2016-10-03 17:08:24 +00:00
*/
public static function getName(): string
{
return 'import.specific_ing_name';
2016-10-03 17:08:24 +00:00
}
/**
2018-07-22 15:08:56 +02:00
* Run the specific code.
*
2016-10-03 17:08:24 +00:00
* @param array $row
*
* @return array
2018-07-22 15:08:56 +02:00
*
2016-10-03 17:08:24 +00:00
*/
public function run(array $row): array
{
2017-12-12 20:53:16 +01:00
$this->row = array_values($row);
if (count($this->row) >= 8) { // check if the array is correct
2016-10-04 17:50:01 +00:00
switch ($this->row[4]) { // Get value for the mutation type
case 'GT': // InternetBankieren
2016-10-04 17:50:01 +00:00
case 'OV': // Overschrijving
case 'VZ': // Verzamelbetaling
case 'IC': // Incasso
2020-02-23 18:37:41 +01:00
case 'DV': // Divers
$this->removeIBANIngDescription(); // Remove "IBAN:", because it is already at "Tegenrekening"
$this->removeNameIngDescription(); // Remove "Naam:", because it is already at "Naam/ Omschrijving"
2017-12-12 20:53:16 +01:00
// if "tegenrekening" empty, copy the description. Primitive, but it works.
$this->copyDescriptionToOpposite();
2016-10-03 17:08:24 +00:00
break;
2016-10-09 07:58:27 +02:00
case 'BA': // Betaalautomaat
2016-10-03 17:08:24 +00:00
$this->addNameIngDescription();
break;
}
}
return $this->row;
}
/**
* Add the Opposing name from cell 1 in the description for Betaalautomaten
2017-11-15 12:25:49 +01:00
* Otherwise the description is only: 'Pasvolgnr:<nr> <date> Transactie:<NR> Term:<nr>'.
*/
protected function addNameIngDescription(): void
{
2016-10-09 07:58:27 +02:00
$this->row[8] = $this->row[1] . ' ' . $this->row[8];
}
2016-10-03 17:08:24 +00:00
/**
2016-10-04 17:50:01 +00:00
* Remove IBAN number out of the description
2017-11-15 12:25:49 +01:00
* Default description of Description is: Naam: <OPPOS NAME> Omschrijving: <DESCRIPTION> IBAN: <OPPOS IBAN NR>.
2016-10-03 17:08:24 +00:00
*/
protected function removeIBANIngDescription(): void
2016-10-03 17:08:24 +00:00
{
2016-10-04 17:50:01 +00:00
// Try replace the iban number with nothing. The IBAN nr is found in the third row
$this->row[8] = preg_replace('/\sIBAN:\s' . $this->row[3] . '/', '', $this->row[8]);
2016-10-03 17:08:24 +00:00
}
/**
2017-11-15 12:25:49 +01:00
* Remove name from the description (Remove everything before the description incl the word 'Omschrijving' ).
2016-10-03 17:08:24 +00:00
*/
protected function removeNameIngDescription(): void
2016-10-03 17:08:24 +00:00
{
2017-12-12 20:53:16 +01:00
// Try remove everything before the 'Omschrijving'
2016-10-03 17:08:24 +00:00
$this->row[8] = preg_replace('/.+Omschrijving: /', '', $this->row[8]);
}
2017-12-12 20:53:16 +01:00
/**
2018-07-22 15:08:56 +02:00
* Copy description to name of opposite account.
2017-12-12 20:53:16 +01:00
*/
private function copyDescriptionToOpposite(): void
{
$search = ['Naar Oranje Spaarrekening ', 'Afschrijvingen'];
if ('' === (string)$this->row[3]) {
2017-12-12 20:53:16 +01:00
$this->row[3] = trim(str_ireplace($search, '', $this->row[8]));
}
}
2016-10-03 17:08:24 +00:00
}