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
54 __PACKAGE__->register_method(
55 api_name => 'open-ils.storage.action.hold_request.nearest_hold',
57 method => 'nearest_hold',
60 sub next_resp_group_id {
64 # XXX This is not replication safe!!!
66 my ($id) = action::survey->db_Main->selectrow_array(<<" SQL");
67 SELECT NEXTVAL('action.survey_response_group_id_seq'::TEXT)
71 __PACKAGE__->register_method(
72 api_name => 'open-ils.storage.action.survey_response.next_group_id',
74 method => 'next_resp_group_id',
77 sub patron_circ_summary {
82 return undef unless ($id);
83 my $c_table = action::circulation->table;
84 my $b_table = money::billing->table;
86 my $select = <<" SQL";
87 SELECT COUNT(DISTINCT c.id), SUM( COALESCE(b.amount,0) )
89 LEFT OUTER JOIN $b_table b ON (c.id = b.xact)
91 AND c.xact_finish IS NULL
92 AND c.stop_fines NOT IN ('CLAIMSRETURNED','LOST')
95 return action::survey->db_Main->selectrow_arrayref($select, {}, $id);
97 __PACKAGE__->register_method(
98 api_name => 'open-ils.storage.action.circulation.patron_summary',
100 method => 'patron_circ_summary',
103 #XXX Fix stored proc calls
104 sub find_local_surveys {
109 return undef unless ($ou);
110 my $s_table = action::survey->table;
112 my $select = <<" SQL";
115 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
116 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
119 my $sth = action::survey->db_Main->prepare_cached($select);
122 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
126 __PACKAGE__->register_method(
127 api_name => 'open-ils.storage.action.survey.all',
130 method => 'find_local_surveys',
133 #XXX Fix stored proc calls
134 sub find_opac_surveys {
139 return undef unless ($ou);
140 my $s_table = action::survey->table;
142 my $select = <<" SQL";
145 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
146 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
150 my $sth = action::survey->db_Main->prepare_cached($select);
153 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
157 __PACKAGE__->register_method(
158 api_name => 'open-ils.storage.action.survey.opac',
161 method => 'find_opac_surveys',
164 sub find_optional_surveys {
169 return undef unless ($ou);
170 my $s_table = action::survey->table;
172 my $select = <<" SQL";
175 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
176 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
177 AND s.required IS FALSE;
180 my $sth = action::survey->db_Main->prepare_cached($select);
183 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
187 __PACKAGE__->register_method(
188 api_name => 'open-ils.storage.action.survey.optional',
191 method => 'find_optional_surveys',
194 sub find_required_surveys {
199 return undef unless ($ou);
200 my $s_table = action::survey->table;
202 my $select = <<" SQL";
205 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
206 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
207 AND s.required IS TRUE;
210 my $sth = action::survey->db_Main->prepare_cached($select);
213 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
217 __PACKAGE__->register_method(
218 api_name => 'open-ils.storage.action.survey.required',
221 method => 'find_required_surveys',
224 sub find_usr_summary_surveys {
229 return undef unless ($ou);
230 my $s_table = action::survey->table;
232 my $select = <<" SQL";
235 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
236 WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
237 AND s.usr_summary IS TRUE;
240 my $sth = action::survey->db_Main->prepare_cached($select);
243 $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
247 __PACKAGE__->register_method(
248 api_name => 'open-ils.storage.action.survey.usr_summary',
251 method => 'find_usr_summary_surveys',