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

(-)a/C4/Barcodes/ValueBuilder.pm (-72 / +64 lines)
Lines 18-110 Link Here
18
# You should have received a copy of the GNU General Public License
18
# You should have received a copy of the GNU General Public License
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
20
21
{
21
package C4::Barcodes::ValueBuilder::incremental;
22
    package C4::Barcodes::ValueBuilder::incremental;
23
22
24
    use Modern::Perl;
23
use Modern::Perl;
25
    use C4::Context;
24
use C4::Context;
26
    my $DEBUG = 0;
27
25
28
    sub get_barcode {
26
sub get_barcode {
29
        my ($args) = @_;
27
    my ($args) = @_;
30
        my $nextnum;
28
    my $nextnum;
31
        # not the best, two catalogers could add the same barcode easily this way :/
29
    # not the best, two catalogers could add the same barcode easily this way :/
32
        my $query = "select max(abs(barcode)) from items";
30
    my $query = "select max(abs(barcode)) from items";
33
        my $sth = C4::Context->dbh->prepare($query);
31
    my $sth = C4::Context->dbh->prepare($query);
34
        $sth->execute();
32
    $sth->execute();
35
        while (my ($count)= $sth->fetchrow_array) {
33
    while (my ($count)= $sth->fetchrow_array) {
36
            $nextnum = $count;
34
        $nextnum = $count;
37
        }
38
        $nextnum++;
39
        return $nextnum;
40
    }
35
    }
36
    $nextnum++;
37
    return $nextnum;
41
}
38
}
42
39
43
{
40
1;
44
    package C4::Barcodes::ValueBuilder::hbyymmincr;
41
45
    use C4::Context;
42
package C4::Barcodes::ValueBuilder::hbyymmincr;
46
    my $DEBUG = 0;
43
use C4::Context;
47
44
48
    sub get_barcode {
45
sub get_barcode {
49
        my ($args) = @_;
46
    my ($args) = @_;
50
        my $nextnum = 0;
47
    my $nextnum = 0;
51
        my $year = substr($args->{year}, -2);
48
    my $year = substr($args->{year}, -2);
52
        my $month = $args->{mon};
49
    my $month = $args->{mon};
53
        my $query = "SELECT MAX(CAST(SUBSTRING(barcode,-4) AS signed)) AS number FROM items WHERE barcode REGEXP ?";
50
    my $query = "SELECT MAX(CAST(SUBSTRING(barcode,-4) AS signed)) AS number FROM items WHERE barcode REGEXP ?";
54
        my $sth = C4::Context->dbh->prepare($query);
51
    my $sth = C4::Context->dbh->prepare($query);
55
        $sth->execute("^[-a-zA-Z]{1,}$year$month");
52
    $sth->execute("^[-a-zA-Z]{1,}$year$month");
56
        while (my ($count)= $sth->fetchrow_array) {
53
    while (my ($count)= $sth->fetchrow_array) {
57
            $nextnum = $count if $count;
54
        $nextnum = $count if $count;
58
            $nextnum = 0 if $nextnum == 9999; # this sequence only allows for cataloging 9999 items per month
55
        $nextnum = 0 if $nextnum == 9999; # this sequence only allows for cataloging 9999 items per month
59
                warn "Existing incremental number = $nextnum" if $DEBUG;
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');
60
        }
64
        }
61
        $nextnum++;
65
        if ( !form ) {
62
        $nextnum = sprintf("%0*d", "4",$nextnum);
66
            form = document.getElementById('Aform');
63
        $nextnum = $year . $month . $nextnum;
67
        }
64
        warn "New hbyymmincr Barcode = $nextnum" if $DEBUG;
68
        for (i=0 ; i<form.field_value.length ; i++) {
65
        my $scr = "
69
            if (form.tag[i].value == '$args->{loctag}' && form.subfield[i].value == '$args->{locsubfield}') {
66
            var form = document.getElementById('f');
70
                fnum = i;
67
            if ( !form ) {
68
                form = document.getElementById('serials_edit');
69
            }
70
            if ( !form ) {
71
                form = document.getElementById('Aform');
72
            }
73
            for (i=0 ; i<form.field_value.length ; i++) {
74
                if (form.tag[i].value == '$args->{loctag}' && form.subfield[i].value == '$args->{locsubfield}') {
75
                    fnum = i;
76
                }
77
            }
71
            }
78
        if (\$('#' + id).val() == '') {
79
            \$('#' + id).val(form.field_value[fnum].value + '$nextnum');
80
        }
72
        }
81
        ";
73
    if (\$('#' + id).val() == '') {
82
        return $nextnum, $scr;
74
        \$('#' + id).val(form.field_value[fnum].value + '$nextnum');
83
    }
75
    }
76
    ";
77
    return $nextnum, $scr;
84
}
78
}
85
79
86
{
87
    package C4::Barcodes::ValueBuilder::annual;
88
    use C4::Context;
89
    my $DEBUG = 0;
90
80
91
    sub get_barcode {
81
package C4::Barcodes::ValueBuilder::annual;
92
        my ($args) = @_;
82
use C4::Context;
93
        my $nextnum;
83
94
        my $query = "select max(cast( substring_index(barcode, '-',-1) as signed)) from items where barcode like ?";
84
sub get_barcode {
95
        my $sth=C4::Context->dbh->prepare($query);
85
    my ($args) = @_;
96
        $sth->execute($args->{year} . '-%');
86
    my $nextnum;
97
        while (my ($count)= $sth->fetchrow_array) {
87
    my $query = "select max(cast( substring_index(barcode, '-',-1) as signed)) from items where barcode like ?";
98
            warn "Examining Record: $count" if $DEBUG;
88
    my $sth=C4::Context->dbh->prepare($query);
99
            $nextnum = $count if $count;
89
    $sth->execute($args->{year} . '-%');
100
        }
90
    while (my ($count)= $sth->fetchrow_array) {
101
        $nextnum++;
91
        $nextnum = $count if $count;
102
        $nextnum = sprintf("%0*d", "4",$nextnum);
103
        $nextnum = "$args->{year}-$nextnum";
104
        return $nextnum;
105
    }
92
    }
93
    $nextnum++;
94
    $nextnum = sprintf("%0*d", "4",$nextnum);
95
    $nextnum = "$args->{year}-$nextnum";
96
    return $nextnum;
106
}
97
}
107
98
99
1;
100
108
101
109
=head1 Barcodes::ValueBuilder
102
=head1 Barcodes::ValueBuilder
110
103
111
- 

Return to bug 21395