Bug 26340: Code simplification

And rename $range with $barcode_length

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2021-07-12 14:53:38 +02:00
parent 9f6fe663c2
commit f146e1bb36
3 changed files with 10 additions and 19 deletions

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>
<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>
<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;barcode_length=[% batche.barcode_length| 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 %]&amp;range=[% batche.range | 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;barcode_length=[% batche.barcode_length | html %]">Download as PDF</a>
</p>
[% END %]
</fieldset>
@ -78,7 +78,7 @@
[% END %]
<input type="hidden" name="from" value="[% txt_from | html %]" />
<input type="hidden" name="to" value="[% txt_to | html %]" />
<input type="hidden" name="range" value="[% range | html %]" />
<input type="hidden" name="barcode_length" value="[% barcode_length | html %]" />
<fieldset class="rows">
<ol>
<li>

View file

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

View file

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