From deed008e3557779b67dfd00a53eb5bfad572317c Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 21 Jul 2020 10:30:09 +0100 Subject: [PATCH] Bug 24786: Update paycollect to use session register This patch adds handling to allow for the use of the session cash register by default if it has been set, otherwise it defaults to '-- None --' and requires the end user to select the register to proceed with the payment. Signed-off-by: Andrew Fuerste-Henry --- Koha/Template/Plugin/Registers.pm | 8 ++++-- .../prog/en/includes/html_helpers.inc | 5 ++-- .../prog/en/modules/members/paycollect.tt | 22 ++++----------- members/paycollect.pl | 28 +------------------ 4 files changed, 15 insertions(+), 48 deletions(-) diff --git a/Koha/Template/Plugin/Registers.pm b/Koha/Template/Plugin/Registers.pm index a23fdb5e2d..ea38dff1eb 100644 --- a/Koha/Template/Plugin/Registers.pm +++ b/Koha/Template/Plugin/Registers.pm @@ -44,7 +44,7 @@ sub session_register_name { =head2 [% SET registers = Registers.all() %] - [% SET registers = Registers.all( { branch => branchcode } ); + [% SET registers = Registers.all( { filters => { current_branch => 1 } } ); Returns a list of all cash registers available that adhere to the passed filters. @@ -53,7 +53,11 @@ Returns a list of all cash registers available that adhere to the passed filters sub all { my ( $self, $params ) = @_; - my $registers = Koha::Cash::Registers->search()->unblessed(); + my $filters = $params->{filters}; + my $where; + $where->{branch} = C4::Context->userenv->{'branch'} + if $filters->{current_branch}; + my $registers = Koha::Cash::Registers->search($where)->unblessed(); for my $register ( @{$registers} ) { $register->{selected} = ( defined( $self->session_register_id ) && $register->{id} == $self->session_register_id ) ? 1 : 0; 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 19f89bb810..dd9467f161 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc @@ -24,10 +24,9 @@ [% END %] [% BLOCK options_for_registers %] - - + [% FOREACH r IN registers %] - [% IF r.branch == branch %] + [% IF r.branch == Branches.GetLoggedInBranchcode %] [% IF r.selected %] [% ELSE %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt index 5b07842f26..4e3cacdb8a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt @@ -2,6 +2,7 @@ [% USE Asset %] [% USE Koha %] [% USE Branches %] +[% USE Registers %] [% USE Price %] [% SET footerjs = 1 %] [% PROCESS 'payments.inc' %] @@ -20,6 +21,7 @@ [% END %] [% END %] +[% SET registers = Registers.all( filters => { current_branch => 1 } ) %] Koha › Patrons › [% IF type == 'WRITEOFF' %] Write off an amount for [% patron.firstname | html %] [% patron.surname | html %] @@ -86,7 +88,7 @@ [% END %] [% IF ( pay_individual ) %] - [% IF ( error_registers ) %] + [% IF Koha.Preference('UseCashRegisters') && ( registers.size == 0 ) %] [% PROCESS 'cash_register_required' %] [% ELSE %] @@ -153,13 +155,7 @@ <li> <label for="cash_register">Cash register: </label> <select name="cash_register" id="cash_register"> - [% FOREACH register IN registers %] - [% IF register.id == default_register %] - <option value="[% register.id | html %]" selected="selected">[% register.name | html %]</option> - [% ELSE %] - <option value="[% register.id | html %]">[% register.name | html %]</option> - [% END %] - [% END %] + [% PROCESS options_for_registers register_required => 1 %] </select> </li> [% END %] @@ -225,7 +221,7 @@ </div> </form> [% ELSE %] - [% IF ( error_registers && type != 'writeoff' ) %] + [% IF Koha.Preference('UseCashRegisters') && ( registers.size == 0 ) && ( type != 'writeoff' ) %] [% PROCESS 'cash_register_required' %] [% ELSE %] @@ -289,13 +285,7 @@ <li> <label for="cash_register">Cash register: </label> <select name="cash_register" id="cash_register"> - [% FOREACH register IN registers %] - [% IF register.id == default_register %] - <option value="[% register.id | html %]" selected="selected">[% register.name | html %]</option> - [% ELSE %] - <option value="[% register.id | html %]">[% register.name | html %]</option> - [% END %] - [% END %] + [% PROCESS options_for_registers register_required => 1 %] </select> </li> [% END %] diff --git a/members/paycollect.pl b/members/paycollect.pl index 471559202e..5e3381e456 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -77,33 +77,7 @@ my $payment_note = uri_unescape scalar $input->param('payment_note'); my $payment_type = scalar $input->param('payment_type'); my $accountlines_id; -my $cash_register_id; -if ( C4::Context->preference('UseCashRegisters') ) { - $cash_register_id = $input->param('cash_register'); - my $registers = Koha::Cash::Registers->search( - { branch => $library_id, archived => 0 }, - { order_by => { '-asc' => 'name' } } - ); - - if ( !$registers->count ) { - $template->param( error_registers => 1 ); - } - else { - - if ( !$cash_register_id ) { - my $default_register = Koha::Cash::Registers->find( - { branch => $library_id, branch_default => 1 } ); - $cash_register_id = $default_register->id if $default_register; - } - $cash_register_id = $registers->next->id if !$cash_register_id; - - $template->param( - default_register => $cash_register_id, - registers => $registers, - ); - } -} - +my $cash_register_id = $input->param('cash_register'); if ( $pay_individual || $writeoff_individual ) { if ($pay_individual) { $template->param( pay_individual => 1 ); -- 2.20.1