Bug 26340: When printing labels from a barcode range, keep zero padding

TEST PLAN:

1. Go  Tools > Label creator
2. Click +New -> Barcode range
3. Print barcode range with zero(s) in the start (Ex. from 00011881 to 00012000 )
4. Select a template to be applied:: Code à barre 48467
Select a layout to be applied: Code à barres
5. Export
6. Open PDF

The prefix is not displayed. We should see 00011881 on the labels, but we see 11881, 11882, ... without zeros in the start of labels.
This patch fix it.

Signed-off-by: hakam <hakam@inlibro.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Ivan Dziuba 2021-06-14 14:41:14 -04:00 committed by Jonathan Druart
parent e16b93b4fa
commit a75bd01883
4 changed files with 77 additions and 14 deletions

View File

@ -67,27 +67,60 @@
<script>
function Xport() {
var str = "";
str += "from=" + parseInt(document.getElementById("from-input").value) + "&";
str += "to=" + parseInt(document.getElementById("to-input").value);
str += "from=" + document.getElementById("from-input").value + "&";
str += "to=" + document.getElementById("to-input").value;
return GB_showCenter('Export labels', "/cgi-bin/koha/labels/label-print.pl?" + str, 400, 800);
}
function checkTwoValue(_from, _to, _id){
var result = _from.length == _to.length;
if (_from[0] == "0" || _to[0] == "0") {
switch (_id){
case 'from-input':
var to_inp = $("#to-input")
if (to_inp.hasClass('error')){
to_inp.removeClass('error').addClass('valid');
$("to-input-error").remove();
}
if ($('#to-input-error').length){
$("#to-input-error").remove();
}
return result;
case 'to-input':
var from_inp = $("#from-input")
if (from_inp.hasClass('error')){
from_inp.removeClass('error').addClass('valid');
}
if ($('#from-input-error').length){
$("#from-input-error").remove();
}
return result;
}
}
return true;
}
$(document).ready(function () {
$.validator.addMethod("gt", function(value, element, params) {
return parseInt(value) >= parseInt($(params).val());
}, _("Must be greater or equal to the from value."));
$.validator.addMethod("eq", function(value, element, params) {
return checkTwoValue($("#from-input").val(), $("#to-input").val(), $(element).attr('id'));
}, _("From and to values must have the same length."));
$("form[name=add_by_number]").validate({
rules: {
from: {
required: true,
number: true,
min: 1
eq: "#from-input",
eq: "#to-input",
},
to: {
required: true,
number: true,
gt: "#from-input"
gt: "#from-input",
eq: "#from-input",
eq: "#to-input",
}
}
});
@ -98,6 +131,13 @@
}
});
});
</script>
[% END %]

View File

@ -21,7 +21,7 @@
<fieldset>
[% IF ( batche.label_ids ) %]
<legend>[% IF ( batche.label_count == 1 ) %][% batche.label_count | html %] single label[% ELSE %][% batche.label_count | html %] single labels[% END %]</legend>
<p><a class="document pdf" href="/cgi-bin/koha/labels/[% batche.create_script | html %]?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 %][% batche.label_ids | html %]">Download as PDF</a></p>
<a class="document pdf" href="/cgi-bin/koha/labels/label-create-pdf.pl?batch_id=0&amp;template_id=[% batche.template_id | html %]&amp;layout_id=[% batche.layout_id | html %]&amp;start_label=[% batche.start_label | html %]&amp;from=[% batche.from | html %]&amp;to=[% batche.to | html %]&amp;range=[% batche.range | html %]">Download as PDF</a>
<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.label_ids | html %]">Download as CSV</a></p>
@ -45,7 +45,7 @@
[% ELSIF (batche.from && batche.to) %]
<legend>Barcodes from [% batche.from | html %] to [% batche.to | html %]</legend>
<p>
<a class="document pdf" href="/cgi-bin/koha/labels/label-create-pdf.pl?batch_id=0&amp;template_id=[% batche.template_id | html %]&amp;layout_id=[% batche.layout_id | html %]&amp;start_label=[% batche.start_label | html %]&amp;from=[% batche.from | html %]&amp;to=[% batche.to | html %]">Download as PDF</a>
<a class="document pdf" href="/cgi-bin/koha/labels/label-create-pdf.pl?batch_id=0&amp;template_id=[% batche.template_id | html %]&amp;layout_id=[% batche.layout_id | html %]&amp;start_label=[% batche.start_label | html %]&amp;from=[% batche.from | html %]&amp;to=[% batche.to | html %]&amp;range=[% batche.range | html %]">Download as PDF</a>
</p>
[% END %]
</fieldset>
@ -76,8 +76,9 @@
[% 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 | html %]" />
<input type="hidden" name="to" value="[% to | html %]" />
<input type="text" name="from" value="[% txt_from | html %]" />
<input type="text" name="to" value="[% txt_to | html %]" />
<input type="text" name="range" value="[% range | html %]" />
<fieldset class="rows">
<ol>
<li>

View File

@ -45,6 +45,9 @@ my $start_label = $cgi->param('start_label') || 1;
@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 $range = $cgi->param('range') || undef;
warn ("range_pdf = " . Data::Dumper::Dumper($range));
my $items = undef;
@ -117,7 +120,17 @@ elsif (@item_numbers) {
}
elsif ($from and $to) {
for (my $i = $from; $i <= $to; $i++) {
push @{$items}, {'item_number' => $i};
my $compare_range = $range - length($i);
if ($compare_range == 0){
push @{$items}, {'item_number' => $i};
} else {
my $a = '';
for (my $j = 1; $j <= $compare_range; $j++){
$a .= '0';
}
$a .= $i;
push @{$items}, {'item_number' => $a};
}
}
}
else {

View File

@ -51,8 +51,13 @@ 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 $txt_from = $cgi->param('from') || undef;
my $txt_to = $cgi->param('to') || undef;
my $from = int($txt_from) || undef;
my $to = int($txt_to) || undef;
my $range = length($txt_from) || undef;
warn ("range = " . Data::Dumper::Dumper($range));
my $layouts = undef;
my $templates = undef;
@ -124,6 +129,7 @@ if ($op eq 'export') {
push (@batches, {create_script => 'label-create-pdf.pl',
from => $from,
to => $to,
range => $range,
template_id => $template_id,
layout_id => $layout_id,
start_label => $start_label,
@ -156,7 +162,10 @@ elsif ($op eq 'none') {
item_count => $item_count,
referer => $referer,
from => $from,
to => $to
to => $to,
range => $range,
txt_from => $txt_from,
txt_to => $txt_to
);
}
output_html_with_http_headers $cgi, $cookie, $template->output;