Bug 32030: ERM - Add vendor to license
[koha-ffzg.git] / Koha / Recall.pm
index 03c6167..c993bb7 100644 (file)
@@ -21,9 +21,10 @@ use Modern::Perl;
 
 use Koha::Database;
 use Koha::DateUtils qw( dt_from_string );
-use Koha::Patron;
-use Koha::Biblio;
-use Koha::Item;
+use Koha::Biblios;
+use Koha::Items;
+use Koha::Libraries;
+use Koha::Patrons;
 
 use base qw(Koha::Object);
 
@@ -33,7 +34,7 @@ Koha::Recall - Koha Recall Object class
 
 =head1 API
 
-=head2 Internal methods
+=head2 Class methods
 
 =cut
 
@@ -77,7 +78,7 @@ Returns the related Koha::Patron object for this recall.
 
 sub patron {
     my ( $self ) = @_;
-    my $patron_rs = $self->_result->borrower;
+    my $patron_rs = $self->_result->patron;
     return unless $patron_rs;
     return Koha::Patron->_new_from_dbic( $patron_rs );
 }
@@ -92,8 +93,9 @@ Returns the related Koha::Library object for this recall.
 
 sub library {
     my ( $self ) = @_;
-    $self->{_library} = Koha::Libraries->find( $self->branchcode );
-    return $self->{_library};
+    my $library_rs = $self->_result->library;
+    return unless $library_rs;
+    return Koha::Library->_new_from_dbic( $library_rs );
 }
 
 =head3 checkout
