bulk price plan: label as Name <email>, supress extraneous service list, RT#3519
authorivan <ivan>
Tue, 24 Mar 2009 02:40:04 +0000 (02:40 +0000)
committerivan <ivan>
Tue, 24 Mar 2009 02:40:04 +0000 (02:40 +0000)
FS/FS/Record.pm
FS/FS/cust_bill.pm
FS/FS/cust_svc.pm
FS/FS/h_cust_svc.pm
FS/FS/part_pkg.pm
FS/FS/part_pkg/bulk.pm

index ad6613e..f35fe4c 100644 (file)
@@ -1444,7 +1444,7 @@ sub ut_money {
 =item ut_text COLUMN
 
 Check/untaint text.  Alphanumerics, spaces, and the following punctuation
-symbols are currently permitted: ! @ # $ % & ( ) - + ; : ' " , . ? / = [ ]
+symbols are currently permitted: ! @ # $ % & ( ) - + ; : ' " , . ? / = [ ] < >
 May not be null.  If there is an error, returns the error, otherwise returns
 false.
 
@@ -1456,7 +1456,7 @@ sub ut_text {
   #warn "notexist ". \&notexist. "\n";
   #warn "AUTOLOAD ". \&AUTOLOAD. "\n";
   $self->getfield($field)
-    =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]+)$/
+    =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]\<\>]+)$/
       or return gettext('illegal_or_empty_text'). " $field: ".
                  $self->getfield($field);
   $self->setfield($field,$1);
