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