[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 2acd22229677fa23c731d55a51208cb744bc8c9b

Mark Wells mark at 420.am
Tue Feb 21 11:45:40 PST 2012


The branch, FREESIDE_2_3_BRANCH has been updated
       via  2acd22229677fa23c731d55a51208cb744bc8c9b (commit)
       via  bbd0138791eaf4a7a64448418dee176721e6067b (commit)
      from  64df4aadbe83844c3eb91f9e45bd66531e4ffeef (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 2acd22229677fa23c731d55a51208cb744bc8c9b
Merge: bbd0138 64df4aa
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Feb 20 23:58:23 2012 -0800

    Merge branch 'FREESIDE_2_3_BRANCH' of git.freeside.biz:/home/git/freeside into 2.3


commit bbd0138791eaf4a7a64448418dee176721e6067b
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Feb 20 23:02:16 2012 -0800

    customer signup date event condition, #16591

diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm
index 6cc32bd..63eb47c 100644
--- a/FS/FS/Mason.pm
+++ b/FS/FS/Mason.pm
@@ -546,6 +546,8 @@ sub mason_interps {
     ${$_[0]} =~ s/(['\\])/\\$1/g;
     ${$_[0]} =~ s/\r/\\r/g;
     ${$_[0]} =~ s/\n/\\n/g;
+    # prevent premature termination of the script
+    ${$_[0]} =~ s[</script>][<\\/script>]ig;
     ${$_[0]} = "'". ${$_[0]}. "'";
   };
 
diff --git a/FS/FS/part_event/Condition.pm b/FS/FS/part_event/Condition.pm
index b624407..826d4d6 100644
--- a/FS/FS/part_event/Condition.pm
+++ b/FS/FS/part_event/Condition.pm
@@ -253,6 +253,23 @@ sub option_label {
 
 =back
 
+=item option_type OPTION
+
+Returns the type of the option, as a string: 'text', 'money', 'date',
+or 'freq'.
+
+=cut
+
+sub option_type {
+  my( $self, $optionname ) = @_;
+
+  my %option_fields = $self->option_fields;
+
+  ref( $option_fields{$optionname} )
+    ? $option_fields{$optionname}->{'type'} 
+    : 'text'
+}
+
 =item option_age_from OPTION FROM_TIMESTAMP
 
 Retreives a condition option, parses it from a frequency (such as "1d", "1w" or
diff --git a/FS/FS/part_event/Condition/signupdate.pm b/FS/FS/part_event/Condition/signupdate.pm
new file mode 100644
index 0000000..30613a2
--- /dev/null
+++ b/FS/FS/part_event/Condition/signupdate.pm
@@ -0,0 +1,48 @@
+package FS::part_event::Condition::signupdate;
+
+use strict;
+use base qw( FS::part_event::Condition );
+use FS::Record qw(str2time_sql str2time_sql_closing);
+use Date::Parse 'str2time';
+
+sub description { 'Customer signed up during date range' }
+
+sub option_fields {
+  (
+    # actually stored as strings
+    'start' => {  label   => 'First day',
+                  type    => 'date',
+                  format  => '%Y-%m-%d', },
+    'end'   => {  label => 'Last day',
+                  type  => 'date', 
+                  format  => '%Y-%m-%d', },
+  );
+}
+
+sub condition {
+
+  my($self, $object, %opt) = @_;
+
+  my $cust_main = $self->cust_main($object);
+  my $start = $self->option('start');
+  my $end = $self->option('end');
+
+  (!$start or $cust_main->signupdate >= str2time($start)) and
+  (!$end   or $cust_main->signupdate <  str2time($end) + 86400);
+}
+
+sub condition_sql {
+  my( $class, $table, %opt ) = @_;
+  return 'true' if $opt{'driver_name'} ne 'Pg';
+
+  my $start = $class->condition_sql_option('start');
+  my $end = $class->condition_sql_option('end');
+
+  $start = "$start IS NULL OR cust_main.signupdate >=" . 
+           str2time_sql . "($start)::timestamp" . str2time_sql_closing;
+  $end   = "$end IS NULL OR cust_main.signupdate < 86400 + " . 
+           str2time_sql . "($end)::timestamp" . str2time_sql_closing;
+  "($start) AND ($end)";
+}
+
+1;
diff --git a/httemplate/edit/part_event.html b/httemplate/edit/part_event.html
index 6a53222..dc1eba0 100644
--- a/httemplate/edit/part_event.html
+++ b/httemplate/edit/part_event.html
@@ -485,6 +485,9 @@ tie my %all_conditions, 'Tie::IxHash',
   '' => { 'description' => '*** Select new condition ***', },
   FS::part_event_condition->conditions();
 
+# *** Select new condition *** sorts to the beginning anyway
+(tied %all_conditions)->SortByValue;
+
 my %condition_labels = map { $_ => $all_conditions{$_}->{'description'} }
                            keys %all_conditions;
 
@@ -524,6 +527,8 @@ tie my %all_actions, 'Tie::IxHash',
   '' => { 'description' => '*** Select event action ***', },
   FS::part_event->actions();
 
+(tied %all_actions)->SortByValue;
+
 my %action_labels = map { $_ => $all_actions{$_}->{'description'} }
                         keys %all_actions;
 
diff --git a/httemplate/elements/selectlayers.html b/httemplate/elements/selectlayers.html
index 89fe41b..dd279bd 100644
--- a/httemplate/elements/selectlayers.html
+++ b/httemplate/elements/selectlayers.html
@@ -162,6 +162,7 @@ Example:
 
 my $conf = new FS::Conf;
 my $money_char = $conf->config('money_char') || '$';
+my $date_noinit = 0;
 
 </%once>
 <%init>
@@ -220,10 +221,24 @@ sub layer_callback {
     my $type = $lf->{type} || 'text';
 
     my $include = $type;
-    $include = "input-$include" if $include =~ /^(text|money)$/;
-    $include = "tr-$include" unless $include eq 'hidden';
 
-    $html .= include( "/elements/$include.html",
+    if ( $include eq 'date' ) {
+      # several important differences from other tr-*
+      $html .= include( '/elements/tr-input-date-field.html',
+        {
+          'name'  => "$layer_prefix$field",
+          'value' => $value,
+          'label' => $lf->{label},
+          'format'=> $lf->{format},
+          'noinit'=> $date_noinit,
+        }
+      );
+      $date_noinit = 1;
+    }
+    else {
+      $include = "input-$include" if $include =~ /^(text|money)$/;
+      $include = "tr-$include" unless $include eq 'hidden';
+      $html .= include( "/elements/$include.html",
                         %$lf,
                         'field'      => "$layer_prefix$field",
                         'id'         => "$layer_prefix$field", #separate?
@@ -233,8 +248,8 @@ sub layer_callback {
                         'value'      => ( $lf->{'value'} || $value ), #hmm.
                         'curr_value' => $value,
                     );
-
-  }
+    }
+  } #foreach $field
   $html .= '</TABLE>';
   return $html;
 }

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

Summary of changes:
 FS/FS/Mason.pm                           |    2 +
 FS/FS/part_event/Condition.pm            |   17 ++++++++++
 FS/FS/part_event/Condition/signupdate.pm |   48 ++++++++++++++++++++++++++++++
 httemplate/edit/part_event.html          |    5 +++
 httemplate/elements/selectlayers.html    |   25 ++++++++++++---
 5 files changed, 92 insertions(+), 5 deletions(-)
 create mode 100644 FS/FS/part_event/Condition/signupdate.pm




More information about the freeside-commits mailing list