index 70c7a7f..0dbe1b9 100644 (file)
@@ -2593,8 +2593,11 @@ sub _items_cust_bill_pkg {
         my $description = $desc;
         $description .= ' Setup' if $cust_bill_pkg->recur != 0;
 
-        my @d = map &{$escape_function}($_),
-                       $cust_pkg->h_labels_short($self->_date);
+        my @d = ();
+        push @d, map &{$escape_function}($_),
+                     $cust_pkg->h_labels_short($self->_date)
+          unless $cust_pkg->part_pkg->hide_svc_detail;
+
         push @d, $cust_bill_pkg->details(%details_opt)
           if $cust_bill_pkg->recur == 0;
 
@@ -2617,12 +2620,17 @@ sub _items_cust_bill_pkg {
                           " - ". time2str("%x", $cust_bill_pkg->edate). ")";
         }
 
+        my @d = ();
+
         #at least until cust_bill_pkg has "past" ranges in addition to
         #the "future" sdate/edate ones... see #3032
-        my @d = map &{$escape_function}($_),
-                    $cust_pkg->h_labels_short($self->_date);
-                                              #$cust_bill_pkg->edate,
-                                              #$cust_bill_pkg->sdate),
+        push @d, map &{$escape_function}($_),
+                     $cust_pkg->h_labels_short($self->_date)
+                                               #$cust_bill_pkg->edate,
+                                               #$cust_bill_pkg->sdate),
+          unless $cust_pkg->part_pkg->hide_svc_detail
+              || $cust_bill_pkg->itemdesc;
+
         push @d, $cust_bill_pkg->details(%details_opt);
 
         push @b, {
index 42681a0..316af4e 100644 (file)
@@ -369,23 +369,34 @@ Usage example:
 
   my($label, $value, $svcdb) = $cust_svc->label;
 
+=item label_long
+
+Like the B<label> method, except the second item in the list ("meaningful
+identifier") may be longer - typically, a full name is included.
+
 =cut
 
-sub label {
+sub label      { shift->_label('svc_label',      @_); }
+sub label_long { shift->_label('svc_label_long', @_); }
+
+sub _label {
   my $self = shift;
-  carp "FS::cust_svc::label called on $self" if $DEBUG;
+  my $method = shift;
   my $svc_x = $self->svc_x
     or return "can't find ". $self->part_svc->svcdb. '.svcnum '. $self->svcnum;
 
-  $self->_svc_label($svc_x);
+  $self->$method($svc_x);
 }
 
+sub svc_label      { shift->_svc_label('label',      @_); }
+sub svc_label_long { shift->_svc_label('label_long', @_); }
+
 sub _svc_label {
-  my( $self, $svc_x ) = ( shift, shift );
+  my( $self, $method, $svc_x ) = ( shift, shift, shift );
 
   (
     $self->part_svc->svc,
-    $svc_x->label(@_),
+    $svc_x->$method(@_),
     $self->part_svc->svcdb,
     $self->svcnum
   );
index 921be3a..4be6a77 100644 (file)
@@ -52,9 +52,15 @@ If a service is found, returns a list consisting of:
 
 =cut
 
-sub label {
+sub label      { shift->_label('svc_label',      @_); }
+sub label_long { shift->_label('svc_label_long', @_); }
+
+sub _label {
   my $self = shift;
-  carp "FS::h_cust_svc::label called on $self" if $DEBUG;
+  my $method = shift;
+
+  #carp "FS::h_cust_svc::_label called on $self" if $DEBUG;
+  warn "FS::h_cust_svc::_label called on $self for $method" if $DEBUG;
   my $svc_x = $self->h_svc_x(@_);
   return () unless $svc_x;
   my $part_svc = $self->part_svc;
@@ -65,7 +71,7 @@ sub label {
   }
 
   my @label;
-  eval { @label = $self->_svc_label($svc_x, @_); };
+  eval { @label = $self->$method($svc_x, @_); };
 
   if ($@) {
     carp 'while resolving history record for svcdb/svcnum ' . 
index 7c8c678..1c23b18 100644 (file)
@@ -945,6 +945,9 @@ sub plan_info {
   \%plans;
 }
 
+#fallback for everything except bulk.pm
+sub hide_svc_detail { 0; }
+
 =item format OPTION DATA
 
 Returns data formatted according to the function 'format' described
index 749f054..d01bd4e 100644 (file)
@@ -7,7 +7,7 @@ use FS::part_pkg::flat;
 
 @ISA = qw(FS::part_pkg::flat);
 
-$DEBUG = 0;
+$DEBUG = 1;
 $me = '[FS::part_pkg::bulk]';
 
 %info = (
@@ -45,6 +45,9 @@ sub calc_recur {
 
   my $last_bill = $cust_pkg->last_bill;
 
+  return sprintf("%.2f", $self->base_recur($cust_pkg) )
+    unless $$sdate > $last_bill;
+
   my $total_svc_charge = 0;
 
   warn "$me billing for bulk services from ". time2str('%x', $last_bill).
@@ -52,16 +55,15 @@ sub calc_recur {
     if $DEBUG;
 
                                            #   END      START
-  foreach my $h_svc ( $cust_pkg->h_cust_svc( $$sdate, $last_bill ) ) {
+  foreach my $h_cust_svc ( $cust_pkg->h_cust_svc( $$sdate, $last_bill ) ) {
 
-    my @label = $h_svc->label_long( $$sdate, $last_bill );
+    my @label = $h_cust_svc->label_long( $$sdate, $last_bill );
     die "fatal: no historical label found, wtf?" unless scalar(@label); #?
-    #my $svc_details = $label[0].': '. $label[1]. ': ';
-    my $svc_details = $label[1]. ': ';
+    my $svc_details = $label[0]. ': '. $label[1]. ': ';
 
     my $svc_charge = 0;
 
-    my $svc_start = $h_svc->date_inserted;
+    my $svc_start = $h_cust_svc->date_inserted;
     if ( $svc_start < $last_bill ) {
       $svc_start = $last_bill;
     } elsif ( $svc_setup_fee ) {
@@ -69,7 +71,7 @@ sub calc_recur {
       $svc_details .= $money_char. sprintf('%.2f setup, ', $svc_setup_fee);
     }
 
-    my $svc_end = $h_svc->date_deleted;
+    my $svc_end = $h_cust_svc->date_deleted;
     $svc_end = ( !$svc_end || $svc_end > $$sdate ) ? $$sdate : $svc_end;
 
     $svc_charge = $self->option('svc_recur_fee') * ( $svc_end - $svc_start )
@@ -88,6 +90,10 @@ sub calc_recur {
   sprintf("%.2f", $self->base_recur($cust_pkg) + $total_svc_charge );
 }
 
+sub hide_svc_detail {
+  1;
+}
+
 sub is_free_options {
   qw( setup_fee recur_fee svc_setup_fee svc_recur_fee );
 }