Browse Source

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

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
20.11.x
Martin Renvoize 1 year ago
committed by Jonathan Druart
parent
commit
5b1934312b
  1. 23
      C4/Auth.pm
  2. 21
      C4/Context.pm
  3. 65
      Koha/Template/Plugin/Registers.pm
  4. 31
      circ/set-library.pl
  5. 27
      koha-tmpl/intranet-tmpl/prog/en/includes/header.inc
  6. 18
      koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc
  7. 57
      koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt

23
C4/Auth.pm

@ -867,7 +867,8 @@ sub checkauth {
$session->param('surname'), $session->param('branch'),
$session->param('branchname'), $session->param('flags'),
$session->param('emailaddress'), $session->param('shibboleth'),
$session->param('desk_id'), $session->param('desk_name')
$session->param('desk_id'), $session->param('desk_name'),
$session->param('register_id')
);
C4::Context::set_shelves_userenv( 'bar', $session->param('barshelves') );
C4::Context::set_shelves_userenv( 'pub', $session->param('pubshelves') );
@ -1089,7 +1090,8 @@ sub checkauth {
C4::Context->_unset_userenv($sessionID);
}
my ( $borrowernumber, $firstname, $surname, $userflags,
$branchcode, $branchname, $emailaddress, $desk_id, $desk_name );
$branchcode, $branchname, $emailaddress, $desk_id,
$desk_name, $register_id );
if ( $return == 1 ) {
my $select = "
@ -1138,6 +1140,9 @@ sub checkauth {
my $desk = Koha::Desks->find($desk_id);
$desk_name = $desk ? $desk->desk_name : '';
}
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') ) {
@ -1182,6 +1187,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;
@ -1191,7 +1197,8 @@ sub checkauth {
$session->param('surname'), $session->param('branch'),
$session->param('branchname'), $session->param('flags'),
$session->param('emailaddress'), $session->param('shibboleth'),
$session->param('desk_id'), $session->param('desk_name')
$session->param('desk_id'), $session->param('desk_name'),
$session->param('register_id')
);
}
@ -1470,7 +1477,8 @@ sub check_api_auth {
$session->param('surname'), $session->param('branch'),
$session->param('branchname'), $session->param('flags'),
$session->param('emailaddress'), $session->param('shibboleth'),
$session->param('desk_id'), $session->param('desk_name')
$session->param('desk_id'), $session->param('desk_name'),
$session->param('register_id')
);
my $ip = $session->param('ip');
@ -1631,8 +1639,10 @@ sub check_api_auth {
$session->param('number'), $session->param('id'),
$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('desk_id'), $session->param('desk_name')
$session->param('desk_id'), $session->param('desk_name'),
$session->param('register_id')
);
return ( "ok", $cookie, $sessionID );
} else {
@ -1721,7 +1731,8 @@ sub check_cookie_auth {
$session->param('surname'), $session->param('branch'),
$session->param('branchname'), $session->param('flags'),
$session->param('emailaddress'), $session->param('shibboleth'),
$session->param('desk_id'), $session->param('desk_name')
$session->param('desk_id'), $session->param('desk_name'),
$session->param('register_id')
);
my $ip = $session->param('ip');

21
C4/Context.pm

@ -805,7 +805,8 @@ sub userenv {
$userfirstname, $usersurname,
$userbranch, $branchname, $userflags,
$emailaddress, $shibboleth
$desk_id, $desk_name);
$desk_id, $desk_name,
$register_id);
Establish a hash of user environment variables.
@ -816,7 +817,7 @@ set_userenv is called in Auth.pm
#'
sub set_userenv {
shift @_;
my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $shibboleth, $desk_id, $desk_name)=
my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $shibboleth, $desk_id, $desk_name, $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"} || '';
@ -826,14 +827,16 @@ sub set_userenv {
"cardnumber" => $usercnum,
"firstname" => $userfirstname,
"surname" => $usersurname,
#possibly a law problem
"branch" => $userbranch,
"branchname" => $branchname,
"desk_id" => $desk_id,
"desk_name" => $desk_name,
"flags" => $userflags,
"emailaddress" => $emailaddress,
"shibboleth" => $shibboleth,
"branch" => $userbranch,
"branchname" => $branchname,
"flags" => $userflags,
"emailaddress" => $emailaddress,
"shibboleth" => $shibboleth,
"desk_id" => $desk_id,
"desk_name" => $desk_name,
"register_id" => $register_id,
};
$context->{userenv}->{$var} = $cell;
return $cell;

65
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_id {
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_id);
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_id )
&& $register->{id} == $self->session_register_id ) ? 1 : 0;
}
return $registers;
}
1;

31
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;
use Koha::Desks;
@ -41,19 +42,20 @@ 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 $desk_id = $query->param('desk_id');
my $userenv_branch = C4::Context->userenv->{'branch'} || '';
my $userenv_desk = C4::Context->userenv->{'desk_id'} || '';
my $branch = $query->param('branch');
my $desk_id = $query->param('desk_id');
my $register_id = $query->param('register_id');
my $userenv_branch = C4::Context->userenv->{'branch'} || '';
my $userenv_desk = C4::Context->userenv->{'desk_id'} || '';
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,
@ -76,6 +78,20 @@ if ( $branch and my $library = Koha::Libraries->find($branch) ) {
old_desk => $old_desk_name,
};
}
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
$desk_id = $userenv_desk;
@ -88,11 +104,12 @@ foreach ($query->param()) {
$_ or next; # disclude blanks
$_ eq "branch" and next; # disclude branch
$_ eq "desk_id" and next; # disclude desk_id
$_ 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};

