Lines 1466-1471
sub GetMarcPrice {
Link Here
|
1466 |
for my $subfield_value ($field->subfield($subfield)){ |
1466 |
for my $subfield_value ($field->subfield($subfield)){ |
1467 |
#check value |
1467 |
#check value |
1468 |
$subfield_value = MungeMarcPrice( $subfield_value ); |
1468 |
$subfield_value = MungeMarcPrice( $subfield_value ); |
|
|
1469 |
( $subfield_value ) = $subfield_value =~ m/(\d[\d\,\. ]*\d{0,2})/; |
1470 |
# remove comma,dot or space when used as separators from hundreds |
1471 |
$subfield_value =~s/[\,\. ](\d{3})/$1/g; |
1472 |
# convert comma to dot to ensure correct display of decimals if existing |
1473 |
$subfield_value =~s/,/./; |
1469 |
return $subfield_value if ($subfield_value); |
1474 |
return $subfield_value if ($subfield_value); |
1470 |
} |
1475 |
} |
1471 |
} |
1476 |
} |
Lines 1479-1516
Return the best guess at what the actual price is from a price field.
Link Here
|
1479 |
|
1484 |
|
1480 |
sub MungeMarcPrice { |
1485 |
sub MungeMarcPrice { |
1481 |
my ( $price ) = @_; |
1486 |
my ( $price ) = @_; |
1482 |
|
|
|
1483 |
return unless ( $price =~ m/\d/ ); ## No digits means no price. |
1487 |
return unless ( $price =~ m/\d/ ); ## No digits means no price. |
1484 |
|
1488 |
# Look for the currency symbol and the normalized code of the active currency, if it's there, |
1485 |
## Look for the currency symbol of the active currency, if it's there, |
1489 |
my $active_currency = C4::Budgets->GetCurrency(); |
1486 |
## start the price string right after the symbol. This allows us to prefer |
1490 |
my $symbol = $active_currency->{'symbol'}; |
1487 |
## this native currency price over other currency prices, if possible. |
1491 |
my $isocode = $active_currency->{'isocode'}; |
1488 |
my $active_currency = C4::Context->dbh->selectrow_hashref( 'SELECT * FROM currency WHERE active = 1', {} ); |
1492 |
my $localprice; |
1489 |
my $symbol = quotemeta( $active_currency->{'symbol'} ); |
1493 |
if ( $symbol ) { |
1490 |
if ( $price =~ m/$symbol/ ) { |
1494 |
my @matches =($price=~ / |
1491 |
my @parts = split(/$symbol/, $price ); |
1495 |
\s? |
1492 |
$price = $parts[1]; |
1496 |
( # start of capturing parenthesis |
1493 |
} |
1497 |
(?: |
1494 |
|
1498 |
(?:\p{Sc}|[a-zA-Z]){1,3} # currency sign (unicode propriety) or alphabetical character whitin 1 to 3 occurrences : call this whole block 'symbol block' |
1495 |
## Grab the first number in the string ( can use commas or periods for thousands separator and/or decimal separator ) |
1499 |
|(?:\d+[\p{P}\s]?){1,4} # or else at least one digit followed or not by a punctuation sign or whitespace, all theese within 1 to 4 occurrences : call this whole block 'digits block' |
1496 |
( $price ) = $price =~ m/([\d\,\.]+[[\,\.]\d\d]?)/; |
1500 |
) |
1497 |
|
1501 |
\s?\p{Sc}?\s? # followed or not by a whitespace. \p{Sc}?\s? are for cases like '25$ USD' |
1498 |
## Split price into array on periods and commas |
1502 |
(?: |
1499 |
my @parts = split(/[\,\.]/, $price); |
1503 |
(?:\p{Sc}|[a-zA-Z]){1,3} # followed by same block as symbol block |
1500 |
|
1504 |
|(?:\d+[\p{P}\s]?){1,4} # or by same block as digits block |
1501 |
## If the last grouping of digits is more than 2 characters, assume there is no decimal value and put it back. |
1505 |
) |
1502 |
my $decimal = pop( @parts ); |
1506 |
\s? # followed or not by a whitespace |
1503 |
if ( length( $decimal ) > 2 ) { |
1507 |
) # end of capturing parenthesis |
1504 |
push( @parts, $decimal ); |
1508 |
(?:\p{P}|\z) # followed by a punctuation sign or by the end of the string |
1505 |
$decimal = ''; |
1509 |
/gx); |
1506 |
} |
1510 |
|
1507 |
|
1511 |
if ( @matches ) { |
1508 |
$price = join('', @parts ); |
1512 |
foreach ( @matches ) { |
1509 |
|
1513 |
$localprice = $_ and last if index($_, $isocode)>=0; |
1510 |
if ( $decimal ) { |
1514 |
} |
1511 |
$price .= ".$decimal"; |
1515 |
if ( !$localprice ) { |
|
|
1516 |
foreach ( @matches ) { |
1517 |
$localprice = $_ and last if $_=~ /(^|[^A-Za-z\p{Sc}])\Q$symbol\E([^A-Za-z\p{Sc}]|\z)/; |
1518 |
} |
1519 |
} |
1520 |
} |
1521 |
$price=$localprice; |
1512 |
} |
1522 |
} |
1513 |
|
|
|
1514 |
return $price; |
1523 |
return $price; |
1515 |
} |
1524 |
} |
1516 |
|
1525 |
|