Skip to content

Commit

Permalink
add sparkasse for csv upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mrothauer committed May 2, 2022
1 parent 160a0f6 commit a3fc47e
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/app_config.php
Expand Up @@ -82,7 +82,7 @@
'depositForManufacturersStartDate' => '2016-01-01',

/**
* 'Raiffeisen' or 'Volksbank'
* 'Raiffeisen' OR 'Volksbank' OR 'Sparkasse'
*/
'bankNameForCreditSystem' => 'Raiffeisen',

Expand Down
70 changes: 70 additions & 0 deletions src/Lib/Csv/SparkasseBankingReader.php
@@ -0,0 +1,70 @@
<?php
/**
* FoodCoopShop - The open source software for your foodcoop
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @since FoodCoopShop 3.5.0
* @license https://opensource.org/licenses/mit-license.php MIT License
* @author Mario Rothauer <office@foodcoopshop.com>
* @copyright Copyright (c) Mario Rothauer, https://www.rothauer-it.com
* @link https://www.foodcoopshop.com
*/
namespace App\Lib\Csv;

use Cake\Core\Configure;

class SparkasseBankingReader extends BankingReader {

public function configureType(): void
{
$this->setDelimiter(';');
$this->setHeaderOffset(0);
}

public function checkStructureForRecord($record): bool
{

$result = false;

if (count($record) == 11 &&
strlen($record['Buchungsdatum']) == 10 &&
$record['W盲hrung'] == 'EUR' &&
is_numeric(Configure::read('app.numberHelper')->getStringAsFloat($record['Betrag'])) &&
!empty($record['Buchungs-Info'])
) {
$result = true;
}

return $result;
}

public function equalizeStructure(array $records): array
{

$preparedRecords = [];
foreach($records as $record){

$contentFields = [
$record['Buchungs-Info'],
$record['Partnername'],
$record['Partner IBAN'],
$record['Buchungsreferenz'],
];

$record['content'] = join(' ', $contentFields);
$record['amount'] = $record['Betrag'];
$record['date'] = $record['Buchungsdatum'];

$preparedRecords[] = $record;
}

return $preparedRecords;
}


}

?>
54 changes: 54 additions & 0 deletions tests/TestCase/src/Lib/Csv/SparkasseBankingReaderTest.php
@@ -0,0 +1,54 @@
<?php
/**
* FoodCoopShop - The open source software for your foodcoop
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @since FoodCoopShop 3.5.0
* @license https://opensource.org/licenses/mit-license.php MIT License
* @author Mario Rothauer <office@foodcoopshop.com>
* @copyright Copyright (c) Mario Rothauer, https://www.rothauer-it.com
* @link https://www.foodcoopshop.com
*/
use App\Lib\Csv\SparkasseBankingReader;
use App\Test\TestCase\AppCakeTestCase;
use Cake\Core\Configure;

class SparkasseBankingReaderTest extends AppCakeTestCase
{

public function tearDown(): void
{
$this->assertLogFilesForErrors();
}

public function testRead()
{
$reader = SparkasseBankingReader::createFromPath(TESTS . 'config' . DS . 'data' . DS . 'bankCsvExports' . DS . 'sparkasse.csv');
$records = $reader->getPreparedRecords($reader->getRecords());
foreach($records as $record) {
$this->assertEquals(4, count($record));
}

$this->assertEquals('2022-04-13 00:00:00.000000', $records[0]['date']);
$this->assertEquals(18, $records[0]['amount']);
$this->assertEquals(Configure::read('test.adminId'), $records[0]['original_id_customer']);

$this->assertEquals(1, count($records));
}

public function testCheckStructureNotOk()
{
$reader = SparkasseBankingReader::createFromPath(TESTS . 'config' . DS . 'data' . DS . 'bankCsvExports' . DS . 'sparkasse-wrong-structure.csv');
$this->assertFalse($reader->checkStructure());
}

public function testCheckStructureOk()
{
$reader = SparkasseBankingReader::createFromPath(TESTS . 'config' . DS . 'data' . DS . 'bankCsvExports' . DS . 'sparkasse.csv');
$this->assertTrue($reader->checkStructure());
}

}
@@ -0,0 +1,2 @@
"Buchungsdatum";"Betrag";"Buchungs-Info";"Partnername";"Partner IBAN";"BIC/SWIFT";"Partner Kontonummer";"Bankleitzahl";"W盲hrung";"Buchungsreferenz";"Notiz"
xxx"13.04.2022";"18,00";"E-COMM 18,00 DE K1 12.04. 08:20 TEDXTEXT 2022... 280";"TEDXTEXT 2022...";"";"";"77319989";"20320";"EUR";"203202204132ALB-006CCQ7BI8W8";""
2 changes: 2 additions & 0 deletions tests/config/data/bankCsvExports/sparkasse.csv
@@ -0,0 +1,2 @@
"Buchungsdatum";"Betrag";"Buchungs-Info";"Partnername";"Partner IBAN";"BIC/SWIFT";"Partner Kontonummer";"Bankleitzahl";"W盲hrung";"Buchungsreferenz";"Notiz"
"13.04.2022";"18,00";"E-COMM 18,00 DE K1 12.04. 08:20 TEDXTEXT 2022... 280 838B34A3";"TEDXTEXT 2022...";"";"";"77319989";"20320";"EUR";"203202204132ALB-006CCQ7BI8W8";""

0 comments on commit a3fc47e

Please sign in to comment.