View | Details | Raw Unified | Return to bug 9593
Collapse All | Expand All

(-)a/C4/Biblio.pm (-30 / +42 lines)
Lines 1477-1514 Return the best guess at what the actual price is from a price field. Link Here
1477
1477
1478
sub MungeMarcPrice {
1478
sub MungeMarcPrice {
1479
    my ( $price ) = @_;
1479
    my ( $price ) = @_;
1480
1481
    return unless ( $price =~ m/\d/ ); ## No digits means no price.
1480
    return unless ( $price =~ m/\d/ ); ## No digits means no price.
1482
1481
    # Look for the currency symbol and the normalized code of the active currency, if it's there,
1483
    ## Look for the currency symbol of the active currency, if it's there,
1482
    my $active_currency = C4::Budgets->GetCurrency();
1484
    ## start the price string right after the symbol. This allows us to prefer
1483
    my $symbol = $active_currency->{'symbol'};
1485
    ## this native currency price over other currency prices, if possible.
1484
    my $isocode = $active_currency->{'isocode'};
1486
    my $active_currency = C4::Context->dbh->selectrow_hashref( 'SELECT * FROM currency WHERE active = 1', {} );
1485
    my $localprice;
1487
    my $symbol = quotemeta( $active_currency->{'symbol'} );
1486
    if ( $symbol ) {
1488
    if ( $price =~ m/$symbol/ ) {
1487
        my @matches =($price=~ /
1489
        my @parts = split(/$symbol/, $price );
1488
            \s?
1490
        $price = $parts[1];
1489
            (                          # start of capturing parenthesis
1491
    }
1490
            (?:
1492
1491
            (?:\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'
1493
    ## Grab the first number in the string ( can use commas or periods for thousands separator and/or decimal separator )
1492
            |(?:\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'
1494
    ( $price ) = $price =~ m/([\d\,\.]+[[\,\.]\d\d]?)/;
1493
            )
1495
1494
            \s?\p{Sc}?\s?              # followed or not by a whitespace. \p{Sc}?\s? are for cases like '25$ USD'
1496
    ## Split price into array on periods and commas
1495
            (?:
1497
    my @parts = split(/[\,\.]/, $price);
1496
            (?:\p{Sc}|[a-zA-Z]){1,3}   # followed by same block as symbol block
1498
1497
            |(?:\d+[\p{P}\s]?){1,4}    # or by same block as digits block
1499
    ## If the last grouping of digits is more than 2 characters, assume there is no decimal value and put it back.
1498
            )
1500
    my $decimal = pop( @parts );
1499
            \s?                        # followed or not by a whitespace
1501
    if ( length( $decimal ) > 2 ) {
1500
            )                          # end of capturing parenthesis
1502
        push( @parts, $decimal );
1501
            (?:\p{P}|\z)               # followed by a punctuation sign or by the end of the string
1503
        $decimal = '';
1502
            /gx);
1504
    }
1503
1505
1504
        if ( @matches ) {
1506
    $price = join('', @parts );
1505
            foreach ( @matches ) {
1507
1506
                $localprice = $_ and last if index($_, $isocode)>=0;
1508
    if ( $decimal ) {
1507
            }
1509
     $price .= ".$decimal";
1508
            if ( !$localprice ) {
1509
                foreach ( @matches ) {
1510
                    $localprice = $_ and last if $_=~ /(^|[^A-Za-z\p{Sc}])\Q$symbol\E([^A-Za-z\p{Sc}]|\z)/;
1511
                }
1512
            }
1513
        }
1514
        $price=$localprice;
1515
        if ($price) {
1516
            # eliminate symbol/isocode from the string
1517
            ( $price ) = $price =~ m/(\d[\d\,\. ]*\d{0,2})/;
1518
            # remove comma,dot or space when used as separators from hundreds
1519
            $price =~s/[\,\. ](\d{3})/$1/g;
1520
            # convert comma to dot to ensure correct display of decimals if existing
1521
            $price =~s/,/./;
1522
        }
1510
    }
1523
    }
1511
1512
    return $price;
1524
    return $price;
1513
}
1525
}
1514
1526
(-)a/admin/currency.pl (-2 / +5 lines)
Lines 185-190 sub add_validate { Link Here
185
    my $rec = {
185
    my $rec = {
186
        rate     => $input->param('rate'),
186
        rate     => $input->param('rate'),
187
        symbol   => $input->param('symbol') || q{},
187
        symbol   => $input->param('symbol') || q{},
188
        isocode  => $input->param('isocode') || q{},
188
        active   => $input->param('active') || 0,
189
        active   => $input->param('active') || 0,
189
        currency => $input->param('currency'),
190
        currency => $input->param('currency'),
190
    };
191
    };
Lines 198-217 sub add_validate { Link Here
198
        {}, $input->param('currency') );
199
        {}, $input->param('currency') );
199
    if ($row_count) {
200
    if ($row_count) {
200
        $dbh->do(
201
        $dbh->do(
201
q|UPDATE currency SET rate = ?, symbol = ?, active = ? WHERE currency = ? |,
202
q|UPDATE currency SET rate = ?, symbol = ?, isocode = ?, active = ? WHERE currency = ? |,
202
            {},
203
            {},
203
            $rec->{rate},
204
            $rec->{rate},
204
            $rec->{symbol},
205
            $rec->{symbol},
206
            $rec->{isocode},
205
            $rec->{active},
207
            $rec->{active},
206
            $rec->{currency}
208
            $rec->{currency}
207
        );
209
        );
208
    } else {
210
    } else {
209
        $dbh->do(
211
        $dbh->do(
210
q|INSERT INTO currency (currency, rate, symbol, active) VALUES (?,?,?,?) |,
212
q|INSERT INTO currency (currency, rate, symbol, isocode, active) VALUES (?,?,?,?,?) |,
211
            {},
213
            {},
212
            $rec->{currency},
214
            $rec->{currency},
213
            $rec->{rate},
215
            $rec->{rate},
214
            $rec->{symbol},
216
            $rec->{symbol},
217
            $rec->{isocode},
215
            $rec->{active}
218
            $rec->{active}
216
        );
219
        );
217
220
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 692-697 DROP TABLE IF EXISTS `currency`; Link Here
692
CREATE TABLE `currency` (
692
CREATE TABLE `currency` (
693
  `currency` varchar(10) NOT NULL default '',
693
  `currency` varchar(10) NOT NULL default '',
694
  `symbol` varchar(5) default NULL,
694
  `symbol` varchar(5) default NULL,
695
  `isocode` varchar(5) default NULL,
695
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
696
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
696
  `rate` float(15,5) default NULL,
697
  `rate` float(15,5) default NULL,
697
  `active` tinyint(1) default NULL,
698
  `active` tinyint(1) default NULL,
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +6 lines)
Lines 7146-7152 if ( CheckVersion($DBversion) ) { Link Here
7146
    SetVersion($DBversion);
7146
    SetVersion($DBversion);
7147
}
7147
}
7148
7148
7149
7150
$DBversion = "3.13.00.022";
7149
$DBversion = "3.13.00.022";
7151
if ( CheckVersion($DBversion) ) {
7150
if ( CheckVersion($DBversion) ) {
7152
    $dbh->do("DELETE from auth_tag_structure WHERE tagfield IN ('68a','68b')");
7151
    $dbh->do("DELETE from auth_tag_structure WHERE tagfield IN ('68a','68b')");
Lines 7595-7600 if ( CheckVersion($DBversion) ) { Link Here
7595
    SetVersion($DBversion);
7594
    SetVersion($DBversion);
7596
}
7595
}
7597
7596
7597
$DBversion = "3.13.00.XXX";
7598
if ( CheckVersion($DBversion) ) {
7599
    $dbh->do("ALTER TABLE currency ADD isocode VARCHAR(5) default NULL AFTER symbol;");
7600
    print "Upgrade to $DBversion done (Added isocode to the currency table)\n";
7601
    SetVersion($DBversion);
7602
}
7598
7603
7599
=head1 FUNCTIONS
7604
=head1 FUNCTIONS
7600
7605
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt (-3 / +11 lines)
Lines 24-29 Link Here
24
        if (f.symbol.value.length==0) {
24
        if (f.symbol.value.length==0) {
25
            _alertString += _("- Symbol missing") + "\n";
25
            _alertString += _("- Symbol missing") + "\n";
26
        }
26
        }
27
        if (f.isocode.value.length==0) {
28
            _alertString += _("- Iso code missing") + "\n";
29
        }
27
        if (_alertString.length==0) {
30
        if (_alertString.length==0) {
28
            document.Aform.submit();
31
            document.Aform.submit();
29
        } else {
32
        } else {
Lines 72-78 Link Here
72
<div id="bd">
75
<div id="bd">
73
    <div id="yui-main">
76
    <div id="yui-main">
74
    <div class="yui-b">
77
    <div class="yui-b">
75
78
<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/>
79
The symbol may be the pure currency sign or a string in which it's included ( like '$US' ).</p></div>
76
[% IF ( else ) %]
80
[% IF ( else ) %]
77
<div id="toolbar" class="btn-toolbar">
81
<div id="toolbar" class="btn-toolbar">
78
    <a class="btn btn-small" id="newcurrency" href="[% script_name %]?op=add_form"><i class="icon-plus"></i> New currency</a>
82
    <a class="btn btn-small" id="newcurrency" href="[% script_name %]?op=add_form"><i class="icon-plus"></i> New currency</a>
Lines 107-113 Link Here
107
            <label for="symbol">Symbol: </label>
111
            <label for="symbol">Symbol: </label>
108
            <input type="text" name="symbol" id="symbol" size="5" maxlength="5" value="[% symbol %]" />
112
            <input type="text" name="symbol" id="symbol" size="5" maxlength="5" value="[% symbol %]" />
109
        </li>
113
        </li>
110
114
        <li>
115
            <label for="isocode">Iso code: </label>
116
            <input type="text" name="isocode" id="isocode" size="5" maxlength="5" value="[% isocode %]" />
117
        </li>
111
        <li>
118
        <li>
112
            <span class="label">Last updated: </span>[% timestamp %]
119
            <span class="label">Last updated: </span>[% timestamp %]
113
        </li>
120
        </li>
Lines 187-192 Link Here
187
            <th>Currency</th>
194
            <th>Currency</th>
188
            <th>Rate</th>
195
            <th>Rate</th>
189
            <th>Symbol</th>
196
            <th>Symbol</th>
197
            <th>Iso code</th>
190
            <th>Last updated</th>
198
            <th>Last updated</th>
191
            <th>Active</th>
199
            <th>Active</th>
192
            <th colspan="2">Actions&nbsp;</th>
200
            <th colspan="2">Actions&nbsp;</th>
Lines 200-205 Link Here
200
            <td>[% loo.currency %]</td>
208
            <td>[% loo.currency %]</td>
201
            <td>[% loo.rate %]</td>
209
            <td>[% loo.rate %]</td>
202
            <td>[% loo.symbol |html %]</td>
210
            <td>[% loo.symbol |html %]</td>
211
            <td>[% loo.isocode |html %]</td>
203
            <td>[% loo.timestamp %]</td>
212
            <td>[% loo.timestamp %]</td>
204
            <td style="color:green;">[% IF ( loo.active ) %]✓[% END %]</td>
213
            <td style="color:green;">[% IF ( loo.active ) %]✓[% END %]</td>
205
            <td><a href="[% loo.script_name %]?op=add_form&amp;searchfield=[% loo.currency %]">Edit</a></td>
214
            <td><a href="[% loo.script_name %]?op=add_form&amp;searchfield=[% loo.currency %]">Edit</a></td>
206
- 

Return to bug 9593