suspend event option to skip packages with a start_date, RT#83847
[freeside.git] / FS / FS / part_event / Action / referral_pkg_billdate.pm
1 package FS::part_event::Action::referral_pkg_billdate;
2
3 use strict;
4 use base qw( FS::part_event::Action );
5
6 sub description { "Increment the referring customer's package's next bill date"; }
7
8 #sub eventtable_hashref {
9 #}
10
11 sub option_fields {
12   (
13     'if_pkgpart' => { 'label'    => 'Only packages',
14                       'type'     => 'select-part_pkg',
15                       'multiple' => 1,
16                     },
17     'increment'  => { 'label'    => 'Increment by',
18                       'type'     => 'freq',
19                       'value'    => '1m',
20                     },
21   );
22 }
23
24 #false laziness w/referral_pkg_discount, probably should make
25 # Mixin/referral_pkg.pm if we need changes or anything else in this vein
26 sub do_action {
27   my( $self, $cust_object, $cust_event ) = @_;
28
29   my $cust_main = $self->cust_main($cust_object);
30
31   return 'No referring customer' unless $cust_main->referral_custnum;
32
33   my $referring_cust_main = $cust_main->referring_cust_main;
34   #return 'Referring customer is cancelled'
35   #  if $referring_cust_main->status eq 'cancelled';
36
37   my %if_pkgpart = map { $_=>1 } split(/\s*,\s*/, $self->option('if_pkgpart') );
38   my @cust_pkg = grep $if_pkgpart{ $_->pkgpart },
39                       $referring_cust_main->billing_pkgs;
40   return 'No qualifying billing package definition' unless @cust_pkg;
41
42   my $cust_pkg = $cust_pkg[0]; #only one
43
44   #end of false laziness
45
46   my $bill = $cust_pkg->bill || $cust_pkg->setup || time;
47
48   $cust_pkg->bill(
49     $cust_pkg->part_pkg->add_freq( $bill, $self->option('increment') )
50   );
51
52   my $error = $cust_pkg->replace;
53   die "Error incrementing next bill date: $error" if $error;
54
55   '';
56
57 }
58
59 1;