1 package OpenILS::Application::Circ;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
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;
13 use OpenILS::Application::AppUtils;
14 my $apputils = "OpenILS::Application::AppUtils";
17 use OpenILS::Utils::ModsParser;
19 use OpenSRF::EX qw(:try);
20 use OpenSRF::Utils::Logger qw(:logger);
21 #my $logger = "OpenSRF::Utils::Logger";
24 # ------------------------------------------------------------------------
25 # Top level Circ package;
26 # ------------------------------------------------------------------------
30 OpenILS::Application::Circ::Rules->initialize();
31 OpenILS::Application::Circ::Circulate->initialize();
35 # ------------------------------------------------------------------------
36 # Returns an array of {circ, record} hashes checked out by the user.
37 # ------------------------------------------------------------------------
38 __PACKAGE__->register_method(
39 method => "checkouts_by_user",
40 api_name => "open-ils.circ.actor.user.checked_out",
42 Returns a list of open circulations as a pile of objects. each object
43 contains the relevant copy, circ, and record
46 sub checkouts_by_user {
47 my( $self, $client, $user_session, $user_id ) = @_;
49 my( $requestor, $target, $copy, $record, $evt );
51 ( $requestor, $target, $evt ) =
52 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
55 my $circs = $apputils->simplereq(
57 "open-ils.storage.direct.action.open_circulation.search.atomic",
58 # { usr => $target->id, xact_finish => undef } );
59 { usr => $target->id } );
62 for my $circ (@$circs) {
64 ( $copy, $evt ) = $apputils->fetch_copy($circ->target_copy);
67 $logger->debug("Retrieving record for copy " . $circ->target_copy);
69 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
72 my $mods = $apputils->record_to_mvr($record);
74 push( @results, { copy => $copy, circ => $circ, record => $mods } );
83 __PACKAGE__->register_method(
84 method => "checkouts_by_user_slim",
85 api_name => "open-ils.circ.actor.user.checked_out.slim",
87 Returns a list of open circulation objects
90 sub checkouts_by_user_slim {
91 my( $self, $client, $user_session, $user_id ) = @_;
93 my( $requestor, $target, $copy, $record, $evt );
95 ( $requestor, $target, $evt ) =
96 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
99 $logger->debug( 'User ' . $requestor->id .
100 " retrieving checked out items for user " . $target->id );
102 return $apputils->simplereq(
104 "open-ils.storage.direct.action.open_circulation.search.atomic",
105 # { usr => $target->id, xact_finish => undef } );
106 { usr => $target->id } );
112 __PACKAGE__->register_method(
113 method => "title_from_transaction",
114 api_name => "open-ils.circ.circ_transaction.find_title",
115 NOTES => <<" NOTES");
116 Returns a mods object for the title that is linked to from the
117 copy from the hold that created the given transaction
120 sub title_from_transaction {
121 my( $self, $client, $login_session, $transactionid ) = @_;
123 my( $user, $circ, $title, $evt );
125 ( $user, $evt ) = $apputils->checkses( $login_session );
128 ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
131 ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
134 return $apputils->record_to_mvr($title);
138 __PACKAGE__->register_method(
139 method => "set_circ_lost",
140 api_name => "open-ils.circ.circulation.set_lost",
141 NOTES => <<" NOTES");
142 Params are login, circid
143 login must have SET_CIRC_LOST perms
144 Sets a circulation to lost
147 __PACKAGE__->register_method(
148 method => "set_circ_lost",
149 api_name => "open-ils.circ.circulation.set_claims_returned",
150 NOTES => <<" NOTES");
151 Params are login, circid
152 login must have SET_CIRC_MISSING perms
153 Sets a circulation to lost
157 my( $self, $client, $login, $circid ) = @_;
158 my( $user, $circ, $evt );
160 ( $user, $evt ) = $apputils->checkses($login);
163 ( $circ, $evt ) = $apputils->fetch_circulation( $circid );
166 if($self->api_name =~ /lost/) {
167 if($evt = $apputils->checkperms(
168 $user->id, $circ->circ_lib, "SET_CIRC_LOST")) {
171 $circ->stop_fines("LOST");
174 # XXX Back date the checkin time so the patron has no fines
175 if($self->api_name =~ /claims_returned/) {
176 if($evt = $apputils->checkperms(
177 $user->id, $circ->circ_lib, "SET_CIRC_CLAIMS_RETURNED")) {
180 $circ->stop_fines("CLAIMSRETURNED");
183 my $s = $apputils->simplereq(
185 "open-ils.storage.direct.action.circulation.update", $circ );
187 if(!$s) { throw OpenSRF::EX::ERROR ("Error updating circulation with id $circid"); }
190 __PACKAGE__->register_method(
191 method => "create_in_house_use",
192 api_name => 'open-ils.circ.in_house_use.create',
194 Creates an in-house use action.
195 @param $authtoken The login session key
196 @param params A named list of params including
197 'location' The org unit id where the in-house use occurs
198 'copyid' The copy in question
199 'count' The number of in-house uses to apply to this copy
200 @return An array of id's representing the id's of the newly created
201 in-house use objects or an event on an error
204 sub create_in_house_use {
205 my( $self, $client, $authtoken, %params ) = @_;
207 my( $staff, $evt, $copy );
208 my $org = $params{location};
209 my $copyid = $params{copyid};
210 my $count = $params{count} || 1;
212 ($staff, $evt) = $U->checkses($authtoken);
215 ($copy, $evt) = $U->fetch_copy($copyid);
218 $evt = $U->check_perms($staff->id, $org, 'CREATE_IN_HOUSE_USE');
221 $logger->activity("User " . $staff->id .
222 " creating $count in-house use(s) for copy $copyid at location $org");
226 my $ihu = Fieldmapper::action::in_house_use->new;
229 $ihu->staff($staff->id);
230 $ihu->org_unit($org);
231 $ihu->use_time('now');
233 my $id = $U->simplereq(
235 'open-ils.storage.direct.action.in_house_use.create', $ihu );
237 return $U->DB_UPDATE_FAILED($ihu) unless $id;