=cut
+=head3 patron
+
+Return the patron linked to this account line
+
+=cut
+
+sub patron {
+ my ( $self ) = @_;
+ my $rs = $self->_result->borrowernumber;
+ return unless $rs;
+ return Koha::Patron->_new_from_dbic( $rs );
+}
+
=head3 item
Return the item linked to this account line if exists
=head3 void
-$payment_accountline->void();
+ $payment_accountline->void();
+
+Used to 'void' (or reverse) a payment/credit. It will roll back any offsets
+created by the application of this credit upon any debits and mark the credit
+as 'void' by updating it's status to "VOID".
=cut
$self->set(
{
- accounttype => 'VOID',
+ status => 'VOID',
amountoutstanding => 0,
amount => 0,
}
my $debits = $account->outstanding_debits;
my $outstanding_amount = $credit->apply( { debits => $debits, [ offset_type => $offset_type ] } );
-Applies the credit to a given debits set.
+Applies the credit to a given debits array reference.
=head4 arguments hashref
my $schema = Koha::Database->new->schema;
$schema->txn_do( sub {
- while ( my $debit = $debits->next ) {
+ for my $debit ( @{$debits} ) {
unless ( $debit->is_debit ) {
Koha::Exceptions::Account::IsNotDebit->throw(
$self->amountoutstanding( $available_credit * -1 )->store;
$debit->amountoutstanding( $owed - $amount_to_cancel )->store;
+
+ # Same logic exists in Koha::Account::pay
+ if ( $debit->amountoutstanding == 0
+ && $debit->itemnumber
+ && $debit->accounttype
+ && $debit->accounttype eq 'LOST' )
+ {
+ C4::Circulation::ReturnLostItem( $self->borrowernumber, $debit->itemnumber );
+ }
+
}
});
return !$self->is_credit;
}
+=head3 to_api_mapping
+
+This method returns the mapping for representing a Koha::Account::Line object
+on the API.
+
+=cut
+
+sub to_api_mapping {
+ return {
+ accountlines_id => 'account_line_id',
+ accounttype => 'account_type',
+ amountoutstanding => 'amount_outstanding',
+ borrowernumber => 'patron_id',
+ branchcode => 'library_id',
+ issue_id => 'checkout_id',
+ itemnumber => 'item_id',
+ manager_id => 'user_id',
+ note => 'internal_note',
+ };
+}
+
=head2 Internal methods
=cut