Bug 7468: Add warning when range has non-existent barcodes

+ Added a warning when the user selects a range with some non-existent barcodes, and a layout without barcodes.
This allows the user to print barcodes of items not in the database if he so desires, but will warn him if he tries to print only biblios (which results in missing entries or a blank page).

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
David Bourgault 2017-10-05 09:40:19 -04:00 committed by Martin Renvoize
parent 6a7ef5c965
commit dc68633a1f
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
2 changed files with 16 additions and 0 deletions

View File

@ -11,6 +11,9 @@
[% IF ( batches ) %]
<form>
<h3>Click on the following links to download the exported batch(es).</h3>
[% IF warn_empty_range %]
<div style="color: red; font-weight: bold;">Some or all of the barcodes in the range you have selected have no corresponding items. Because you are using a layout without barcodes, this may result in missing entries or a blank page.</div>
[% END %]
[% FOREACH batche IN batches %]
<fieldset>
[% IF ( batche.label_ids ) %]

View File

@ -22,6 +22,7 @@ use Modern::Perl;
use CGI qw ( -utf8 );
use Data::Dumper;
use C4::Context;
use C4::Auth qw(get_template_and_user);
use C4::Output qw(output_html_with_http_headers);
use C4::Creators::Lib qw(get_all_templates get_all_layouts get_output_formats);
@ -110,6 +111,18 @@ if ($op eq 'export') {
);
}
elsif ($from and $to) {
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare('SELECT COUNT(*) AS has_barcode FROM creator_layouts WHERE printing_type LIKE("%BAR%") AND layout_id = ?;');
$sth->execute($layout_id);
if ($sth->fetchrow_hashref->{'has_barcode'} == 0) {
$sth = $dbh->prepare('SELECT COUNT(*) AS existing_count FROM items WHERE CAST(barcode AS unsigned) BETWEEN ? AND ?;');
$sth->execute($from, $to);
if ($sth->fetchrow_hashref->{'existing_count'} < ($to - $from + 1)) {
$template->param( warn_empty_range => 1 )
}
}
push (@batches, {create_script => 'label-create-pdf.pl',
from => $from,
to => $to,