@@ -, +, @@ --- Koha/Account.pm | 53 ++++++++++++------- Koha/Exceptions/Account.pm | 11 +++- .../prog/en/modules/members/paycollect.tt | 31 +++++++++++ members/paycollect.pl | 22 +++++++- 4 files changed, 95 insertions(+), 22 deletions(-) --- a/Koha/Account.pm +++ a/Koha/Account.pm @@ -71,16 +71,17 @@ Koha::Account->new( { patron_id => $borrowernumber } )->pay( sub pay { my ( $self, $params ) = @_; - my $amount = $params->{amount}; - my $sip = $params->{sip}; - 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 $sip = $params->{sip}; + 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; @@ -88,6 +89,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 @@ -229,6 +234,7 @@ sub pay { manager_id => $manager_id, interface => $interface, branchcode => $library_id, + cash_register => $cash_register, note => $note, } )->store(); @@ -330,16 +336,17 @@ 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 $sip = $params->{sip}; - 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 $sip = $params->{sip}; + my $payment_type = $params->{payment_type}; + my $type = $params->{type} || 'payment'; + my $item_id = $params->{item_id}; unless ( $interface ) { Koha::Exceptions::MissingParameter->throw( @@ -347,6 +354,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}; @@ -372,6 +384,7 @@ sub add_credit { manager_id => $user_id, interface => $interface, branchcode => $library_id, + cash_register => $cash_register, itemnumber => $item_id, } )->store(); --- a/Koha/Exceptions/Account.pm +++ a/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; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt @@ -122,6 +122,20 @@ [% END %] + [% IF Koha.Preference('UseCashRegisters') %] +