$trans->screen_msg('Invalid patron barcode.');
return $trans;
}
- my $ok = $trans->pay( $patron->{borrowernumber}, $fee_amt, $pay_type, $fee_id, $is_writeoff, $disallow_overpayment );
+ my $trans_result = $trans->pay( $patron->{borrowernumber}, $fee_amt, $pay_type, $fee_id, $is_writeoff, $disallow_overpayment );
+ my $ok = $trans_result->{ok};
$trans->ok($ok);
- return $trans;
+ return {
+ status => $trans,
+ pay_response => $trans_result->{pay_response}
+ };
}
sub add_hold {
my $account = Koha::Account->new( { patron_id => $borrowernumber } );
if ($disallow_overpayment) {
- return 0 if $account->balance < $amt;
+ return { ok => 0 } if $account->balance < $amt;
}
if ($fee_id) {
my $fee = Koha::Account::Lines->find($fee_id);
if ( $fee ) {
- $account->pay(
+ my $pay_response = $account->pay(
{
amount => $amt,
type => $type,
interface => C4::Context->interface
}
);
- return 1;
+ return {
+ ok => 1,
+ pay_response => $pay_response
+ };
}
else {
- return 0;
+ return {
+ ok => 0
+ };
}
}
else {
- $account->pay(
+ my $pay_response = $account->pay(
{
amount => $amt,
type => $type,
interface => C4::Context->interface
}
);
- return 1;
+ return {
+ ok => 1,
+ pay_response => $pay_response
+ };
}
}
use C4::Auth qw(&check_api_auth);
use Koha::Patron::Attributes;
+use Koha::Items;
use UNIVERSAL::can;
$ils->check_inst_id( $inst_id, "handle_fee_paid" );
- $status = $ils->pay_fee( $patron_id, $patron_pwd, $fee_amt, $fee_type, $pay_type, $fee_id, $trans_id, $currency, $is_writeoff, $disallow_overpayment );
+ my $pay_result = $ils->pay_fee( $patron_id, $patron_pwd, $fee_amt, $fee_type, $pay_type, $fee_id, $trans_id, $currency, $is_writeoff, $disallow_overpayment );
+ $status = $pay_result->{status};
+ my $pay_response = $pay_result->{pay_response};
+
+ my $failmap = {
+ "no_item" => "No matching item could be found",
+ "no_checkout" => "Item is not checked out",
+ "too_soon" => "Cannot yet be renewed",
+ "too_many" => "Renewed the maximum number of times",
+ "auto_too_soon" => "Scheduled for automatic renewal and cannot yet be renewed",
+ "auto_too_late" => "Scheduled for automatic renewal and cannot yet be any more",
+ "auto_account_expired" => "Scheduled for automatic renewal and cannot be renewed because the patron's account has expired",
+ "auto_renew" => "Scheduled for automatic renewal",
+ "auto_too_much_oweing" => "Scheduled for automatic renewal",
+ "on_reserve" => "On hold for another patron",
+ "patron_restricted" => "Patron is currently restricted",
+ "item_denied_renewal" => "Item is not allowed renewal",
+ "onsite_checkout" => "Item is an onsite checkout"
+ };
+ my @success = ();
+ my @fail = ();
+ foreach my $result( @{$pay_response->{renew_result}} ) {
+ my $item = Koha::Items->find({ itemnumber => $result->{itemnumber} });
+ if ($result->{success}) {
+ push @success, '"' . $item->biblio->title . '"';
+ } else {
+ push @fail, '"' . $item->biblio->title . '" : ' . $failmap->{$result->{error}};
+ }
+ }
+
+ my $msg = "";
+ if (scalar @success > 0) {
+ $msg.="The following items were renewed: " . join(", ", @success) . ". ";
+ }
+ if (scalar @fail > 0) {
+ $msg.="The following items were not renewed: " . join(", ", @fail) . ".";
+ }
+ if (length $msg > 0) {
+ $status->screen_msg($status->screen_msg . " $msg");
+ }
$resp .= ( $status->ok ? 'Y' : 'N' ) . timestamp;
$resp .= add_field( FID_INST_ID, $inst_id, $server );
&& !defined($cash_register) );
my @fines_paid; # List of account lines paid on with this payment
- # Item numbers that have had a fine paid where the line has a accounttype
- # of OVERDUE and a status of UNRETURNED. We might want to try and renew
- # these items.
- my $overdue_unreturned = {};
+
+ # The outcome of any attempted item renewals as a result of fines being
+ # paid off
+ my $renew_outcomes = [];
my $balance_remaining = $amount; # Set it now so we can adjust the amount if necessary
$balance_remaining ||= 0;
$fine->amountoutstanding($new_amountoutstanding)->store();
$balance_remaining = $balance_remaining - $amount_to_pay;
- # If we need to make a note of the item associated with this line,
- # in order that we can potentially renew it, do so.
- if (
- $new_amountoutstanding == 0 &&
- $fine->accounttype &&
- $fine->accounttype eq 'OVERDUE' &&
- $fine->status &&
- $fine->status eq 'UNRETURNED'
- ) {
- $overdue_unreturned->{$fine->itemnumber} = $fine;
+ # Attempt to renew the item associated with this debit if
+ # appropriate
+ if ($fine->renewable) {
+ # We're ignoring the definition of $interface above, by all
+ # accounts we can't rely on C4::Context::interface, so here
+ # we're only using what we've been explicitly passed
+ my $outcome = $fine->renew_item($params->{interface});
+ push @{$renew_outcomes}, $outcome if $outcome;
}
# Same logic exists in Koha::Account::Line::apply
# If we need to make a note of the item associated with this line,
# in order that we can potentially renew it, do so.
- if (
- $old_amountoutstanding - $amount_to_pay == 0 &&
- $fine->accounttype &&
- $fine->accounttype eq 'OVERDUE' &&
- $fine->status &&
- $fine->status eq 'UNRETURNED'
- ) {
- $overdue_unreturned->{$fine->itemnumber} = $fine;
+ my $amt = $old_amountoutstanding - $amount_to_pay;
+ if ($fine->renewable) {
+ my $outcome = $fine->renew_item;
+ push @{$renew_outcomes}, $outcome;
}
if ( $fine->amountoutstanding == 0
}
);
- # If we have overdue unreturned items that have had payments made
- # against them, check whether the balance on those items is now zero
- # and, if the syspref is set, renew them
- # Same logic exists in Koha::Account::Line::apply
- if (
- C4::Context->preference('RenewAccruingItemWhenPaid') &&
- keys %{$overdue_unreturned}
- ) {
- foreach my $itemnumber (keys %{$overdue_unreturned}) {
- # Only do something if this item has no fines left on it
- my $fine = C4::Overdues::GetFine( $itemnumber, $self->{patron_id} );
- next if $fine && $fine > 0;
-
- my ( $renew_ok, $error ) =
- C4::Circulation::CanBookBeRenewed(
- $self->{patron_id}, $itemnumber
- );
- if ( $renew_ok ) {
- C4::Circulation::AddRenewal(
- $self->{patron_id},
- $itemnumber,
- $library_id,
- undef,
- undef,
- 1
- );
- }
- }
- }
-
if ( C4::Context->preference("FinesLog") ) {
logaction(
"FINES", 'CREATE',
}
}
- return $payment->id;
+ return { payment_id => $payment->id, renew_result => $renew_outcomes };
}
=head3 add_credit
my $schema = Koha::Database->new->schema;
- # Item numbers that have had a fine paid where the line has a accounttype
- # of OVERDUE and a status of UNRETURNED. We might want to try and renew
- # these items.
- my $overdue_unreturned = {};
-
$schema->txn_do( sub {
for my $debit ( @{$debits} ) {
$self->amountoutstanding( $available_credit * -1 )->store;
$debit->amountoutstanding( $owed - $amount_to_cancel )->store;
- # If we need to make a note of the item associated with this line,
- # in order that we can potentially renew it, do so.
- # Same logic existing in Koha::Account::pay
- if (
- $debit->amountoutstanding == 0 &&
- $debit->accounttype &&
- $debit->accounttype eq 'OVERDUE' &&
- $debit->status &&
- $debit->status eq 'UNRETURNED'
- ) {
- $overdue_unreturned->{$debit->itemnumber} = $debit;
+ # Attempt to renew the item associated with this debit if
+ # appropriate
+ if ($debit->renewable) {
+ $debit->renew_item($params->{interface});
}
# Same logic exists in Koha::Account::pay
}
});
- # If we have overdue unreturned items that have had payments made
- # against them, check whether the balance on those items is now zero
- # and, if the syspref is set, renew them
- # Same logic existing in Koha::Account::pay
- if (
- C4::Context->preference('RenewAccruingItemWhenPaid') &&
- keys %{$overdue_unreturned}
- ) {
- foreach my $itemnumber (keys %{$overdue_unreturned}) {
- # Only do something if this item has no fines left on it
- my $fine = C4::Overdues::GetFine( $itemnumber, $self->borrowernumber );
- next if $fine && $fine > 0;
-
- my ( $renew_ok, $error ) =
- C4::Circulation::CanBookBeRenewed(
- $self->borrowernumber, $itemnumber
- );
- if ( $renew_ok ) {
- C4::Circulation::AddRenewal(
- $self->borrowernumber,
- $itemnumber,
- $overdue_unreturned->{$itemnumber}->{branchcode},
- undef,
- undef,
- 1
- );
- }
- }
- }
-
return $available_credit;
}
manager_id => 'user_id',
note => 'internal_note',
};
+
+=head3 renewable
+
+ my $bool = $line->renewable;
+
+=cut
+
+sub renewable {
+ my ($self) = @_;
+
+ return (
+ $self->amountoutstanding == 0 &&
+ $self->accounttype &&
+ $self->accounttype eq 'OVERDUE' &&
+ $self->status &&
+ $self->status eq 'UNRETURNED'
+ ) ? 1 : 0;
+}
+
+=head3 renew_item
+
+ my $renew_result = $line->renew_item;
+
+Conditionally attempt to renew an item and return the outcome. This is
+as a consequence of the fine on an item being fully paid off
+
+=cut
+
+sub renew_item {
+ my ($self, $params) = @_;
+
+ my $outcome = {};
+
+ # We want to reject the call to renew if any of these apply:
+ # - The RenewAccruingItemWhenPaid syspref is off
+ # - The line item doesn't have an item attached to it
+ # - The line item doesn't have a patron attached to it
+ #
+ # - The RenewAccruingItemInOpac syspref is off
+ # AND
+ # - There is an interface param passed and it's value is 'opac'
+
+ if (
+ !C4::Context->preference('RenewAccruingItemWhenPaid') ||
+ !$self->item ||
+ !$self->patron ||
+ (
+ !C4::Context->preference('RenewAccruingItemInOpac') &&
+ $params->{interface} &&
+ $params->{interface} eq 'opac'
+ )
+ ) {
+ return;
+ }
+
+ my $itemnumber = $self->item->itemnumber;
+ my $borrowernumber = $self->patron->borrowernumber;
+ # Only do something if this item has no fines left on it
+ my $fine = C4::Overdues::GetFine($itemnumber, $borrowernumber);
+ if ($fine && $fine > 0) {
+ return {
+ itemnumber => $itemnumber,
+ error => 'has_fine',
+ success => 0
+ };
+ }
+ my ( $can_renew, $error ) = C4::Circulation::CanBookBeRenewed(
+ $borrowernumber,
+ $itemnumber
+ );
+ if ( $can_renew ) {
+ my $due_date = C4::Circulation::AddRenewal(
+ $borrowernumber,
+ $itemnumber,
+ $self->{branchcode},
+ undef,
+ undef,
+ 1
+ );
+ return {
+ itemnumber => $itemnumber,
+ due_date => $due_date,
+ success => 1
+ };
+ } else {
+ return {
+ itemnumber => $itemnumber,
+ error => $error,
+ success => 0
+ };
+ }
+
}
=head2 Internal methods
my $outstanding_credit = $credit->amountoutstanding;
if ($debits) {
# pay them!
- $outstanding_credit = $credit->apply({ debits => [ $debits->as_list ], offset_type => 'payment' });
+ $outstanding_credit = $credit->apply({ debits => [ $debits->as_list ], offset_type => 'payment' })->{outstanding_amount};
}
if ($outstanding_credit) {
--- /dev/null
+$DBversion = 'XXX'; # will be replaced by the RM
+if( CheckVersion( $DBversion ) ) {
+
+ $dbh->do( q| INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('RenewAccruingItemInOpac', '0', 'If enabled, when the fines on an item accruing is paid off in the OPAC via a payment plugin, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue', '', 'YesNo'); | );
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 23051 - Add RenewAccruingItemInOpac syspref)\n";
+}
$DBversion = 'XXX'; # will be replaced by the RM
if( CheckVersion( $DBversion ) ) {
- $dbh->do( q| INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('RenewAccruingItemWhenPaid', '0', 'If enabled, when the fines on an item accruing is paid off, attempt to renew that item', '', 'YesNo'); | );
+ $dbh->do( q| INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('RenewAccruingItemWhenPaid', '0', 'If enabled, when the fines on an item accruing is paid off, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue', '', 'YesNo'); | );
SetVersion( $DBversion );
print "Upgrade to $DBversion done (Bug 23051 - Add RenewAccruingItemWhenPaid syspref)\n";
('RandomizeHoldsQueueWeight','0',NULL,'if ON, the holds queue in circulation will be randomized, either based on all location codes, or by the location codes specified in StaticHoldsQueueWeight','YesNo'),
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
-('RenewAccruingItemWhenPaid','0','','If enabled, when the fines on an item accruing is paid off, attempt to renew that item','YesNo'),
+('RenewAccruingItemWhenPaid','0','','If enabled, when the fines on an item accruing is paid off, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue','YesNo'),
+('RenewAccruingItemInOpac','0','','If enabled, when the fines on an item accruing is paid off in the OPAC via a payment plugin, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue','YesNo'),
('RenewalLog','0','','If ON, log information about renewals','YesNo'),
('RenewalPeriodBase','date_due','date_due|now','Set whether the renewal date should be counted from the date_due or from the moment the Patron asks for renewal ','Choice'),
('RenewalSendNotice','0','',NULL,'YesNo'),
--- /dev/null
+[% IF renew_results && renew_results.size > 0 %]
+ <div class="alert">
+ The fines on the following items were paid off, renewal results are displayed below:
+ [% FOREACH result IN renew_results %]
+ [% IF result.success %]
+ <p>[% INCLUDE 'biblio-title.inc' biblio=result.item.biblio %] ( [% result.item.barcode | html %] ): Renewed - due [% result.info | html %]</p>
+ [% ELSE %]
+ <p>[% INCLUDE 'biblio-title.inc' biblio=result.item.biblio %] ( [% result.item.barcode | html %] ): Not renewed - [% INCLUDE 'renew_strings.inc' error=result.info %]</p>
+ [% END %]
+ [% END %]
+ </div>
+[% END %]
--- /dev/null
+[% SWITCH error %]
+[% CASE 'no_item' %]
+ No matching item could be found
+[% CASE 'no_checkout' %]
+ Item is not checked out
+[% CASE 'too_soon' %]
+ Cannot yet be renewed
+[% CASE 'too_many' %]
+ Renewed the maximum number of times
+[% CASE 'auto_too_soon' %]
+ Scheduled for automatic renewal and cannot yet be renewed
+[% CASE 'auto_too_late' %]
+ Scheduled for automatic renewal and cannot yet be any more
+[% CASE 'auto_account_expired' %]
+ Scheduled for automatic renewal and cannot be renewed because the patron's account has expired
+[% CASE 'auto_renew' %]
+ Scheduled for automatic renewal
+[% CASE 'auto_too_much_oweing' %]
+ Scheduled for automatic renewal
+[% CASE 'on_reserve' %]
+ On hold for another patron
+[% CASE 'patron_restricted' %]
+ Patron is currently restricted
+[% CASE 'item_denied_renewal' %]
+ Item is not allowed renewal
+[% CASE 'onsite_checkout' %]
+ Item is an onsite checkout
+[% CASE 'has_fine' %]
+ Item has an outstanding fine
+[% CASE %]
+ Unknown error
+[% END %]
choices:
yes: Renew
no: "Don't renew"
- - the item automatically.
+ - the item automatically. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue.
+ -
+ - If a patron pays off all fines on an overdue item that is accruing fines in the OPAC via a payment plugin
+ - pref: RenewAccruingItemInOpac
+ choices:
+ yes: Renew
+ no: "Don't renew"
+ - the item automatically. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue.
-
- pref: ItemsDeniedRenewal
type: textarea
<li><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Create manual credit</a></li>
</ul>
<div class="tabs-container">
+[% INCLUDE 'renew_results.inc' renew_results=renew_results %]
<!-- The table with the account items -->
<table id="table_account_fines">
<thead>
<form action="/cgi-bin/koha/members/pay.pl" method="post" id="pay-fines-form">
<input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber | html %]" />
<p><span class="checkall"><a id="CheckAll" href="#"><i class="fa fa-check"></i> Select all</a></span> | <span class="clearall"><a id="CheckNone" href="#"><i class="fa fa-remove"></i> Clear all</a></span></p>
+[% INCLUDE 'renew_results.inc' renew_results=renew_results %]
<table id="finest">
<thead>
<tr>
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
+use URI::Escape;
use C4::Auth;
use C4::Output;
use Koha::Cash::Registers;
use Koha::Patrons;
use Koha::Patron::Categories;
+use Koha::Items;
my $input=new CGI;
my $payment_id = $input->param('payment_id');
my $change_given = $input->param('change_given');
my $action = $input->param('action') || '';
+my @renew_results = $input->param('renew_result');
my $logged_in_user = Koha::Patrons->find( $loggedinuser );
my $library_id = C4::Context->userenv->{'branch'};
$totalcredit = 1;
}
+# Populate an arrayref with everything we need to display any
+# renew errors that occurred based on what we were passed
+my $renew_results_display = [];
+foreach my $renew_result(@renew_results) {
+ my ($itemnumber, $success, $info) = split(/,/, $renew_result);
+ my $item = Koha::Items->find($itemnumber);
+ if ($success) {
+ $info = uri_unescape($info);
+ }
+ push @{$renew_results_display}, {
+ item => $item,
+ success => $success,
+ info => $info
+ };
+}
+
$template->param(
patron => $patron,
finesview => 1,
accounts => \@accountlines,
payment_id => $payment_id,
change_given => $change_given,
+ renew_results => $renew_results_display,
);
output_html_with_http_headers $input, $cookie, $template->output;
use C4::Koha;
use C4::Overdues;
use Koha::Patrons;
+use Koha::Items;
use Koha::Patron::Categories;
use URI::Escape;
my $payment_id = $input->param('payment_id');
our $change_given = $input->param('change_given');
+our @renew_results = $input->multi_param('renew_result');
# get borrower details
my $logged_in_user = Koha::Patrons->find( $loggedinuser );
}
}
+# Populate an arrayref with everything we need to display any
+# renew results that occurred based on what we were passed
+my $renew_results_display = [];
+foreach my $renew_result(@renew_results) {
+ my ($itemnumber, $success, $info) = split(/,/, $renew_result);
+ my $item = Koha::Items->find($itemnumber);
+ if ($success) {
+ $info = uri_unescape($info);
+ }
+ push @{$renew_results_display}, {
+ item => $item,
+ success => $success,
+ info => $info
+ };
+}
+
$template->param(
finesview => 1,
payment_id => $payment_id,
change_given => $change_given,
+ renew_results => $renew_results_display
);
add_accounts_to_template();
use Koha::AuthorisedValues;
use Koha::Account;
use Koha::Token;
+use Koha::DateUtils;
my $input = CGI->new();
token => scalar $input->param('csrf_token'),
});
+ my $url;
+ my $pay_result;
if ($pay_individual) {
my $line = Koha::Account::Lines->find($accountlines_id);
- $payment_id = $account->pay(
+ $pay_result = $account->pay(
{
lines => [$line],
amount => $total_paid,
cash_register => $registerid
}
);
- print $input->redirect(
- "/cgi-bin/koha/members/pay.pl?borrowernumber=$borrowernumber&payment_id=$payment_id&change_given=$change_given");
+ $payment_id = $pay_result->{payment_id};
+
+ $url = "/cgi-bin/koha/members/pay.pl";
} else {
if ($selected_accts) {
if ( $total_paid > $total_due ) {
} else {
my $note = $input->param('selected_accts_notes');
- $payment_id = $account->pay(
+ $pay_result = $account->pay(
{
type => $type,
amount => $total_paid,
payment_type => $payment_type,
cash_register => $registerid
}
- );
+ );
}
+ $payment_id = $pay_result->{payment_id};
}
else {
my $note = $input->param('selected_accts_notes');
- $payment_id = $account->pay(
+ $pay_result = $payment_id = $account->pay(
{
amount => $total_paid,
library_id => $library_id,
}
);
}
+ $payment_id = $pay_result->{payment_id};
- print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber&payment_id=$payment_id&change_given=$change_given");
+ $url = "/cgi-bin/koha/members/boraccount.pl";
+ }
+ # It's possible renewals took place, parse any renew results
+ # and pass on
+ my @renew_result = ();
+ foreach my $ren( @{$pay_result->{renew_result}} ) {
+ my $str = "renew_result=$ren->{itemnumber},$ren->{success},";
+ my $app = $ren->{success} ?
+ uri_escape(
+ output_pref({ dt => $ren->{due_date}, as_due_date => 1 })
+ ) : $ren->{error};
+ push @renew_result, "${str}${app}";
}
+ my $append = scalar @renew_result ? '&' . join('&', @renew_result) : '';
+
+ $url .= "?borrowernumber=$borrowernumber&payment_id=$payment_id&change_given=${change_given}${append}";
+
+ print $input->redirect($url);
}
} else {
$total_paid = '0.00'; #TODO not right with pay_individual
my $borrowernumber = $borrower->borrowernumber;
my $data = '20.00';
my $payment_note = '$20.00 payment note';
- my $id = $account->pay( { amount => $data, note => $payment_note, payment_type => "TEST_TYPE" } );
+ my $id = $account->pay( { amount => $data, note => $payment_note, payment_type => "TEST_TYPE" } )->{payment_id};
my $accountline = Koha::Account::Lines->find( $id );
is( $accountline->payment_type, "TEST_TYPE", "Payment type passed into pay is set in account line correctly" );
is($note,'$200.00 payment note', '$200.00 payment note is registered');
my $line3 = $account->add_debit({ type => 'ACCOUNT', amount => 42, interface => 'commandline' });
- my $payment_id = $account->pay( { lines => [$line3], amount => 42 } );
+ my $payment_id = $account->pay( { lines => [$line3], amount => 42 } )->{payment_id};
my $payment = Koha::Account::Lines->find( $payment_id );
is( $payment->amount()+0, -42, "Payment paid the specified fine" );
$line3 = Koha::Account::Lines->find( $line3->id );
amount => 42,
type => 'WRITEOFF',
}
- );
+ )->{payment_id};
$line->_result->discard_changes();
lines => [$line1, $line2],
amount => 30,
}
- );
+ )->{payment_id};
# Test debit and credit methods for Koha::Account::Offset
my $account_offset = Koha::Account::Offsets->find( { credit_id => $id, debit_id => $line1->id } );
$letter->store();
t::lib::Mocks::mock_preference('UseEmailReceipts', '0');
- my $id = $account->pay( { amount => 1 } );
+ my $id = $account->pay( { amount => 1 } )->{payment_id};
is( Koha::Notice::Messages->search()->count(), 0, 'Notice for payment not sent if UseEmailReceipts is disabled' );
- $id = $account->pay( { amount => 1, type => 'WRITEOFF' } );
+ $id = $account->pay( { amount => 1, type => 'WRITEOFF' } )->{payment_id};
is( Koha::Notice::Messages->search()->count(), 0, 'Notice for writeoff not sent if UseEmailReceipts is disabled' );
t::lib::Mocks::mock_preference('UseEmailReceipts', '1');
- $id = $account->pay( { amount => 12, library_id => $branchcode } );
+ $id = $account->pay( { amount => 12, library_id => $branchcode } )->{payment_id};
my $notice = Koha::Notice::Messages->search()->next();
is( $notice->subject, 'Account payment', 'Notice subject is correct for payment' );
is( $notice->letter_code, 'ACCOUNT_PAYMENT', 'Notice letter code is correct for payment' );
$letter->content('[%- USE Price -%]A writeoff of [% credit.amount * -1 | $Price %] has been applied to your account. Your [% branch.branchcode %]');
$letter->store();
- $id = $account->pay( { amount => 13, type => 'WRITEOFF', library_id => $branchcode } );
+ $id = $account->pay( { amount => 13, type => 'WRITEOFF', library_id => $branchcode } )->{payment_id};
$notice = Koha::Notice::Messages->search()->next();
is( $notice->subject, 'Account writeoff', 'Notice subject is correct for payment' );
is( $notice->letter_code, 'ACCOUNT_WRITEOFF', 'Notice letter code is correct for writeoff' );
use Modern::Perl;
-use Test::More tests => 11;
+use Test::More tests => 12;
use Test::MockModule;
use Test::Exception;
my $context = Test::MockModule->new('C4::Context');
$context->mock( 'userenv', { branch => $library->id } );
- my $credit_1_id = $account->pay({ amount => 200 });
+ my $credit_1_id = $account->pay({ amount => 200 })->{payment_id};
my $credit_1 = Koha::Account::Lines->find( $credit_1_id );
is( $credit_1->branchcode, undef, 'No branchcode is set if library_id was not passed' );
- my $credit_2_id = $account->pay({ amount => 150, library_id => $library->id });
+ my $credit_2_id = $account->pay({ amount => 150, library_id => $library->id })->{payment_id};
my $credit_2 = Koha::Account::Lines->find( $credit_2_id );
is( $credit_2->branchcode, $library->id, 'branchcode set because library_id was passed' );
use Modern::Perl;
-use Test::More tests => 11;
+use Test::More tests => 12;
use Test::Exception;
use Test::MockModule;
my $module = new Test::MockModule('C4::Circulation');
$module->mock('AddRenewal', sub { $called = 1; });
my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' });
- my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id });
+ my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list;
$credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } );
is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
$schema->storage->txn_rollback;
};
+subtest 'Renewal related tests' => sub {
+
+ plan tests => 7;
+
+ $schema->storage->txn_begin;
+
+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
+ my $staff = $builder->build_object( { class => 'Koha::Patrons' } );
+ my $item = $builder->build_object({ class => 'Koha::Items' });
+ my $issue = $builder->build_object(
+ {
+ class => 'Koha::Checkouts',
+ value => {
+ itemnumber => $item->itemnumber,
+ onsite_checkout => 0,
+ renewals => 99,
+ auto_renew => 0
+ }
+ }
+ );
+ my $line = Koha::Account::Line->new(
+ {
+ borrowernumber => $patron->borrowernumber,
+ manager_id => $staff->borrowernumber,
+ itemnumber => $item->itemnumber,
+ accounttype => "OVERDUE",
+ status => "UNRETURNED",
+ amountoutstanding => 0,
+ interface => 'commandline',
+ })->store;
+
+ is( $line->renewable, 1, "Item is returned as renewable when it meets the conditions" );
+ $line->amountoutstanding(5);
+ is( $line->renewable, 0, "Item is returned as unrenewable when it has outstanding fine" );
+ $line->amountoutstanding(0);
+ $line->accounttype("VOID");
+ is( $line->renewable, 0, "Item is returned as unrenewable when it has the wrong account type" );
+ $line->accounttype("OVERDUE");
+ $line->status("RETURNED");
+ is( $line->renewable, 0, "Item is returned as unrenewable when it has the wrong account status" );
+
+
+ t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 0 );
+ is ($line->renew_item, 0, 'Attempt to renew fails when syspref is not set');
+ t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 );
+ is_deeply(
+ $line->renew_item,
+ {
+ itemnumber => $item->itemnumber,
+ error => 'too_many',
+ success => 0
+ },
+ 'Attempt to renew fails when CanBookBeRenewed returns false'
+ );
+ $issue->delete;
+ $issue = $builder->build_object(
+ {
+ class => 'Koha::Checkouts',
+ value => {
+ itemnumber => $item->itemnumber,
+ onsite_checkout => 0,
+ renewals => 0,
+ auto_renew => 0
+ }
+ }
+ );
+ my $called = 0;
+ my $module = new Test::MockModule('C4::Circulation');
+ $module->mock('AddRenewal', sub { $called = 1; });
+ $line->renew_item;
+ is( $called, 1, 'Attempt to renew succeeds when conditions are met' );
+
+ $schema->storage->txn_rollback;
+};
+
subtest 'adjust() tests' => sub {
plan tests => 29;
lines => [$line1, $line2],
amount => 30,
}
- );
+ )->{payment_id};
my $account_payment = Koha::Account::Lines->find( $id );