2 # status of a Hold transaction
4 package C4::SIP::ILS::Transaction::Hold;
8 use C4::SIP::ILS::Transaction;
10 use C4::Reserves; # AddReserve
13 use parent qw(C4::SIP::ILS::Transaction);
19 pickup_location => undef,
20 constraint_type => undef,
25 my $self = $class->SUPER::new();
26 foreach my $element (keys %fields) {
27 $self->{_permitted}->{$element} = $fields{$element};
29 @{$self}{keys %fields} = values %fields;
30 return bless $self, $class;
35 return $self->item->hold_queue_position($self->patron->id);
40 unless ( $self->{patron} ) {
41 $self->screen_msg('do_hold called with undefined patron');
45 my $patron = Koha::Patrons->find( { cardnumber => $self->{patron}->id } );
47 $self->screen_msg( 'No borrower matches cardnumber "' . $self->{patron}->id . '".' );
51 my $item = Koha::Items->find({ barcode => $self->{item}->id });
53 $self->screen_msg( 'No biblio record matches barcode "' . $self->{item}->id . '".' );
57 my $branch = ( $self->pickup_location || $self->{patron}->{branchcode} );
59 $self->screen_msg('No branch specified (or found w/ patron).');
63 unless ( $item->can_be_transferred( { to => Koha::Libraries->find( $branch ) } ) ) {
64 $self->screen_msg('Item cannot be transferred.');
69 my $priority = C4::Reserves::CalculatePriority($item->biblionumber);
72 priority => $priority,
74 borrowernumber => $patron->borrowernumber,
75 biblionumber => $item->biblionumber
79 # unfortunately no meaningful return value
86 unless ($self->{patron}) {
87 $self->screen_msg('drop_hold called with undefined patron');
91 my $patron = Koha::Patrons->find( { cardnumber => $self->{patron}->id } );
93 $self->screen_msg('No borrower matches cardnumber "' . $self->{patron}->id . '".');
98 my $item = Koha::Items->find({ barcode => $self->{item}->id });
99 my $holds = $item->holds->search({ borrowernumber => $patron->borrowernumber });
101 return $self unless $holds->count;
103 $holds->next->cancel;
111 unless ($self->{patron}) {
112 $self->screen_msg('change_hold called with undefined patron');
116 my $patron = Koha::Patrons->find( { cardnumber => $self->{patron}->id } );
118 $self->screen_msg('No borrower matches cardnumber "' . $self->{patron}->id . '".');
122 my $item = Koha::Items->find({ barcode => $self->{item}->id });
124 $self->screen_msg('No biblio record matches barcode "' . $self->{item}->id . '".');
128 my $branch = ($self->pickup_location || $self->{patron}->branchcode);
130 $self->screen_msg('No branch specified (or found w/ patron).');
134 ModReserve({ biblionumber => $item->biblionumber, borrowernumber => $patron->borrowernumber, branchcode => $branch });