@@ -, +, @@ --- C4/Biblio.pm | 45 ++++++++++++++++++++ acqui/addorderiso2709.pl | 7 +++- .../intranet-tmpl/prog/en/modules/acqui/basket.tt | 9 ++-- 3 files changed, 56 insertions(+), 5 deletions(-) --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -84,6 +84,7 @@ BEGIN { &GetXmlBiblio &GetCOinSBiblio &GetMarcPrice + &MungeMarcPrice &GetMarcQuantity &GetAuthorisedValueDesc @@ -1279,12 +1280,56 @@ sub GetMarcPrice { for my $field ( $record->field(@listtags) ) { for my $subfield_value ($field->subfield($subfield)){ #check value + $subfield_value = MungeMarcPrice( $subfield_value ); return $subfield_value if ($subfield_value); } } return 0; # no price found } +=head2 MungeMarcPrice + +Return the best guess at what the actual price is from a price field. +=cut + +sub MungeMarcPrice { + my ( $price ) = @_; + + return unless ( $price =~ m/\d/ ); ## No digits means no price. + + ## Look for the currency symbol of the active currency, if it's there, + ## start the price string right after the symbol. This allows us to prefer + ## this native currency price over other currency prices, if possible. + my $active_currency = C4::Context->dbh->selectrow_hashref( 'SELECT * FROM currency WHERE active = 1', {} ); + my $symbol = quotemeta( $active_currency->{'symbol'} ); + if ( $price =~ m/$symbol/ ) { + my @parts = split(/$symbol/, $price ); + $price = $parts[1]; + } + + ## Grab the first number in the string ( can use commas or periods for thousands separator and/or decimal separator ) + ( $price ) = $price =~ m/([\d\,\.]+[[\,\.]\d\d]?)/; + + ## Split price into array on periods and commas + my @parts = split(/[\,\.]/, $price); + + ## If the last grouping of digits is more than 2 characters, assume there is no decimal value and put it back. + my $decimal = pop( @parts ); + if ( length( $decimal ) > 2 ) { + push( @parts, $decimal ); + $decimal = ''; + } + + $price = join('', @parts ); + + if ( $decimal ) { + $price .= ".$decimal"; + } + + return $price; +} + + =head2 GetMarcQuantity return the quantity of a book. Used in acquisition only, when importing a file an iso2709 from a bookseller --- a/acqui/addorderiso2709.pl +++ a/acqui/addorderiso2709.pl @@ -207,9 +207,14 @@ if ($op eq ""){ # filter by storing only the 1st number # we suppose the currency is correct, as we have no possibilities to get it. my $price= GetMarcPrice($marcrecord, C4::Context->preference('marcflavour')); - if ($price){ + + ## unformat_number will choke if there is more than one period (.) in $price + ## MARC standards do not limit this field to a single period, so unless there + ## is only one period, skip number unformatting. + unless ( $price =~ /\..*\./ ) { $price = $num->unformat_number($price); } + if ($price){ $orderinfo{'listprice'} = $price; eval { --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -269,6 +269,7 @@   [% qty_total %] [% total_est_gsti %] +   [% END %] @@ -285,10 +286,10 @@ [% IF ( books_loo.publicationyear ) %], [% books_loo.publicationyear %][% END %]

- [% books_loo.rrp %] - [% books_loo.ecost %] - [% books_loo.quantity %] - [% books_loo.line_total %] + [% books_loo.rrp %] + [% books_loo.ecost %] + [% books_loo.quantity %] + [% books_loo.line_total %] [% books_loo.budget_name %] [% IF ( active ) %] [% UNLESS ( closedate ) %] --