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

(-)a/C4/Biblio.pm (-30 / +26 lines)
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/;
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-1517 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 ( $isocode and $price=~/[A-Z]{3}/ ) {
1490
    if ( $price =~ m/$symbol/ ) {
1494
        $price =~ s/\p{Currency_Symbol}//g; # in case price look like '$800 LRD, $10 USD'.
1491
        my @parts = split(/$symbol/, $price );
1495
        # find if the currency code precedes or follows the numeric part of price
1492
        $price = $parts[1];
1496
        if ( substr($price,0,1) =~/[0-9]/ ) {
1493
    }
1497
            ($localprice)=$price =~ /([\p{P}\d\s]+$isocode)/;
1494
1498
        } else {
1495
    ## Grab the first number in the string ( can use commas or periods for thousands separator and/or decimal separator )
1499
            ($localprice)=$price =~ /($isocode[\p{P}\d\s]+)/;
1496
    ( $price ) = $price =~ m/([\d\,\.]+[[\,\.]\d\d]?)/;
1500
        }
1497
1498
    ## Split price into array on periods and commas
1499
    my @parts = split(/[\,\.]/, $price);
1500
1501
    ## If the last grouping of digits is more than 2 characters, assume there is no decimal value and put it back.
1502
    my $decimal = pop( @parts );
1503
    if ( length( $decimal ) > 2 ) {
1504
        push( @parts, $decimal );
1505
        $decimal = '';
1506
    }
1501
    }
1507
1502
    if ( !$localprice and $symbol ) {
1508
    $price = join('', @parts );
1503
        if ( substr($price,0,1) =~/[0-9]/ ) {
1509
1504
            ($localprice)=$price =~ /([\p{P}\d\s]+\Q$symbol\E)/;
1510
    if ( $decimal ) {
1505
        } else {
1511
     $price .= ".$decimal";
1506
            ($localprice)=$price =~ /(\Q$symbol\E[\p{P}\d\s]+)/;
1507
        }
1512
    }
1508
    }
1513
1509
    $localprice||= $price;
1514
    return $price;
1510
    return $localprice;
1515
}
1511
}
1516
1512
1517
1513
(-)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/updatedatabase.pl (+7 lines)
Lines 6784-6789 if ( CheckVersion($DBversion) ) { Link Here
6784
    SetVersion ($DBversion);
6784
    SetVersion ($DBversion);
6785
}
6785
}
6786
6786
6787
$DBversion = "3.11.00.XXX";
6788
if ( CheckVersion($DBversion) ) {
6789
    $dbh->do("ALTER TABLE currency ADD isocode VARCHAR(5) default NULL AFTER symbol;");
6790
    print "Upgrade to $DBversion done (Added isocode to the currency table)\n";
6791
    SetVersion($DBversion);
6792
}
6793
6787
6794
6788
=head1 FUNCTIONS
6795
=head1 FUNCTIONS
6789
6796
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt (-2 / +6 lines)
Lines 107-113 Link Here
107
            <label for="symbol">Symbol: </label>
107
            <label for="symbol">Symbol: </label>
108
            <input type="text" name="symbol" id="symbol" size="5" maxlength="5" value="[% symbol %]" />
108
            <input type="text" name="symbol" id="symbol" size="5" maxlength="5" value="[% symbol %]" />
109
        </li>
109
        </li>
110
110
        <li>
111
            <label for="isocode">Iso code: </label>
112
            <input type="text" name="isocode" id="isocode" size="5" maxlength="5" value="[% isocode %]" />
113
        </li>
111
        <li>
114
        <li>
112
            <span class="label">Last updated: </span>[% timestamp %]
115
            <span class="label">Last updated: </span>[% timestamp %]
113
        </li>
116
        </li>
Lines 187-192 Link Here
187
            <th>Currency</th>
190
            <th>Currency</th>
188
            <th>Rate</th>
191
            <th>Rate</th>
189
            <th>Symbol</th>
192
            <th>Symbol</th>
193
            <th>Code iso</th>
190
            <th>Last updated</th>
194
            <th>Last updated</th>
191
            <th>Active</th>
195
            <th>Active</th>
192
            <th colspan="2">Actions&nbsp;</th>
196
            <th colspan="2">Actions&nbsp;</th>
Lines 200-205 Link Here
200
            <td>[% loo.currency %]</td>
204
            <td>[% loo.currency %]</td>
201
            <td>[% loo.rate %]</td>
205
            <td>[% loo.rate %]</td>
202
            <td>[% loo.symbol |html %]</td>
206
            <td>[% loo.symbol |html %]</td>
207
            <td>[% loo.isocode |html %]</td>
203
            <td>[% loo.timestamp %]</td>
208
            <td>[% loo.timestamp %]</td>
204
            <td style="color:green;">[% IF ( loo.active ) %]✓[% END %]</td>
209
            <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>
210
            <td><a href="[% loo.script_name %]?op=add_form&amp;searchfield=[% loo.currency %]">Edit</a></td>
206
- 

Return to bug 9593