summaryrefslogtreecommitdiff
path: root/FS/FS/part_event/Action/addtag.pm
blob: c4e9820b72e14872ed4512e7ee27799ebaf7c7ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package FS::part_event::Action::addtag;

use strict;
use base qw( FS::part_event::Action );
use FS::Record qw( qsearch );

sub description { 'Add customer tag'; }

sub eventtable_hashref {
    { 'cust_main'      => 1,
      'cust_bill'      => 1,
      'cust_pkg'       => 1,
      'cust_pay'       => 1,
      'cust_pay_batch' => 1,
      'cust_statement' => 1,
    };
}

sub option_fields {
  (
    'tagnum'  => { 'label'    => 'Customer tag',
                   'type'     => 'select-cust_tag',
                   'multiple' => 1,
                 },
  );
}

sub default_weight { 20; }

sub do_action {
  my( $self, $object, $tagnum ) = @_;

  my %exists = map { $_->tagnum => $_->tagnum } 
        qsearch({
          table     => 'cust_tag',
          hashref   => { custnum  => $object->custnum, },
        });

  my @tags = split(/\,/, $self->option('tagnum'));
  foreach my $tagnum ( split(/\,/, $self->option('tagnum') ) ) {
    if ( !$exists{$tagnum} ) {
      my $cust_tag = new FS::cust_tag { 'tagnum'  => $tagnum,
                                        'custnum' => $object->custnum, };
      my $error = $cust_tag->insert;
      die $error if $error;
    }
  }
  '';
}

1;