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();
32 # ------------------------------------------------------------------------
33 # Returns an array of {circ, record} hashes checked out by the user.
34 # ------------------------------------------------------------------------
35 __PACKAGE__->register_method(
36 method => "checkouts_by_user",
37 api_name => "open-ils.circ.actor.user.checked_out",
39 Returns a list of open circulations as a pile of objects. each object
40 contains the relevant copy, circ, and record
43 sub checkouts_by_user {
44 my( $self, $client, $user_session, $user_id ) = @_;
46 my( $requestor, $target, $copy, $record, $evt );
48 ( $requestor, $target, $evt ) =
49 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
52 my $circs = $apputils->simplereq(
54 "open-ils.storage.direct.action.open_circulation.search.atomic",
55 { usr => $target->id } );
58 for my $circ (@$circs) {
60 ( $copy, $evt ) = $apputils->fetch_copy($circ->target_copy);
63 $logger->debug("Retrieving record for copy " . $circ->target_copy);
65 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
68 my $mods = $apputils->record_to_mvr($record);
70 push( @results, { copy => $copy, circ => $circ, record => $mods } );
78 __PACKAGE__->register_method(
79 method => "title_from_transaction",
80 api_name => "open-ils.circ.circ_transaction.find_title",
82 Returns a mods object for the title that is linked to from the
83 copy from the hold that created the given transaction
86 sub title_from_transaction {
87 my( $self, $client, $login_session, $transactionid ) = @_;
89 my( $user, $circ, $title, $evt );
91 ( $user, $evt ) = $apputils->checkses( $login_session );
94 ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
97 ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
100 return $apputils->record_to_mvr($title);
104 __PACKAGE__->register_method(
105 method => "set_circ_lost",
106 api_name => "open-ils.circ.circulation.set_lost",
107 NOTES => <<" NOTES");
108 Params are login, circid
109 login must have SET_CIRC_LOST perms
110 Sets a circulation to lost
113 __PACKAGE__->register_method(
114 method => "set_circ_lost",
115 api_name => "open-ils.circ.circulation.set_claims_returned",
116 NOTES => <<" NOTES");
117 Params are login, circid
118 login must have SET_CIRC_MISSING perms
119 Sets a circulation to lost
123 my( $self, $client, $login, $circid ) = @_;
124 my( $user, $circ, $evt );
126 ( $user, $evt ) = $apputils->checkses($login);
129 ( $circ, $evt ) = $apputils->fetch_circulation( $circid );
132 if($self->api_name =~ /lost/) {
133 if($evt = $apputils->checkperms(
134 $user->id, $circ->circ_lib, "SET_CIRC_LOST")) {
137 $circ->stop_fines("LOST");
140 if($self->api_name =~ /claims_returned/) {
141 if($evt = $apputils->checkperms(
142 $user->id, $circ->circ_lib, "SET_CIRC_CLAIMS_RETURNED")) {
145 $circ->stop_fines("CLAIMSRETURNED");
148 my $s = $apputils->simplereq(
150 "open-ils.storage.direct.action.circulation.update", $circ );
152 if(!$s) { throw OpenSRF::EX::ERROR ("Error updating circulation with id $circid"); }