default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / FS / FS / part_event / Condition / pkg_class.pm
1 package FS::part_event::Condition::pkg_class;
2
3 use strict;
4
5 use base qw( FS::part_event::Condition );
6 use FS::Record qw( qsearch );
7 use FS::pkg_class;
8
9 sub description {
10   'Package Class';
11 }
12
13 sub eventtable_hashref {
14     { 'cust_main' => 1,
15       'cust_bill' => 1,
16       'cust_pkg'  => 1,
17     };
18 }
19
20 #something like this
21 sub option_fields {
22   (
23     'pkgclass'  => { 'label'    => 'Package Class',
24                      'type'     => 'select-pkg_class',
25                      'multiple' => 1,
26                    },
27   );
28 }
29
30 sub condition {
31   my( $self, $object ) = @_;
32
33   # interpretation depends on the eventtable
34   my $hashref = $self->option('pkgclass') || {};
35   if ( $object->isa('FS::cust_pkg') ) {
36     # is this package in that class?
37     $hashref->{ $object->part_pkg->classnum };
38   }
39   elsif ( $object->isa('FS::cust_main') ) {
40     # does this customer have an active package in that class?
41     grep { $hashref->{ $_->part_pkg->classnum } } $object->ncancelled_pkgs;
42   }
43   elsif ( $object->isa('FS::cust_bill') ) {
44     # does a package of that class appear on this invoice?
45     grep { $hashref->{ $_->part_pkg->classnum } } $object->cust_pkg;
46   }
47 }
48
49 1;