Bugzilla – Attachment 21274 Details for
Bug 9593
Prices not imported correctly from a staged file
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9593 Prices not imported correctly from a staged file
0001-Bug-9593-Prices-not-imported-correctly-from-a-staged.patch (text/plain), 10.02 KB, created by
Koha Team University Lyon 3
on 2013-09-20 13:27:31 UTC
(
hide
)
Description:
Bug 9593 Prices not imported correctly from a staged file
Filename:
MIME Type:
Creator:
Koha Team University Lyon 3
Created:
2013-09-20 13:27:31 UTC
Size:
10.02 KB
patch
obsolete
>From 8cbcf4c3ce9494fa228fb7bdef5ebd201f57088f Mon Sep 17 00:00:00 2001 >From: Lyon3 Team <koha@univ-lyon3.fr> >Date: Tue, 4 Jun 2013 15:38:15 +0200 >Subject: [PATCH] Bug 9593 Prices not imported correctly from a staged file > >Bug 9593 Prices not imported correctly from a staged file > >Initial bug : >When there's a round price with no decimals after it, >or when the symbol is after the digits, the price is not captured >by regular expression in MungeMarcPrice routine and the variable is not initialized. > >Enhancement : >The MungeMarcPrice routine had been widely modified. >It 's still possible to priority pick the active currency but unlike the previous mechanism >that worked only for prices preceded by the currency sign, it's now valid wherever the symbol is situated. >As symbol you may enter a pure currency sign as well as a string including it like '$US'. >Moreover, an 'isocode' column had been added in currency table (editable in the pro interface >from Administration/Currencies and exchange rates). So the active currency can be picked either >through its symbol or through its iso code. >--- > C4/Biblio.pm | 69 +++++++++++--------- > admin/currency.pl | 7 ++- > installer/data/mysql/kohastructure.sql | 1 + > installer/data/mysql/updatedatabase.pl | 8 ++ > .../prog/en/modules/admin/currency.tt | 13 +++- > 5 files changed, 64 insertions(+), 34 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index cf83ae6..86c7701 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -1466,6 +1466,11 @@ sub GetMarcPrice { > for my $subfield_value ($field->subfield($subfield)){ > #check value > $subfield_value = MungeMarcPrice( $subfield_value ); >+ ( $subfield_value ) = $subfield_value =~ m/(\d[\d\,\. ]*\d{0,2})/; >+ # remove comma,dot or space when used as separators from hundreds >+ $subfield_value =~s/[\,\. ](\d{3})/$1/g; >+ # convert comma to dot to ensure correct display of decimals if existing >+ $subfield_value =~s/,/./; > return $subfield_value if ($subfield_value); > } > } >@@ -1479,38 +1484,42 @@ Return the best guess at what the actual price is from a price field. > > 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"; >+ # Look for the currency symbol and the normalized code of the active currency, if it's there, >+ my $active_currency = C4::Budgets->GetCurrency(); >+ my $symbol = $active_currency->{'symbol'}; >+ my $isocode = $active_currency->{'isocode'}; >+ my $localprice; >+ if ( $symbol ) { >+ my @matches =($price=~ / >+ \s? >+ ( # start of capturing parenthesis >+ (?: >+ (?:\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' >+ |(?:\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' >+ ) >+ \s?\p{Sc}?\s? # followed or not by a whitespace. \p{Sc}?\s? are for cases like '25$ USD' >+ (?: >+ (?:\p{Sc}|[a-zA-Z]){1,3} # followed by same block as symbol block >+ |(?:\d+[\p{P}\s]?){1,4} # or by same block as digits block >+ ) >+ \s? # followed or not by a whitespace >+ ) # end of capturing parenthesis >+ (?:\p{P}|\z) # followed by a punctuation sign or by the end of the string >+ /gx); >+ >+ if ( @matches ) { >+ foreach ( @matches ) { >+ $localprice = $_ and last if index($_, $isocode)>=0; >+ } >+ if ( !$localprice ) { >+ foreach ( @matches ) { >+ $localprice = $_ and last if $_=~ /(^|[^A-Za-z\p{Sc}])\Q$symbol\E([^A-Za-z\p{Sc}]|\z)/; >+ } >+ } >+ } >+ $price=$localprice; > } >- > return $price; > } > >diff --git a/admin/currency.pl b/admin/currency.pl >index ea22431..abbdca2 100755 >--- a/admin/currency.pl >+++ b/admin/currency.pl >@@ -185,6 +185,7 @@ sub add_validate { > my $rec = { > rate => $input->param('rate'), > symbol => $input->param('symbol') || q{}, >+ isocode => $input->param('isocode') || q{}, > active => $input->param('active') || 0, > currency => $input->param('currency'), > }; >@@ -198,20 +199,22 @@ sub add_validate { > {}, $input->param('currency') ); > if ($row_count) { > $dbh->do( >-q|UPDATE currency SET rate = ?, symbol = ?, active = ? WHERE currency = ? |, >+q|UPDATE currency SET rate = ?, symbol = ?, isocode = ?, active = ? WHERE currency = ? |, > {}, > $rec->{rate}, > $rec->{symbol}, >+ $rec->{isocode}, > $rec->{active}, > $rec->{currency} > ); > } else { > $dbh->do( >-q|INSERT INTO currency (currency, rate, symbol, active) VALUES (?,?,?,?) |, >+q|INSERT INTO currency (currency, rate, symbol, isocode, active) VALUES (?,?,?,?,?) |, > {}, > $rec->{currency}, > $rec->{rate}, > $rec->{symbol}, >+ $rec->{isocode}, > $rec->{active} > ); > >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index fdab879..29414a6 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -691,6 +691,7 @@ DROP TABLE IF EXISTS `currency`; > CREATE TABLE `currency` ( > `currency` varchar(10) NOT NULL default '', > `symbol` varchar(5) default NULL, >+ `isocode` varchar(5) default NULL, > `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, > `rate` float(15,5) default NULL, > `active` tinyint(1) default NULL, >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 31f494a..9f0ae7d 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -7139,6 +7139,14 @@ if ( CheckVersion($DBversion) ) { > SetVersion ($DBversion); > } > >+$DBversion = "3.13.00.XXX"; >+if ( CheckVersion($DBversion) ) { >+ $dbh->do("ALTER TABLE currency ADD isocode VARCHAR(5) default NULL AFTER symbol;"); >+ print "Upgrade to $DBversion done (Added isocode to the currency table)\n"; >+ SetVersion($DBversion); >+} >+ >+ > =head1 FUNCTIONS > > =head2 TableExists($table) >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt >index 99f693b..fce3b21 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt >@@ -24,6 +24,9 @@ > if (f.symbol.value.length==0) { > _alertString += _("- Symbol missing") + "\n"; > } >+ if (f.isocode.value.length==0) { >+ _alertString += _("- Iso code missing") + "\n"; >+ } > if (_alertString.length==0) { > document.Aform.submit(); > } else { >@@ -72,7 +75,8 @@ > <div id="bd"> > <div id="yui-main"> > <div class="yui-b"> >- >+<div class="message dialog"><p style="text-align:justify" >The active currency priority will be picked during the importation process from a staged file whenever the price data is provided under different currencies.<br/> >+The symbol may be the pure currency sign or a string in which it's included ( like '$US' ).</p></div> > [% IF ( else ) %] > <div id="toolbar" class="btn-toolbar"> > <a class="btn btn-small" id="newcurrency" href="[% script_name %]?op=add_form"><i class="icon-plus"></i> New currency</a> >@@ -107,7 +111,10 @@ > <label for="symbol">Symbol: </label> > <input type="text" name="symbol" id="symbol" size="5" maxlength="5" value="[% symbol %]" /> > </li> >- >+ <li> >+ <label for="isocode">Iso code: </label> >+ <input type="text" name="isocode" id="isocode" size="5" maxlength="5" value="[% isocode %]" /> >+ </li> > <li> > <span class="label">Last updated: </span>[% timestamp %] > </li> >@@ -187,6 +194,7 @@ > <th>Currency</th> > <th>Rate</th> > <th>Symbol</th> >+ <th>Iso code</th> > <th>Last updated</th> > <th>Active</th> > <th colspan="2">Actions </th> >@@ -200,6 +208,7 @@ > <td>[% loo.currency %]</td> > <td>[% loo.rate %]</td> > <td>[% loo.symbol |html %]</td> >+ <td>[% loo.isocode |html %]</td> > <td>[% loo.timestamp %]</td> > <td style="color:green;">[% IF ( loo.active ) %]รข[% END %]</td> > <td><a href="[% loo.script_name %]?op=add_form&searchfield=[% loo.currency %]">Edit</a></td> >-- >1.7.2.5 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 9593
:
15269
|
15270
|
15569
|
15587
|
15615
|
17923
|
17948
|
17949
|
18070
|
18075
|
18265
|
18405
|
18640
|
21274
|
21477
|
22151
|
22541
|
22820
|
23580
|
24086
|
25984
|
26125
|
26127
|
27006
|
27009
|
27123
|
27124
|
27391
|
27392
|
27657
|
27658