From cffdae0dcd8de224d42f344c9f1f0da51b46dae8 Mon Sep 17 00:00:00 2001 From: David Bourgault Date: Fri, 15 Sep 2017 11:09:16 -0400 Subject: [PATCH] Bug 19325 - Add an option to pad barcode length Inserts a small change to C4::Label::barcode() Test case: 1) Apply patch 2) Run updatedatabase.pl 3) Print some barcodes to PDF. They should look as usual. 4) Go in systempreferences and enable "BarcodePaddingEnable". Set the a length and a character. 5) Print some barcodes to PDF. They should now be of fixed length. --- C4/Labels/Label.pm | 12 ++++++++++++ .../mysql/atomicupdate/Bug19325-BarcodePadding.syspref.sql | 4 ++++ .../prog/en/modules/admin/preferences/tools.pref | 13 +++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/Bug19325-BarcodePadding.syspref.sql diff --git a/C4/Labels/Label.pm b/C4/Labels/Label.pm index 8fe725f..3738d2a 100644 --- a/C4/Labels/Label.pm +++ b/C4/Labels/Label.pm @@ -502,6 +502,18 @@ sub barcode { my %params = @_; $params{'barcode_data'} = _get_label_item($self->{'item_number'}, 1) if !$params{'barcode_data'}; $params{'barcode_type'} = $self->{'barcode_type'} if !$params{'barcode_type'}; + + my $enableBarcodePadding = C4::Context->preference("BarcodePaddingEnable"); + my $paddingCharacter = C4::Context->preference("BarcodePaddingCharacter") || 0; + my $paddingLength = C4::Context->preference("BarcodePaddingLength") || 0; + + if (length($paddingCharacter) > 1) { + $paddingCharacter = substr $paddingCharacter, 0, 1; + } + if ($enableBarcodePadding and length($params{'barcode_data'}) < $paddingLength) { + $params{'barcode_data'} = ($paddingCharacter x ($paddingLength - length($params{'barcode_data'}))) . $params{'barcode_data'}; + } + my $x_scale_factor = 1; my $num_of_bars = length($params{'barcode_data'}); my $tot_bar_length = 0; diff --git a/installer/data/mysql/atomicupdate/Bug19325-BarcodePadding.syspref.sql b/installer/data/mysql/atomicupdate/Bug19325-BarcodePadding.syspref.sql new file mode 100644 index 0000000..0347ee0 --- /dev/null +++ b/installer/data/mysql/atomicupdate/Bug19325-BarcodePadding.syspref.sql @@ -0,0 +1,4 @@ +INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES +('BarcodePaddingEnable','0','Enables padding the barcode when printing to PDF',NULL,'YesNo'), +('BarcodePaddingLength','0','The total length of the padded barcode',NULL,'Integer'), +('BarcodePaddingCharacter','0','The character to use when padding. Only string[0] is used.',NULL,'string'); \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/tools.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/tools.pref index 4ca398d..97219dc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/tools.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/tools.pref @@ -38,3 +38,16 @@ Tools: - pref: NumSavedReports class: integer - reports on the Saved Reports page. + Labels: + - + - pref: BarcodePaddingEnable + choices: + yes: "Enable" + no: "Disable" + - "padding the length of printed barcodes up to length" + - pref: BarcodePaddingLength + class: integer + - " with the character " + - pref: BarcodePaddingCharacter + class: integer + - " This has no effect if the barcode is longer than length. Length and character default to 0 if fields are empty." -- 2.7.4