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);
=head1 API
-=head2 Internal methods
+=head2 Class methods
=cut
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 );
}
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
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({
sub requested {
my ( $self ) = @_;
- my $status = $self->status;
- return $status && $status eq 'R';
+ return $self->status eq 'requested';
}
=head3 waiting
sub waiting {
my ( $self ) = @_;
- my $status = $self->status;
- return $status && $status eq 'W';
+ return $self->status eq 'waiting';
}
=head3 overdue
sub overdue {
my ( $self ) = @_;
- my $status = $self->status;
- return $status && $status eq 'O';
+ return $self->status eq 'overdue';
}
=head3 in_transit
sub in_transit {
my ( $self ) = @_;
- my $status = $self->status;
- return $status && $status eq 'T';
+ return $self->status eq 'in_transit';
}
=head3 expired
sub expired {
my ( $self ) = @_;
- my $status = $self->status;
- return $status && $status eq 'E';
+ return $self->status eq 'expired';
}
=head3 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
my ( $self ) = @_;
my $item;
- if ( $self->item_level_recall ) {
+ if ( $self->item_level ) {
$item = $self->item;
} elsif ( $self->checkout ) {
$item = $self->checkout->item;
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 );
}
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;
=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.
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,
},
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;
}
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;
}
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;
}
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