]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
This is the basic circulation scaffolding for the circulation methods
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Circ / Circulate.pm
1 package OpenILS::Application::Circ::Circulate;
2 use base 'OpenSRF::Application';
3 use strict; use warnings;
4 use Data::Dumper;
5 use OpenSRF::EX qw(:try);
6 use OpenSRF::Utils::Logger qw(:logger);
7 use OpenILS::Utils::ScriptRunner;
8 use OpenILS::Application::AppUtils;
9 my $apputils = "OpenILS::Application::AppUtils";
10
11 my %scripts;            # - circulation script filenames
12 my $standings;          # - cached patron standings
13 my $group_tree; # - cached permission group tree
14
15 # ------------------------------------------------------------------------------
16 # Load the circ script from the config
17 # ------------------------------------------------------------------------------
18 sub initialize {
19
20         my $self = shift;
21         my $conf = OpenSRF::Utils::SettingsClient->new;
22         my @pfx = ( "apps", "open-ils.circ","app_settings", "scripts" );
23
24         my $p           = $conf->config_value(  @pfx, 'permission' );
25         my $d           = $conf->config_value(  @pfx, 'duration' );
26         my $f           = $conf->config_value(  @pfx, 'recurring_fines' );
27         my $m           = $conf->config_value(  @pfx, 'max_fines' );
28         my $pr  = $conf->config_value(  @pfx, 'permit_renew' );
29         my $ph  = $conf->config_value(  @pfx, 'permit_hold' );
30
31         $logger->error( "Missing circ script(s)" ) 
32                 unless( $p and $d and $f and $m and $pr and $ph );
33
34         $scripts{circ_permit}                   = $p;
35         $scripts{circ_duration}                 = $d;
36         $scripts{circ_recurring_fines}= $f;
37         $scripts{circ_max_fines}                = $m;
38         $scripts{circ_renew_permit}     = $pr;
39         $scripts{hold_permit}                   = $ph;
40
41         $logger->debug("Loaded rules scripts for circ: " .
42                 "circ permit : $p, circ duration :$d , circ recurring fines : $f, " .
43                 "circ max fines : $m, circ renew permit : $pr, permit hold: $ph");
44 }
45
46
47 # ------------------------------------------------------------------------------
48 # Loads the necessary circ objects and pushes them into the script environment
49 # Returns ( $data, $evt ).  if $evt is defined, then an
50 # unexpedted event occurred and should be dealt with / returned to the caller
51 # ------------------------------------------------------------------------------
52 sub create_circ_env {
53         my %params = @_;
54
55         my $barcode = $params{barcode};
56         my $patron = $params{patron};
57         my ( $copy, $title, $evt );
58
59         if(!$standings) {
60                 $standings = $apputils->fetch_patron_standings();
61                 $group_tree = $apputils->fetch_permission_group_tree();
62         }
63
64         ( $copy, $evt ) = $apputils->fetch_copy_by_barcode( $barcode );
65         return ( undef, $evt ) if $evt;
66
67         ( $title, $evt ) = $apputils->fetch_record_by_copy( $copy->id );
68         return ( undef, $evt ) if $evt;
69
70         my $runner = OpenILS::Utils::ScriptRunner->new( type => 'js' );
71         $runner->insert( 'patron', $patron );
72         $runner->insert( 'title', $title );
73         $runner->insert( 'copy', $copy );
74         $runner->insert( 'standings', $standings );
75         $runner->insert( 'group_tree', $group_tree );
76
77         return { 
78                 runner          => $runner, 
79                 title                   => $title, 
80                 patron          => $patron, 
81                 copy                    => $copy, 
82                 standings       => $standings, 
83                 group_tree      => $group_tree };
84 }
85
86
87 # ------------------------------------------------------------------------------
88
89 __PACKAGE__->register_method(
90         method  => "permit_circ",
91         api_name        => "open-ils.circ.permit_checkout_",
92         notes           => <<"  NOTES");
93                 Determines if the given checkout can occur
94                 PARAMS( authtoken, barcode => bc, patron => pid, renew => t/f )
95                 Returns an event
96         NOTES
97
98 sub permit_circ {
99         my( $self, $client, $authtoken, %params ) = @_;
100         my $barcode             = $params{barcode};
101         my $patronid    = $params{patron};
102         my $isrenew             = $params{renew};
103         my ( $requestor, $patron, $env, $evt );
104
105         ( $requestor, $patron, $evt) = 
106                 $apputils->checkses_requestor( 
107                 $authtoken, $patronid, 'VIEW_PERMIT_CHECKOUT' );
108         return $evt if $evt;
109
110         ( $env, $evt ) = create_circ_env( barcode => $barcode, patron => $patron );
111         return $evt if $evt;
112
113         my $runner = $env->{runner};
114         $runner->load($scripts{circ_permit});
115
116         if( ! $runner->run ) {
117                 throw OpenSRF::EX::ERROR 
118                         ("Error running permit circ script: " . $scripts{circ_permit});
119         }
120
121         # Insepect the script results and return correct event
122
123         return OpenILS::Event->new( 'SUCCESS' );
124 }
125
126
127 # ------------------------------------------------------------------------------
128
129 __PACKAGE__->register_method(
130         method  => "circulate",
131         api_name        => "open-ils.circ.checkout.barcode_",
132         notes           => <<"  NOTES");
133                 Checks out an item based on barcode
134                 PARAMS( authtoken, barcode => bc, patron => pid )
135         NOTES
136
137 sub circulate {
138         my( $self, $client, $authtoken, %params ) = @_;
139         my $barcode             = $params{barcode};
140         my $patronid    = $params{patron};
141 }
142
143
144 # ------------------------------------------------------------------------------
145
146 __PACKAGE__->register_method(
147         method  => "checkin",
148         api_name        => "open-ils.circ.checkin.barcode_",
149         notes           => <<"  NOTES");
150         PARAMS( authtoken, barcode => bc )
151         Checks in based on barcode
152         Returns an event object whose payload contains the record, circ, and copy
153         If the item needs to be routed, the event is a ROUTE_COPY event
154         with an additional 'route_to' variable set on the event
155         NOTES
156
157 sub checkin {
158         my( $self, $client, $authtoken, %params ) = @_;
159         my $barcode             = $params{barcode};
160 }
161
162 # ------------------------------------------------------------------------------
163
164 __PACKAGE__->register_method(
165         method  => "renew",
166         api_name        => "open-ils.circ.renew_",
167         notes           => <<"  NOTES");
168         PARAMS( authtoken, circ => circ_id );
169         open-ils.circ.renew(login_session, circ_object);
170         Renews the provided circulation.  login_session is the requestor of the
171         renewal and if the logged in user is not the same as circ->usr, then
172         the logged in user must have RENEW_CIRC permissions.
173         NOTES
174
175 sub renew {
176         my( $self, $client, $authtoken, %params ) = @_;
177         my $circ        = $params{circ};
178 }
179
180         
181
182
183 1;