new tax rating engine
[freeside.git] / FS / FS / cust_bill.pm
index 11e198d..f536c97 100644 (file)
@@ -1876,8 +1876,8 @@ sub print_generic {
 
       my $convert_map = $convert_maps{$format}{$include};
 
-      @inc_src = map { s/\[@--/$delimiters{$format}[0]/g;
-                       s/--@\]/$delimiters{$format}[1]/g;
+      @inc_src = map { s/\[\@--/$delimiters{$format}[0]/g;
+                       s/--\@\]/$delimiters{$format}[1]/g;
                        $_;
                      } 
                  &$convert_map( $conf->config($inc_file) );
@@ -2486,9 +2486,18 @@ sub _items_pkg {
   $self->_items_cust_bill_pkg(\@cust_bill_pkg, %options);
 }
 
+sub _taxsort {
+  return 0 unless $a cmp $b;
+  return -1 if $b eq 'Tax';
+  return 1 if $a eq 'Tax';
+  return -1 if $b eq 'Other surcharges';
+  return 1 if $a eq 'Other surcharges';
+  $a cmp $b;
+}
+
 sub _items_tax {
   my $self = shift;
-  my @cust_bill_pkg = grep { ! $_->pkgnum } $self->cust_bill_pkg;
+  my @cust_bill_pkg = sort _taxsort grep { ! $_->pkgnum } $self->cust_bill_pkg;
   $self->_items_cust_bill_pkg(\@cust_bill_pkg, @_);
 }
 
@@ -2499,6 +2508,8 @@ sub _items_cust_bill_pkg {
   my @b = ();
   foreach my $cust_bill_pkg ( @$cust_bill_pkg ) {
 
+    my $cust_pkg = $cust_bill_pkg->cust_pkg;
+
     my $desc = $cust_bill_pkg->desc;
 
     if ( $cust_bill_pkg->pkgnum > 0 ) {
@@ -2506,7 +2517,7 @@ sub _items_cust_bill_pkg {
       if ( $cust_bill_pkg->setup != 0 ) {
         my $description = $desc;
         $description .= ' Setup' if $cust_bill_pkg->recur != 0;
-        my @d = $cust_bill_pkg->cust_pkg->h_labels_short($self->_date);
+        my @d = $cust_pkg->h_labels_short($self->_date);
         push @d, $cust_bill_pkg->details if $cust_bill_pkg->recur == 0;
         push @b, {
           description     => $description,
@@ -2529,8 +2540,11 @@ sub _items_cust_bill_pkg {
           pkgnum          => $cust_bill_pkg->pkgnum,
           amount          => sprintf("%.2f", $cust_bill_pkg->recur),
           ext_description =>
-            [ $cust_bill_pkg->cust_pkg->h_labels_short( $cust_bill_pkg->edate,
-                                                        $cust_bill_pkg->sdate),
+            #at least until cust_bill_pkg has "past" ranges in addition to
+            #the "future" sdate/edate ones... see #3032
+            [ $cust_pkg->h_labels_short( $self->_date ),
+                                         #$cust_bill_pkg->edate,
+                                         #$cust_bill_pkg->sdate),
               $cust_bill_pkg->details,
             ],
         };