From f146e1bb360c3a914230411d09aba7975c89ec12 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 12 Jul 2021 14:53:38 +0200 Subject: [PATCH] Bug 26340: Code simplification And rename $range with $barcode_length Signed-off-by: Jonathan Druart --- .../prog/en/modules/labels/label-print.tt | 6 +++--- labels/label-create-pdf.pl | 17 ++++------------- labels/label-print.pl | 6 +++--- 3 files changed, 10 insertions(+), 19 deletions(-) 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 6c15534144..a4c54a779d 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 @@ -21,7 +21,7 @@
[% IF ( batche.label_ids ) %] [% IF ( batche.label_count == 1 ) %][% batche.label_count | html %] single label[% ELSE %][% batche.label_count | html %] single labels[% END %] - Download as PDF + Download as PDF

Download as CSV

@@ -45,7 +45,7 @@ [% ELSIF (batche.from && batche.to) %] Barcodes from [% batche.from | html %] to [% batche.to | html %]

- Download as PDF + Download as PDF

[% END %]
@@ -78,7 +78,7 @@ [% END %] - +
  1. diff --git a/labels/label-create-pdf.pl b/labels/label-create-pdf.pl index ecb16a5a5b..b76a013cdf 100755 --- a/labels/label-create-pdf.pl +++ b/labels/label-create-pdf.pl @@ -45,7 +45,7 @@ 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; +my $barcode_length = $cgi->param('barcode_length'); my $items = undef; @@ -117,18 +117,9 @@ elsif (@item_numbers) { } @item_numbers; } elsif ($from and $to) { - for (my $i = $from; $i <= $to; $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}; - } + for my $i ( $from .. $to ) { + my $padding = '0' x ( $barcode_length - length($i) ); + push @$items, { item_number => $padding . $i }; } } else { diff --git a/labels/label-print.pl b/labels/label-print.pl index 1347390b8e..0d1e0bba19 100755 --- a/labels/label-print.pl +++ b/labels/label-print.pl @@ -55,7 +55,7 @@ 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; +my $barcode_length = length($txt_from) || undef; my $layouts = undef; my $templates = undef; @@ -127,7 +127,7 @@ if ($op eq 'export') { push (@batches, {create_script => 'label-create-pdf.pl', from => $from, to => $to, - range => $range, + barcode_length => $barcode_length, template_id => $template_id, layout_id => $layout_id, start_label => $start_label, @@ -161,7 +161,7 @@ elsif ($op eq 'none') { referer => $referer, from => $from, to => $to, - range => $range, + barcode_length => $barcode_length, txt_from => $txt_from, txt_to => $txt_to ); -- 2.39.5