From 724862daa36f361c5dabd6aee1c656a3c7fbb60d Mon Sep 17 00:00:00 2001 From: Ivan Dziuba <ivan.dziuba@inlibro.com> Date: Mon, 14 Jun 2021 14:41:14 -0400 Subject: [PATCH] Bug 26340: When printing labels from a barcode range, keep zero padding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> --- .../en/modules/labels/label-edit-range.tt | 52 ++++++++++++++++--- .../prog/en/modules/labels/label-print.tt | 9 ++-- labels/label-create-pdf.pl | 15 +++++- labels/label-print.pl | 15 ++++-- 4 files changed, 77 insertions(+), 14 deletions(-) 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 index 6f3a463086..a1bb56fe4f 100644 --- 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 @@ -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 %] 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 fcf706b87f..48ebbec8b7 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 @@ <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 %]&template_id=[% batche.template_id | html %]&layout_id=[% batche.layout_id | html %]&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&template_id=[% batche.template_id | html %]&layout_id=[% batche.layout_id | html %]&start_label=[% batche.start_label | html %]&from=[% batche.from | html %]&to=[% batche.to | html %]&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 %]&template_id=[% batche.template_id | html %]&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&template_id=[% batche.template_id | html %]&layout_id=[% batche.layout_id | html %]&start_label=[% batche.start_label | html %]&from=[% batche.from | html %]&to=[% batche.to | html %]">Download as PDF</a> + <a class="document pdf" href="/cgi-bin/koha/labels/label-create-pdf.pl?batch_id=0&template_id=[% batche.template_id | html %]&layout_id=[% batche.layout_id | html %]&start_label=[% batche.start_label | html %]&from=[% batche.from | html %]&to=[% batche.to | html %]&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> diff --git a/labels/label-create-pdf.pl b/labels/label-create-pdf.pl index a8d89e8bd4..15b8a3f422 100755 --- a/labels/label-create-pdf.pl +++ b/labels/label-create-pdf.pl @@ -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 { diff --git a/labels/label-print.pl b/labels/label-print.pl index 6a4ac13a1c..cb928504e4 100755 --- a/labels/label-print.pl +++ b/labels/label-print.pl @@ -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; -- 2.25.1