X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_event%2FAction%2Fpkg_discount.pm;h=a10822ef3a6a498677da7260e27a55f7e27ee8a5;hb=fe32569659388d3edbd08fe2b1327ec0005da4f8;hp=04a3a0f402c751ac6a7e2df17f1a5c9df401a474;hpb=f4def30fba7da2daed58df35b80ffce0e9d0c776;p=freeside.git diff --git a/FS/FS/part_event/Action/pkg_discount.pm b/FS/FS/part_event/Action/pkg_discount.pm index 04a3a0f40..a10822ef3 100644 --- a/FS/FS/part_event/Action/pkg_discount.pm +++ b/FS/FS/part_event/Action/pkg_discount.pm @@ -3,10 +3,12 @@ package FS::part_event::Action::pkg_discount; use strict; use base qw( FS::part_event::Action ); -sub description { "Discount active customer packages"; } +sub description { "Discount unsuspended package(s) (monthly recurring only)"; } sub eventtable_hashref { - { 'cust_main' => 1 }; + { 'cust_main' => 1, + 'cust_pkg' => 1, + }; } sub event_stage { 'pre-bill'; } @@ -24,12 +26,15 @@ sub option_fields { 'discountnum' => { 'label' => 'Discount', 'type' => 'select-table', #we don't handle the select-discount create a discount case 'table' => 'discount', - 'name_col' => 'description', #well, method - 'order_by' => 'ORDER BY discountnum', #requied because name_col is a method + #(well, since 2013 it winds up calling select-discount + # anyway (but not tr-select-discount) + #'name_col' => 'description', #well, method + #'order_by' => 'ORDER BY discountnum', #requied because name_col is a method + 'disable_empty' => 1, 'hashref' => { 'disabled' => '', 'months' => { op=>'!=', value=>'0' }, }, - 'disable_empty' => 1, + 'disable_custom_discount' => 1, }, ); } @@ -41,11 +46,29 @@ sub do_action { my $cust_main = $self->cust_main($object); my %if_pkgpart = map { $_=>1 } split(/\s*,\s*/, $self->option('if_pkgpart') ); - my @cust_pkg = grep { $if_pkgpart{ $_->pkgpart } && $_->part_pkg->freq - #can remove after fixing discount bug with non-monthly pkgs - && ( $_->part_pkg->freq =~ /^\d+$/) } - $cust_main->active_pkgs; - return 'No qualifying packages' unless @cust_pkg; + my $allpkgs = (keys %if_pkgpart) ? 0 : 1; + + my @cust_pkg = (); + if ( $object->table eq 'cust_pkg' ) { + + return 'Package is suspended' if $object->susp; + return 'Package not selected' + if ! $allpkgs && ! $if_pkgpart{ $object->pkgpart }; + return 'Package frequency not monthly or a multiple' + if $object->part_pkg->freq !~ /^\d+$/; + + @cust_pkg = ( $object ); + + } else { + + @cust_pkg = grep { ( $allpkgs || $if_pkgpart{ $_->pkgpart } ) + && $_->part_pkg->freq + #remove after fixing discount bug with non-monthly pkgs + && ( $_->part_pkg->freq =~ /^\d+$/) } + $cust_main->unsuspended_pkgs; + return 'No qualifying packages' unless @cust_pkg; + + } my $gotit = 0; foreach my $cust_pkg (@cust_pkg) {