From 51ff2b5a010457c6692625c7979fde84f82fb5c0 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 21 Aug 2019 14:02:33 +0100 Subject: [PATCH] Bug 23321: Add cash register support to paycollect This patch ties in the cash registers system to the paycollect payment pages in the staff client. Test plan: 1) Add some manual fees to a test patron 2) Select some fees to pay off 3) Note the addition of a select box for selecting your cash register upon payment. 4) Set a branch default cash register for the current branch 5) Repeat step 3 and note that the pre-selected cash register is the one set in step 4. 6) Unset the branch default cash register for the current branch 7) Repeat step 3 and note that there is no cash register pre-selected 8) Set 'UseCashRegisters' to 'Do not' 9) Repeat step 3 and note that there is no longer an option to select a cash register 10) Signoff Signed-off-by: Maryse Simard --- Koha/Account.pm | 49 ++++++++++++------- Koha/Exceptions/Account.pm | 11 ++++- .../prog/en/modules/members/paycollect.tt | 31 ++++++++++++ members/paycollect.pl | 22 ++++++++- 4 files changed, 93 insertions(+), 20 deletions(-) diff --git a/Koha/Account.pm b/Koha/Account.pm index 35b438a0e1..719ea1da96 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -70,15 +70,16 @@ Koha::Account->new( { patron_id => $borrowernumber } )->pay( sub pay { my ( $self, $params ) = @_; - my $amount = $params->{amount}; - my $description = $params->{description}; - my $note = $params->{note} || q{}; - my $library_id = $params->{library_id}; - my $lines = $params->{lines}; - my $type = $params->{type} || 'payment'; - my $payment_type = $params->{payment_type} || undef; - my $account_type = $params->{account_type}; - my $offset_type = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment'; + my $amount = $params->{amount}; + my $description = $params->{description}; + my $note = $params->{note} || q{}; + my $library_id = $params->{library_id}; + my $lines = $params->{lines}; + my $type = $params->{type} || 'payment'; + my $payment_type = $params->{payment_type} || undef; + my $account_type = $params->{account_type}; + my $offset_type = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment'; + my $cash_register = $params->{cash_register}; my $userenv = C4::Context->userenv; @@ -86,6 +87,10 @@ sub pay { my $manager_id = $userenv ? $userenv->{number} : 0; my $interface = $params ? ( $params->{interface} || C4::Context->interface ) : C4::Context->interface; + Koha::Exceptions::Account::RegisterRequired->throw() + if ( C4::Context->preference("UseCashRegisters") + && !defined($cash_register) + && ( $interface ne 'opac' ) ); my @fines_paid; # List of account lines paid on with this payment @@ -227,6 +232,7 @@ sub pay { manager_id => $manager_id, interface => $interface, branchcode => $library_id, + register_id => $cash_register, note => $note, } )->store(); @@ -327,15 +333,16 @@ sub add_credit { my ( $self, $params ) = @_; # amount is passed as a positive value, but we store credit as negative values - my $amount = $params->{amount} * -1; - my $description = $params->{description} // q{}; - my $note = $params->{note} // q{}; - my $user_id = $params->{user_id}; - my $interface = $params->{interface}; - my $library_id = $params->{library_id}; - my $payment_type = $params->{payment_type}; - my $type = $params->{type} || 'payment'; - my $item_id = $params->{item_id}; + my $amount = $params->{amount} * -1; + my $description = $params->{description} // q{}; + my $note = $params->{note} // q{}; + my $user_id = $params->{user_id}; + my $interface = $params->{interface}; + my $library_id = $params->{library_id}; + my $cash_register = $params->{cash_register}; + my $payment_type = $params->{payment_type}; + my $type = $params->{type} || 'payment'; + my $item_id = $params->{item_id}; unless ( $interface ) { Koha::Exceptions::MissingParameter->throw( @@ -343,6 +350,11 @@ sub add_credit { ); } + Koha::Exceptions::Account::RegisterRequired->throw() + if ( C4::Context->preference("UseCashRegisters") + && !defined($cash_register) + && ( $payment_type eq 'CASH' ) ); + my $schema = Koha::Database->new->schema; my $account_type = $Koha::Account::account_type_credit->{$type}; @@ -364,6 +376,7 @@ sub add_credit { manager_id => $user_id, interface => $interface, branchcode => $library_id, + register_id => $cash_register, itemnumber => $item_id, } )->store(); diff --git a/Koha/Exceptions/Account.pm b/Koha/Exceptions/Account.pm index 4c2e2c3ff7..ea2df18f48 100644 --- a/Koha/Exceptions/Account.pm +++ b/Koha/Exceptions/Account.pm @@ -41,8 +41,11 @@ use Exception::Class ( 'Koha::Exceptions::Account::UnrecognisedType' => { isa => 'Koha::Exceptions::Account', description => 'Account type was not recognised' + }, + 'Koha::Exceptions::Account::RegisterRequired' => { + isa => 'Koha::Exceptions::Account', + description => 'Account transaction requires a cash register' } - ); =head1 NAME @@ -81,4 +84,10 @@ Exception to be used when a passed credit or debit is not of a recognised type. =cut +=head2 Koha::Exceptions::Account::RegisterRequired + +Exception to be used when UseCashRegisters is enabled and one is not passed for a transaction. + +=cut + 1; 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 2f0b1679b3..535b66b6cc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt @@ -122,6 +122,20 @@ [% END %] + [% IF Koha.Preference('UseCashRegisters') %] +
  • + + +
  • + [% END %] @@ -216,6 +230,7 @@ 0.00 + [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %] [% IF payment_types %]
  • @@ -228,6 +243,22 @@
  • [% END %] + + [% IF Koha.Preference('UseCashRegisters') %] +
  • + + +
  • + [% END %] +
  • diff --git a/members/paycollect.pl b/members/paycollect.pl index a25f6a4030..2a1aeb9b0b 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -28,6 +28,7 @@ use C4::Members; use C4::Accounts; use C4::Koha; +use Koha::Cash::Registers; use Koha::Patrons; use Koha::Patron::Categories; use Koha::AuthorisedValues; @@ -74,6 +75,21 @@ 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 $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) { $template->param( pay_individual => 1 ); @@ -130,6 +146,7 @@ if ( $total_paid and $total_paid ne '0.00' ) { note => $payment_note, interface => C4::Context->interface, payment_type => $payment_type, + cash_register => $registerid } ); print $input->redirect( @@ -160,6 +177,7 @@ if ( $total_paid and $total_paid ne '0.00' ) { note => $note, interface => C4::Context->interface, payment_type => $payment_type, + cash_register => $registerid } ); } @@ -171,7 +189,9 @@ if ( $total_paid and $total_paid ne '0.00' ) { library_id => $library_id, note => $note, payment_type => $payment_type, - interface => C4::Context->interface + interface => C4::Context->interface, + payment_type => $payment_type, + cash_register => $registerid } ); } -- 2.20.1