1 package OpenILS::Application::Circ;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
5 use OpenILS::Application::Circ::Rules;
6 use OpenILS::Application::Circ::Survey;
7 use OpenILS::Application::Circ::StatCat;
8 use OpenILS::Application::Circ::Holds;
9 use OpenILS::Application::Circ::Money;
11 use OpenILS::Application::AppUtils;
12 my $apputils = "OpenILS::Application::AppUtils";
14 use OpenILS::Utils::ModsParser;
16 use OpenSRF::EX qw(:try);
17 use OpenSRF::Utils::Logger qw(:logger);
18 #my $logger = "OpenSRF::Utils::Logger";
21 # ------------------------------------------------------------------------
22 # Top level Circ package;
23 # ------------------------------------------------------------------------
27 OpenILS::Application::Circ::Rules->initialize();
31 # ------------------------------------------------------------------------
32 # Returns an array of {circ, record} hashes checked out by the user.
33 # ------------------------------------------------------------------------
34 __PACKAGE__->register_method(
35 method => "checkouts_by_user",
36 api_name => "open-ils.circ.actor.user.checked_out",
38 Returns a list of open circulations as a pile of objects. each object
39 contains the relevant copy, circ, and record
42 sub checkouts_by_user {
43 my( $self, $client, $user_session, $user_id ) = @_;
45 my( $requestor, $target, $copy, $record, $evt );
47 ( $requestor, $target, $evt ) =
48 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
51 my $circs = $apputils->simplereq(
53 "open-ils.storage.direct.action.open_circulation.search.atomic",
54 { usr => $target->id } );
57 for my $circ (@$circs) {
59 ( $copy, $evt ) = $apputils->fetch_copy($circ->target_copy);
62 $logger->debug("Retrieving record for copy " . $circ->target_copy);
64 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
67 my $mods = $apputils->record_to_mvr($record);
69 push( @results, { copy => $copy, circ => $circ, record => $mods } );
78 __PACKAGE__->register_method(
79 method => "checkouts_by_user_slim",
80 api_name => "open-ils.circ.actor.user.checked_out.slim",
82 Returns a list of open circulation objects
85 sub checkouts_by_user_slim {
86 my( $self, $client, $user_session, $user_id ) = @_;
88 my( $requestor, $target, $copy, $record, $evt );
90 ( $requestor, $target, $evt ) =
91 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
94 return $apputils->simplereq(
96 "open-ils.storage.direct.action.open_circulation.search.atomic",
97 { usr => $target->id } );
103 __PACKAGE__->register_method(
104 method => "title_from_transaction",
105 api_name => "open-ils.circ.circ_transaction.find_title",
106 NOTES => <<" NOTES");
107 Returns a mods object for the title that is linked to from the
108 copy from the hold that created the given transaction
111 sub title_from_transaction {
112 my( $self, $client, $login_session, $transactionid ) = @_;
114 my( $user, $circ, $title, $evt );
116 ( $user, $evt ) = $apputils->checkses( $login_session );
119 ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
122 ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
125 return $apputils->record_to_mvr($title);
129 __PACKAGE__->register_method(
130 method => "set_circ_lost",
131 api_name => "open-ils.circ.circulation.set_lost",
132 NOTES => <<" NOTES");
133 Params are login, circid
134 login must have SET_CIRC_LOST perms
135 Sets a circulation to lost
138 __PACKAGE__->register_method(
139 method => "set_circ_lost",
140 api_name => "open-ils.circ.circulation.set_claims_returned",
141 NOTES => <<" NOTES");
142 Params are login, circid
143 login must have SET_CIRC_MISSING perms
144 Sets a circulation to lost
148 my( $self, $client, $login, $circid ) = @_;
149 my( $user, $circ, $evt );
151 ( $user, $evt ) = $apputils->checkses($login);
154 ( $circ, $evt ) = $apputils->fetch_circulation( $circid );
157 if($self->api_name =~ /lost/) {
158 if($evt = $apputils->checkperms(
159 $user->id, $circ->circ_lib, "SET_CIRC_LOST")) {
162 $circ->stop_fines("LOST");
165 if($self->api_name =~ /claims_returned/) {
166 if($evt = $apputils->checkperms(
167 $user->id, $circ->circ_lib, "SET_CIRC_CLAIMS_RETURNED")) {
170 $circ->stop_fines("CLAIMSRETURNED");
173 my $s = $apputils->simplereq(
175 "open-ils.storage.direct.action.circulation.update", $circ );
177 if(!$s) { throw OpenSRF::EX::ERROR ("Error updating circulation with id $circid"); }