mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Updates for parseformat
This commit is contained in:
parent
f325aecaed
commit
c4807be9df
@ -211,6 +211,7 @@ class Document extends BaseModel
|
||||
public function link()
|
||||
{
|
||||
$entity_id = $this->encodePrimaryKey($this->documentable_id);
|
||||
$link = '';
|
||||
|
||||
match($this->documentable_type) {
|
||||
'App\Models\Vendor' => $link = "vendors/{$entity_id}",
|
||||
@ -222,7 +223,7 @@ class Document extends BaseModel
|
||||
'App\Models\Payment' => $link = "payments/{$entity_id}/edit",
|
||||
'App\Models\Task' => $link = "tasks/{$entity_id}/edit",
|
||||
'App\Models\Client' => $link = "clients/{$entity_id}",
|
||||
default => $link = ''
|
||||
default => $link = '',
|
||||
};
|
||||
|
||||
return $link;
|
||||
|
@ -93,7 +93,7 @@ class Number
|
||||
* @param string $value The formatted number to be converted back to float
|
||||
* @return float The formatted value
|
||||
*/
|
||||
public static function parseFloat($value)
|
||||
public static function parseFloat2($value)
|
||||
{
|
||||
if(!$value)
|
||||
return 0;
|
||||
@ -104,7 +104,7 @@ class Number
|
||||
$decimal = strpos($value, '.');
|
||||
$comma = strpos($value, ',');
|
||||
|
||||
if(!$comma) //no comma must be a decimal number already
|
||||
if($comma === false) //no comma must be a decimal number already
|
||||
return (float) $value;
|
||||
|
||||
if($decimal < $comma){ //decimal before a comma = euro
|
||||
@ -143,9 +143,9 @@ class Number
|
||||
// return (float) $s;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
//next iteration of float parsing
|
||||
public static function parseFloatv2($value)
|
||||
public static function parseFloat($value)
|
||||
{
|
||||
|
||||
if(!$value) {
|
||||
@ -187,7 +187,8 @@ class Number
|
||||
return (float)$value;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public static function parseStringFloat($value)
|
||||
{
|
||||
$value = preg_replace('/[^0-9-.]+/', '', $value);
|
||||
|
@ -20,6 +20,53 @@ use Tests\TestCase;
|
||||
*/
|
||||
class NumberTest extends TestCase
|
||||
{
|
||||
|
||||
public function testRangeOfNumberFormats()
|
||||
{
|
||||
|
||||
|
||||
$floatvals = [
|
||||
"22000.76" =>"22 000,76",
|
||||
"22000.76" =>"22.000,76",
|
||||
"22000.76" =>"22,000.76",
|
||||
"22000" =>"22 000",
|
||||
"22000" =>"22,000",
|
||||
"22000" =>"22.000",
|
||||
"22000.76" =>"22000.76",
|
||||
"22000.76" =>"22000,76",
|
||||
"1022000.76" =>"1.022.000,76",
|
||||
"1022000.76" =>"1,022,000.76",
|
||||
"1000000" =>"1,000,000",
|
||||
"1000000" =>"1.000.000",
|
||||
"1022000.76" =>"1022000.76",
|
||||
"1022000.76" =>"1022000,76",
|
||||
"1022000" =>"1022000",
|
||||
"0.76" =>"0.76",
|
||||
"0.76" =>"0,76",
|
||||
"0" =>"0.00",
|
||||
"0" =>"0,00",
|
||||
"1" =>"1.00",
|
||||
"1" =>"1,00",
|
||||
"423545" =>"423545 €",
|
||||
"423545" =>"423,545 €",
|
||||
"423545" =>"423.545 €",
|
||||
"1" =>"1,00 €",
|
||||
"1.02" =>"€ 1.02",
|
||||
"1000.02" =>"1'000,02 EUR",
|
||||
"1000.02" =>"1 000.02$",
|
||||
"1000.02" =>"1,000.02$",
|
||||
"1000.02" =>"1.000,02 EURO"
|
||||
];
|
||||
|
||||
|
||||
foreach($floatvals as $key => $value) {
|
||||
|
||||
$this->assertEquals($key, Number::parseFloat($value));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testNegativeFloatParse()
|
||||
{
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user