From ae65fba9aaf34c8ca953c1a62e365c0e97c047a7 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. --- Koha/Template/Plugin/Registers.pm | 8 +++-- .../prog/en/includes/html_helpers.inc | 2 +- .../prog/en/modules/members/paycollect.tt | 30 +++++++------------ members/paycollect.pl | 28 +---------------- 4 files changed, 18 insertions(+), 50 deletions(-) diff --git a/Koha/Template/Plugin/Registers.pm b/Koha/Template/Plugin/Registers.pm index e4ef8cd3d2..b2952fc57c 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 ) && $register->{id} == $self->session_register ) ? 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 6ecb03cd7b..0bb0b8426f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc @@ -12,7 +12,7 @@ [% 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 7eee67249b..4de56b058f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt @@ -2,11 +2,13 @@ [% USE Asset %] [% USE Koha %] [% USE Branches %] +[% USE Registers %] [% USE Price %] [% SET footerjs = 1 %] [% PROCESS 'payments.inc' %] [% PROCESS 'accounts.inc' %] [% INCLUDE 'doc-head-open.inc' %] +[% SET registers = Registers.all( filters => { current_branch => 1 } ) %] Koha › Patrons › [% IF type == 'WRITEOFF' %] Write off an amount for [% patron.firstname | html %] [% patron.surname | html %] @@ -73,7 +75,7 @@ [% END %] [% IF ( pay_individual ) %] - [% IF ( error_registers ) %] + [% IF Koha.Preference('UseCashRegisters') && ( registers.size == 0 ) %] <div id="error_message" class="dialog alert"> You must have at least one cash register associated with this branch before you can record payments. </div> @@ -140,15 +142,9 @@ [% IF Koha.Preference('UseCashRegisters') %] <li> - <label for="cash_register">Cash register: </label> - <select name="cash_register" id="cash_register"> - [% FOREACH register IN registers %] - [% IF register.id == registerid %] - <option value="[% register.id | html %]" selected="selected">[% register.name | html %]</option> - [% ELSE %] - <option value="[% register.id | html %]">[% register.name | html %]</option> - [% END %] - [% END %] + <label for="registerid">Cash register: </label> + <select name="registerid" id="registerid"> + [% PROCESS options_for_registers register_required => 1 %] </select> </li> [% END %] @@ -214,7 +210,7 @@ </div> </form> [% ELSE %] - [% IF ( error_registers && type != 'writeoff' ) %] + [% IF Koha.Preference('UseCashRegisters') && ( registers.size == 0 ) && ( type != 'writeoff' ) %] <div id="error_message" class="dialog alert"> You must have at least one cash register associated with this branch before you can record payments. </div> @@ -278,15 +274,9 @@ [% IF Koha.Preference('UseCashRegisters') %] <li> - <label for="cash_register">Cash register: </label> - <select name="cash_register" id="cash_register"> - [% FOREACH register IN registers %] - [% IF register.id == registerid %] - <option value="[% register.id | html %]" selected="selected">[% register.name | html %]</option> - [% ELSE %] - <option value="[% register.id | html %]">[% register.name | html %]</option> - [% END %] - [% END %] + <label for="registerid">Cash register: </label> + <select name="registerid" id="registerid"> + [% PROCESS options_for_registers register_required => 1 %] </select> </li> [% END %] diff --git a/members/paycollect.pl b/members/paycollect.pl index c258560bc9..e40d5e7b71 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -78,33 +78,7 @@ my $payment_note = uri_unescape scalar $input->param('payment_note'); my $payment_type = scalar $input->param('payment_type'); my $accountlines_id; -my $registerid; -if ( C4::Context->preference('UseCashRegisters') ) { - $registerid = $input->param('registerid'); - 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 ( !$registerid ) { - my $default_register = Koha::Cash::Registers->find( - { branch => $library_id, branch_default => 1 } ); - $registerid = $default_register->id if $default_register; - } - $registerid = $registers->next->id if !$registerid; - - $template->param( - registerid => $registerid, - registers => $registers, - ); - } -} - +my $registerid = $input->param('registerid'); if ( $pay_individual || $writeoff_individual ) { if ($pay_individual) { $template->param( pay_individual => 1 ); -- 2.20.1