27
koha-tmpl/intranet-tmpl/prog/en/includes/header.inc

@ -1,6 +1,7 @@
[% USE raw %]
[% USE Branches %]
[% USE Desks %]
[% USE Registers %]
[% USE Koha %]
<nav class="navbar">
<div class="navbar-header">
@ -96,7 +97,14 @@
<span class="logged-in-desk-id content_hidden">[% Desks.GetLoggedInDeskId | html %]</span>
[% END %]
</strong>
[% END %]
[% END %]
[% IF Koha.Preference('UseCashRegisters') && !(Registers.session_register_name == '') %]
<span class="separator">|</span>
<strong>
<span class="logged-in-register-name">[% Registers.session_register_name | html %]</span>
<span class="logged-in-register-id content_hidden">[% Registers.session_register_id | html %]</span>
</strong>
[% END %]
</span>
<b class="caret"></b>
</a>
@ -133,23 +141,38 @@
[% IF !( Koha.Preference('IndependentBranches') && !CAN_user_superlibrarian && !CAN_user_editcatalogue_edit_catalogue ) %]
<li role="separator" class="loggedin-menu-label divider"></li>
<li>
[% IF Koha.Preference('UseCirculationDesks') %]
[% IF Koha.Preference('UseCirculationDesks') && Koha.Preference('UseCashRegisters') %]
<a class="toplinks" href="/cgi-bin/koha/circ/set-library.pl">Set library, desk and register</a>
[% ELSIF Koha.Preference('UseCirculationDesks') %]
<a class="toplinks" href="/cgi-bin/koha/circ/set-library.pl">Set library and desk</a>
[% ELSIF Koha.Preference('UseCashRegisters') %]
<a class="toplinks" href="/cgi-bin/koha/circ/set-library.pl">Set library and cash register</a>
[% ELSE %]
<a class="toplinks" href="/cgi-bin/koha/circ/set-library.pl">Set library</a>
[% END %]
</li>
[% ELSIF Koha.Preference('UseCirculationDesks') && Koha.Preference('UseCashRegisters') %]
<li role="separator" class="loggedin-menu-label divider"></li>
<li>
<a class="toplinks" href="/cgi-bin/koha/circ/set-library.pl">Set desk and cash register</a>
</li>
[% ELSIF Koha.Preference('UseCirculationDesks') %]
<li role="separator" class="loggedin-menu-label divider"></li>
<li>
<a class="toplinks" href="/cgi-bin/koha/circ/set-library.pl">Set desk</a>
</li>
[% ELSIF Koha.Preference('UseCashRegisters') %]
<li role="separator" class="loggedin-menu-label divider"></li>
<li>
<a class="toplinks" href="/cgi-bin/koha/circ/set-library.pl">Set cash register</a>
</li>
[% END %]
[% IF EnableSearchHistory %]
<li>
<a class="toplinks" href="/cgi-bin/koha/catalogue/search-history.pl">Search history</a>
</li>
[% END %]
[% IF loggedinusernumber %]
<li class ="toplinks-myaccount">
<a class="toplinks" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% loggedinusernumber | html %]">My account</a>

18
koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc

@ -19,7 +19,23 @@
[% END %]
[% ELSE %]
<option class="[% d.branchcode | html %]" value="[% d.desk_id | html %]" disabled hidden>[% d.desk_name | html %]</option>
[% END%]
[% END %]
[% 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 %]

57
koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt

@ -2,6 +2,7 @@
[% USE Asset %]
[% USE Branches %]
[% USE Desks %]
[% USE Registers %]
[% USE Koha %]
[% SET footerjs = 1 %]
[% INCLUDE 'doc-head-open.inc' %]
@ -43,10 +44,16 @@
<h2>Update succeeded</h2>
Updated:<ul>
[% FOREACH update IN updated %]
[% IF ( update.updated_branch ) %]
[% IF ( update.updated_branch || update.updated_desk || update.updated_register ) %]
[% IF ( updated.updated.branch ) %]
<li>Library: [% update.old_branch or "?" | html %] &rArr; [% update.new_branch or "?" | html %]</li>
[% ELSIF (update.updated_desk) %]
[% END %]
[% IF ( update.updated_desk ) %]
<li>Desk: [% update.old_desk or "?" | html %] &rArr; [% LoginDeskname or "?" | html %]</li>
[% END %]
[% IF ( updated.updated_register ) %]
<li>Register: [% updated.new_register | html %]</li>
[% END %]
[% ELSE %]
<li>ERROR - unknown</li>
[% END %]
@ -91,6 +98,21 @@ Updated:<ul>
</ol>
</fieldset>
[% END %]
[% 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>
@ -119,9 +141,38 @@ Updated:<ul>
</div> <!-- /.col-sm-12 -->
</div> <!-- /.row -->
[% MACRO jsinclude BLOCK %]
[% Asset.js("js/desk_selection.js") | $raw %]
<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' %]

Loading…
Cancel
Save