[freeside-commits] branch FREESIDE_3_BRANCH updated. a140ffb44cd6ce9f5346e337eac68a4f874b7675

Christopher Burger burgerc at freeside.biz
Mon Apr 2 10:07:30 PDT 2018


The branch, FREESIDE_3_BRANCH has been updated
       via  a140ffb44cd6ce9f5346e337eac68a4f874b7675 (commit)
       via  6f401f92ef5362b8e42e76fee24d89e46d78a0dd (commit)
      from  24bf56f635ae27fb6c7fcf8571e3eeedef60936d (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 a140ffb44cd6ce9f5346e337eac68a4f874b7675
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Tue Mar 27 14:20:11 2018 -0400

    RT# 33362 - fixed Argument 1d is not numeric when trying to discount daily recuring packages

diff --git a/FS/FS/part_pkg/discount_Mixin.pm b/FS/FS/part_pkg/discount_Mixin.pm
index 5bcf561c2..f634913cc 100644
--- a/FS/FS/part_pkg/discount_Mixin.pm
+++ b/FS/FS/part_pkg/discount_Mixin.pm
@@ -92,7 +92,10 @@ sub calc_discount {
     # $chg_months: the number of months we are charging recur for
     # $months: $chg_months or the months left on the discount, whchever is less
 
-    my $chg_months = $cust_pkg->part_pkg->freq || 1;
+    my $chg_months = 1;
+    unless ($cust_pkg->part_pkg->freq !~ /^\d+$/) {
+      $chg_months = $cust_pkg->part_pkg->freq || 1;
+    }
     if ( defined($param->{'months'}) ) { # then override
       $chg_months = $param->{'months'};
     }

commit 6f401f92ef5362b8e42e76fee24d89e46d78a0dd
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Mon Dec 4 13:06:20 2017 -0500

    RT# 33362 - fixed discount_mixin to not throw perl error when trying to discount non monthly recuring.

diff --git a/FS/FS/part_event/Action/pkg_discount.pm b/FS/FS/part_event/Action/pkg_discount.pm
index dd85ada9b..d245ef40b 100644
--- a/FS/FS/part_event/Action/pkg_discount.pm
+++ b/FS/FS/part_event/Action/pkg_discount.pm
@@ -23,10 +23,10 @@ sub option_fields {
                        'extra_sql' => q(AND freq NOT LIKE '0%' AND freq NOT LIKE '%d' AND freq NOT LIKE '%h' AND freq NOT LIKE '%w'), 
                        'multiple' => 1,
                      },
-    'if_pkg_class'    => { label    => 'Only package class',
-                           type     => 'select-pkg_class',
-                           multiple => 1,
-                         },
+    'if_pkg_class' => { 'label'    => 'Only package class',
+                        'type'     => 'select-pkg_class',
+                        'multiple' => 1,
+                      },
     'discountnum' => { 'label'    => 'Discount',
                        'type'     => 'select-table', #we don't handle the select-discount create a discount case
                        'table'    => 'discount',
@@ -54,7 +54,7 @@ sub do_action {
 
   my $cust_main = $self->cust_main($object);
   my %if_pkgpart = map { $_=>1 } split(/\s*,\s*/, $self->option('if_pkgpart') );
-  my $if_pkg_class = $self->option('if_pkg_class') || {};
+  my %if_pkg_class = map { $_=>1 } split(/\s*,\s*/, $self->option('if_pkg_class') );
 
   my $allpkgs = (keys %if_pkgpart) ? 0 : 1;
 
@@ -65,8 +65,8 @@ sub do_action {
     return 'Package not selected'
       if ! $allpkgs && ! $if_pkgpart{ $object->pkgpart };
     return 'Package not of selected class'
-      if keys %$if_pkg_class
-      && ! $if_pkg_class->{ $object->part_pkg->classnum };
+      if keys %if_pkg_class
+      && ! $if_pkg_class{ $object->part_pkg->classnum };
     return 'Package frequency not monthly or a multiple'
       if $object->part_pkg->freq !~ /^\d+$/;
 
@@ -76,7 +76,7 @@ sub do_action {
 
     @cust_pkg = grep {
          ( $allpkgs || $if_pkgpart{ $_->pkgpart } ) 
-      && ( ! keys %$if_pkg_class || $if_pkg_class->{ $_->part_pkg->classnum } )
+      && ( ! keys %if_pkg_class || $if_pkg_class{ $_->part_pkg->classnum } )
       && $_->part_pkg->freq
       #remove after fixing discount bug with non-monthly pkgs
       && ( $_->part_pkg->freq =~ /^\d+$/)
diff --git a/FS/FS/part_pkg/discount_Mixin.pm b/FS/FS/part_pkg/discount_Mixin.pm
index 5b3f10094..5bcf561c2 100644
--- a/FS/FS/part_pkg/discount_Mixin.pm
+++ b/FS/FS/part_pkg/discount_Mixin.pm
@@ -46,7 +46,11 @@ sub calc_discount {
   my $conf = new FS::Conf;
 
   my $br = $self->base_recur($cust_pkg, $sdate);
-  $br += $param->{'override_charges'} * ($cust_pkg->part_pkg->freq || 0) if $param->{'override_charges'};
+
+  ## can not multiply non monthly recurring frequency so skip.
+  unless ($cust_pkg->part_pkg->freq !~ /^\d+$/) {
+    $br += $param->{'override_charges'} * ($cust_pkg->part_pkg->freq || 0) if $param->{'override_charges'};
+  }
 
   my $tot_discount = 0;
   #UI enforces just 1 for now, will need ordering when they can be stacked
@@ -139,6 +143,9 @@ sub calc_discount {
       # the "estimated recurring fee" is only for as long as the discount
       # lasts.
 
+      # can not multiply non monthly recurring frequency so skip.
+      next if $self->freq !~ /^\d+$/;
+
       my $recur_charge = $br * $months / $self->freq;
       # round this, because the real recur charge is rounded
       $recur_charge = sprintf('%.2f', $recur_charge);

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

Summary of changes:
 FS/FS/part_event/Action/pkg_discount.pm | 16 ++++++++--------
 FS/FS/part_pkg/discount_Mixin.pm        | 14 ++++++++++++--
 2 files changed, 20 insertions(+), 10 deletions(-)




More information about the freeside-commits mailing list