Lines 20-25
use Modern::Perl;
Link Here
|
20 |
use Mojo::Base 'Mojolicious::Controller'; |
20 |
use Mojo::Base 'Mojolicious::Controller'; |
21 |
|
21 |
|
22 |
use Koha::Biblios; |
22 |
use Koha::Biblios; |
|
|
23 |
use Koha::DateUtils; |
23 |
use Koha::Ratings; |
24 |
use Koha::Ratings; |
24 |
use Koha::RecordProcessor; |
25 |
use Koha::RecordProcessor; |
25 |
use C4::Biblio qw( DelBiblio ); |
26 |
use C4::Biblio qw( DelBiblio ); |
Lines 305-313
sub add_item {
Link Here
|
305 |
|
306 |
|
306 |
my $item = Koha::Item->new_from_api($body); |
307 |
my $item = Koha::Item->new_from_api($body); |
307 |
|
308 |
|
308 |
if ( ! defined $item->barcode && C4::Context->preference('autoBarcode') eq 'incremental' ) { |
309 |
if ( !defined $item->barcode ) { |
309 |
my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode; |
310 |
|
310 |
$item->barcode($barcode); |
311 |
# FIXME This should be moved to Koha::Item->store |
|
|
312 |
my $autoBarcode = C4::Context->preference('autoBarcode'); |
313 |
my $barcode = ''; |
314 |
## Please see file perltidy.ERR |
315 |
if ( !$autoBarcode || $autoBarcode eq 'OFF' ) { |
316 |
|
317 |
#We do nothing |
318 |
} |
319 |
elsif ( $autoBarcode eq 'incremental' ) { |
320 |
($barcode) = |
321 |
C4::Barcodes::ValueBuilder::incremental::get_barcode; |
322 |
} |
323 |
elsif ( $autoBarcode eq 'annual' ) { |
324 |
my $year = Koha::DateUtils::dt_from_string()->year(); |
325 |
($barcode) = |
326 |
C4::Barcodes::ValueBuilder::annual::get_barcode({ year => $year }); |
327 |
} |
328 |
elsif ( $autoBarcode eq 'hbyymmincr' ) { |
329 |
|
330 |
# Generates a barcode where hb = home branch Code, yymm = year/month catalogued, incr = incremental number, reset yearly -fbcit |
331 |
my $now = Koha::DateUtils::dt_from_string(); |
332 |
my $year = $now->year(); |
333 |
my $month = $now->month(); |
334 |
my $homebranch = $item->homebranch // ''; |
335 |
($barcode) = |
336 |
C4::Barcodes::ValueBuilder::hbyymmincr::get_barcode({ year => $year, mon => $month }); |
337 |
$barcode = $homebranch . $barcode; |
338 |
} |
339 |
elsif ( $autoBarcode eq 'EAN13' ) { |
340 |
|
341 |
# not the best, two catalogers could add the same barcode easily this way :/ |
342 |
my $query = "select max(abs(barcode)) from items"; |
343 |
my $dbh = C4::Context->dbh; |
344 |
my $sth = $dbh->prepare($query); |
345 |
$sth->execute(); |
346 |
my $nextnum; |
347 |
while ( my ($last) = $sth->fetchrow_array ) { |
348 |
$nextnum = $last; |
349 |
} |
350 |
my $ean = CheckDigits('ean'); |
351 |
if ( $ean->is_valid($nextnum) ) { |
352 |
my $next = $ean->basenumber($nextnum) + 1; |
353 |
$nextnum = $ean->complete($next); |
354 |
$nextnum = |
355 |
'0' x ( 13 - length($nextnum) ) . $nextnum; # pad zeros |
356 |
} |
357 |
else { |
358 |
warn "ERROR: invalid EAN-13 $nextnum, using increment"; |
359 |
$nextnum++; |
360 |
} |
361 |
$barcode = $nextnum; |
362 |
} |
363 |
else { |
364 |
warn "ERROR: unknown autoBarcode: $autoBarcode"; |
365 |
} |
366 |
$item->barcode($barcode) if $barcode; |
311 |
} |
367 |
} |
312 |
|
368 |
|
313 |
$item->store->discard_changes; |
369 |
$item->store->discard_changes; |
314 |
- |
|
|