Bugzilla – Attachment 107739 Details for
Bug 24786
Allow setting a cash register for a login session and configuring library-default cash registers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24786: Allow setting a register for the session
Bug-24786-Allow-setting-a-register-for-the-session.patch (text/plain), 18.94 KB, created by
Martin Renvoize (ashimema)
on 2020-08-04 10:35:58 UTC
(
hide
)
Description:
Bug 24786: Allow setting a register for the session
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-08-04 10:35:58 UTC
Size:
18.94 KB
patch
obsolete
>From 1beff6eb78d79a3f637a5864e5d46d08f9f1ce72 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 20 Jul 2020 16:14:17 +0100 >Subject: [PATCH] Bug 24786: Allow setting a register for the session > >This patch adds the ability to set a register for the current session >from the 'set library' page. > >Upon entering the page, the current selection will be displayed. >Changing the branch will trigger the register select list to update to >display only those registers associated with the updated branch and will >automatically select either 'no register' or the 'branch default' >register. The user can then override that selection to choose a >different register for the session. > >Test plan >1/ Enable cash registers with the 'UseCashRegisters' system preference >2/ Select the 'Set library' option from the top right menu >3/ Note that you can now select a cash register from the subsequent page >4/ Change the branch and note that the cash register selection is >updated to reflect the change >5/ Note that the 'branch default' register is auto-selected upon branch >selection if one has been defined, otherwise '-- None --' is selected >6/ You can then alter the selection before submitting the form >7/ Once submitted note that you are returned to the page you were on >prior to attempting to change the library and register >8/ Note the present of the register name next to the library name at the >top of the screen. >9/ Signoff >--- > C4/Auth.pm | 22 +++++-- > C4/Context.pm | 24 ++++--- > Koha/Template/Plugin/Registers.pm | 65 +++++++++++++++++++ > circ/set-library.pl | 38 ++++++++--- > .../intranet-tmpl/prog/en/includes/header.inc | 12 ++++ > .../prog/en/includes/html_helpers.inc | 16 +++++ > .../prog/en/modules/circ/set-library.tt | 57 +++++++++++++++- > 7 files changed, 208 insertions(+), 26 deletions(-) > create mode 100644 Koha/Template/Plugin/Registers.pm > >diff --git a/C4/Auth.pm b/C4/Auth.pm >index 259b6d6063..c8f8a06af0 100644 >--- a/C4/Auth.pm >+++ b/C4/Auth.pm >@@ -844,8 +844,8 @@ sub checkauth { > $session->param('cardnumber'), $session->param('firstname'), > $session->param('surname'), $session->param('branch'), > $session->param('branchname'), $session->param('flags'), >- $session->param('emailaddress'), >- $session->param('shibboleth') >+ $session->param('emailaddress'), $session->param('shibboleth'), >+ $session->param('register_id') > ); > C4::Context::set_shelves_userenv( 'bar', $session->param('barshelves') ); > C4::Context::set_shelves_userenv( 'pub', $session->param('pubshelves') ); >@@ -1065,7 +1065,7 @@ sub checkauth { > C4::Context->_unset_userenv($sessionID); > } > my ( $borrowernumber, $firstname, $surname, $userflags, >- $branchcode, $branchname, $emailaddress ); >+ $branchcode, $branchname, $emailaddress, $register_id ); > > if ( $return == 1 ) { > my $select = " >@@ -1109,6 +1109,9 @@ sub checkauth { > my $library = Koha::Libraries->find($branchcode); > $branchname = $library? $library->branchname: ''; > } >+ if ( $query->param('register_id') ) { >+ $register_id = $query->param('register_id'); >+ } > my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search }; > if ( $type ne 'opac' and C4::Context->boolean_preference('AutoLocation') ) { > >@@ -1150,6 +1153,7 @@ sub checkauth { > $session->param( 'lasttime', time() ); > $session->param( 'interface', $type); > $session->param( 'shibboleth', $shibSuccess ); >+ $session->param( 'register_id', $register_id ); > $debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map { $session->param($_) } qw(cardnumber firstname surname branch); > } > $session->param('cas_ticket', $cas_ticket) if $cas_ticket; >@@ -1158,7 +1162,8 @@ sub checkauth { > $session->param('cardnumber'), $session->param('firstname'), > $session->param('surname'), $session->param('branch'), > $session->param('branchname'), $session->param('flags'), >- $session->param('emailaddress'), $session->param('shibboleth') >+ $session->param('emailaddress'), $session->param('shibboleth'), >+ $session->param('register_id') > ); > > } >@@ -1435,7 +1440,8 @@ sub check_api_auth { > $session->param('cardnumber'), $session->param('firstname'), > $session->param('surname'), $session->param('branch'), > $session->param('branchname'), $session->param('flags'), >- $session->param('emailaddress') >+ $session->param('emailaddress'), $session->param('shibboleth'), >+ $session->param('register_id') > ); > > my $ip = $session->param('ip'); >@@ -1595,7 +1601,8 @@ sub check_api_auth { > $session->param('cardnumber'), $session->param('firstname'), > $session->param('surname'), $session->param('branch'), > $session->param('branchname'), $session->param('flags'), >- $session->param('emailaddress') >+ $session->param('emailaddress'), $session->param('shibboleth'), >+ $session->param('register_id') > ); > return ( "ok", $cookie, $sessionID ); > } else { >@@ -1683,7 +1690,8 @@ sub check_cookie_auth { > $session->param('cardnumber'), $session->param('firstname'), > $session->param('surname'), $session->param('branch'), > $session->param('branchname'), $session->param('flags'), >- $session->param('emailaddress') >+ $session->param('emailaddress'), $session->param('shibboleth'), >+ $session->param('register_id') > ); > > my $ip = $session->param('ip'); >diff --git a/C4/Context.pm b/C4/Context.pm >index 8c621e8576..eec43c2cdd 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -807,7 +807,8 @@ sub userenv { > C4::Context->set_userenv($usernum, $userid, $usercnum, > $userfirstname, $usersurname, > $userbranch, $branchname, $userflags, >- $emailaddress, $shibboleth); >+ $emailaddress, $shibboleth, >+ $register_id); > > Establish a hash of user environment variables. > >@@ -818,8 +819,13 @@ set_userenv is called in Auth.pm > #' > sub set_userenv { > shift @_; >- my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $shibboleth)= >- map { Encode::is_utf8( $_ ) ? $_ : Encode::decode('UTF-8', $_) } # CGI::Session doesn't handle utf-8, so we decode it here >+ my ( >+ $usernum, $userid, $usercnum, $userfirstname, >+ $usersurname, $userbranch, $branchname, $userflags, >+ $emailaddress, $shibboleth, $register_id >+ ) >+ = >+ map { Encode::is_utf8($_) ? $_ : Encode::decode( 'UTF-8', $_ ) } # CGI::Session doesn't handle utf-8, so we decode it here > @_; > my $var=$context->{"activeuser"} || ''; > my $cell = { >@@ -828,12 +834,14 @@ sub set_userenv { > "cardnumber" => $usercnum, > "firstname" => $userfirstname, > "surname" => $usersurname, >+ > #possibly a law problem >- "branch" => $userbranch, >- "branchname" => $branchname, >- "flags" => $userflags, >- "emailaddress" => $emailaddress, >- "shibboleth" => $shibboleth, >+ "branch" => $userbranch, >+ "branchname" => $branchname, >+ "flags" => $userflags, >+ "emailaddress" => $emailaddress, >+ "shibboleth" => $shibboleth, >+ "register_id" => $register_id, > }; > $context->{userenv}->{$var} = $cell; > return $cell; >diff --git a/Koha/Template/Plugin/Registers.pm b/Koha/Template/Plugin/Registers.pm >new file mode 100644 >index 0000000000..e4ef8cd3d2 >--- /dev/null >+++ b/Koha/Template/Plugin/Registers.pm >@@ -0,0 +1,65 @@ >+package Koha::Template::Plugin::Registers; >+ >+# Copyright PTFS Europe 2020 >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Template::Plugin; >+use base qw( Template::Plugin ); >+ >+use C4::Koha; >+use C4::Context; >+use Koha::Cash::Registers; >+ >+sub session_register { >+ my ($self) = @_; >+ >+ return C4::Context->userenv ? >+ C4::Context->userenv->{'register_id'} : >+ ''; >+} >+ >+sub session_register_name { >+ my ($self) = @_; >+ >+ my $register = Koha::Cash::Registers->find($self->session_register); >+ return $register ? $register->name : ''; >+} >+ >+=head2 >+ >+ [% SET registers = Registers.all() %] >+ [% SET registers = Registers.all( { branch => branchcode } ); >+ >+Returns a list of all cash registers available that adhere to the passed filters. >+ >+=cut >+ >+sub all { >+ my ( $self, $params ) = @_; >+ >+ my $registers = Koha::Cash::Registers->search()->unblessed(); >+ for my $register ( @{$registers} ) { >+ $register->{selected} = ( defined( $self->session_register ) >+ && $register->{id} == $self->session_register ) ? 1 : 0; >+ } >+ >+ return $registers; >+} >+ >+1; >diff --git a/circ/set-library.pl b/circ/set-library.pl >index 35b013ca33..e05f715d1b 100755 >--- a/circ/set-library.pl >+++ b/circ/set-library.pl >@@ -25,6 +25,7 @@ use C4::Output; > use C4::Auth qw/:DEFAULT get_session/; > use C4::Koha; > use Koha::BiblioFrameworks; >+use Koha::Cash::Registers; > use Koha::Libraries; > > my $query = CGI->new(); >@@ -41,23 +42,38 @@ my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user({ > my $sessionID = $query->cookie("CGISESSID"); > my $session = get_session($sessionID); > >-my $branch = $query->param('branch' ); >-my $userenv_branch = C4::Context->userenv->{'branch'} || ''; >+my $branch = $query->param('branch'); >+my $register_id = $query->param('register_id'); >+my $userenv_branch = C4::Context->userenv->{'branch'} || ''; >+my $userenv_register_id = C4::Context->userenv->{'register_id'} || ''; > my @updated; > >-# $session lddines here are doing the updating >+# $session lines here are doing the updating > if ( $branch and my $library = Koha::Libraries->find($branch) ) { > if (! $userenv_branch or $userenv_branch ne $branch ) { > my $branchname = $library->branchname; > $session->param('branchname', $branchname); # update sesssion in DB > $session->param('branch', $branch); # update sesssion in DB >- $session->flush(); > push @updated, { > updated_branch => 1, > old_branch => $userenv_branch, > new_branch => $branch, > }; > } # else branch the same, no update >+ if ( defined($userenv_register_id) >+ && ( $userenv_register_id ne $register_id ) ) >+ { >+ my $register = Koha::Cash::Registers->find($register_id); >+ $template->param(LoginRegisterID => $register_id); # update template for new register >+ $template->param(LoginRegisterName => $register ? $register->name : ''); # update template for new register >+ $session->param( 'register_id', $register_id ); >+ push @updated, >+ { >+ updated_register => 1, >+ new_register => $register ? $register->name : '' >+ }; >+ } >+ $session->flush(); > } else { > $branch = $userenv_branch; # fallback value > } >@@ -65,14 +81,16 @@ if ( $branch and my $library = Koha::Libraries->find($branch) ) { > $template->param(updated => \@updated) if (scalar @updated); > > my @recycle_loop; >-foreach ($query->param()) { >- $_ or next; # disclude blanks >- $_ eq "branch" and next; # disclude branch >- $_ eq "oldreferer" and next; # disclude oldreferer >- push @recycle_loop, { >+foreach ( $query->param() ) { >+ $_ or next; # disclude blanks >+ $_ eq "branch" and next; # disclude branch >+ $_ eq "register_id" and next; # disclude register >+ $_ eq "oldreferer" and next; # disclude oldreferer >+ push @recycle_loop, >+ { > param => $_, > value => scalar $query->param($_), >- }; >+ }; > } > > my $referer = $query->param('oldreferer') || $ENV{HTTP_REFERER}; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc >index ef6cf61c70..68c7cd8968 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc >@@ -1,5 +1,6 @@ > [% USE raw %] > [% USE Branches %] >+[% USE Registers %] > [% USE Koha %] > <nav class="navbar"> > <div class="navbar-header"> >@@ -85,6 +86,17 @@ > <span class="logged-in-branch-code content_hidden">[% Branches.GetLoggedInBranchcode | html %]</span> > </strong> > [% END %] >+ [% IF Koha.Preference('UseCashRegisters') %] >+ <span class="separator">|</span> >+ <strong> >+ [% IF ( Registers.session_register_name == '' ) %] >+ <span class="logged-in-desk-name">REGISTER NOT SET</span> >+ [% ELSE %] >+ <span class="logged-in-desk-name">[% Registers.session_register_name | html %]</span> >+ <span class="logged-in-desk-id content_hidden">[% Registers.session_register | html %]</span> >+ [% END %] >+ </strong> >+ [% END %] > </span> > <b class="caret"></b> > </a> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc >index b7616886d4..bbd35efe7f 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc >@@ -8,6 +8,22 @@ > [% END %] > [% END %] > >+[% BLOCK options_for_registers %] >+ <!-- <option hidden disabled selected value> -- select an option -- </option> --> >+ <option id="noregister" value="">-- None --</option> >+ [% FOREACH r IN registers %] >+ [% IF r.branch == branch %] >+ [% IF r.selected %] >+ <option class="[% r.branch | html %] [% IF r.branch_default %]default[% END %]" value="[% r.id | html %]" selected="selected">[% r.name | html %]</option> >+ [% ELSE %] >+ <option class="[% r.branch | html %] [% IF r.branch_default %]default[% END %]" value="[% r.id | html %]">[% r.name | html %]</option> >+ [% END%] >+ [% ELSE %] >+ <option class="[% r.branch | html %] [% IF r.branch_default %]default[% END %]" value="[% r.id | html %]" disabled hidden>[% r.name | html %]</option> >+ [% END %] >+ [% END %] >+[% END %] >+ > [% BLOCK options_for_authorised_value_categories %] > [% FOREACH avc IN authorised_value_categories %] > [% IF avc.selected %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt >index 14784e7d98..dac89b8a50 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt >@@ -1,5 +1,7 @@ > [% USE Branches %] >+[% USE Registers %] > [% USE Koha %] >+[% SET footerjs = 1 %] > [% INCLUDE 'doc-head-open.inc' %] > <title>Koha › Circulation › Set library</title> > [% INCLUDE 'doc-head-close.inc' %] >@@ -35,8 +37,13 @@ > <h2>Update succeeded</h2> > Updated:<ul> > [% FOREACH update IN updated %] >- [% IF ( update.updated_branch ) %] >+ [% IF ( update.updated_branch || update.updated_register ) %] >+ [% IF ( updated.updated.branch ) %] > <li>Library: [% update.old_branch or "?" | html %] ⇒ [% update.new_branch or "?" | html %]</li> >+ [% END %] >+ [% IF ( updated.updated_register ) %] >+ <li>Register: [% updated.new_register | html %]</li> >+ [% END %] > [% ELSE %] > <li>ERROR - unknown</li> > [% END %] >@@ -67,6 +74,21 @@ Updated:<ul> > [% END %] > </ol> > </fieldset> >+ >+[% IF Koha.Preference('UseCashRegisters') %] >+<fieldset class="rows"> >+ <legend>Set cash register</legend> >+ <ol> >+ <li> >+ <label for="register_id">Choose cash register:</label> >+ <select name="register_id" id="register_id"> >+ [% PROCESS options_for_registers registers => Registers.all() %] >+ </select> >+ </li> >+ </ol> >+</fieldset> >+[% END %] >+ > <fieldset class="action"> > <input type="submit" value="Submit" /> > <a class="cancel" id="cancel_set_library" href="[% referer or '/cgi-bin/koha/circ/circulation.pl' %]">Cancel</a> >@@ -95,4 +117,37 @@ Updated:<ul> > </div> <!-- /.col-sm-12 --> > </div> <!-- /.row --> > >+[% MACRO jsinclude BLOCK %] >+<script> >+ $(document).ready(function() { >+ $("#branch").on("change", function() { >+ var selectedBranch = $("#branch").children( >+ "option:selected").val(); >+ >+ $("#register_id").children().each(function() { >+ // default to no-register >+ if ($(this).is("#noregister")) { >+ $(this).prop("selected", true) >+ } >+ // display branch registers >+ else if ($(this).hasClass(selectedBranch)) { >+ $(this).prop("disabled", false); >+ $(this).show(); >+ // default to branch default if there is one >+ if ($(this).hasClass("default")) { >+ $(this).prop("selected", true) >+ } >+ } >+ // hide non-branch registers >+ else >+ { >+ $(this).hide(); >+ $(this).prop("disabled", true); >+ } >+ }); >+ }); >+ }); >+</script> >+[% END %] >+ > [% INCLUDE 'intranet-bottom.inc' %] >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24786
:
107145
|
107146
|
107147
|
107148
|
107149
|
107739
|
107740
|
107741
|
107742
|
107743
|
107754
|
107755
|
107756
|
107757
|
107758
|
107759
|
107957
|
107958
|
107959
|
107960
|
107961
|
107962
|
108060
|
108061
|
108062
|
108063
|
108064
|
108065
|
108066
|
108510
|
108511
|
108512
|
108513
|
108514
|
108515
|
108516
|
110162
|
110163
|
110164
|
110165
|
110166
|
110167
|
110168
|
110187
|
110188
|
110189
|
110190
|
110191
|
110192
|
110193
|
111066
|
111067
|
111068
|
111069
|
111070
|
111071
|
111072
|
111074
|
111126
|
111127
|
111128
|
111129
|
111130
|
111131
|
111132
|
111133
|
111220
|
111221
|
111222
|
111223
|
111224
|
111225
|
111226
|
111227
|
111228
|
111229
|
111230
|
111231
|
111232
|
111233
|
111234
|
111235
|
111611
|
111612
|
111613
|
111614
|
111615
|
111616
|
111617
|
111618
|
111619
|
111620
|
111623
|
111725
|
111757
|
111758
|
111759
|
111760
|
111761
|
111762
|
111763
|
111764
|
111765
|
111766
|
111767
|
111768
|
111769
|
111770
|
111776
|
111777
|
111778
|
111779
|
111780
|
111781
|
111782
|
111783
|
111784
|
111785
|
111786
|
111787
|
111788
|
112985
|
112988
|
112989
|
113226
|
113227
|
113241
|
113251
|
113253
|
113256
|
113257
|
113260