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

Sponsored-by: PTFS Europe
Sponsored-by: Cheshire Libraries Shared Services

Signed-off-by: Maryse Simard <maryse.simard@inlibro.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Martin Renvoize 2019-09-17 12:24:27 +01:00
parent 6461dc1a17
commit 1a740fda1e
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
4 changed files with 93 additions and 20 deletions

View File

@ -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();

View File

@ -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;

View File

@ -122,6 +122,20 @@
</select>
</li>
[% END %]
[% 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 %]" selected="selected">[% register.name | html %]</option>
[% ELSE %]
<option value="[% register.id %]">[% register.name | html %]</option>
[% END %]
[% END %]
</select>
</li>
[% END %]
</ol>
</fieldset>
@ -216,6 +230,7 @@
<label>Change to give: </label>
<span id="change">0.00</span>
</li>
[% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
[% IF payment_types %]
<li>
@ -228,6 +243,22 @@
</select>
</li>
[% END %]
[% 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 %]" selected="selected">[% register.name | html %]</option>
[% ELSE %]
<option value="[% register.id %]">[% register.name | html %]</option>
[% END %]
[% END %]
</select>
</li>
[% END %]
<li>
<label for="selected_accts_notes">Note: </label>
<textarea name="selected_accts_notes" id="selected_accts_notes">[% selected_accts_notes | html %]</textarea>

View File

@ -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
}
);
}