]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm
circ updates
[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 OpenILS::Application::Storage::CDBI::action;
4 #use OpenSRF::Utils::Logger qw/:level/;
5 #use OpenILS::Utils::Fieldmapper;
6 #
7 #my $log = 'OpenSRF::Utils::Logger';
8
9 sub patron_circ_summary {
10         my $self = shift;
11         my $client = shift;
12         my $id = ''.shift();
13
14         return undef unless ($id);
15         my $c_table = action::circulation->table;
16         my $b_table = money::billing->table;
17
18         my $select = <<"        SQL";
19                 SELECT  COUNT(DISTINCT c.id), SUM( COALESCE(b.amount,0) )
20                   FROM  $c_table c
21                         LEFT OUTER JOIN $b_table b ON (c.id = b.xact)
22                   WHERE c.usr = ?
23                         AND c.xact_finish IS NULL
24                         AND c.stop_fines NOT IN ('CLAIMSRETURNED','LOST')
25         SQL
26
27         return action::survey->db_Main->selectrow_arrayref($select, {}, $id);
28 }
29 __PACKAGE__->register_method(
30         api_name        => 'open-ils.storage.action.circulation.patron_summary',
31         api_level       => 1,
32         method          => 'patron_circ_summary',
33 );
34
35 #XXX Fix stored proc calls
36 sub find_local_surveys {
37         my $self = shift;
38         my $client = shift;
39         my $ou = ''.shift();
40
41         return undef unless ($ou);
42         my $s_table = action::survey->table;
43
44         my $select = <<"        SQL";
45                 SELECT  s.*
46                   FROM  $s_table s
47                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
48                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
49         SQL
50
51         my $sth = action::survey->db_Main->prepare_cached($select);
52         $sth->execute($ou);
53
54         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
55
56         return undef;
57 }
58 __PACKAGE__->register_method(
59         api_name        => 'open-ils.storage.action.survey.all',
60         api_level       => 1,
61         stream          => 1,
62         method          => 'find_local_surveys',
63 );
64
65 #XXX Fix stored proc calls
66 sub find_opac_surveys {
67         my $self = shift;
68         my $client = shift;
69         my $ou = ''.shift();
70
71         return undef unless ($ou);
72         my $s_table = action::survey->table;
73
74         my $select = <<"        SQL";
75                 SELECT  s.*
76                   FROM  $s_table s
77                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
78                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
79                         AND s.opac IS TRUE;
80         SQL
81
82         my $sth = action::survey->db_Main->prepare_cached($select);
83         $sth->execute($ou);
84
85         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
86
87         return undef;
88 }
89 __PACKAGE__->register_method(
90         api_name        => 'open-ils.storage.action.survey.opac',
91         api_level       => 1,
92         stream          => 1,
93         method          => 'find_opac_surveys',
94 );
95
96 sub find_optional_surveys {
97         my $self = shift;
98         my $client = shift;
99         my $ou = ''.shift();
100
101         return undef unless ($ou);
102         my $s_table = action::survey->table;
103
104         my $select = <<"        SQL";
105                 SELECT  s.*
106                   FROM  $s_table s
107                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
108                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
109                         AND s.required IS FALSE;
110         SQL
111
112         my $sth = action::survey->db_Main->prepare_cached($select);
113         $sth->execute($ou);
114
115         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
116
117         return undef;
118 }
119 __PACKAGE__->register_method(
120         api_name        => 'open-ils.storage.action.survey.optional',
121         api_level       => 1,
122         stream          => 1,
123         method          => 'find_optional_surveys',
124 );
125
126 sub find_required_surveys {
127         my $self = shift;
128         my $client = shift;
129         my $ou = ''.shift();
130
131         return undef unless ($ou);
132         my $s_table = action::survey->table;
133
134         my $select = <<"        SQL";
135                 SELECT  s.*
136                   FROM  $s_table s
137                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
138                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
139                         AND s.required IS TRUE;
140         SQL
141
142         my $sth = action::survey->db_Main->prepare_cached($select);
143         $sth->execute($ou);
144
145         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
146
147         return undef;
148 }
149 __PACKAGE__->register_method(
150         api_name        => 'open-ils.storage.action.survey.required',
151         api_level       => 1,
152         stream          => 1,
153         method          => 'find_required_surveys',
154 );
155
156 sub find_usr_summary_surveys {
157         my $self = shift;
158         my $client = shift;
159         my $ou = ''.shift();
160
161         return undef unless ($ou);
162         my $s_table = action::survey->table;
163
164         my $select = <<"        SQL";
165                 SELECT  s.*
166                   FROM  $s_table s
167                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
168                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
169                         AND s.usr_summary IS TRUE;
170         SQL
171
172         my $sth = action::survey->db_Main->prepare_cached($select);
173         $sth->execute($ou);
174
175         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
176
177         return undef;
178 }
179 __PACKAGE__->register_method(
180         api_name        => 'open-ils.storage.action.survey.usr_summary',
181         api_level       => 1,
182         stream          => 1,
183         method          => 'find_usr_summary_surveys',
184 );
185
186
187 1;