3 # A Class for hiding the ILS's concept of the item from the OpenSIP
7 package OpenILS::SIP::Item;
8 use strict; use warnings;
10 use Sys::Syslog qw(syslog);
13 use OpenILS::SIP::Transaction;
14 use OpenILS::Application::AppUtils;
15 use OpenILS::Application::Circ::ScriptBuilder;
17 use OpenILS::Const qw/:const/;
18 use OpenSRF::Utils qw/:datetime/;
19 use DateTime::Format::ISO8601;
20 my $U = 'OpenILS::Application::AppUtils';
25 my ($class, $item_id) = @_;
26 my $type = ref($class) || $class;
27 my $self = bless( {}, $type );
29 syslog('LOG_DEBUG', "OILS: Loading item $item_id...");
30 return undef unless $item_id;
32 my $e = OpenILS::SIP->editor();
34 my $copy = $e->search_asset_copy(
36 { barcode => $item_id, deleted => 'f' },
40 acp => [ 'circ_lib', 'call_number', 'status' ],
41 acn => [ 'owning_lib', 'record' ],
51 syslog("LOG_DEBUG", "OILS: Item '%s' : not found", $item_id);
55 my ($circ) = $U->fetch_open_circulation($copy->id);
57 # if i am checked out, set $self->{patron} to the user's barcode
58 my $user = $e->retrieve_actor_user(
61 { flesh => 1, flesh_fields => { "au" => [ 'card' ] } }
65 my $bc = ($user) ? $user->card->barcode : "";
66 $self->{patron} = $bc;
67 $self->{patron_object} = $user;
69 syslog('LOG_DEBUG', "OILS: Open circulation exists on $item_id : user = $bc");
72 $self->{id} = $item_id;
73 $self->{copy} = $copy;
74 $self->{volume} = $copy->call_number;
75 $self->{record} = $copy->call_number->record;
76 $self->{mods} = $U->record_to_mvr($self->{record}) if $self->{record}->marc;
78 syslog("LOG_DEBUG", "OILS: Item('$item_id'): found with title '%s'", $self->title_id);
85 return 1 if $self->{ran_script};
86 $self->{ran_script} = 1;
88 my $config = OpenILS::SIP->config();
89 my $path = $config->{implementation_config}->{scripts}->{path};
90 my $item_config_script = $config->{implementation_config}->{scripts}->{item_config};
92 syslog('LOG_DEBUG', "OILS: Script path = $path, Item config script = $item_config_script");
95 OpenILS::Application::Circ::ScriptBuilder->build(
97 copy => $self->{copy},
98 editor => OpenILS::SIP->editor(),
102 $runner->add_path($path);
103 $runner->load($item_config_script);
105 unless( $self->{item_config_result} = $runner->run ) {
106 warn "Item config script [$path : $item_config_script] failed to run: $@\n";
107 syslog('LOG_ERR', "OILS: Item config script [$path : $item_config_script] failed to run: $@");
116 return 0 unless $self->run_attr_script;
117 my $mag = $self->{item_config_result}->{magneticMedia};
118 syslog('LOG_DEBUG', "OILS: magnetic = $mag");
119 return ($mag and $mag eq 't') ? 1 : 0;
124 return 0 unless $self->run_attr_script;
125 my $media = $self->{item_config_result}->{SIPMediaType};
126 syslog('LOG_DEBUG', "OILS: media type = $media");
127 return ($media) ? $media : '001';
130 sub sip_item_properties {
136 my ($self, $props) = @_;
137 my $status = OpenILS::SIP::Transaction->new;
138 $self->{sip_item_properties} = $props;
151 return ($self->{mods}) ? $self->{mods}->title : $self->{copy}->dummy_title;
154 sub permanent_location {
156 return $self->{volume}->owning_lib->name;
159 sub current_location {
161 return $self->{copy}->circ_lib->name;
170 # 05 Charged; not to be recalled until earliest recall date
173 # 08 Waiting on hold shelf
174 # 09 Waiting to be re-shelved
175 # 10 In transit between library locations
176 # 11 Claimed returned
179 sub sip_circulation_status {
181 my $stat = $self->{copy}->status->id;
183 return '02' if $stat == OILS_COPY_STATUS_ON_ORDER;
184 return '03' if $stat == OILS_COPY_STATUS_AVAILABLE;
185 return '04' if $stat == OILS_COPY_STATUS_CHECKED_OUT;
186 return '06' if $stat == OILS_COPY_STATUS_IN_PROCESS;
187 return '08' if $stat == OILS_COPY_STATUS_ON_HOLDS_SHELF;
188 return '09' if $stat == OILS_COPY_STATUS_RESHELVING;
189 return '10' if $stat == OILS_COPY_STATUS_IN_TRANSIT;
190 return '12' if $stat == OILS_COPY_STATUS_LOST;
191 return '13' if $stat == OILS_COPY_STATUS_MISSING;
196 sub sip_security_marker {
212 return OpenILS::SIP->config()->{implementation_config}->{currency};
217 return $self->{volume}->owning_lib->name;
225 sub hold_queue_position {
226 my ($self, $patron_id) = @_;
232 my $e = OpenILS::SIP->editor();
234 my $circ = $e->search_action_circulation(
235 { target_copy => $self->{copy}->id, stop_fines => undef } )->[0];
238 # if not, lets look for other circs we can check in
239 $circ = $e->search_action_circulation(
241 target_copy => $self->{copy}->id,
242 xact_finish => undef,
243 stop_fines => [ 'CLAIMSRETURNED', 'LOST', 'LONGOVERDUE' ]
247 return 0 unless $circ;
248 my $due = OpenILS::SIP->format_date($circ->due_date);
249 syslog('LOG_DEBUG', "Item due date = $due");
258 sub hold_pickup_date {
263 # message to display on console
266 return $self->{screen_msg} || '';
273 return $self->{print_line} || '';
277 # An item is available for a patron if
278 # 1) It's not checked out and (there's no hold queue OR patron
279 # is at the front of the queue)
281 # 2) It's checked out to the patron and there's no hold queue
283 my ($self, $for_patron) = @_;
285 my $stat = $self->{copy}->status->id;
287 $stat == OILS_COPY_STATUS_AVAILABLE or
288 $stat == OILS_COPY_STATUS_RESHELVING;