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';
9 my $grace = shift || '';
11 my $c_t = action::circulation->table;
13 $grace = " - ($grace * (fine_interval))" if ($grace);
18 WHERE stop_fines IS NULL
19 AND due_date < ( CURRENT_TIMESTAMP $grace)
22 my $sth = action::circulation->db_Main->prepare_cached($sql);
25 $client->respond( $_->to_fieldmapper ) for ( map { action::circulation->construct($_) } $sth->fetchall_hash );
30 __PACKAGE__->register_method(
31 api_name => 'open-ils.storage.action.circulation.overdue',
34 method => 'grab_overdue',
43 my ($id) = action::hold_request->db_Main->selectrow_array(<<" SQL", {}, $pl,$cp);
45 FROM action.hold_request h
46 JOIN action.hold_copy_map hm ON (hm.hold = h.id)
47 WHERE h.pickup_lib = ?
48 AND hm.target_copy = ?
49 AND h.capture_time IS NULL
50 ORDER BY h.pickup_lib - (SELECT home_ou FROM actor.usr a WHERE a.id = h.usr), h.request_time
55 __PACKAGE__->register_method(
56 api_name => 'open-ils.storage.action.hold_request.nearest_hold',
58 method => 'nearest_hold',
61 sub next_resp_group_id {
65 # XXX This is not replication safe!!!
67 my ($id) = action::survey->db_Main->selectrow_array(<<" SQL");
68 SELECT NEXTVAL('action.survey_response_group_id_seq'::TEXT)
72 __PACKAGE__->register_method(
73 api_name => 'open-ils.storage.action.survey_response.next_group_id',
75 method => 'next_resp_group_id',
78 sub patron_circ_summary {
83 return undef unless ($id);
84 my $c_table = action::circulation->table;
85 my $b_table = money::billing->table;
87 my $select = <<" SQL";
88 SELECT COUNT(DISTINCT c.id), SUM( COALESCE(b.amount,0) )
90 LEFT OUTER JOIN $b_table b ON (c.id = b.xact)
92 AND c.xact_finish IS NULL
93 AND c.stop_fines NOT IN ('CLAIMSRETURNED','LOST')
96 return action::survey->db_Main->selectrow_arrayref($select, {}, $id);
98 __PACKAGE__->register_method(
99 api_name => 'open-ils.storage.action.circulation.patron_summary',
101 method => 'patron_circ_summary',
104 #XXX Fix stored proc calls
105 sub find_local_surveys {
110 return undef unless ($ou);
111 my $s_table = action::survey->table;
113 my $select = <<" SQL";
116 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
117 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
120 my $sth = action::survey->db_Main->prepare_cached($select);
123 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
127 __PACKAGE__->register_method(
128 api_name => 'open-ils.storage.action.survey.all',
131 method => 'find_local_surveys',
134 #XXX Fix stored proc calls
135 sub find_opac_surveys {
140 return undef unless ($ou);
141 my $s_table = action::survey->table;
143 my $select = <<" SQL";
146 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
147 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
151 my $sth = action::survey->db_Main->prepare_cached($select);
154 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
158 __PACKAGE__->register_method(
159 api_name => 'open-ils.storage.action.survey.opac',
162 method => 'find_opac_surveys',
165 sub find_optional_surveys {
170 return undef unless ($ou);
171 my $s_table = action::survey->table;
173 my $select = <<" SQL";
176 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
177 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
178 AND s.required IS FALSE;
181 my $sth = action::survey->db_Main->prepare_cached($select);
184 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
188 __PACKAGE__->register_method(
189 api_name => 'open-ils.storage.action.survey.optional',
192 method => 'find_optional_surveys',
195 sub find_required_surveys {
200 return undef unless ($ou);
201 my $s_table = action::survey->table;
203 my $select = <<" SQL";
206 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
207 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
208 AND s.required IS TRUE;
211 my $sth = action::survey->db_Main->prepare_cached($select);
214 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
218 __PACKAGE__->register_method(
219 api_name => 'open-ils.storage.action.survey.required',
222 method => 'find_required_surveys',
225 sub find_usr_summary_surveys {
230 return undef unless ($ou);
231 my $s_table = action::survey->table;
233 my $select = <<" SQL";
236 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
237 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
238 AND s.usr_summary IS TRUE;
241 my $sth = action::survey->db_Main->prepare_cached($select);
244 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
248 __PACKAGE__->register_method(
249 api_name => 'open-ils.storage.action.survey.usr_summary',
252 method => 'find_usr_summary_surveys',