1 package FS::part_event::Action::rt_ticket;
4 use base qw( FS::part_event::Action );
5 use FS::Record qw( qsearchs );
8 sub description { 'Open an RT ticket for the customer' }
10 #need to be valid for msg_template substitution
11 sub eventtable_hashref {
22 'msgnum' => { 'label' => 'Template',
23 'type' => 'select-table',
24 'table' => 'msg_template',
25 'name_col' => 'msgname',
26 'hashref' => { disabled => '', msgclass => 'email' },
29 'queueid' => { 'label' => 'Queue',
30 'type' => 'select-rt-queue',
32 'requestor' => { 'label' => 'Requestor',
34 'options' => [ 0, 1 ],
36 0 => 'Customer\'s invoice address',
37 1 => 'Template From: address',
44 sub default_weight { 59; }
48 my( $self, $object ) = @_;
50 my $cust_main = $self->cust_main($object)
51 or die "Could not load cust_main";
53 my $msgnum = $self->option('msgnum');
54 my $msg_template = qsearchs('msg_template', { 'msgnum' => $msgnum } )
55 or die "Template $msgnum not found";
57 my $queueid = $self->option('queueid')
58 or die "No queue specified";
60 # technically this only works if create_ticket is implemented,
61 # and it is only implemented in RT_Internal,
62 # but we can let create_ticket throw that error
63 my $conf = new FS::Conf;
64 die "rt_ticket event - no ticket system configured"
65 unless $conf->config('ticket_system');
67 FS::TicketSystem->init();
69 my $cust_msg = $msg_template->prepare(
70 'cust_main' => $cust_main,
74 my $subject = $cust_msg->entity->head->get('Subject');
77 my $requestor = $self->option('requestor')
78 ? $msg_template->from_addr
79 : [ $cust_main->invoicing_list_emailonly ];
81 my $svcnum = ref($object) eq 'FS::svc_acct'
85 my $err_or_ticket = FS::TicketSystem->create_ticket(
86 '', #session should already exist
88 'subject' => $subject,
89 'requestor' => $requestor,
90 'message' => $cust_msg->preview,
91 'mime_type' => 'text/html',
92 'custnum' => $cust_main->custnum,
95 die $err_or_ticket unless ref($err_or_ticket);