dce97df8f8c82350e98eed6e3816495283bd1aff
[freeside.git] / FS / FS / part_event / Condition / has_cust_payby_auto.pm
1 package FS::part_event::Condition::has_cust_payby_auto;
2
3 use strict;
4 use Tie::IxHash;
5 use FS::payby;
6 use FS::Record qw(qsearch);
7
8 use base qw( FS::part_event::Condition );
9
10 sub description {
11   'Customer has automatic payment information';
12 }
13
14 tie my %payby, 'Tie::IxHash', FS::payby->cust_payby2shortname;
15 delete $payby{'DCRD'};
16 delete $payby{'DCHK'};
17
18 sub option_fields {
19   (
20     'payby' => { 
21                  label         => 'Has automatic payment info',
22                  type          => 'select',
23                  options       => [ keys %payby ],
24                  option_labels => \%payby,
25                },
26   );
27 }
28
29 sub condition {
30   my( $self, $object ) = @_;
31
32   my $cust_main = $self->cust_main($object);
33
34   scalar( qsearch({ 
35     'table'     => 'cust_payby',
36     'hashref'   => { 'custnum' => $cust_main->custnum,
37                      'payby'   => $self->option('payby')
38                    },
39     'order_by'  => 'LIMIT 1',
40   }) );
41
42 }
43
44 1;