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

135 lines
4.2 KiB
PHP
Raw Normal View History

2016-10-03 12:08:24 -05:00
<?php
/**
* IngDescription.php
2017-11-15 05:25:49 -06:00
* Copyright (C) 2016 https://github.com/tomwerf.
2016-10-03 12:08:24 -05:00
*
2017-10-21 01:40:00 -05:00
* This file is part of Firefly III.
*
2017-10-21 01:40:00 -05:00
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2017-12-17 07:41:58 -06:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
2016-10-03 12:08:24 -05:00
*/
declare(strict_types=1);
2016-10-03 12:08:24 -05:00
namespace FireflyIII\Import\Specifics;
/**
2017-11-15 05:25:49 -06:00
* Class IngDescription.
2016-10-03 12:08:24 -05: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 12:08:24 -05:00
*/
class IngDescription implements SpecificInterface
{
2017-11-15 05:25:49 -06:00
/** @var array */
2016-10-03 12:08:24 -05:00
public $row;
/**
* @return string
*/
public static function getDescription(): string
{
2016-10-04 12:50:01 -05:00
return 'Create better descriptions in ING import files.';
2016-10-03 12:08:24 -05:00
}
/**
* @return string
*/
public static function getName(): string
{
2016-10-04 12:50:01 -05:00
return 'ING description';
2016-10-03 12:08:24 -05:00
}
/**
* @param array $row
*
* @return array
*/
public function run(array $row): array
{
2017-12-12 13:53:16 -06:00
$this->row = array_values($row);
2016-10-04 12:50:01 -05:00
if (count($this->row) >= 8) { // check if the array is correct
switch ($this->row[4]) { // Get value for the mutation type
case 'GT': // InternetBankieren
2016-10-04 12:50:01 -05:00
case 'OV': // Overschrijving
case 'VZ': // Verzamelbetaling
case 'IC': // Incasso
2016-10-03 12:08:24 -05:00
$this->removeIBANIngDescription();
$this->removeNameIngDescription();
2017-12-12 13:53:16 -06:00
// if "tegenrekening" empty, copy the description. Primitive, but it works.
$this->copyDescriptionToOpposite();
2016-10-03 12:08:24 -05:00
break;
2016-10-09 00:58:27 -05:00
case 'BA': // Betaalautomaat
2016-10-03 12:08:24 -05:00
$this->addNameIngDescription();
break;
}
}
return $this->row;
}
/**
* Add the Opposing name from cell 1 in the description for Betaalautomaten
2017-11-15 05:25:49 -06:00
* Otherwise the description is only: 'Pasvolgnr:<nr> <date> Transactie:<NR> Term:<nr>'.
*
* @return bool true
*/
protected function addNameIngDescription()
{
2016-10-09 00:58:27 -05:00
$this->row[8] = $this->row[1] . ' ' . $this->row[8];
return true;
}
2016-10-03 12:08:24 -05:00
/**
2016-10-04 12:50:01 -05:00
* Remove IBAN number out of the description
2017-11-15 05:25:49 -06:00
* Default description of Description is: Naam: <OPPOS NAME> Omschrijving: <DESCRIPTION> IBAN: <OPPOS IBAN NR>.
2016-10-03 12:08:24 -05:00
*
2016-10-04 12:50:01 -05:00
* @return bool true
2016-10-03 12:08:24 -05:00
*/
protected function removeIBANIngDescription()
{
2016-10-04 12:50:01 -05: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 12:08:24 -05:00
return true;
}
/**
2017-11-15 05:25:49 -06:00
* Remove name from the description (Remove everything before the description incl the word 'Omschrijving' ).
2016-10-03 12:08:24 -05:00
*
2016-10-04 12:50:01 -05:00
* @return bool true
2016-10-03 12:08:24 -05:00
*/
protected function removeNameIngDescription()
{
2017-12-12 13:53:16 -06:00
// Try remove everything before the 'Omschrijving'
2016-10-03 12:08:24 -05:00
$this->row[8] = preg_replace('/.+Omschrijving: /', '', $this->row[8]);
return true;
}
2017-12-12 13:53:16 -06:00
/**
*
*/
private function copyDescriptionToOpposite(): void
{
$search = ['Naar Oranje Spaarrekening ', 'Afschrijvingen'];
2017-12-22 11:32:43 -06:00
if (0 === strlen($this->row[3])) {
2017-12-12 13:53:16 -06:00
$this->row[3] = trim(str_ireplace($search, '', $this->row[8]));
}
}
2016-10-03 12:08:24 -05:00
}