Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
tests/config/data/bankCsvExports/sparkasse-wrong-structure.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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";"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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";"" |