From 179e9bbfea75ec547e19b50678b9b87ee44889c6 Mon Sep 17 00:00:00 2001 From: David Bourgault Date: Mon, 18 Sep 2017 10:55:05 -0400 Subject: [PATCH] Bug 7468 - Print barcodes by range Adds an option to the label creator to print a range of barcodes. Only allows printing to PDF. C4/Label.pm had to get minor changes to override database-based barcode generation. Same with labels/label-create-pdf.pl. By default, the barcode is fetched from the database using the itemnumber, but when printing ranges, you might not have a corresponding database entry. --- C4/Labels/Label.pm | 4 +- .../prog/en/includes/labels-toolbar.inc | 1 + .../prog/en/modules/labels/label-edit-range.tt | 96 ++++++++++++++++++++++ .../prog/en/modules/labels/label-print.tt | 9 +- labels/label-create-pdf.pl | 10 ++- labels/label-edit-range.pl | 40 +++++++++ labels/label-print.pl | 18 ++++ 7 files changed, 173 insertions(+), 5 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-range.tt create mode 100755 labels/label-edit-range.pl diff --git a/C4/Labels/Label.pm b/C4/Labels/Label.pm index 8fe725f..9cd0a5e 100644 --- a/C4/Labels/Label.pm +++ b/C4/Labels/Label.pm @@ -332,7 +332,7 @@ sub new { justify => $params{'justify'}, format_string => $params{'format_string'}, text_wrap_cols => $params{'text_wrap_cols'}, - barcode => 0, + barcode => $params{'barcode'}, }; if ($self->{'guidebox'}) { $self->{'guidebox'} = _guide_box($self->{'llx'}, $self->{'lly'}, $self->{'width'}, $self->{'height'}); @@ -500,7 +500,7 @@ sub draw_guide_box { sub barcode { my $self = shift; my %params = @_; - $params{'barcode_data'} = _get_label_item($self->{'item_number'}, 1) if !$params{'barcode_data'}; + $params{'barcode_data'} = ($self->{'barcode'} || _get_label_item($self->{'item_number'}, 1)) if !$params{'barcode_data'}; $params{'barcode_type'} = $self->{'barcode_type'} if !$params{'barcode_type'}; my $x_scale_factor = 1; my $num_of_bars = length($params{'barcode_data'}); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/labels-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/labels-toolbar.inc index aa25fb1..e0b5d85 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/labels-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/labels-toolbar.inc @@ -7,6 +7,7 @@
  • Layout
  • Label template
  • Printer profile
  • +
  • Barcode range
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-range.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-range.tt new file mode 100644 index 0000000..79a2161 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-range.tt @@ -0,0 +1,96 @@ + [% INCLUDE 'doc-head-open.inc' %] + Koha › Tools › Label creator + [% INCLUDE 'doc-head-close.inc' %] + [% INCLUDE 'greybox.inc' %] + [% IF ( bidi ) %] + + [% END %] + + + + [% INCLUDE 'header.inc' %] + [% INCLUDE 'cat-search.inc' %] + +
    +
    +
    +
    +
    + [% INCLUDE 'labels-toolbar.inc' %] +
    + +
    +

    Print barcode range

    +
    +
    +
    +
    +
      +
    1. + +
    2. +
    3. + + + +
      +
    4. +
    5. + + + +
      +
    6. +
    +
    +
    +
    + +
    +
    +
    + [% INCLUDE 'tools-menu.inc' %] +
    +
    + [% INCLUDE 'intranet-bottom.inc' %] 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 663a0d7..f1b17ee 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 @@ -27,7 +27,7 @@

    Download as CSV

    Download as XML

    - [% ELSE %] + [% ELSIF ( batche.batch_id) %] Label Batch Number [% batche.batch_id | html %]

    Download as PDF

    @@ -36,6 +36,11 @@

    Download as XML

    + [% ELSIF (batche.from && batche.to) %] + Barcodes from [% batche.from %] to [% batche.to %] +

    + Download as PDF +

    [% END %] [% END %] @@ -65,6 +70,8 @@ [% FOREACH item_number IN item_numbers %] [% END %] + +
    1. diff --git a/labels/label-create-pdf.pl b/labels/label-create-pdf.pl index edff024..2077dc3 100755 --- a/labels/label-create-pdf.pl +++ b/labels/label-create-pdf.pl @@ -46,11 +46,11 @@ my $layout_id = $cgi->param('layout_id') || undef; my $start_label = $cgi->param('start_label') || 1; @label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id'); @item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number'); +my $from = $cgi->param('from') || undef; +my $to = $cgi->param('to') || undef; my $items = undef; - - my $pdf_file = (@label_ids || @item_numbers ? "label_single_" . scalar(@label_ids || @item_numbers) : "label_batch_$batch_id"); print $cgi->header( -type => 'application/pdf', -encoding => 'utf-8', @@ -118,6 +118,11 @@ elsif (@item_numbers) { push(@{$items}, {item_number => $_}); } @item_numbers; } +elsif ($from and $to) { + for (my $i = $from; $i <= $to; $i++) { + push @{$items}, {'item_number' => $i}; + } +} else { $items = $batch->get_attr('items'); } @@ -198,6 +203,7 @@ foreach my $item (@{$items}) { text_wrap_cols => $layout->get_text_wrap_cols(label_width => $template->get_attr('label_width'), left_text_margin => $template->get_attr('left_text_margin')), ); $pdf->Add($label->draw_guide_box) if $layout->get_attr('guidebox'); + $label->{'barcode'} = $item->{'item_number'} if ($from and $to); my $label_text = $label->create_label(); _print_text($label_text) if $label_text; ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos($row_count, $col_count, $llx, $lly); diff --git a/labels/label-edit-range.pl b/labels/label-edit-range.pl new file mode 100755 index 0000000..8f73934 --- /dev/null +++ b/labels/label-edit-range.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl +# +# Copyright 2017 Solutions inLibto +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use strict; +use warnings; + +use CGI qw ( -utf8 ); + +use C4::Auth qw(get_template_and_user); +use C4::Output qw(output_html_with_http_headers); + +my $cgi = new CGI; +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "labels/label-edit-range.tt", + query => $cgi, + type => "intranet", + authnotrequired => 0, + flagsrequired => { catalogue => 1 }, + debug => 1, + } +); + +output_html_with_http_headers $cgi, $cookie, $template->output; diff --git a/labels/label-print.pl b/labels/label-print.pl index e8a42fa..3835ec4 100755 --- a/labels/label-print.pl +++ b/labels/label-print.pl @@ -52,6 +52,9 @@ my @item_numbers; my $output_format = $cgi->param('output_format') || 'pdf'; my $referer = $cgi->param('referer') || undef; +my $from = $cgi->param('from') || undef; +my $to = $cgi->param('to') || undef; + my $layouts = undef; my $templates = undef; my $output_formats = undef; @@ -106,6 +109,19 @@ if ($op eq 'export') { referer => $referer, ); } + elsif ($from and $to) { + push (@batches, {create_script => 'label-create-pdf.pl', + from => $from, + to => $to, + template_id => $template_id, + layout_id => $layout_id, + start_label => $start_label, + }); + $template->param( + batches => \@batches, + referer => $referer, + ); + } } elsif ($op eq 'none') { # setup select menus for selecting layout and template for this run... @@ -128,6 +144,8 @@ elsif ($op eq 'none') { label_count => $label_count, item_count => $item_count, referer => $referer, + from => $from, + to => $to ); } output_html_with_http_headers $cgi, $cookie, $template->output; -- 2.7.4