Merge branch 'master' of git.freeside.biz:/home/git/freeside
authorIvan Kohler <ivan@freeside.biz>
Wed, 4 Feb 2015 20:07:32 +0000 (12:07 -0800)
committerIvan Kohler <ivan@freeside.biz>
Wed, 4 Feb 2015 20:07:32 +0000 (12:07 -0800)
FS/FS/Template_Mixin.pm
FS/FS/cust_bill.pm
FS/FS/part_event/Condition/has_referral_custnum.pm
FS/FS/part_event/Condition/has_referral_pkgpart.pm

index e26592c..d8e46c5 100644 (file)
@@ -2830,6 +2830,8 @@ sub _items_fee {
   my $self = shift;
   my %options = @_;
   my @cust_bill_pkg = grep { $_->feepart } $self->cust_bill_pkg;
+  my $escape_function = $options{escape_function};
+
   my @items;
   foreach my $cust_bill_pkg (@cust_bill_pkg) {
     # cache this, so we don't look it up again in every section
@@ -2865,12 +2867,17 @@ sub _items_fee {
     foreach (sort keys(%base_invnums)) {
       next if $_ == $self->invnum;
       push @ext_desc,
-        $self->mt('from invoice \\#[_1] on [_2]', $_, $base_invnums{$_});
+        &{$escape_function}(
+          $self->mt('from invoice #[_1] on [_2]', $_, $base_invnums{$_})
+        );
     }
+    my $desc = $part_fee->itemdesc_locale($self->cust_main->locale);
+    $desc = &{$escape_function}($desc);
+
     push @items,
       { feepart     => $cust_bill_pkg->feepart,
         amount      => sprintf('%.2f', $cust_bill_pkg->setup + $cust_bill_pkg->recur),
-        description => $part_fee->itemdesc_locale($self->cust_main->locale),
+        description => $desc,
         ext_description => \@ext_desc
         # sdate/edate?
       };
index 888e88b..068d0d1 100644 (file)
@@ -1900,7 +1900,14 @@ sub print_csv {
   if ( lc($opt{'format'}) eq 'billco' ) {
 
     my $lineseq = 0;
-    foreach my $item ( $self->_items_pkg ) {
+    my %items_opt = ( format => 'template',
+                      escape_function => sub { shift } );
+    # I don't know what characters billco actually tolerates in spool entries.
+    # Text::CSV will take care of delimiters, though.
+
+    my @items = ( $self->_items_pkg(%items_opt),
+                  $self->_items_fee(%items_opt) );
+    foreach my $item (@items) {
 
       my $description = $item->{'description'};
       if ( $item->{'_is_discount'} and exists($item->{ext_description}[0]) ) {
index c505794..f8a2b82 100644 (file)
@@ -31,19 +31,22 @@ sub condition {
   my($self, $object, %opt) = @_;
 
   my $cust_main = $self->cust_main($object);
+  return 0 unless $cust_main; #sanity check
+  return 0 unless $cust_main->referral_custnum;
+
+  my $referring_cust_main = $cust_main->referral_custnum_cust_main;
+  return 0 unless $referring_cust_main; #sanity check;
+
+  #referring customer must sign up before referred customer
+  return 0 unless $cust_main->signupdate > $referring_cust_main->signupdate;
 
   if ( $self->option('active') ) {
-    return 0 unless $cust_main->referral_custnum;
     #check for no cust_main for referral_custnum? (deleted?)
-    return 0 unless $cust_main->referral_custnum_cust_main->status eq 'active';
-  } else {
-    return 0 unless $cust_main->referral_custnum; # ? 1 : 0;
+    return 0 unless $referring_cust_main->status eq 'active';
   }
 
   return 1 unless $self->option('check_bal');
 
-  my $referring_cust_main = $cust_main->referral_custnum_cust_main;
-
   #false laziness w/ balance_age_under
   my $under = $self->option('balance');
   $under = 0 unless length($under);
index 60ba7cc..7062f6c 100644 (file)
@@ -1,6 +1,7 @@
 package FS::part_event::Condition::has_referral_pkgpart;
 use base qw( FS::part_event::Condition );
 
+use FS::part_event::Condition::has_referral_custnum;
 #maybe i should be incorporated in has_referral_custnum
 
 use strict;
@@ -19,10 +20,10 @@ sub option_fields {
 sub condition {
   my($self, $object, %opt) = @_;
 
+  return 0 unless FS::part_event::Condition::has_referral_custnum::condition($self, $object, %opt);
+
   my $cust_main = $self->cust_main($object);
 
-  return 0 unless $cust_main->referral_custnum;
-  
   my $if_pkgpart = $self->option('if_pkgpart') || {};
   grep $if_pkgpart->{ $_->pkgpart },
     $cust_main->referral_custnum_cust_main->ncancelled_pkgs;