Lines 21-33
use strict;
Link Here
|
21 |
use warnings; |
21 |
use warnings; |
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::Debug; |
24 |
use C4::Context; |
25 |
use C4::Context; |
25 |
require C4::Dates; |
26 |
require C4::Dates; |
26 |
|
27 |
|
27 |
use Algorithm::CheckDigits; |
28 |
use Algorithm::CheckDigits; |
28 |
|
29 |
|
29 |
my $DEBUG = 0; |
|
|
30 |
|
31 |
=head1 |
30 |
=head1 |
32 |
|
31 |
|
33 |
plugin_parameters : other parameters added when the plugin is called by the dopop function |
32 |
plugin_parameters : other parameters added when the plugin is called by the dopop function |
Lines 67-73
sub plugin_javascript {
Link Here
|
67 |
my $query; |
66 |
my $query; |
68 |
my $scr; |
67 |
my $scr; |
69 |
my $autoBarcodeType = C4::Context->preference("autoBarcode"); |
68 |
my $autoBarcodeType = C4::Context->preference("autoBarcode"); |
70 |
warn "Barcode type = $autoBarcodeType" if $DEBUG; |
69 |
warn "Barcode type = $autoBarcodeType" if $debug; |
71 |
if ((not $autoBarcodeType) or $autoBarcodeType eq 'OFF') { |
70 |
if ((not $autoBarcodeType) or $autoBarcodeType eq 'OFF') { |
72 |
# don't return a value unless we have the appropriate syspref set |
71 |
# don't return a value unless we have the appropriate syspref set |
73 |
return ($function_name, |
72 |
return ($function_name, |
Lines 83-89
sub plugin_javascript {
Link Here
|
83 |
my $sth=$dbh->prepare($query); |
82 |
my $sth=$dbh->prepare($query); |
84 |
$sth->execute("$year%"); |
83 |
$sth->execute("$year%"); |
85 |
while (my ($count)= $sth->fetchrow_array) { |
84 |
while (my ($count)= $sth->fetchrow_array) { |
86 |
warn "Examining Record: $count" if $DEBUG; |
85 |
warn "Examining Record: $count" if $debug; |
87 |
$nextnum = $count if $count; |
86 |
$nextnum = $count if $count; |
88 |
} |
87 |
} |
89 |
$nextnum++; |
88 |
$nextnum++; |
Lines 100-105
sub plugin_javascript {
Link Here
|
100 |
} |
99 |
} |
101 |
$nextnum++; |
100 |
$nextnum++; |
102 |
} |
101 |
} |
|
|
102 |
|
103 |
|
103 |
elsif ($autoBarcodeType eq 'hbyymmincr') { # Generates a barcode where hb = home branch Code, yymm = year/month catalogued, incr = incremental number, reset yearly -fbcit |
104 |
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); |
105 |
$year = substr($year, -2); |
105 |
$query = "SELECT MAX(CAST(SUBSTRING(barcode,-4) AS signed)) AS number FROM items WHERE barcode REGEXP ?"; |
106 |
$query = "SELECT MAX(CAST(SUBSTRING(barcode,-4) AS signed)) AS number FROM items WHERE barcode REGEXP ?"; |
Lines 108-119
sub plugin_javascript {
Link Here
|
108 |
while (my ($count)= $sth->fetchrow_array) { |
109 |
while (my ($count)= $sth->fetchrow_array) { |
109 |
$nextnum = $count if $count; |
110 |
$nextnum = $count if $count; |
110 |
$nextnum = 0 if $nextnum == 9999; # this sequence only allows for cataloging 10000 books per month |
111 |
$nextnum = 0 if $nextnum == 9999; # this sequence only allows for cataloging 10000 books per month |
111 |
warn "Existing incremental number = $nextnum" if $DEBUG; |
112 |
warn "Existing incremental number = $nextnum" if $debug; |
112 |
} |
113 |
} |
113 |
$nextnum++; |
114 |
$nextnum++; |
114 |
$nextnum = sprintf("%0*d", "4",$nextnum); |
115 |
$nextnum = sprintf("%0*d", "4",$nextnum); |
115 |
$nextnum = $year . $mon . $nextnum; |
116 |
$nextnum = $year . $mon . $nextnum; |
116 |
warn "New hbyymmincr Barcode = $nextnum" if $DEBUG; |
117 |
warn "New hbyymmincr Barcode = $nextnum" if $debug; |
|
|
118 |
$scr = " |
119 |
for (i=0 ; i<document.f.field_value.length ; i++) { |
120 |
if (document.f.tag[i].value == '$loctag' && document.f.subfield[i].value == '$locsubfield') { |
121 |
fnum = i; |
122 |
} |
123 |
} |
124 |
if (\$('#' + id).val() == '' || force) { |
125 |
\$('#' + id).val(document.f.field_value[fnum].value + '$nextnum'); |
126 |
} |
127 |
"; |
128 |
} |
129 |
|
130 |
elsif ($autoBarcodeType eq 'hbincr') { # Generates a barcode where hb = home branch Code, incr = an 8 digit incremental number |
131 |
|
132 |
$query = "SELECT MAX(CAST(SUBSTRING(barcode,-8) AS signed)) AS number FROM items WHERE barcode REGEXP ?"; |
133 |
my $sth = $dbh->prepare($query); |
134 |
$sth->execute("^[-a-zA-Z]{1,}"); |
135 |
while (my ($count)= $sth->fetchrow_array) { |
136 |
$nextnum = $count if $count; |
137 |
|
138 |
warn "Existing incremental number = $nextnum" if $debug; |
139 |
} |
140 |
$nextnum++; |
141 |
$nextnum = sprintf("%0*d", "8",$nextnum); |
142 |
$nextnum = $nextnum; |
143 |
warn "New hbincr Barcode = $nextnum" if $debug; |
117 |
$scr = " |
144 |
$scr = " |
118 |
for (i=0 ; i<document.f.field_value.length ; i++) { |
145 |
for (i=0 ; i<document.f.field_value.length ; i++) { |
119 |
if (document.f.tag[i].value == '$loctag' && document.f.subfield[i].value == '$locsubfield') { |
146 |
if (document.f.tag[i].value == '$loctag' && document.f.subfield[i].value == '$locsubfield') { |
Lines 147-152
sub plugin_javascript {
Link Here
|
147 |
warn "ERROR: unknown autoBarcode: $autoBarcodeType"; |
174 |
warn "ERROR: unknown autoBarcode: $autoBarcodeType"; |
148 |
} |
175 |
} |
149 |
|
176 |
|
|
|
177 |
|
150 |
# default js body (if not filled by hbyymmincr) |
178 |
# default js body (if not filled by hbyymmincr) |
151 |
$scr or $scr = <<END_OF_JS; |
179 |
$scr or $scr = <<END_OF_JS; |
152 |
if (\$('#' + id).val() == '' || force) { |
180 |
if (\$('#' + id).val() == '' || force) { |