Lines 22-27
use warnings;
Link Here
|
22 |
no warnings 'redefine'; # otherwise loading up multiple plugins fills the log with subroutine redefine warnings |
22 |
no warnings 'redefine'; # otherwise loading up multiple plugins fills the log with subroutine redefine warnings |
23 |
|
23 |
|
24 |
use C4::Context; |
24 |
use C4::Context; |
|
|
25 |
require C4::Barcodes::ValueBuilder; |
25 |
require C4::Dates; |
26 |
require C4::Dates; |
26 |
|
27 |
|
27 |
use Algorithm::CheckDigits; |
28 |
use Algorithm::CheckDigits; |
Lines 57-70
the 3 scripts are inserted after the <input> in the html code
Link Here
|
57 |
sub plugin_javascript { |
58 |
sub plugin_javascript { |
58 |
my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_; |
59 |
my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_; |
59 |
my $function_name= "barcode".(int(rand(100000))+1); |
60 |
my $function_name= "barcode".(int(rand(100000))+1); |
|
|
61 |
my %args; |
60 |
|
62 |
|
61 |
# find today's date |
63 |
# find today's date |
62 |
my ($year, $mon, $day) = split('-', C4::Dates->today('iso')); |
64 |
($args{year}, $args{mon}, $args{day}) = split('-', C4::Dates->today('iso')); |
63 |
my ($tag,$subfield) = GetMarcFromKohaField("items.barcode", ''); |
65 |
($args{tag},$args{subfield}) = GetMarcFromKohaField("items.barcode", ''); |
64 |
my ($loctag,$locsubfield) = GetMarcFromKohaField("items.homebranch", ''); |
66 |
($args{loctag},$args{locsubfield}) = GetMarcFromKohaField("items.homebranch", ''); |
65 |
|
67 |
|
66 |
my $nextnum; |
68 |
my $nextnum; |
67 |
my $query; |
|
|
68 |
my $scr; |
69 |
my $scr; |
69 |
my $autoBarcodeType = C4::Context->preference("autoBarcode"); |
70 |
my $autoBarcodeType = C4::Context->preference("autoBarcode"); |
70 |
warn "Barcode type = $autoBarcodeType" if $DEBUG; |
71 |
warn "Barcode type = $autoBarcodeType" if $DEBUG; |
Lines 79-129
sub plugin_javascript {
Link Here
|
79 |
</script>"); |
80 |
</script>"); |
80 |
} |
81 |
} |
81 |
if ($autoBarcodeType eq 'annual') { |
82 |
if ($autoBarcodeType eq 'annual') { |
82 |
$query = "select max(cast( substring_index(barcode, '-',-1) as signed)) from items where barcode like ?"; |
83 |
($nextnum, $scr) = C4::Barcodes::ValueBuilder::annual::get_barcode(\%args); |
83 |
my $sth=$dbh->prepare($query); |
|
|
84 |
$sth->execute("$year%"); |
85 |
while (my ($count)= $sth->fetchrow_array) { |
86 |
warn "Examining Record: $count" if $DEBUG; |
87 |
$nextnum = $count if $count; |
88 |
} |
89 |
$nextnum++; |
90 |
$nextnum = sprintf("%0*d", "4",$nextnum); |
91 |
$nextnum = "$year-$nextnum"; |
92 |
} |
84 |
} |
93 |
elsif ($autoBarcodeType eq 'incremental') { |
85 |
elsif ($autoBarcodeType eq 'incremental') { |
94 |
# not the best, two catalogers could add the same barcode easily this way :/ |
86 |
($nextnum, $scr) = C4::Barcodes::ValueBuilder::incremental::get_barcode(\%args); |
95 |
$query = "select max(abs(barcode)) from items"; |
|
|
96 |
my $sth = $dbh->prepare($query); |
97 |
$sth->execute(); |
98 |
while (my ($count)= $sth->fetchrow_array) { |
99 |
$nextnum = $count; |
100 |
} |
101 |
$nextnum++; |
102 |
} |
87 |
} |
103 |
elsif ($autoBarcodeType eq 'hbyymmincr') { # Generates a barcode where hb = home branch Code, yymm = year/month catalogued, incr = incremental number, reset yearly -fbcit |
88 |
elsif ($autoBarcodeType eq 'hbyymmincr') { # Generates a barcode where hb = home branch Code, yymm = year/month catalogued, incr = incremental number, reset yearly -fbcit |
104 |
$year = substr($year, -2); |
89 |
($nextnum, $scr) = C4::Barcodes::ValueBuilder::hbyymmincr::get_barcode(\%args); |
105 |
$query = "SELECT MAX(CAST(SUBSTRING(barcode,-4) AS signed)) AS number FROM items WHERE barcode REGEXP ?"; |
|
|
106 |
my $sth = $dbh->prepare($query); |
107 |
$sth->execute("^[-a-zA-Z]{1,}$year"); |
108 |
while (my ($count)= $sth->fetchrow_array) { |
109 |
$nextnum = $count if $count; |
110 |
$nextnum = 0 if $nextnum == 9999; # this sequence only allows for cataloging 10000 books per month |
111 |
warn "Existing incremental number = $nextnum" if $DEBUG; |
112 |
} |
113 |
$nextnum++; |
114 |
$nextnum = sprintf("%0*d", "4",$nextnum); |
115 |
$nextnum = $year . $mon . $nextnum; |
116 |
warn "New hbyymmincr Barcode = $nextnum" if $DEBUG; |
117 |
$scr = " |
118 |
for (i=0 ; i<document.f.field_value.length ; i++) { |
119 |
if (document.f.tag[i].value == '$loctag' && document.f.subfield[i].value == '$locsubfield') { |
120 |
fnum = i; |
121 |
} |
122 |
} |
123 |
if (\$('#' + id).val() == '' || force) { |
124 |
\$('#' + id).val(document.f.field_value[fnum].value + '$nextnum'); |
125 |
} |
126 |
"; |
127 |
} |
90 |
} |
128 |
elsif ($autoBarcodeType eq 'EAN13') { |
91 |
elsif ($autoBarcodeType eq 'EAN13') { |
129 |
# not the best, two catalogers could add the same barcode easily this way :/ |
92 |
# not the best, two catalogers could add the same barcode easily this way :/ |