1 package Koha
::Template
::Plugin
::Registers
;
3 # Copyright PTFS Europe 2020
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 Koha::Template::Plugin::Registers
26 The Registers plugin is a helper that returns register related session information for templates
31 [% SET registers = Registers.all() %]
32 [% SET registers = Registers.all( { filters => { current_branch => 1 } } );
39 use base
qw( Template::Plugin );
43 use Koha
::Cash
::Registers
;
47 =head2 session_register_id
49 Return the register_id for the register attached to the current session.
53 sub session_register_id
{
56 return C4
::Context
->userenv ?
57 C4
::Context
->userenv->{'register_id'} :
61 =head2 session_register_name
63 Return the register_name for the register attached to the current session.
67 sub session_register_name
{
70 return C4
::Context
->userenv
71 ? C4
::Context
->userenv->{'register_name'}
77 [% SET registers = Registers.all() %]
78 [% SET registers = Registers.all( { filters => { current_branch => 1 } } );
80 Returns a list of all cash registers available that adhere to the passed filters.
85 my ( $self, $params ) = @_;
87 return unless C4
::Context
->preference('UseCashRegisters');
89 my $filters = $params->{filters
} // {};
90 my $where = { archived
=> 0 };
91 $where->{branch
} = C4
::Context
->userenv->{'branch'}
92 if ( $filters->{current_branch
} && C4
::Context
->userenv );
93 my $registers = Koha
::Cash
::Registers
->search($where)->unblessed();
95 my $selected = $params->{selected
};
96 for my $register ( @
{$registers} ) {
97 if ( defined($selected) ) {
98 $register->{selected
} = ( $register->{id
} == $selected ) ?
1 : 0;
101 $register->{selected
} = ( defined( $self->session_register_id )
102 && $register->{id
} eq $self->session_register_id ) ?
1 : 0;