Update ING description for #1015

This commit is contained in:
James Cole 2017-12-12 20:53:16 +01:00
parent 1b4edae4d9
commit bad889d450
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
4 changed files with 32 additions and 13 deletions

View File

@ -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;
}

View File

@ -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 correct
switch ($this->row[4]) { // Get value for the mutation type
case 'GT': // InternetBankieren
@ -69,6 +69,8 @@ class IngDescription implements SpecificInterface
case '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]));
}
}
}

View File

@ -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;

View File

@ -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();