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