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;
17 # ------------------------------------------------------------------------
18 # Top level Circ package;
19 # ------------------------------------------------------------------------
23 OpenILS::Application::Circ::Rules->initialize();
28 # ------------------------------------------------------------------------
29 # Returns an array of {circ, record} hashes checked out by the user.
30 # ------------------------------------------------------------------------
31 __PACKAGE__->register_method(
32 method => "checkouts_by_user",
33 api_name => "open-ils.circ.actor.user.checked_out",
35 Returns a list of open circulations as a pile of objects. each object
36 contains the relevant copy, circ, and record
39 sub checkouts_by_user {
40 my( $self, $client, $user_session, $user_id ) = @_;
42 my $session = OpenSRF::AppSession->create("open-ils.storage");
43 my $user_obj = $apputils->check_user_session($user_session);
45 if(!$user_id) { $user_id = $user_obj->id(); }
47 my $circs = $session->request(
48 "open-ils.storage.direct.action.open_circulation.search.atomic",
49 { usr => $user_id } );
50 $circs = $circs->gather(1);
53 for my $circ (@$circs) {
55 my $copy = $session->request(
56 "open-ils.storage.direct.asset.copy.retrieve",
59 warn "Retrieving record for copy " . $circ->target_copy . "\n";
61 my $record = $session->request(
62 "open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy",
65 $copy = $copy->gather(1);
66 $record = $record->gather(1);
70 my $u = OpenILS::Utils::ModsParser->new();
71 $u->start_mods_batch( $record->marc() );
72 my $mods = $u->finish_mods_batch();
73 $mods->doc_id($record->id());
75 push( @results, { copy => $copy, circ => $circ, record => $mods } );
83 __PACKAGE__->register_method(
84 method => "title_from_transaction",
85 api_name => "open-ils.circ.circ_transaction.find_title",
87 Returns a mods object for the title that is linked to from the
88 copy from the hold that created the given transaction
91 sub title_from_transaction {
93 my( $self, $client, $login_session, $transactionid ) = @_;
94 my $user = $apputils->check_user_session($login_session);
95 my $session = OpenSRF::AppSession->create('open-ils.storage');
97 my $circ = $session->request(
98 "open-ils.storage.direct.action.circulation.retrieve", $transactionid )->gather(1);
101 my $title = $session->request(
102 "open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy",
103 $circ->target_copy )->gather(1);
106 my $u = OpenILS::Utils::ModsParser->new();
107 $u->start_mods_batch( $title->marc );
108 return $u->finish_mods_batch();
116 __PACKAGE__->register_method(
117 method => "set_circ_lost",
118 api_name => "open-ils.circ.circulation.set_lost",
119 NOTES => <<" NOTES");
120 Params are login, circid
121 login must have SET_CIRC_LOST perms
122 Sets a circulation to lost
125 __PACKAGE__->register_method(
126 method => "set_circ_lost",
127 api_name => "open-ils.circ.circulation.set_claims_returned",
128 NOTES => <<" NOTES");
129 Params are login, circid
130 login must have SET_CIRC_MISSING perms
131 Sets a circulation to lost
135 my( $self, $client, $login, $circid ) = @_;
137 my $user = $apputils->check_user_session($login);
138 my $session = OpenSRF::AppSession->create('open-ils.storage');
139 my $circ = $session->request(
140 "open-ils.storage.direct.action.circulation.retrieve", $circid )->gather(1);
142 if(!$circ) { throw OpenSRF::EX::ERROR ("No circulation exists with id $circid"); }
144 if($self->api_name =~ /lost/) {
145 if($apputils->check_user_perms($user->id, $circ->circ_lib, "SET_CIRC_LOST")) {
146 return OpenILS::Perm->new("SET_CIRC_LOST");
148 $circ->stop_fines("LOST");
151 if($self->api_name =~ /claims_returned/) {
152 if($apputils->check_user_perms($user->id, $circ->circ_lib, "SET_CIRC_CLAIMS_RETURNED")) {
153 return OpenILS::Perm->new("SET_CIRC_CLAIMS_RETURNED");
155 $circ->stop_fines("CLAIMSRETURNED");
159 my $s = $session->request(
160 "open-ils.storage.direct.action.circulation.update", $circ )->gather(1);
162 if(!$s) { throw OpenSRF::EX::ERROR ("Error updating circulation with id $circid"); }