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

(-)a/C4/Barcodes/ValueBuilder.pm (-8 / +11 lines)
Lines 24-39 use C4::Context; Link Here
24
24
25
sub get_barcode {
25
sub get_barcode {
26
    my ($args) = @_;
26
    my ($args) = @_;
27
    my $nextnum;
28
    # not the best, two catalogers could add the same barcode easily this way :/
27
    # not the best, two catalogers could add the same barcode easily this way :/
29
    my $query = "select max(abs(barcode)) from items";
28
    my $query = q|
30
    my $sth = C4::Context->dbh->prepare($query);
29
        SELECT ABS(barcode), barcode
31
    $sth->execute();
30
        FROM items
32
    while (my ($count)= $sth->fetchrow_array) {
31
        ORDER BY ABS(barcode) DESC LIMIT 1
33
        $nextnum = $count;
32
    |;
33
    my $dbh = C4::Context->dbh;
34
    my ( $barcode, $max) = $dbh->selectrow_array($query);
35
    my $next_barcode = ++$max;
36
    if ( $barcode && $barcode =~ m|^0| ) {
37
        $next_barcode = sprintf "%0" . length($barcode) . "d", $next_barcode;
34
    }
38
    }
35
    $nextnum++;
39
    return $next_barcode;
36
    return $nextnum;
37
}
40
}
38
41
39
1;
42
1;
(-)a/t/db_dependent/Barcodes_ValueBuilder.t (-2 / +10 lines)
Lines 16-22 Link Here
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
18
19
use Test::More tests => 7;
19
use Test::More tests => 8;
20
use Test::MockModule;
20
use Test::MockModule;
21
use t::lib::TestBuilder;
21
use t::lib::TestBuilder;
22
22
Lines 77-81 ok(length($scr) > 0, 'hbyymmincr javascript'); Link Here
77
is($nextnum, '2012-0035', 'annual barcode');
77
is($nextnum, '2012-0035', 'annual barcode');
78
is($scr, undef, 'annual javascript');
78
is($scr, undef, 'annual javascript');
79
79
80
my $item_5 = $builder->build_sample_item(
81
    {
82
        barcode => '0033333074344564'
83
    }
84
);
85
86
($nextnum, $scr) = C4::Barcodes::ValueBuilder::incremental::get_barcode(\%args);
87
is($nextnum, "0033333074344565", 'incremental barcode must keep leading zeros');
88
80
$schema->storage->txn_rollback;
89
$schema->storage->txn_rollback;
81
90
82
- 

Return to bug 27426