]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm
adding generate-fines and supporting functions
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Storage / Publisher / action.pm
1 package OpenILS::Application::Storage::Publisher::action;
2 use base qw/OpenILS::Application::Storage/;
3 use OpenSRF::Utils::Logger qw/:level/;
4 my $log = 'OpenSRF::Utils::Logger';
5
6 sub grab_overdue {
7         my $self = shift;
8         my $client = shift;
9         my $grace = shift || '';
10
11         my $c_t = action::circulation->table;
12
13         $grace = ' - (1 * (fine_interval))' if ($grace);
14
15         my $sql = <<"   SQL";
16                 SELECT  *
17                   FROM  $c_t
18                   WHERE stop_fines IS NULL
19                         AND due_date < ( CURRENT_TIMESTAMP $grace)
20         SQL
21
22         my $sth = action::circulation->db_Main->prepare_cached($sql);
23         $sth->execute;
24
25         $client->respond( $_->to_fieldmapper ) for ( map { action::circulation->construct($_) } $sth->fetchall_hash );
26
27         return undef;
28
29 }
30 __PACKAGE__->register_method(
31         api_name        => 'open-ils.storage.action.circulation.overdue',
32         api_level       => 1,
33         stream          => 1,
34         method          => 'grab_overdue',
35 );
36
37 sub next_resp_group_id {
38         my $self = shift;
39         my $client = shift;
40
41         # XXX This is not replication safe!!!
42
43         my ($id) = action::survey->db_Main->selectrow_array(<<" SQL");
44                 SELECT NEXTVAL('action.survey_response_group_id_seq'::TEXT)
45         SQL
46         return $id;
47 }
48 __PACKAGE__->register_method(
49         api_name        => 'open-ils.storage.action.survey_response.next_group_id',
50         api_level       => 1,
51         method          => 'next_resp_group_id',
52 );
53
54 sub patron_circ_summary {
55         my $self = shift;
56         my $client = shift;
57         my $id = ''.shift();
58
59         return undef unless ($id);
60         my $c_table = action::circulation->table;
61         my $b_table = money::billing->table;
62
63         my $select = <<"        SQL";
64                 SELECT  COUNT(DISTINCT c.id), SUM( COALESCE(b.amount,0) )
65                   FROM  $c_table c
66                         LEFT OUTER JOIN $b_table b ON (c.id = b.xact)
67                   WHERE c.usr = ?
68                         AND c.xact_finish IS NULL
69                         AND c.stop_fines NOT IN ('CLAIMSRETURNED','LOST')
70         SQL
71
72         return action::survey->db_Main->selectrow_arrayref($select, {}, $id);
73 }
74 __PACKAGE__->register_method(
75         api_name        => 'open-ils.storage.action.circulation.patron_summary',
76         api_level       => 1,
77         method          => 'patron_circ_summary',
78 );
79
80 #XXX Fix stored proc calls
81 sub find_local_surveys {
82         my $self = shift;
83         my $client = shift;
84         my $ou = ''.shift();
85
86         return undef unless ($ou);
87         my $s_table = action::survey->table;
88
89         my $select = <<"        SQL";
90                 SELECT  s.*
91                   FROM  $s_table s
92                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
93                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
94         SQL
95
96         my $sth = action::survey->db_Main->prepare_cached($select);
97         $sth->execute($ou);
98
99         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
100
101         return undef;
102 }
103 __PACKAGE__->register_method(
104         api_name        => 'open-ils.storage.action.survey.all',
105         api_level       => 1,
106         stream          => 1,
107         method          => 'find_local_surveys',
108 );
109
110 #XXX Fix stored proc calls
111 sub find_opac_surveys {
112         my $self = shift;
113         my $client = shift;
114         my $ou = ''.shift();
115
116         return undef unless ($ou);
117         my $s_table = action::survey->table;
118
119         my $select = <<"        SQL";
120                 SELECT  s.*
121                   FROM  $s_table s
122                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
123                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
124                         AND s.opac IS TRUE;
125         SQL
126
127         my $sth = action::survey->db_Main->prepare_cached($select);
128         $sth->execute($ou);
129
130         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
131
132         return undef;
133 }
134 __PACKAGE__->register_method(
135         api_name        => 'open-ils.storage.action.survey.opac',
136         api_level       => 1,
137         stream          => 1,
138         method          => 'find_opac_surveys',
139 );
140
141 sub find_optional_surveys {
142         my $self = shift;
143         my $client = shift;
144         my $ou = ''.shift();
145
146         return undef unless ($ou);
147         my $s_table = action::survey->table;
148
149         my $select = <<"        SQL";
150                 SELECT  s.*
151                   FROM  $s_table s
152                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
153                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
154                         AND s.required IS FALSE;
155         SQL
156
157         my $sth = action::survey->db_Main->prepare_cached($select);
158         $sth->execute($ou);
159
160         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
161
162         return undef;
163 }
164 __PACKAGE__->register_method(
165         api_name        => 'open-ils.storage.action.survey.optional',
166         api_level       => 1,
167         stream          => 1,
168         method          => 'find_optional_surveys',
169 );
170
171 sub find_required_surveys {
172         my $self = shift;
173         my $client = shift;
174         my $ou = ''.shift();
175
176         return undef unless ($ou);
177         my $s_table = action::survey->table;
178
179         my $select = <<"        SQL";
180                 SELECT  s.*
181                   FROM  $s_table s
182                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
183                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
184                         AND s.required IS TRUE;
185         SQL
186
187         my $sth = action::survey->db_Main->prepare_cached($select);
188         $sth->execute($ou);
189
190         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
191
192         return undef;
193 }
194 __PACKAGE__->register_method(
195         api_name        => 'open-ils.storage.action.survey.required',
196         api_level       => 1,
197         stream          => 1,
198         method          => 'find_required_surveys',
199 );
200
201 sub find_usr_summary_surveys {
202         my $self = shift;
203         my $client = shift;
204         my $ou = ''.shift();
205
206         return undef unless ($ou);
207         my $s_table = action::survey->table;
208
209         my $select = <<"        SQL";
210                 SELECT  s.*
211                   FROM  $s_table s
212                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
213                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
214                         AND s.usr_summary IS TRUE;
215         SQL
216
217         my $sth = action::survey->db_Main->prepare_cached($select);
218         $sth->execute($ou);
219
220         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
221
222         return undef;
223 }
224 __PACKAGE__->register_method(
225         api_name        => 'open-ils.storage.action.survey.usr_summary',
226         api_level       => 1,
227         stream          => 1,
228         method          => 'find_usr_summary_surveys',
229 );
230
231
232 1;