]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
added the beginnings of the noncat code + events
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Circ.pm
1 package OpenILS::Application::Circ;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
4
5 use OpenILS::Application::Circ::Circulate;
6 use OpenILS::Application::Circ::Rules;
7 use OpenILS::Application::Circ::Survey;
8 use OpenILS::Application::Circ::StatCat;
9 use OpenILS::Application::Circ::Holds;
10 use OpenILS::Application::Circ::Money;
11 use OpenILS::Application::Circ::NonCat;
12
13 use OpenILS::Application::AppUtils;
14 my $apputils = "OpenILS::Application::AppUtils";
15 use OpenSRF::Utils;
16 use OpenILS::Utils::ModsParser;
17 use OpenILS::Event;
18 use OpenSRF::EX qw(:try);
19 use OpenSRF::Utils::Logger qw(:logger);
20 #my $logger = "OpenSRF::Utils::Logger";
21
22
23 # ------------------------------------------------------------------------
24 # Top level Circ package;
25 # ------------------------------------------------------------------------
26
27 sub initialize {
28         my $self = shift;
29         OpenILS::Application::Circ::Rules->initialize();
30         OpenILS::Application::Circ::Circulate->initialize();
31 }
32
33
34 # ------------------------------------------------------------------------
35 # Returns an array of {circ, record} hashes checked out by the user.
36 # ------------------------------------------------------------------------
37 __PACKAGE__->register_method(
38         method  => "checkouts_by_user",
39         api_name        => "open-ils.circ.actor.user.checked_out",
40         NOTES           => <<"  NOTES");
41         Returns a list of open circulations as a pile of objects.  each object
42         contains the relevant copy, circ, and record
43         NOTES
44
45 sub checkouts_by_user {
46         my( $self, $client, $user_session, $user_id ) = @_;
47
48         my( $requestor, $target, $copy, $record, $evt );
49
50         ( $requestor, $target, $evt ) = 
51                 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
52         return $evt if $evt;
53
54         my $circs = $apputils->simplereq(
55                 'open-ils.storage',
56                 "open-ils.storage.direct.action.open_circulation.search.atomic", 
57 #               { usr => $target->id, xact_finish => undef } );
58                 { usr => $target->id } );
59
60         my @results;
61         for my $circ (@$circs) {
62
63                 ( $copy, $evt )  = $apputils->fetch_copy($circ->target_copy);
64                 return $evt if $evt;
65
66                 $logger->debug("Retrieving record for copy " . $circ->target_copy);
67
68                 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
69                 return $evt if $evt;
70
71                 my $mods = $apputils->record_to_mvr($record);
72
73                 push( @results, { copy => $copy, circ => $circ, record => $mods } );
74         }
75
76         return \@results;
77
78 }
79
80
81
82 __PACKAGE__->register_method(
83         method  => "checkouts_by_user_slim",
84         api_name        => "open-ils.circ.actor.user.checked_out.slim",
85         NOTES           => <<"  NOTES");
86         Returns a list of open circulation objects
87         NOTES
88
89 sub checkouts_by_user_slim {
90         my( $self, $client, $user_session, $user_id ) = @_;
91
92         my( $requestor, $target, $copy, $record, $evt );
93
94         ( $requestor, $target, $evt ) = 
95                 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
96         return $evt if $evt;
97
98         $logger->debug( 'User ' . $requestor->id . 
99                 " retrieving checked out items for user " . $target->id );
100
101         return $apputils->simplereq(
102                 'open-ils.storage',
103                 "open-ils.storage.direct.action.open_circulation.search.atomic", 
104 #               { usr => $target->id, xact_finish => undef } );
105                 { usr => $target->id } );
106 }
107
108
109
110
111 __PACKAGE__->register_method(
112         method  => "title_from_transaction",
113         api_name        => "open-ils.circ.circ_transaction.find_title",
114         NOTES           => <<"  NOTES");
115         Returns a mods object for the title that is linked to from the 
116         copy from the hold that created the given transaction
117         NOTES
118
119 sub title_from_transaction {
120         my( $self, $client, $login_session, $transactionid ) = @_;
121
122         my( $user, $circ, $title, $evt );
123
124         ( $user, $evt ) = $apputils->checkses( $login_session );
125         return $evt if $evt;
126
127         ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
128         return $evt if $evt;
129         
130         ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
131         return $evt if $evt;
132
133         return $apputils->record_to_mvr($title);
134 }
135
136
137 __PACKAGE__->register_method(
138         method  => "set_circ_lost",
139         api_name        => "open-ils.circ.circulation.set_lost",
140         NOTES           => <<"  NOTES");
141         Params are login, circid
142         login must have SET_CIRC_LOST perms
143         Sets a circulation to lost
144         NOTES
145
146 __PACKAGE__->register_method(
147         method  => "set_circ_lost",
148         api_name        => "open-ils.circ.circulation.set_claims_returned",
149         NOTES           => <<"  NOTES");
150         Params are login, circid
151         login must have SET_CIRC_MISSING perms
152         Sets a circulation to lost
153         NOTES
154
155 sub set_circ_lost {
156         my( $self, $client, $login, $circid ) = @_;
157         my( $user, $circ, $evt );
158
159         ( $user, $evt ) = $apputils->checkses($login);
160         return $evt if $evt;
161
162         ( $circ, $evt ) = $apputils->fetch_circulation( $circid );
163         return $evt if $evt;
164
165         if($self->api_name =~ /lost/) {
166                 if($evt = $apputils->checkperms(
167                         $user->id, $circ->circ_lib, "SET_CIRC_LOST")) {
168                         return $evt;
169                 }
170                 $circ->stop_fines("LOST");              
171         }
172
173         # XXX Back date the checkin time so the patron has no fines
174         if($self->api_name =~ /claims_returned/) {
175                 if($evt = $apputils->checkperms(
176                         $user->id, $circ->circ_lib, "SET_CIRC_CLAIMS_RETURNED")) {
177                         return $evt;
178                 }
179                 $circ->stop_fines("CLAIMSRETURNED");
180         }
181
182         my $s = $apputils->simplereq(
183                 'open-ils.storage',
184                 "open-ils.storage.direct.action.circulation.update", $circ );
185
186         if(!$s) { throw OpenSRF::EX::ERROR ("Error updating circulation with id $circid"); }
187 }
188
189
190
191
192
193
194 1;