From d1a3dbceabae9933264287cc06ecf75ea80c8ea9 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). --- .../intranet-tmpl/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 8cf9c41..d06333c 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 @@ -22,6 +22,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 6d23e05..b81d8d1 100755 --- a/labels/label-print.pl +++ b/labels/label-print.pl @@ -23,6 +23,7 @@ use warnings; 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); @@ -111,6 +112,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.7.4