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;
12 use OpenILS::Application::Circ::CopyLocations;
14 use OpenILS::Application::AppUtils;
15 my $apputils = "OpenILS::Application::AppUtils";
18 use OpenILS::Utils::ModsParser;
20 use OpenSRF::EX qw(:try);
21 use OpenSRF::Utils::Logger qw(:logger);
22 #my $logger = "OpenSRF::Utils::Logger";
25 # ------------------------------------------------------------------------
26 # Top level Circ package;
27 # ------------------------------------------------------------------------
31 OpenILS::Application::Circ::Rules->initialize();
32 OpenILS::Application::Circ::Circulate->initialize();
36 # ------------------------------------------------------------------------
37 # Returns an array of {circ, record} hashes checked out by the user.
38 # ------------------------------------------------------------------------
39 __PACKAGE__->register_method(
40 method => "checkouts_by_user",
41 api_name => "open-ils.circ.actor.user.checked_out",
43 Returns a list of open circulations as a pile of objects. each object
44 contains the relevant copy, circ, and record
47 sub checkouts_by_user {
48 my( $self, $client, $user_session, $user_id ) = @_;
50 my( $requestor, $target, $copy, $record, $evt );
52 ( $requestor, $target, $evt ) =
53 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
56 my $circs = $apputils->simplereq(
58 "open-ils.storage.direct.action.open_circulation.search.atomic",
59 # { usr => $target->id, xact_finish => undef } );
60 { usr => $target->id } );
63 for my $circ (@$circs) {
65 ( $copy, $evt ) = $apputils->fetch_copy($circ->target_copy);
68 $logger->debug("Retrieving record for copy " . $circ->target_copy);
70 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
73 my $mods = $apputils->record_to_mvr($record);
75 push( @results, { copy => $copy, circ => $circ, record => $mods } );
84 __PACKAGE__->register_method(
85 method => "checkouts_by_user_slim",
86 api_name => "open-ils.circ.actor.user.checked_out.slim",
88 Returns a list of open circulation objects
91 sub checkouts_by_user_slim {
92 my( $self, $client, $user_session, $user_id ) = @_;
94 my( $requestor, $target, $copy, $record, $evt );
96 ( $requestor, $target, $evt ) =
97 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
100 $logger->debug( 'User ' . $requestor->id .
101 " retrieving checked out items for user " . $target->id );
103 return $apputils->simplereq(
105 "open-ils.storage.direct.action.open_circulation.search.atomic",
106 # { usr => $target->id, xact_finish => undef } );
107 { usr => $target->id } );
113 __PACKAGE__->register_method(
114 method => "title_from_transaction",
115 api_name => "open-ils.circ.circ_transaction.find_title",
116 NOTES => <<" NOTES");
117 Returns a mods object for the title that is linked to from the
118 copy from the hold that created the given transaction
121 sub title_from_transaction {
122 my( $self, $client, $login_session, $transactionid ) = @_;
124 my( $user, $circ, $title, $evt );
126 ( $user, $evt ) = $apputils->checkses( $login_session );
129 ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
132 ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
135 return $apputils->record_to_mvr($title);
139 __PACKAGE__->register_method(
140 method => "set_circ_lost",
141 api_name => "open-ils.circ.circulation.set_lost",
142 NOTES => <<" NOTES");
143 Params are login, circid
144 login must have SET_CIRC_LOST perms
145 Sets a circulation to lost
148 __PACKAGE__->register_method(
149 method => "set_circ_lost",
150 api_name => "open-ils.circ.circulation.set_claims_returned",
151 NOTES => <<" NOTES");
152 Params are login, circid
153 login must have SET_CIRC_MISSING perms
154 Sets a circulation to lost
158 my( $self, $client, $login, $circid ) = @_;
159 my( $user, $circ, $evt );
161 ( $user, $evt ) = $apputils->checkses($login);
164 ( $circ, $evt ) = $apputils->fetch_circulation( $circid );
167 if($self->api_name =~ /lost/) {
168 if($evt = $apputils->checkperms(
169 $user->id, $circ->circ_lib, "SET_CIRC_LOST")) {
172 $circ->stop_fines("LOST");
175 # XXX Back date the checkin time so the patron has no fines
176 if($self->api_name =~ /claims_returned/) {
177 if($evt = $apputils->checkperms(
178 $user->id, $circ->circ_lib, "SET_CIRC_CLAIMS_RETURNED")) {
181 $circ->stop_fines("CLAIMSRETURNED");
184 my $s = $apputils->simplereq(
186 "open-ils.storage.direct.action.circulation.update", $circ );
188 if(!$s) { throw OpenSRF::EX::ERROR ("Error updating circulation with id $circid"); }
191 __PACKAGE__->register_method(
192 method => "create_in_house_use",
193 api_name => 'open-ils.circ.in_house_use.create',
195 Creates an in-house use action.
196 @param $authtoken The login session key
197 @param params A hash of params including
198 'location' The org unit id where the in-house use occurs
199 'copyid' The copy in question
200 'count' The number of in-house uses to apply to this copy
201 @return An array of id's representing the id's of the newly created
202 in-house use objects or an event on an error
205 sub create_in_house_use {
206 my( $self, $client, $authtoken, $params ) = @_;
208 my( $staff, $evt, $copy );
209 my $org = $params->{location};
210 my $copyid = $params->{copyid};
211 my $count = $params->{count} || 1;
213 ($staff, $evt) = $U->checkses($authtoken);
216 ($copy, $evt) = $U->fetch_copy($copyid);
219 $evt = $U->check_perms($staff->id, $org, 'CREATE_IN_HOUSE_USE');
222 $logger->activity("User " . $staff->id .
223 " creating $count in-house use(s) for copy $copyid at location $org");
227 my $ihu = Fieldmapper::action::in_house_use->new;
230 $ihu->staff($staff->id);
231 $ihu->org_unit($org);
232 $ihu->use_time('now');
234 my $id = $U->simplereq(
236 'open-ils.storage.direct.action.in_house_use.create', $ihu );
238 return $U->DB_UPDATE_FAILED($ihu) unless $id;