1 package OpenILS::SIP::Item;
2 use strict; use warnings;
4 use Sys::Syslog qw(syslog);
7 use OpenILS::SIP::Transaction;
8 use OpenILS::Application::AppUtils;
9 use OpenILS::Application::Circ::ScriptBuilder;
11 use OpenILS::Const qw/:const/;
12 use OpenSRF::Utils qw/:datetime/;
13 use DateTime::Format::ISO8601;
14 my $U = 'OpenILS::Application::AppUtils';
19 my ($class, $item_id) = @_;
20 my $type = ref($class) || $class;
21 my $self = bless( {}, $type );
23 syslog('LOG_DEBUG', "OILS: Loading item $item_id...");
24 return undef unless $item_id;
26 my $e = OpenILS::SIP->editor();
28 my $copy = $e->search_asset_copy(
30 { barcode => $item_id, deleted => 'f' },
34 acp => [ 'circ_lib', 'call_number', 'status' ],
35 acn => [ 'owning_lib', 'record' ],
45 syslog("LOG_DEBUG", "OILS: Item '%s' : not found", $item_id);
49 my ($circ) = $U->fetch_open_circulation($copy->id);
51 # if i am checked out, set $self->{patron} to the user's barcode
52 my $user = $e->retrieve_actor_user(
55 { flesh => 1, flesh_fields => { "au" => [ 'card' ] } }
59 my $bc = ($user) ? $user->card->barcode : "";
60 $self->{patron} = $bc;
61 $self->{patron_object} = $user;
63 syslog('LOG_DEBUG', "OILS: Open circulation exists on $item_id : user = $bc");
66 $self->{id} = $item_id;
67 $self->{copy} = $copy;
68 $self->{volume} = $copy->call_number;
69 $self->{record} = $copy->call_number->record;
70 $self->{mods} = $U->record_to_mvr($self->{record}) if $self->{record}->marc;
72 syslog("LOG_DEBUG", "OILS: Item('$item_id'): found with title '%s'", $self->title_id);
79 return 1 if $self->{ran_script};
80 $self->{ran_script} = 1;
82 my $config = OpenILS::SIP->config();
83 my $path = $config->{implementation_config}->{scripts}->{path};
84 my $item_config_script = $config->{implementation_config}->{scripts}->{item_config};
86 $path = ref($path) eq 'ARRAY' ? $path : [$path];
88 syslog('LOG_DEBUG', "OILS: Script path = $path, Item config script = $item_config_script");
91 OpenILS::Application::Circ::ScriptBuilder->build(
93 copy => $self->{copy},
94 editor => OpenILS::SIP->editor(),
98 $runner->add_path($_) for @$path;
99 $runner->load($item_config_script);
101 unless( $self->{item_config_result} = $runner->run ) {
103 warn "Item config script [$path : $item_config_script] failed to run: $@\n";
104 syslog('LOG_ERR', "OILS: Item config script [$path : $item_config_script] failed to run: $@");
114 return 0 unless $self->run_attr_script;
115 my $mag = $self->{item_config_result}->{magneticMedia};
116 syslog('LOG_DEBUG', "OILS: magnetic = $mag");
117 return ($mag and $mag eq 't') ? 1 : 0;
122 return 0 unless $self->run_attr_script;
123 my $media = $self->{item_config_result}->{SIPMediaType};
124 syslog('LOG_DEBUG', "OILS: media type = $media");
125 return ($media) ? $media : '001';
128 sub sip_item_properties {
134 my ($self, $props) = @_;
135 my $status = OpenILS::SIP::Transaction->new;
136 $self->{sip_item_properties} = $props;
149 return ($self->{mods}) ? $self->{mods}->title : $self->{copy}->dummy_title;
152 sub permanent_location {
154 return $self->{volume}->owning_lib->name;
157 sub current_location {
159 return $self->{copy}->circ_lib->name;
168 # 05 Charged; not to be recalled until earliest recall date
171 # 08 Waiting on hold shelf
172 # 09 Waiting to be re-shelved
173 # 10 In transit between library locations
174 # 11 Claimed returned
177 sub sip_circulation_status {
179 my $stat = $self->{copy}->status->id;
181 return '02' if $stat == OILS_COPY_STATUS_ON_ORDER;
182 return '03' if $stat == OILS_COPY_STATUS_AVAILABLE;
183 return '04' if $stat == OILS_COPY_STATUS_CHECKED_OUT;
184 return '06' if $stat == OILS_COPY_STATUS_IN_PROCESS;
185 return '08' if $stat == OILS_COPY_STATUS_ON_HOLDS_SHELF;
186 return '09' if $stat == OILS_COPY_STATUS_RESHELVING;
187 return '10' if $stat == OILS_COPY_STATUS_IN_TRANSIT;
188 return '12' if $stat == OILS_COPY_STATUS_LOST;
189 return '13' if $stat == OILS_COPY_STATUS_MISSING;
194 sub sip_security_marker {
210 return OpenILS::SIP->config()->{implementation_config}->{currency};
215 return $self->{volume}->owning_lib->name;
223 sub hold_queue_position {
224 my ($self, $patron_id) = @_;
231 # this should force correct circ fetching
232 require OpenILS::Utils::CStoreEditor;
233 my $e = OpenILS::Utils::CStoreEditor->new(xact => 1);
234 #my $e = OpenILS::SIP->editor();
236 my $circ = $e->search_action_circulation(
237 { target_copy => $self->{copy}->id, checkin_time => undef } )->[0];
240 syslog('LOG_INFO', "OILS: No open circ found for copy");
244 my $due = OpenILS::SIP->format_date($circ->due_date);
245 syslog('LOG_DEBUG', "OILS: Found item due date = $due");
254 sub hold_pickup_date {
259 # message to display on console
262 return $self->{screen_msg} || '';
269 return $self->{print_line} || '';
273 # An item is available for a patron if
274 # 1) It's not checked out and (there's no hold queue OR patron
275 # is at the front of the queue)
277 # 2) It's checked out to the patron and there's no hold queue
279 my ($self, $for_patron) = @_;
281 my $stat = $self->{copy}->status->id;
283 $stat == OILS_COPY_STATUS_AVAILABLE or
284 $stat == OILS_COPY_STATUS_RESHELVING;