@@ -106,11 +108,11 @@ Returns the related Koha::Checkout object for this recall.
 
 sub checkout {
     my ( $self ) = @_;
-    $self->{_checkout} ||= Koha::Checkouts->find({ itemnumber => $self->itemnumber });
+    $self->{_checkout} ||= Koha::Checkouts->find({ itemnumber => $self->item_id });
 
-    unless ( $self->item_level_recall ) {
+    unless ( $self->item_level ) {
         # Only look at checkouts of items that are allowed to be recalled, and get the oldest one
-        my @items = Koha::Items->search({ biblionumber => $self->biblionumber });
+        my @items = Koha::Items->search({ biblionumber => $self->biblio_id })->as_list;
         my @itemnumbers;
         foreach (@items) {
             my $recalls_allowed = Koha::CirculationRules->get_effective_rule({
@@ -142,8 +144,7 @@ Return true if recall status is requested.
 
 sub requested {
     my ( $self ) = @_;
-    my $status = $self->status;
-    return $status && $status eq 'R';
+    return $self->status eq 'requested';
 }
 
 =head3 waiting
@@ -158,8 +159,7 @@ Return true if recall is awaiting pickup.
 
 sub waiting {
     my ( $self ) = @_;
-    my $status = $self->status;
-    return $status && $status eq 'W';
+    return $self->status eq 'waiting';
 }
 
 =head3 overdue
@@ -174,8 +174,7 @@ Return true if recall is overdue to be returned.
 
 sub overdue {
     my ( $self ) = @_;
-    my $status = $self->status;
-    return $status && $status eq 'O';
+    return $self->status eq 'overdue';
 }
 
 =head3 in_transit
@@ -190,8 +189,7 @@ Return true if recall is in transit.
 
 sub in_transit {
     my ( $self ) = @_;
-    my $status = $self->status;
-    return $status && $status eq 'T';
+    return $self->status eq 'in_transit';
 }
 
 =head3 expired
@@ -206,8 +204,7 @@ Return true if recall has expired.
 
 sub expired {
     my ( $self ) = @_;
-    my $status = $self->status;
-    return $status && $status eq 'E';
+    return $self->status eq 'expired';
 }
 
 =head3 cancelled
@@ -222,24 +219,22 @@ Return true if recall has been cancelled.
 
 sub cancelled {
     my ( $self ) = @_;
-    my $status = $self->status;
-    return $status && $status eq 'C';
+    return $self->status eq 'cancelled';
 }
 
-=head3 finished
+=head3 fulfilled
 
-    if ( $recall->finished )
+    if ( $recall->fulfilled )
 
-    [% IF recall.finished %]
+    [% IF recall.fulfilled %]
 
-Return true if recall is finished and has been fulfilled.
+Return true if the recall has been fulfilled.
 
 =cut
 
-sub finished {
+sub fulfilled {
     my ( $self ) = @_;
-    my $status = $self->status;
-    return $status && $status eq 'F';
+    return $self->status eq 'fulfilled';
 }
 
 =head3 calc_expirationdate
@@ -255,7 +250,7 @@ sub calc_expirationdate {
     my ( $self ) = @_;
 
     my $item;
-    if ( $self->item_level_recall ) {
+    if ( $self->item_level ) {
         $item = $self->item;
     } elsif ( $self->checkout ) {
         $item = $self->checkout->item;
@@ -290,15 +285,15 @@ Set the recall as in transit.
 sub start_transfer {
     my ( $self, $params ) = @_;
 
-    if ( $self->item_level_recall ) {
+    if ( $self->item_level ) {
         # already has an itemnumber
-        $self->update({ status => 'T' });
+        $self->update({ status => 'in_transit' });
     } else {
         my $itemnumber = $params->{item}->itemnumber;
-        $self->update({ status => 'T', itemnumber => $itemnumber });
+        $self->update({ status => 'in_transit', item_id => $itemnumber });
     }
 
-    my ( $dotransfer, $messages ) = C4::Circulation::transferbook({ to_branch => $self->branchcode, from_branch => $self->item->holdingbranch, barcode => $self->item->barcode, trigger => 'Recall' });
+    my ( $dotransfer, $messages ) = C4::Circulation::transferbook({ to_branch => $self->pickup_library_id, from_branch => $self->item->holdingbranch, barcode => $self->item->barcode, trigger => 'Recall' });
 
     return ( $self, $dotransfer, $messages );
 }
@@ -314,10 +309,10 @@ If a transfer is cancelled, revert the recall to requested.
 sub revert_transfer {
     my ( $self ) = @_;
 
-    if ( $self->item_level_recall ) {
-        $self->update({ status => 'R' });
+    if ( $self->item_level ) {
+        $self->update({ status => 'requested' });
     } else {
-        $self->update({ status => 'R', itemnumber => undef });
+        $self->update({ status => 'requested', item_id => undef });
     }
 
     return $self;
@@ -325,10 +320,11 @@ sub revert_transfer {
 
 =head3 set_waiting
 
-    $recall->set_waiting({
-        expirationdate => $expirationdate,
-        item => $item_object
-    });
+    $recall->set_waiting(
+        {   expirationdate => $expirationdate,
+            item           => $item_object
+        }
+    );
 
 Set the recall as waiting and update expiration date.
 Notify the recall requester.
@@ -339,24 +335,24 @@ sub set_waiting {
     my ( $self, $params ) = @_;
 
     my $itemnumber;
-    if ( $self->item_level_recall ) {
-        $itemnumber = $self->itemnumber;
-        $self->update({ status => 'W', waitingdate => dt_from_string, expirationdate => $params->{expirationdate} });
+    if ( $self->item_level ) {
+        $itemnumber = $self->item_id;
+        $self->update({ status => 'waiting', waiting_date => dt_from_string, expiration_date => $params->{expirationdate} });
     } else {
         # biblio-level recall with no itemnumber. need to set itemnumber
         $itemnumber = $params->{item}->itemnumber;
-        $self->update({ status => 'W', waitingdate => dt_from_string, expirationdate => $params->{expirationdate}, itemnumber => $itemnumber });
+        $self->update({ status => 'waiting', waiting_date => dt_from_string, expiration_date => $params->{expirationdate}, item_id => $itemnumber });
     }
 
     # send notice to recaller to pick up item
     my $letter = C4::Letters::GetPreparedLetter(
         module => 'circulation',
         letter_code => 'PICKUP_RECALLED_ITEM',
-        branchcode => $self->branchcode,
+        branchcode => $self->pickup_library_id,
         want_librarian => 0,
         tables => {
-            biblio => $self->biblionumber,
-            borrowers => $self->borrowernumber,
+            biblio => $self->biblio_id,
+            borrowers => $self->patron_id,
             items => $itemnumber,
             recalls => $self->recall_id,
         },
@@ -377,10 +373,10 @@ Revert recall waiting status.
 
 sub revert_waiting {
     my ( $self ) = @_;
-    if ( $self->item_level_recall ){
-        $self->update({ status => 'R', waitingdate => undef });
+    if ( $self->item_level ){
+        $self->update({ status => 'requested', waiting_date => undef });
     } else {
-        $self->update({ status => 'R', waitingdate => undef, itemnumber => undef });
+        $self->update({ status => 'requested', waiting_date => undef, item_id => undef });
     }
     return $self;
 }
@@ -414,8 +410,8 @@ Set a recall as overdue when the recall has been requested and the borrower who
 sub set_overdue {
     my ( $self, $params ) = @_;
     my $interface = $params->{interface} || 'COMMANDLINE';
-    $self->update({ status => 'O' });
-    C4::Log::logaction( 'RECALLS', 'OVERDUE', $self->recall_id, "Recall status set to overdue", $interface ) if ( C4::Context->preference('RecallsLog') );
+    $self->update({ status => 'overdue' });
+    C4::Log::logaction( 'RECALLS', 'OVERDUE', $self->id, "Recall status set to overdue", $interface ) if ( C4::Context->preference('RecallsLog') );
     return $self;
 }
 
@@ -430,8 +426,8 @@ Set a recall as expired. This may be done manually or by a cronjob, either when
 sub set_expired {
     my ( $self, $params ) = @_;
     my $interface = $params->{interface} || 'COMMANDLINE';
-    $self->update({ status => 'E', old => 1, expirationdate => dt_from_string });
-    C4::Log::logaction( 'RECALLS', 'EXPIRE', $self->recall_id, "Recall expired", $interface ) if ( C4::Context->preference('RecallsLog') );
+    $self->update({ status => 'expired', completed => 1, completed_date => dt_from_string });
+    C4::Log::logaction( 'RECALLS', 'EXPIRE', $self->id, "Recall expired", $interface ) if ( C4::Context->preference('RecallsLog') );
     return $self;
 }
 
@@ -445,26 +441,28 @@ Set a recall as cancelled. This may be done manually, either by the borrower tha
 
 sub set_cancelled {
     my ( $self ) = @_;
-    $self->update({ status => 'C', old => 1, cancellationdate => dt_from_string });
-    C4::Log::logaction( 'RECALLS', 'CANCEL', $self->recall_id, "Recall cancelled", 'INTRANET' ) if ( C4::Context->preference('RecallsLog') );
+    $self->update({ status => 'cancelled', completed => 1, completed_date => dt_from_string });
+    C4::Log::logaction( 'RECALLS', 'CANCEL', $self->id, "Recall cancelled", 'INTRANET' ) if ( C4::Context->preference('RecallsLog') );
     return $self;
 }
 
-=head3 set_finished
+=head3 set_fulfilled
 
-    $recall->set_finished;
+    $recall->set_fulfilled;
 
 Set a recall as finished. This should only be called when the item allocated to a recall is checked out to the borrower who requested the recall.
 
 =cut
 
-sub set_finished {
+sub set_fulfilled {
     my ( $self ) = @_;
-    $self->update({ status => 'F', old => 1 });
-    C4::Log::logaction( 'RECALLS', 'FULFILL', $self->recall_id, "Recall fulfilled", 'INTRANET' ) if ( C4::Context->preference('RecallsLog') );
+    $self->update({ status => 'fulfilled', completed => 1, completed_date => dt_from_string });
+    C4::Log::logaction( 'RECALLS', 'FILL', $self->id, "Recall fulfilled", 'INTRANET' ) if ( C4::Context->preference('RecallsLog') );
     return $self;
 }
 
+=head2 Internal methods
+
 =head3 _type
 
 =cut