[freeside-commits] branch FREESIDE_2_3_BRANCH updated. aaaff38cf2f6826e2329f24a318f0122d50e70f3

Mark Wells mark at 420.am
Mon Mar 12 20:24:50 PDT 2012


The branch, FREESIDE_2_3_BRANCH has been updated
       via  aaaff38cf2f6826e2329f24a318f0122d50e70f3 (commit)
      from  4347107a70dd00e9ce0b57e4aaede742edc5fe9c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit aaaff38cf2f6826e2329f24a318f0122d50e70f3
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Mar 12 20:22:11 2012 -0700

    "day-of-month of customer signup" condition, #16827

diff --git a/FS/FS/part_event.pm b/FS/FS/part_event.pm
index d48ecfc..c18c9f3 100644
--- a/FS/FS/part_event.pm
+++ b/FS/FS/part_event.pm
@@ -252,7 +252,7 @@ sub templatename {
   }
 }
 
-=item targets
+=item targets OPTIONS
 
 Returns all objects (of type C<FS::eventtable>, for this object's 
 C<eventtable>) eligible for processing under this event, as of right now.
@@ -267,7 +267,8 @@ but can be useful when configuring events.
 
 sub targets {
   my $self = shift;
-  my $time = time; # $opt{'time'}?
+  my %opt = @_;
+  my $time = $opt{'time'} || time;
 
   my $eventpart = $self->eventpart;
   $eventpart =~ /^\d+$/ or die "bad eventpart $eventpart";
@@ -304,8 +305,8 @@ sub targets {
   });
   my @tested_objects;
   foreach my $object ( @objects ) {
-    my $cust_event = $self->new_cust_event($object, 'time' => $time);
-    next unless $cust_event->test_conditions;
+    my $cust_event = $self->new_cust_event($object);
+    next unless $cust_event->test_conditions('time' => $time);
 
     $object->set('cust_event', $cust_event);
     push @tested_objects, $object;
diff --git a/FS/FS/part_event/Condition/signupdate_day.pm b/FS/FS/part_event/Condition/signupdate_day.pm
new file mode 100644
index 0000000..dbe9e60
--- /dev/null
+++ b/FS/FS/part_event/Condition/signupdate_day.pm
@@ -0,0 +1,54 @@
+package FS::part_event::Condition::signupdate_day;
+
+use strict;
+use Tie::IxHash;
+
+use base qw( FS::part_event::Condition );
+
+sub description {
+  "Customer signed up on the same day of month as today";
+}
+
+sub option_fields {
+  (
+    'delay' => { label  => 'Delay additional days',
+                 type   => 'text',
+                 value  => '0',
+               },
+  );
+}
+
+sub condition {
+  my( $self, $object, %opt ) = @_;
+
+  my $cust_main = $self->cust_main($object);
+
+  my ($today) = (localtime($opt{'time'}))[3];
+
+  my $delay = $self->option('delay') || 0;
+  my $signupday = ((localtime($cust_main->signupdate + $delay * 86400))[3] - 1)
+                   % 28 + 1;
+  
+  $today == $signupday;
+}
+
+sub condition_sql {
+  my( $class, $table, %opt ) = @_;
+  my $mday;
+  if ( $opt{'driver_name'} eq 'Pg' ) {
+    $mday = sub{ "EXTRACT( DAY FROM TO_TIMESTAMP($_[0]) )::INTEGER" };
+  }
+  elsif ( $opt{'driver_name'} eq 'mysql' ) {
+    $mday = sub{ "DAY( FROM_UNIXTIME($_[0]) )" };
+  }
+  else {
+    return 'true';
+  }
+
+  my $delay = $class->condition_sql_option_integer('delay', 
+    $opt{'driver_name'}); # returns 0 for null
+  $mday->($opt{'time'}) . ' = '.
+    '(' . $mday->("cust_main.signupdate + $delay * 86400") . ' - 1) % 28 + 1';
+}
+
+1;
diff --git a/httemplate/browse/part_event.html b/httemplate/browse/part_event.html
index 6be2860..0399643 100644
--- a/httemplate/browse/part_event.html
+++ b/httemplate/browse/part_event.html
@@ -45,7 +45,8 @@ my $link = [ $p.'edit/part_event.html?', 'eventpart' ];
 my $event_sub = sub {
   my $part_event = shift;
   my $onclick = include('/elements/popup_link_onclick.html',
-    action      => $p.'view/part_event-targets.html?'.$part_event->eventpart,
+    action      => $p.'view/part_event-targets.html?eventpart='.
+                    $part_event->eventpart,
     actionlabel => 'Event query - '.$part_event->event,
     width       => 650,
     height      => 420,
diff --git a/httemplate/view/part_event-targets.html b/httemplate/view/part_event-targets.html
index 8c0634e..10b5e98 100644
--- a/httemplate/view/part_event-targets.html
+++ b/httemplate/view/part_event-targets.html
@@ -3,6 +3,16 @@
        'title'   => 'Event query - '.$part_event->event,
      }
 &>
+<FORM STYLE="display:inline" ACTION=<%$cgi->url%> METHOD="GET">
+When event is run on <& /elements/input-date-field.html, {
+  'name'    => 'date',
+  'value'   => $time,
+  'format'  => FS::Conf->new->config('date_format') || '%m/%d/%Y',
+} &>
+<INPUT TYPE="hidden" NAME="eventpart" VALUE="<%$eventpart%>">
+<INPUT TYPE="submit" VALUE="Refresh">
+</FORM>
+<BR><BR>
 % if ( $objects > 0 ) {
   <% emt("[quant,_1,$label]", $objects) %>
 %   if ( $part_event->eventtable ne 'cust_main' ) {
@@ -18,8 +28,8 @@
 
 %   my @rowcolors = ('ffffff','eeeeee');
 %   my $row = 0;
-  <TR style="background-color:#<% $rowcolors[$row++ % 2] %>">
 %   foreach my $object (@targets) {
+  <TR style="background-color:#<% $rowcolors[$row++ % 2] %>">
 %     # now works for all eventtables, including cust_pkg
 %     my $link = $p . 'view/' . $part_event->eventtable . '.cgi?' .
 %        $object->$pkey;
@@ -65,12 +75,14 @@ die "access denied"
   unless $curuser->access_right('Edit billing events')
         || $curuser->access_right('Edit global billing events');
 
-my ($eventpart) = $cgi->keywords;
+my ($eventpart) = $cgi->param('eventpart');
 $eventpart =~ /^\d+$/ or die 'illegal eventpart';
 
+my $time = parse_datetime($cgi->param('date')) || time;
+
 my $part_event = FS::part_event->by_key($eventpart)
   or die "Event definition $eventpart not found.\n";
-my @targets = $part_event->targets;
+my @targets = $part_event->targets('time' => $time);
 my $total = @targets;
 
 # in imitation of search/elements/search-html.html

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/part_event.pm                                |    9 +++--
 .../Condition/{billday.pm => signupdate_day.pm}    |   31 ++++++++++---------
 httemplate/browse/part_event.html                  |    3 +-
 httemplate/view/part_event-targets.html            |   18 +++++++++--
 4 files changed, 38 insertions(+), 23 deletions(-)
 copy FS/FS/part_event/Condition/{billday.pm => signupdate_day.pm} (53%)




More information about the freeside-commits mailing list