This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / FS / FS / part_event / Condition / cust_bill_has_service.pm
1 package FS::part_event::Condition::cust_bill_has_service;
2
3 use strict;
4 use FS::cust_bill;
5
6 use base qw( FS::part_event::Condition );
7
8 sub description {
9   'Invoice is billing for a certain service type';
10 }
11
12 sub eventtable_hashref {
13     { 'cust_main' => 0,
14       'cust_bill' => 1,
15       'cust_pkg'  => 0,
16     };
17 }
18
19 # could not find component for path '/elements/tr-select-part_svc.html'
20 # sub disabled { 1; }
21
22 sub option_fields {
23   (
24     'has_service' => { 'label'      => 'Has service',
25                        'type'       => 'select-part_svc',
26                      },
27   );
28 }
29
30 sub condition {
31   #my($self, $cust_bill, %opt) = @_;
32   my($self, $cust_bill) = @_;
33
34   my $servicenum = $self->option('has_service');
35
36   grep { $servicenum == $_->svcpart } 
37     map { $_->cust_svc }
38         $cust_bill->cust_pkg;
39 }
40
41 sub condition_sql {
42   my( $class, $table, %opt ) = @_;
43
44   my $servicenum =
45     $class->condition_sql_option_integer('has_service', $opt{'driver_name'});
46
47   my $sql = qq| 0 < ( SELECT COUNT(cs.svcpart)
48      FROM cust_bill_pkg cbp, cust_svc cs
49     WHERE cbp.invnum = cust_bill.invnum
50       AND cs.pkgnum = cbp.pkgnum
51       AND cs.svcpart = $servicenum
52   )
53   |;
54   return $sql;
55 }
56
57 1;