[freeside-commits] freeside/FS/FS part_event.pm,1.4,1.4.8.1
Mark Wells
mark at wavetail.420.am
Tue Feb 14 17:31:33 PST 2012
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv27336/FS/FS
Modified Files:
Tag: FREESIDE_2_3_BRANCH
part_event.pm
Log Message:
query billing events to see affected objects, #15142
Index: part_event.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_event.pm,v
retrieving revision 1.4
retrieving revision 1.4.8.1
diff -u -w -d -r1.4 -r1.4.8.1
--- part_event.pm 20 Aug 2009 04:03:34 -0000 1.4
+++ part_event.pm 15 Feb 2012 01:31:30 -0000 1.4.8.1
@@ -252,6 +252,67 @@
}
}
+=item targets
+
+Returns all objects (of type C<FS::eventtable>, for this object's
+C<eventtable>) eligible for processing under this event, as of right now.
+The L<FS::cust_event> object used to test event conditions will be
+included in each object as the 'cust_event' pseudo-field.
+
+This is not used in normal event processing (which is done on a
+per-customer basis to control timing of pre- and post-billing events)
+but can be useful when configuring events.
+
+=cut
+
+sub targets {
+ my $self = shift;
+ my $time = time; # $opt{'time'}?
+
+ my $eventpart = $self->eventpart;
+ $eventpart =~ /^\d+$/ or die "bad eventpart $eventpart";
+ my $eventtable = $self->eventtable;
+
+ # find all objects that meet the conditions for this part_event
+ my $linkage = '';
+ # this is the 'object' side of the FROM clause
+ if ( $eventtable ne 'cust_main' ) {
+ $linkage =
+ #($self->eventtables_cust_join->{$eventtable} || '') . #2.3
+ ' LEFT JOIN cust_main USING (custnum) ';
+ }
+
+ # this is the 'event' side
+ my $join = FS::part_event_condition->join_conditions_sql( $eventtable );
+ my $where = FS::part_event_condition->where_conditions_sql( $eventtable,
+ 'time' => $time
+ );
+ $join = $linkage .
+ " INNER JOIN part_event ON ( part_event.eventpart = $eventpart ) $join";
+
+ $where .= ' AND cust_main.agentnum = '.$self->agentnum
+ if $self->agentnum;
+ # don't enforce check_freq since this is a special, out-of-order check
+ # and don't enforce disabled because we want to be able to see targets
+ # for a disabled event
+
+ my @objects = qsearch({
+ table => $eventtable,
+ hashref => {},
+ addl_from => $join,
+ extra_sql => "WHERE $where",
+ });
+ my @tested_objects;
+ foreach my $object ( @objects ) {
+ my $cust_event = $self->new_cust_event($object, 'time' => $time);
+ next unless $cust_event->test_conditions;
+
+ $object->set('cust_event', $cust_event);
+ push @tested_objects, $object;
+ }
+ @tested_objects;
+}
+
=back
=head1 CLASS METHODS
More information about the freeside-commits
mailing list