Skip to content

Commit

Permalink
Merge pull request #19 from sevenymedia/master
Browse files Browse the repository at this point in the history
Bugfix for floats
  • Loading branch information
fruitl00p committed Sep 16, 2015
2 parents 133ea6c + 85974b6 commit ec5c4fe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/Parser/Banking/Mt940/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,11 @@ protected function parseStatementStartPrice()
if (preg_match('/:60F:([CD])?.*EUR([\d,\.]+)*/', $this->getCurrentStatementData(), $results)
&& !empty($results[2])
) {
$fltSanitizedPrice = $this->sanitizePrice($results[2]);
if (!empty($results[1])) {
$results[2] = ($results[1] === 'D' ? -$results[2] : $results[2]);
$fltSanitizedPrice = ($results[1] === 'D' ? -$fltSanitizedPrice : $fltSanitizedPrice);
}
return $this->sanitizePrice($results[2]);
return $fltSanitizedPrice;
}

return '';
Expand All @@ -241,10 +242,11 @@ protected function parseStatementEndPrice()
if (preg_match('/:62F:([CD])?.*EUR([\d,\.]+)*/', $this->getCurrentStatementData(), $results)
&& !empty($results[2])
) {
$fltSanitizedPrice = $this->sanitizePrice($results[2]);
if (!empty($results[1])) {
$results[2] = ($results[1] === 'D' ? -$results[2] : $results[2]);
$fltSanitizedPrice = ($results[1] === 'D' ? -$fltSanitizedPrice : $fltSanitizedPrice);
}
return $this->sanitizePrice($results[2]);
return $fltSanitizedPrice;
}

return '';
Expand Down
2 changes: 1 addition & 1 deletion test/Parser/Banking/Mt940/Engine/Rabo/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public function testParseStatementBank()
public function testInitialNegativeStatementBalance() {
$this->engine->loadString(file_get_contents(__DIR__ . '/sample2'));
$statements = $this->engine->parse();
$this->assertEquals(-1000, $statements[0]->getStartPrice());
$this->assertEquals(-1000.12, $statements[0]->getStartPrice());
}
}
5 changes: 2 additions & 3 deletions test/Parser/Banking/Mt940/Engine/Rabo/sample2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
:20:940A030107
:25:0800003200000001610722 EUR
:28:00000/00
:60F:D030106EUR000000001000.00
:62F:C030107EUR000000002145.00
:60F:D030106EUR000000001000.12
:62F:C030107EUR000000002145.23
:20:940A030108


0 comments on commit ec5c4fe

Please sign in to comment.