From d57401a60f760c039833ca3bf6bf3e669bef1fa1 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 18 Jul 2019 16:25:24 +0100 Subject: [PATCH] Bug 23321: Add cash register support to paycollect --- 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..19302f61b2 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, + cash_register => $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, + cash_register => $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 78ee2ed934..ea4b912896 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 1cb6cbe41a..95ee8848f4 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; @@ -73,6 +74,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 ); @@ -129,6 +145,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( @@ -159,6 +176,7 @@ if ( $total_paid and $total_paid ne '0.00' ) { note => $note, interface => C4::Context->interface, payment_type => $payment_type, + cash_register => $registerid } ); } @@ -170,7 +188,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