4 # A Class for hiding the ILS's concept of the item from the OpenSIP
13 use Sys::Syslog qw(syslog);
25 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
38 title => "Perl 5 desktop reference",
40 sip_media_type => '001',
45 title => "The deep blue alibi",
47 sip_media_type => '001',
53 reservenotes => undef,
54 constrainttype => 'a',
55 reservedate => '2008-10-09',
57 rtimestamp => '2008-10-09 11:15:06',
58 biblionumber => '406',
59 borrowernumber => '756',
65 title => "Harry Potter y el cáliz de fuego",
67 sip_media_type => '001',
75 defined $a->{priority} or return -1;
76 defined $b->{priority} or return 1;
77 return $a->{priority} <=> $b->{priority};
81 my ($class, $item_id) = @_;
82 my $type = ref($class) || $class;
84 my $itemnumber = GetItemnumberFromBarcode($item_id);
85 my $item = GetBiblioFromItemNumber($itemnumber);
87 syslog("LOG_DEBUG", "new ILS::Item('%s'): not found", $item_id);
88 warn "new ILS::Item($item_id) : No item '$item_id'.";
91 $item->{itemnumber} = $itemnumber;
92 $item->{'id'} = $item->{'barcode'};
93 # check if its on issue and if so get the borrower
94 my $issue = GetItemIssue($item->{'itemnumber'});
95 my $borrower = GetMember($issue->{'borrowernumber'},'borrowernumber');
96 $item->{patron} = $borrower->{'cardnumber'};
97 my @reserves = (@{ GetReservesFromBiblionumber($item->{biblionumber}) });
98 $item->{hold_queue} = [ sort priority_sort @reserves ];
99 $item->{hold_shelf} = [( grep { defined $_->{found} and $_->{found} eq 'W' } @{$item->{hold_queue}} )];
100 $item->{pending_queue} = [( grep {(! defined $_->{found}) or ($_->{found} ne 'W')} @{$item->{hold_queue}} )];
104 syslog("LOG_DEBUG", "new ILS::Item('%s'): found with title '%s'",
105 $item_id, $self->{title});
112 return $self->{magnetic_media};
116 return $self->{sip_media_type};
118 sub sip_item_properties {
120 return $self->{sip_item_properties};
123 sub status_update { # FIXME: this looks unimplemented
124 my ($self, $props) = @_;
125 my $status = new ILS::Transaction;
126 $self->{sip_item_properties} = $props;
137 return $self->{title};
139 sub permanent_location {
141 return $self->{permanent_location} || '';
143 sub current_location {
145 return $self->{current_location} || '';
148 sub sip_circulation_status {
150 if ($self->{patron}) {
151 return '04'; # charged
152 } elsif (scalar @{$self->{hold_queue}}) {
153 return '08'; # waiting on hold shelf
155 return '03'; # available
156 } # FIXME: 01-13 enumerated in spec.
159 sub sip_security_marker {
160 return '02'; # FIXME? 00-other; 01-None; 02-Tattle-Tape Security Strip (3M); 03-Whisper Tape (3M)
163 return '01'; # FIXME? 01-09 enumerated in spec. We just use O1-other/unknown.
168 return $self->{fee} || 0;
172 return $self->{currency} || 'USD';
176 return 'CPL'; # FIXME: UWOLS was hardcoded
180 (defined $self->{hold_queue}) or return [];
181 return $self->{hold_queue};
185 (defined $self->{pending_queue}) or return [];
186 return $self->{pending_queue};
190 (defined $self->{hold_shelf}) or return [];
191 return $self->{hold_shelf};
194 sub hold_queue_position {
195 my ($self, $patron_id) = @_;
196 ($self->{hold_queue}) or return 0;
198 foreach (@{$self->{hold_queue}}) {
200 $_->{patron_id} or next;
201 if ($self->barcode_is_borrowernumber($patron_id, $_->{borrowernumber})) {
202 return $i; # maybe should return $_->{priority}
210 return $self->{due_date} || 0;
214 return $self->{recall_date} || 0;
216 sub hold_pickup_date {
218 return $self->{hold_pickup_date} || 0;
222 return $self->{screen_msg} || '';
226 return $self->{print_line} || '';
229 # This is a partial check of "availability". It is not supposed to check everything here.
230 # An item is available for a patron if it is:
231 # 1) checked out to the same patron
232 # AND no pending (i.e. non-W) hold queue
235 # AND (not on hold_shelf OR is on hold_shelf for patron)
237 # What this means is we are consciously allowing the patron to checkout (but not renew) an item that DOES
238 # have non-W holds on it, but has not been "picked" from the stacks. That is to say, the
239 # patron has retrieved the item before the librarian.
241 # We don't check if the patron is at the front of the pending queue in the first case, because
242 # they should not be able to place a hold on an item they already have.
245 my ($self, $for_patron) = @_;
246 my $count = (defined $self->{pending_queue}) ? scalar @{$self->{pending_queue}} : 0;
247 my $count2 = (defined $self->{hold_shelf} ) ? scalar @{$self->{hold_shelf} } : 0;
248 $debug and print STDERR "availability check: pending_queue size $count, hold_shelf size $count2\n";
249 if (defined($self->{patron_id})) {
250 ($self->{patron_id} eq $for_patron) or return 0;
251 return ($count ? 0 : 1);
252 } else { # not checked out
253 ($count2) and return $self->barcode_is_borrowernumber($for_patron, $self->{hold_shelf}[0]->{borrowernumber});
258 sub _barcode_to_borrowernumber ($) {
260 (defined($known)) or return undef;
261 my $member = GetMember($known,'cardnumber') or return undef;
262 return $member->{borrowernumber};
264 sub barcode_is_borrowernumber ($$$) { # because hold_queue only has borrowernumber...
265 my $self = shift; # not really used
267 my $number = shift or return undef; # can't be zero
268 (defined($barcode)) or return undef; # might be 0 or 000 or 000000
269 my $converted = _barcode_to_borrowernumber($barcode) or return undef;
270 return ($number eq $converted); # even though both *should* be numbers, eq is safer.
272 sub fill_reserve ($$) {
274 my $hold = shift or return undef;
275 foreach (qw(biblionumber borrowernumber reservedate)) {
276 $hold->{$_} or return undef;
278 return ModReserveFill($hold);