]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
88eb3d66480fc529df54f2b48f9b5bdee916e655
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Circ.pm
1 package OpenILS::Application::Circ;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
4
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;
10
11 use OpenILS::Application::AppUtils;
12 my $apputils = "OpenILS::Application::AppUtils";
13 use OpenSRF::Utils;
14 use OpenILS::Utils::ModsParser;
15 use OpenILS::Event;
16 use OpenSRF::EX qw(:try);
17 use OpenSRF::Utils::Logger qw(:logger);
18 #my $logger = "OpenSRF::Utils::Logger";
19
20
21 # ------------------------------------------------------------------------
22 # Top level Circ package;
23 # ------------------------------------------------------------------------
24
25 sub initialize {
26         my $self = shift;
27         OpenILS::Application::Circ::Rules->initialize();
28 }
29
30
31
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",
38         NOTES           => <<"  NOTES");
39         Returns a list of open circulations as a pile of objects.  each object
40         contains the relevant copy, circ, and record
41         NOTES
42
43 sub checkouts_by_user {
44         my( $self, $client, $user_session, $user_id ) = @_;
45
46         my( $requestor, $target, $copy, $record, $evt );
47
48         ( $requestor, $target, $evt ) = 
49                 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
50         return $evt if $evt;
51
52         my $circs = $apputils->simplereq(
53                 'open-ils.storage',
54                 "open-ils.storage.direct.action.open_circulation.search.atomic", 
55                 { usr => $target->id } );
56
57         my @results;
58         for my $circ (@$circs) {
59
60                 ( $copy, $evt )  = $apputils->fetch_copy($circ->target_copy);
61                 return $evt if $evt;
62
63                 $logger->debug("Retrieving record for copy " . $circ->target_copy);
64
65                 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
66                 return $evt if $evt;
67
68                 my $mods = $apputils->record_to_mvr($record);
69
70                 push( @results, { copy => $copy, circ => $circ, record => $mods } );
71         }
72
73         return \@results;
74
75 }
76
77
78 __PACKAGE__->register_method(
79         method  => "title_from_transaction",
80         api_name        => "open-ils.circ.circ_transaction.find_title",
81         NOTES           => <<"  NOTES");
82         Returns a mods object for the title that is linked to from the 
83         copy from the hold that created the given transaction
84         NOTES
85
86 sub title_from_transaction {
87         my( $self, $client, $login_session, $transactionid ) = @_;
88
89         my( $user, $circ, $title, $evt );
90
91         ( $user, $evt ) = $apputils->checkses( $login_session );
92         return $evt if $evt;
93
94         ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
95         return $evt if $evt;
96         
97         ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
98         return $evt if $evt;
99
100         return $apputils->record_to_mvr($title);
101 }
102
103
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
111         NOTES
112
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
120         NOTES
121
122 sub set_circ_lost {
123         my( $self, $client, $login, $circid ) = @_;
124         my( $user, $circ, $evt );
125
126         ( $user, $evt ) = $apputils->checkses($login);
127         return $evt if $evt;
128
129         ( $circ, $evt ) = $apputils->fetch_circulation( $circid );
130         return $evt if $evt;
131
132         if($self->api_name =~ /lost/) {
133                 if($evt = $apputils->checkperms(
134                         $user->id, $circ->circ_lib, "SET_CIRC_LOST")) {
135                         return $evt;
136                 }
137                 $circ->stop_fines("LOST");              
138         }
139
140         if($self->api_name =~ /claims_returned/) {
141                 if($evt = $apputils->checkperms(
142                         $user->id, $circ->circ_lib, "SET_CIRC_CLAIMS_RETURNED")) {
143                         return $evt;
144                 }
145                 $circ->stop_fines("CLAIMSRETURNED");
146         }
147
148         my $s = $apputils->simplereq(
149                 'open-ils.storage',
150                 "open-ils.storage.direct.action.circulation.update", $circ );
151
152         if(!$s) { throw OpenSRF::EX::ERROR ("Error updating circulation with id $circid"); }
153 }
154
155
156
157
158
159
160 1;