]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/SIP/Item.pm
added real statuses and due date
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / SIP / Item.pm
1 #
2 #
3 # A Class for hiding the ILS's concept of the item from the OpenSIP
4 # system
5 #
6
7 package OpenILS::SIP::Item;
8 use strict; use warnings;
9
10 use Sys::Syslog qw(syslog);
11
12 use OpenILS::SIP;
13 use OpenILS::SIP::Transaction;
14 use OpenILS::Application::AppUtils;
15 my $U = 'OpenILS::Application::AppUtils';
16
17 my %item_db;
18
19 sub new {
20     my ($class, $item_id) = @_;
21     my $type = ref($class) || $class;
22     my $self = bless( {}, $type );
23
24         syslog('LOG_DEBUG', "Loading item $item_id...");
25         return undef unless $item_id;
26
27         my $e = OpenILS::SIP->editor();
28
29          # FLESH ME
30         my $copy = $e->search_asset_copy(
31                 [
32                         { barcode => $item_id },
33                         {
34                                 flesh => 3,
35                                 flesh_fields => {
36                                         acp => [ 'circ_lib', 'call_number', 'status' ],
37                                         acn => [ 'owning_lib', 'record' ],
38                                 }
39                         }
40                 ]
41         );
42
43         $copy = $$copy[0];
44
45         if(!$copy) {
46                 syslog("LOG_DEBUG", "OpenILS: Item '%s' : not found", $item_id);
47                 return undef;
48         }
49
50         my ($circ) = $U->fetch_open_circulation($copy->id);
51         if($circ) {
52                 # if i am checked out, set $self->{patron} to the user's barcode
53                 my $user = $e->retrieve_actor_user(
54                         [
55                                 $circ->usr,
56                                 { flesh => 1, flesh_fields => { "au" => [ 'card' ] } }
57                         ]
58                 );
59
60                 my $bc = ($user) ? $user->card->barcode : "";
61                 $self->{patron} = $bc;
62                 $self->{patron_object} = $user;
63
64                 syslog('LOG_DEBUG', "Open circulation exists on $item_id : user = $bc");
65         }
66
67         $self->{id}                     = $item_id;
68         $self->{copy}           = $copy;
69         $self->{volume} = $copy->call_number;
70         $self->{record} = $copy->call_number->record;
71         $self->{mods}           = $U->record_to_mvr($self->{record}) if $self->{record}->marc;
72
73         syslog("LOG_DEBUG", "Item('$item_id'): found with title '%s'", $self->title_id);
74
75         return $self;
76 }
77
78 sub magnetic {
79     my $self = shift;
80          return 0;
81 }
82
83 sub sip_media_type {
84     my $self = shift;
85          return '001';
86 }
87
88 sub sip_item_properties {
89     my $self = shift;
90          return "";
91 }
92
93 sub status_update {
94     my ($self, $props) = @_;
95     my $status = OpenILS::SIP::Transaction->new;
96     $self->{sip_item_properties} = $props;
97     $status->{ok} = 1;
98     return $status;
99 }
100
101
102 sub id {
103     my $self = shift;
104     return $self->{id};
105 }
106
107 sub title_id {
108     my $self = shift;
109     return ($self->{mods}) ? $self->{mods}->title : $self->{copy}->dummy_title;
110 }
111
112 sub permanent_location {
113     my $self = shift;
114          return $self->{volume}->owning_lib->name;
115 }
116
117 sub current_location {
118     my $self = shift;
119          return $self->{copy}->circ_lib->name;
120 }
121
122
123 # 2 chars 0-99 
124 # 01 Other
125 # 02 On order
126 # 03 Available
127 # 04 Charged
128 # 05 Charged; not to be recalled until earliest recall date
129 # 06 In process
130 # 07 Recalled
131 # 08 Waiting on hold shelf
132 # 09 Waiting to be re-shelved
133 # 10 In transit between library locations
134 # 11 Claimed returned
135 # 12 Lost
136 # 13 Missing 
137 sub sip_circulation_status {
138         my $self = shift;
139         return '03' if $self->{copy}->status->name =~ /available/i;
140         return '04' if $self->{copy}->status->name =~ /checked out/i;
141         return '06' if $self->{copy}->status->name =~ /in process/i;
142         return '08' if $self->{copy}->status->name =~ /on holds shelf/i;
143         return '09' if $self->{copy}->status->name =~ /reshelving/i;
144         return '10' if $self->{copy}->status->name =~ /in transit/i;
145         return '12' if $self->{copy}->status->name =~ /lost/i;
146         return 01;
147 }
148
149 sub sip_security_marker {
150     return '02';
151 }
152
153 sub sip_fee_type {
154     return '01';
155 }
156
157 sub fee {
158     my $self = shift;
159          return 0;
160 }
161
162
163 sub fee_currency {
164     my $self = shift;
165     'USD';
166 }
167
168 sub owner {
169     my $self = shift;
170          return $self->{volume}->owning_lib->name;
171 }
172
173 sub hold_queue {
174     my $self = shift;
175          return [];
176 }
177
178 sub hold_queue_position {
179     my ($self, $patron_id) = @_;
180          return 1;
181 }
182
183 sub due_date {
184         my $self = shift;
185         my $e = OpenILS::SIP->editor();
186
187         my $circ = $e->search_action_circulation(
188                 { target_copy => $self->{copy}->id, stop_fines => undef } )->[0];
189
190         if(!$circ) {
191                 # if not, lets look for other circs we can check in
192                 $circ = $e->search_action_circulation(
193                         { 
194                                 target_copy => $self->{copy}->id, 
195                                 xact_finish => undef,
196                                 stop_fines      => [ 'CLAIMSRETURNED', 'LOST', 'LONGOVERDUE' ]
197                         } )->[0];
198         }
199
200         return $circ->due_date if $circ;
201         return 0;
202 }
203
204 sub recall_date {
205     my $self = shift;
206     return 0;
207 }
208
209 sub hold_pickup_date {
210     my $self = shift;
211          return 0;
212 }
213
214 # message to display on console
215 sub screen_msg {
216     my $self = shift;
217     return $self->{screen_msg} || '';
218 }
219
220
221 # reciept printer
222 sub print_line {
223      my $self = shift;
224      return $self->{print_line} || '';
225 }
226
227
228 # An item is available for a patron if
229 # 1) It's not checked out and (there's no hold queue OR patron
230 #    is at the front of the queue)
231 # OR
232 # 2) It's checked out to the patron and there's no hold queue
233 sub available {
234      my ($self, $for_patron) = @_;
235           return 1;
236 }
237
238
239 1;