Bug 23403: Remove cardnumber from SIP
[koha.git] / C4 / SIP / ILS / Transaction / Hold.pm
blobc14a1c8b4ed6e4a586f405da14637d13dba0c9e5
2 # status of a Hold transaction
4 package C4::SIP::ILS::Transaction::Hold;
6 use Modern::Perl;
8 use C4::SIP::ILS::Transaction;
10 use C4::Reserves; # AddReserve
11 use Koha::Holds;
12 use Koha::Patrons;
13 use parent qw(C4::SIP::ILS::Transaction);
15 use Koha::Items;
17 my %fields = (
18 expiration_date => 0,
19 pickup_location => undef,
20 constraint_type => undef,
23 sub new {
24 my $class = shift;
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;
33 sub queue_position {
34 my $self = shift;
35 return $self->item->hold_queue_position($self->patron->id);
38 sub do_hold {
39 my $self = shift;
40 my $patron = Koha::Patrons->find( $self->{patron}->borrowernumber );
41 unless ( $patron ) {
42 $self->screen_msg('do_hold called with undefined patron');
43 $self->ok(0);
44 return $self;
46 my $item = Koha::Items->find({ barcode => $self->{item}->id });
47 unless ($item) {
48 $self->screen_msg( 'No biblio record matches barcode "' . $self->{item}->id . '".' );
49 $self->ok(0);
50 return $self;
52 my $branch = ( $self->pickup_location || $self->{patron}->{branchcode} );
53 unless ($branch) {
54 $self->screen_msg('No branch specified (or found w/ patron).');
55 $self->ok(0);
56 return $self;
58 unless ( $item->can_be_transferred( { to => Koha::Libraries->find( $branch ) } ) ) {
59 $self->screen_msg('Item cannot be transferred.');
60 $self->ok(0);
61 return $self;
64 my $priority = C4::Reserves::CalculatePriority($item->biblionumber);
65 AddReserve(
67 priority => $priority,
68 branchcode => $branch,
69 borrowernumber => $patron->borrowernumber,
70 biblionumber => $item->biblionumber
74 # unfortunately no meaningful return value
75 $self->ok(1);
76 return $self;
79 sub drop_hold {
80 my $self = shift;
81 my $patron = Koha::Patrons->find( $self->{patron}->borrowernumber );
82 unless ($patron) {
83 $self->screen_msg('drop_hold called with undefined patron');
84 $self->ok(0);
85 return $self;
88 my $item = Koha::Items->find({ barcode => $self->{item}->id });
89 my $holds = $item->holds->search({ borrowernumber => $patron->borrowernumber });
91 return $self unless $holds->count;
93 $holds->next->cancel;
95 $self->ok(1);
96 return $self;
99 sub change_hold {
100 my $self = shift;
101 my $patron = Koha::Patrons->find( $self->{patron}->borrowernumber );
102 unless ($patron) {
103 $self->screen_msg('change_hold called with undefined patron');
104 $self->ok(0);
105 return $self;
107 my $item = Koha::Items->find({ barcode => $self->{item}->id });
108 unless ($item) {
109 $self->screen_msg('No biblio record matches barcode "' . $self->{item}->id . '".');
110 $self->ok(0);
111 return $self;
113 my $branch = ($self->pickup_location || $self->{patron}->branchcode);
114 unless ($branch) {
115 $self->screen_msg('No branch specified (or found w/ patron).');
116 $self->ok(0);
117 return $self;
119 ModReserve({ biblionumber => $item->biblionumber, borrowernumber => $patron->borrowernumber, branchcode => $branch });
121 $self->ok(1);
122 return $self;
126 __END__