Bug 8216: Allow SIP modules to pass critic tests
[koha.git] / C4 / SIP / ILS / Transaction / Hold.pm
1 #
2 # status of a Hold transaction
3
4 package ILS::Transaction::Hold;
5
6 use warnings;
7 use strict;
8
9 use ILS;
10 use ILS::Transaction;
11
12 use C4::Reserves;       # AddReserve
13 use C4::Members;        # GetMember
14 use C4::Biblio;         # GetBiblioFromItemNumber GetBiblioItemByBiblioNumber
15
16 use vars qw($VERSION @ISA);
17
18 BEGIN {
19     $VERSION = 3.07.00.049;
20             @ISA = qw(ILS::Transaction);
21 }
22
23 my %fields = (
24         expiration_date => 0,
25         pickup_location => undef,
26         constraint_type => undef,
27 );
28
29 sub new {
30         my $class = shift;
31         my $self = $class->SUPER::new();
32     foreach my $element (keys %fields) {
33                 $self->{_permitted}->{$element} = $fields{$element};
34         }
35         @{$self}{keys %fields} = values %fields;
36         return bless $self, $class;
37 }
38
39 sub queue_position {
40     my $self = shift;
41     return $self->item->hold_queue_position($self->patron->id);
42 }
43
44 sub do_hold {
45         my $self = shift;
46         unless ($self->{patron}) {
47                 $self->screen_msg('do_hold called with undefined patron');
48                 $self->ok(0);
49                 return $self;
50         }
51         my $borrower = GetMember( 'cardnumber'=>$self->{patron}->id);
52         unless ($borrower) {
53                 $self->screen_msg('No borrower matches cardnumber "' . $self->{patron}->id . '".');
54                 $self->ok(0);
55                 return $self;
56         }
57         my $bib = GetBiblioFromItemNumber(undef, $self->{item}->id);
58         unless ($bib) {
59                 $self->screen_msg('No biblio record matches barcode "' . $self->{item}->id . '".');
60                 $self->ok(0);
61                 return $self;
62         }
63         my $branch = ($self->pickup_location || $self->{patron}->branchcode);
64         unless ($branch) {
65                 $self->screen_msg('No branch specified (or found w/ patron).');
66                 $self->ok(0);
67                 return $self;
68         }
69         my $bibno = $bib->{biblionumber};
70         AddReserve($branch, $borrower->{borrowernumber}, 
71                                 $bibno, 'a', GetBiblioItemByBiblioNumber($bibno)) ;
72                 # unfortunately no meaningful return value
73         $self->ok(1);
74         return $self;
75 }
76
77 sub drop_hold {
78         my $self = shift;
79         unless ($self->{patron}) {
80                 $self->screen_msg('drop_hold called with undefined patron');
81                 $self->ok(0);
82                 return $self;
83         }
84         my $borrower = GetMember( 'cardnumber'=>$self->{patron}->id);
85         unless ($borrower) {
86                 $self->screen_msg('No borrower matches cardnumber "' . $self->{patron}->id . '".');
87                 $self->ok(0);
88                 return $self;
89         }
90         my $bib = GetBiblioFromItemNumber(undef, $self->{item}->id);
91         # FIXME: figure out if it is a item or title hold.  Till then, cancel both.
92         CancelReserve($bib->{biblionumber}, undef, $borrower->{borrowernumber});
93         CancelReserve(undef, $self->{item}->id, $borrower->{borrowernumber});
94                 # unfortunately no meaningful return value here either
95         $self->ok(1);
96         return $self;
97 }
98
99 sub change_hold {
100         my $self = shift;
101         unless ($self->{patron}) {
102                 $self->screen_msg('change_hold called with undefined patron');
103                 $self->ok(0);
104                 return $self;
105         }
106         my $borrower = GetMember( 'cardnumber'=>$self->{patron}->id);
107         unless ($borrower) {
108                 $self->screen_msg('No borrower matches cardnumber "' . $self->{patron}->id . '".');
109                 $self->ok(0);
110                 return $self;
111         }
112         my $bib = GetBiblioFromItemNumber(undef, $self->{item}->id);
113         unless ($bib) {
114                 $self->screen_msg('No biblio record matches barcode "' . $self->{item}->id . '".');
115                 $self->ok(0);
116                 return $self;
117         }
118         my $branch = ($self->pickup_location || $self->{patron}->branchcode);
119         unless ($branch) {
120                 $self->screen_msg('No branch specified (or found w/ patron).');
121                 $self->ok(0);
122                 return $self;
123         }
124         my $bibno = $bib->{biblionumber};
125         ModReserve($bibno, $borrower->{borrowernumber}, $branch, GetBiblioItemByBiblioNumber($bibno));
126                 # unfortunately no meaningful return value
127                 # ModReserve needs to be fixed to maintain priority by iteself (Feb 2008)
128         $self->ok(1);
129         return $self;
130 }
131 1;
132 __END__
133
134 # 11 friggin arguments
135 AddReserve($branch,$borrowernumber,$biblionumber,$constraint,$bibitems,$priority,$startdate,$notes,$title,$checkitem,$found)
136
137 ModReserve($rank, $biblio, $borrower, $branch , $itemnumber)
138