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

(-)a/C4/Barcodes/ValueBuilder.pm (-79 / +3 lines)
Lines 1-4 Link Here
1
#!/usr/bin/perl
2
#
1
#
3
# Copyright 2008-2010 Foundations Bible College
2
# Copyright 2008-2010 Foundations Bible College
4
# Parts copyright 2012 C & P Bibliography Services
3
# Parts copyright 2012 C & P Bibliography Services
Lines 18-103 Link Here
18
# You should have received a copy of the GNU General Public License
17
# You should have received a copy of the GNU General Public License
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
19
21
package C4::Barcodes::ValueBuilder::incremental;
22
23
use Modern::Perl;
20
use Modern::Perl;
24
use C4::Context;
25
26
sub get_barcode {
27
    my ($args) = @_;
28
    my $nextnum;
29
    # not the best, two catalogers could add the same barcode easily this way :/
30
    my $query = "select max(abs(barcode)) from items";
31
    my $sth = C4::Context->dbh->prepare($query);
32
    $sth->execute();
33
    while (my ($count)= $sth->fetchrow_array) {
34
        $nextnum = $count;
35
    }
36
    $nextnum++;
37
    return $nextnum;
38
}
39
40
1;
41
42
package C4::Barcodes::ValueBuilder::hbyymmincr;
43
use C4::Context;
44
45
sub get_barcode {
46
    my ($args) = @_;
47
    my $nextnum = 0;
48
    my $year = substr($args->{year}, -2);
49
    my $month = $args->{mon};
50
    my $query = "SELECT MAX(CAST(SUBSTRING(barcode,-4) AS signed)) AS number FROM items WHERE barcode REGEXP ?";
51
    my $sth = C4::Context->dbh->prepare($query);
52
    $sth->execute("^[-a-zA-Z]{1,}$year$month");
53
    while (my ($count)= $sth->fetchrow_array) {
54
        $nextnum = $count if $count;
55
        $nextnum = 0 if $nextnum == 9999; # this sequence only allows for cataloging 9999 items per month
56
    }
57
    $nextnum++;
58
    $nextnum = sprintf("%0*d", "4",$nextnum);
59
    $nextnum = $year . $month . $nextnum;
60
    my $scr = "
61
        var form = document.getElementById('f');
62
        if ( !form ) {
63
            form = document.getElementById('serials_edit');
64
        }
65
        if ( !form ) {
66
            form = document.getElementById('Aform');
67
        }
68
        for (i=0 ; i<form.field_value.length ; i++) {
69
            if (form.tag[i].value == '$args->{loctag}' && form.subfield[i].value == '$args->{locsubfield}') {
70
                fnum = i;
71
            }
72
        }
73
    if (\$('#' + id).val() == '') {
74
        \$('#' + id).val(form.field_value[fnum].value + '$nextnum');
75
    }
76
    ";
77
    return $nextnum, $scr;
78
}
79
80
81
package C4::Barcodes::ValueBuilder::annual;
82
use C4::Context;
83
84
sub get_barcode {
85
    my ($args) = @_;
86
    my $nextnum;
87
    my $query = "select max(cast( substring_index(barcode, '-',-1) as signed)) from items where barcode like ?";
88
    my $sth=C4::Context->dbh->prepare($query);
89
    $sth->execute($args->{year} . '-%');
90
    while (my ($count)= $sth->fetchrow_array) {
91
        $nextnum = $count if $count;
92
    }
93
    $nextnum++;
94
    $nextnum = sprintf("%0*d", "4",$nextnum);
95
    $nextnum = "$args->{year}-$nextnum";
96
    return $nextnum;
97
}
98
99
1;
100
21
22
use C4::Barcodes::ValueBuilder::incremental;
23
use C4::Barcodes::ValueBuilder::hbyymmincr;
24
use C4::Barcodes::ValueBuilder::annual;
101
25
102
=head1 Barcodes::ValueBuilder
26
=head1 Barcodes::ValueBuilder
103
27
(-)a/C4/Barcodes/ValueBuilder/annual.pm (+65 lines)
Line 0 Link Here
1
#
2
# Copyright 2008-2010 Foundations Bible College
3
# Parts copyright 2012 C & P Bibliography Services
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
package C4::Barcodes::ValueBuilder::annual;
21
22
use Modern::Perl;
23
use C4::Context;
24
25
=head1 API
26
27
=cut
28
29
=head2 Functions
30
31
=cut
32
33
=head3 get_barcode
34
35
This is a function for getting the next barcode
36
37
=cut
38
39
sub get_barcode {
40
    my ($args) = @_;
41
    my $nextnum;
42
    my $query = "select max(cast( substring_index(barcode, '-',-1) as signed)) from items where barcode like ?";
43
    my $sth=C4::Context->dbh->prepare($query);
44
    $sth->execute($args->{year} . '-%');
45
    while (my ($count)= $sth->fetchrow_array) {
46
        $nextnum = $count if $count;
47
    }
48
    $nextnum++;
49
    $nextnum = sprintf("%0*d", "4",$nextnum);
50
    $nextnum = "$args->{year}-$nextnum";
51
    return $nextnum;
52
}
53
54
=head1 Barcodes::ValueBuilder
55
56
This module is intended as a shim to ease the eventual transition from
57
having all barcode-related code in the value builder plugin .pl file
58
to using C4::Barcodes. Since the shift will require a rather significant
59
amount of refactoring, this module will return value builder-formatted
60
results, at first by merely running the code that was formerly in the
61
barcodes.pl value builder, but later by using C4::Barcodes.
62
63
=cut
64
65
1;
(-)a/C4/Barcodes/ValueBuilder/hbyymmincr.pm (+85 lines)
Line 0 Link Here
1
#
2
# Copyright 2008-2010 Foundations Bible College
3
# Parts copyright 2012 C & P Bibliography Services
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
package C4::Barcodes::ValueBuilder::hbyymmincr;
21
22
use Modern::Perl;
23
use C4::Context;
24
25
=head1 API
26
27
=cut
28
29
=head2 Functions
30
31
=cut
32
33
=head3 get_barcode
34
35
This is a function for getting the next barcode
36
37
=cut
38
39
sub get_barcode {
40
    my ($args) = @_;
41
    my $nextnum = 0;
42
    my $year = substr($args->{year}, -2);
43
    my $month = $args->{mon};
44
    my $query = "SELECT MAX(CAST(SUBSTRING(barcode,-4) AS signed)) AS number FROM items WHERE barcode REGEXP ?";
45
    my $sth = C4::Context->dbh->prepare($query);
46
    $sth->execute("^[-a-zA-Z]{1,}$year$month");
47
    while (my ($count)= $sth->fetchrow_array) {
48
        $nextnum = $count if $count;
49
        $nextnum = 0 if $nextnum == 9999; # this sequence only allows for cataloging 9999 items per month
50
    }
51
    $nextnum++;
52
    $nextnum = sprintf("%0*d", "4",$nextnum);
53
    $nextnum = $year . $month . $nextnum;
54
    my $scr = "
55
        var form = document.getElementById('f');
56
        if ( !form ) {
57
            form = document.getElementById('serials_edit');
58
        }
59
        if ( !form ) {
60
            form = document.getElementById('Aform');
61
        }
62
        for (i=0 ; i<form.field_value.length ; i++) {
63
            if (form.tag[i].value == '$args->{loctag}' && form.subfield[i].value == '$args->{locsubfield}') {
64
                fnum = i;
65
            }
66
        }
67
    if (\$('#' + id).val() == '') {
68
        \$('#' + id).val(form.field_value[fnum].value + '$nextnum');
69
    }
70
    ";
71
    return $nextnum, $scr;
72
}
73
74
=head1 Barcodes::ValueBuilder
75
76
This module is intended as a shim to ease the eventual transition from
77
having all barcode-related code in the value builder plugin .pl file
78
to using C4::Barcodes. Since the shift will require a rather significant
79
amount of refactoring, this module will return value builder-formatted
80
results, at first by merely running the code that was formerly in the
81
barcodes.pl value builder, but later by using C4::Barcodes.
82
83
=cut
84
85
1;
(-)a/C4/Barcodes/ValueBuilder/incremental.pm (-1 / +64 lines)
Line 0 Link Here
0
- 
1
#
2
# Copyright 2008-2010 Foundations Bible College
3
# Parts copyright 2012 C & P Bibliography Services
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
package C4::Barcodes::ValueBuilder::incremental;
21
22
use Modern::Perl;
23
use C4::Context;
24
25
=head1 API
26
27
=cut
28
29
=head2 Functions
30
31
=cut
32
33
=head3 get_barcode
34
35
This is a function for getting the next barcode
36
37
=cut
38
39
sub get_barcode {
40
    my ($args) = @_;
41
    my $nextnum;
42
    # not the best, two catalogers could add the same barcode easily this way :/
43
    my $query = "select max(abs(barcode)) from items";
44
    my $sth = C4::Context->dbh->prepare($query);
45
    $sth->execute();
46
    while (my ($count)= $sth->fetchrow_array) {
47
        $nextnum = $count;
48
    }
49
    $nextnum++;
50
    return $nextnum;
51
}
52
53
=head1 Barcodes::ValueBuilder
54
55
This module is intended as a shim to ease the eventual transition from
56
having all barcode-related code in the value builder plugin .pl file
57
to using C4::Barcodes. Since the shift will require a rather significant
58
amount of refactoring, this module will return value builder-formatted
59
results, at first by merely running the code that was formerly in the
60
barcodes.pl value builder, but later by using C4::Barcodes.
61
62
=cut
63
64
1;

Return to bug 26683