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.

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-09-18 10:55:05 -04:00 committed by Martin Renvoize
parent d653251562
commit 89b658885f
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
7 changed files with 173 additions and 5 deletions

View File

@ -274,7 +274,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'});
@ -454,7 +454,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'});

View File

@ -7,6 +7,7 @@
<li><a href="/cgi-bin/koha/labels/label-edit-layout.pl?op=new">Layout</a></li>
<li><a href="/cgi-bin/koha/labels/label-edit-template.pl?op=new">Label template</a></li>
<li><a href="/cgi-bin/koha/labels/label-edit-profile.pl?op=new">Printer profile</a></li>
<li><a href="/cgi-bin/koha/labels/label-edit-range.pl">Barcode range</a></li>
</ul>
</div>
<div class="btn-group">

View File

@ -0,0 +1,96 @@
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Tools &rsaquo; Label creator</title>
[% INCLUDE 'doc-head-close.inc' %]
[% INCLUDE 'greybox.inc' %]
[% IF ( bidi ) %]
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/right-to-left.css" />
[% END %]
<script type="text/javascript">
function Xport() {
var str = "";
str += "from=" + parseInt(document.getElementById("from-input").value) + "&";
str += "to=" + parseInt(document.getElementById("to-input").value);
return GB_showCenter('Export labels', "/cgi-bin/koha/labels/label-print.pl?" + str, 400, 800);
return;
}
function print() {
var error = false;
if (parseInt(document.getElementById("from-input").value) == 0) {
document.getElementById("from-error").innerHTML = " *Cannot be smaller than 1";
error = true;
} else {
document.getElementById("from-error").innerHTML = "";
}
if (parseInt(document.getElementById("from-input").value) > parseInt(document.getElementById("to-input").value)) {
document.getElementById("to-error").innerHTML = " *Cannot be smaller than starting value";
error = true;
}
else {
document.getElementById("to-error").innerHTML = "";
}
if (error)
return;
return Xport();
}
</script>
</head>
<body id="labels_label-home" class="tools labels">
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
<div id="breadcrumbs">
<a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
<a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo;
Label creator
</div>
<div id="doc3" class="yui-t2">
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<div class="yui-g">
[% INCLUDE 'labels-toolbar.inc' %]
<div class="yui-u first">
</div>
<h3>Print barcode range</h3>
</div>
<form name="add_by_number" action="/cgi-bin/koha/labels/label-edit-batch.pl" method="post">
<div>
<fieldset class="rows" style="border-bottom: 0px; border: 0px;">
<ol>
<li>
<input type="hidden" name="op" value="add" />
</li>
<li>
<label for="from-input">From:</label>
<input type="number" name="from" id="from-input" value="0" style="text-align: right;"/>
<span id="from-error" style="color: red; font-style: italic;"></span>
<br/>
</li>
<li>
<label for="to-input">To:</label>
<input type="number" name="to" id="to-input" value="0" style="text-align: right;"/>
<span id="to-error" style="color: red; font-style: italic;"></span>
<br/>
</li>
</ol>
</fieldset>
</div>
</form>
<div id="batch-manage" class="btn-toolbar">
<a class="btn btn-default btn-sm" id="print" href="javascript:print()">
<!-- This display a plus. Is there a more appropriate symbol to use?
<i class="fa fa-plus"></i>
-->
Print range
</a>
</div>
</div>
</div>
<div class="yui-b">
[% INCLUDE 'tools-menu.inc' %]
</div>
</div>
[% INCLUDE 'intranet-bottom.inc' %]

View File

@ -27,7 +27,7 @@
<p><a class="document csv" href="/cgi-bin/koha/labels/label-create-csv.pl?batch_id=[% batche.batch_id | html %]&amp;template_id=[% batche.template_id | html %]&amp;layout_id=[% batche.layout_id | html %][% batche.item_numbers | html %]">Download as CSV</a></p>
<p><a class="document xml" href="/cgi-bin/koha/labels/label-create-xml.pl?batch_id=[% batche.batch_id | html %]&amp;template_id=[% batche.template_id | html %]&amp;layout_id=[% batche.layout_id | html %][% batche.item_numbers | html %]">Download as XML</a></p>
[% ELSE %]
[% ELSIF ( batche.batch_id) %]
<legend>Label Batch Number [% batche.batch_id | html %]</legend>
<p><a class="document pdf" href="/cgi-bin/koha/labels/label-create-pdf.pl?batch_id=[% batche.batch_id | html %]&amp;template_id=[% batche.template_id | html %]&amp;layout_id=[% batche.layout_id | html %]&amp;start_label=[% batche.start_label | html %]">Download as PDF</a>
</p>
@ -36,6 +36,11 @@
</p>
<p>
<a class="document xml" href="/cgi-bin/koha/labels/label-create-xml.pl?batch_id=[% batche.batch_id | html %]&amp;template_id=[% batche.template_id | html %]&amp;layout_id=[% batche.layout_id | html %]">Download as XML</a></p>
[% ELSIF (batche.from && batche.to) %]
<legend>Barcodes from [% batche.from %] to [% batche.to %]</legend>
<p>
<a class="document pdf" href="/cgi-bin/koha/labels/label-create-pdf.pl?batch_id=0&amp;template_id=[% batche.template_id %]&amp;layout_id=[% batche.layout_id %]&amp;start_label=[% batche.start_label %]&amp;from=[% batche.from %]&amp;to=[% batche.to %]">Download as PDF</a>
</p>
[% END %]
</fieldset>
[% END %]
@ -65,6 +70,8 @@
[% FOREACH item_number IN item_numbers %]
<input type="hidden" name="item_number" value="[% item_number.item_number | html %]" />
[% END %]
<input type="hidden" name="from" value="[% from %]" />
<input type="hidden" name="to" value="[% to %]" />
<fieldset class="rows">
<ol>
<li>

View File

@ -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);

40
labels/label-edit-range.pl Executable file
View File

@ -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 <http://www.gnu.org/licenses>.
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;

View File

@ -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;