X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=Koha%2FCheckout.pm;h=178a8c0da4aa0bfa56efefc3160d891a22abdcb1;hb=689446fda0fa665202c9e32c50705ba828337c94;hp=8fd7b6ad037be4e9a7376c75152c3f6e399f1d9d;hpb=7ac340e483923af88426b5061597eca80c5c4363;p=koha-ffzg.git diff --git a/Koha/Checkout.pm b/Koha/Checkout.pm index 8fd7b6ad03..178a8c0da4 100644 --- a/Koha/Checkout.pm +++ b/Koha/Checkout.pm @@ -20,13 +20,14 @@ package Koha::Checkout; use Modern::Perl; -use Carp; use DateTime; -use Try::Tiny; +use Try::Tiny qw( catch try ); +use C4::Circulation qw( LostItem MarkIssueReturned ); +use Koha::Checkouts::Renewals; use Koha::Checkouts::ReturnClaims; use Koha::Database; -use Koha::DateUtils; +use Koha::DateUtils qw( dt_from_string ); use Koha::Items; use Koha::Libraries; @@ -78,6 +79,20 @@ sub item { return Koha::Item->_new_from_dbic( $item_rs ); } +=head3 account_lines + +my $account_lines = $checkout->account_lines; + +Return the checked out account_lines + +=cut + +sub account_lines { + my ( $self ) = @_; + my $account_lines_rs = $self->_result->account_lines; + return Koha::Account::Lines->_new_from_dbic( $account_lines_rs ); +} + =head3 library my $library = $checkout->library; @@ -102,10 +117,40 @@ Return the patron for who the checkout has been done sub patron { my ( $self ) = @_; - my $patron_rs = $self->_result->borrower; + my $patron_rs = $self->_result->patron; return Koha::Patron->_new_from_dbic( $patron_rs ); } +=head3 issuer + +my $issuer = $checkout->issuer + +Return the patron by whom the checkout was done + +=cut + +sub issuer { + my ( $self ) = @_; + my $issuer_rs = $self->_result->issuer; + return unless $issuer_rs; + return Koha::Patron->_new_from_dbic( $issuer_rs ); +} + +=head3 renewals + + my $renewals = $checkout->renewals; + +Return a Koha::Checkouts::Renewals set attached to this checkout + +=cut + +sub renewals { + my ( $self ) = @_; + my $renewals_rs = $self->_result->renewals; + return unless $renewals_rs; + return Koha::Checkouts::Renewals->_new_from_dbic( $renewals_rs ); +} + =head3 to_api_mapping This method returns the mapping for representing a Koha::Checkout object @@ -124,12 +169,23 @@ sub to_api_mapping { lastreneweddate => 'last_renewed_date', issuedate => 'checkout_date', notedate => 'note_date', + noteseen => 'note_seen', }; } =head3 claim_returned -my $return_claim = $checkout->claim_returned(); + my $return_claim = $checkout->claim_returned(); + +This method sets the checkout as claimed return. It will: + +1. Add a new row to the `return_claims` table +2. Set the item as lost using the 'ClaimReturnedLostValue' +3. Charge a fee depending on the value of ClaimReturnedChargeFee +3a. If set to charge, then accruing overdues will be halted +3b. If set to charge, then any existing transfers will be cancelled + and the holding branch will be set back to 'frombranch'. +4. The issue will be marked as returned as per the 'MarkLostItemsAsReturned' preference =cut @@ -160,19 +216,25 @@ sub claim_returned { $ClaimReturnedChargeFee eq 'charge' ? 1 : $ClaimReturnedChargeFee eq 'no_charge' ? 0 : $charge_lost_fee; # $ClaimReturnedChargeFee eq 'ask' - C4::Circulation::LostItem( $self->itemnumber, 'claim_returned' ) if $charge_lost_fee; + + if ( $charge_lost_fee ) { + C4::Circulation::LostItem( $self->itemnumber, 'claim_returned' ); + } + elsif ( C4::Context->preference( 'MarkLostItemsAsReturned' ) =~ m/claim_returned/ ) { + C4::Circulation::MarkIssueReturned( $self->borrowernumber, $self->itemnumber, undef, $self->patron->privacy ); + } return $claim; } ); } catch { - if ( $_->isa('Koha::Exceptions::Exception') ) { + if ( $_->isa('Koha::Exception') ) { $_->rethrow(); } else { # ? - Koha::Exceptions::Exception->throw( "Unhandled exception" ); + Koha::Exception->throw( "Unhandled exception" ); } }; }