[freeside-commits] freeside/FS/FS/part_event Condition.pm,1.4,1.5

Ivan,,, ivan at wavetail.420.am
Sat Nov 22 14:17:29 PST 2008


Update of /home/cvs/cvsroot/freeside/FS/FS/part_event
In directory wavetail.420.am:/tmp/cvs-serv30261/FS/FS/part_event

Modified Files:
	Condition.pm 
Log Message:
referral credits overhaul, use billing events, agents can self-configure, limit to once-per-customer, depend on any time from referred package, referred customer payment, specific packages, partial staged credits, RT#3983

Index: Condition.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_event/Condition.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Condition.pm	29 Oct 2007 10:31:31 -0000	1.4
+++ Condition.pm	22 Nov 2008 22:17:27 -0000	1.5
@@ -2,7 +2,7 @@
 
 use strict;
 use base qw( FS::part_event_condition );
-
+use Time::Local qw(timelocal_nocheck);
 use FS::UID qw( driver_name );
 
 =head1 NAME
@@ -251,6 +251,40 @@
 
 =back
 
+=item option_age_from OPTION FROM_TIMESTAMP
+
+Retreives a condition option, parses it from a frequency (such as "1d", "1w" or
+"12m"), and subtracts that interval from the supplied timestamp.  It is
+primarily intended for use in B<condition>.
+
+=cut
+
+sub option_age_from {
+  my( $self, $option, $time ) = @_;
+  my $age = $self->option($option);
+  $age = '0m' unless length($age);
+
+  my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($time) )[0,1,2,3,4,5];
+
+  if ( $age =~ /^(\d+)m$/i ) {
+    $mon -= $1;
+    until ( $mon >= 0 ) { $mon += 12; $year--; }
+  } elsif ( $age =~ /^(\d+)y$/i ) {
+    $year -= $1;
+  } elsif ( $age =~ /^(\d+)w$/i ) {
+    $mday -= $1 * 7;
+  } elsif ( $age =~ /^(\d+)d$/i ) {
+    $mday -= $1;
+  } elsif ( $age =~ /^(\d+)h$/i ) {
+    $hour -= $hour;
+  } else {
+    die "unparsable age: $age";
+  }
+
+  timelocal_nocheck($sec,$min,$hour,$mday,$mon,$year);
+
+}
+
 =item condition_sql_option OPTION
 
 This is a class method that returns an SQL fragment for retreiving a condition



More information about the freeside-commits mailing list