From e5b88e82845b8cd7a6051c91d03cad3746e1178b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 19 Jul 2019 09:20:49 +0100 Subject: [PATCH] Bug 23321: (follow-up) Require cash registers for payments This follow-up catches the case where no cash registers have been defined for the current branch and as such payments cannot be processed. --- .../prog/en/modules/members/paycollect.tt | 15 ++++++++ members/paycollect.pl | 38 ++++++++++++------- 2 files changed, 40 insertions(+), 13 deletions(-) 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 ea4b912896..f22881a2ca 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt @@ -61,6 +61,12 @@ [% END %] [% IF ( pay_individual ) %] + [% IF ( error_registers ) %] +
+ You must have at least one cash register associated with this branch before you can record payments. +
+ [% ELSE %] +
@@ -144,6 +150,7 @@ Cancel
+ [% END %] [% ELSIF ( writeoff_individual ) %]
@@ -190,6 +197,11 @@
[% ELSE %] + [% IF ( error_registers && type != 'writeoff' ) %] +
+ You must have at least one cash register associated with this branch before you can record payments. +
+ [% ELSE %]
@@ -231,6 +243,7 @@ 0.00 + [% IF type != 'writeoff' %] [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %] [% IF payment_types %]
  • @@ -258,6 +271,7 @@
  • [% END %] + [% END %]
  • @@ -270,6 +284,7 @@ Cancel
  • + [% END %] [% END %] diff --git a/members/paycollect.pl b/members/paycollect.pl index 95ee8848f4..9f7fc770b7 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -74,20 +74,32 @@ my $payment_note = uri_unescape scalar $input->param('payment_note'); my $payment_type = scalar $input->param('payment_type'); my $accountlines_id; -my $registerid = $input->param('registerid'); -if ( !$registerid ) { - $registerid = Koha::Cash::Registers->find( - { branch => $library_id, branch_default => 1 }, - )->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 $registers = Koha::Cash::Registers->search( - { branch => $library_id, archived => 0 }, - { order_by => { '-asc' => 'name' } } -); -$template->param( - registerid => $registerid, - registers => $registers, -); if ( $pay_individual || $writeoff_individual ) { if ($pay_individual) { -- 2.20.1