From dc68633a1f2a8410c949c595dcebb66ada2e2cfb Mon Sep 17 00:00:00 2001 From: David Bourgault Date: Thu, 5 Oct 2017 09:40:19 -0400 Subject: [PATCH] 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 Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- .../prog/en/modules/labels/label-print.tt | 3 +++ labels/label-print.pl | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-print.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-print.tt index f1b17ee13f..ee997323c1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-print.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-print.tt @@ -11,6 +11,9 @@ [% IF ( batches ) %]

Click on the following links to download the exported batch(es).

+ [% IF warn_empty_range %] +
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.
+ [% END %] [% FOREACH batche IN batches %]
[% IF ( batche.label_ids ) %] diff --git a/labels/label-print.pl b/labels/label-print.pl index 3835ec4672..310546ff5d 100755 --- a/labels/label-print.pl +++ b/labels/label-print.pl @@ -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, -- 2.39.5