Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / FS / FS / part_event / Action / Mixin / fee.pm
1 package FS::part_event::Action::Mixin::fee;
2
3 use strict;
4 use base qw( FS::part_event::Action );
5
6 sub event_stage { 'pre-bill'; }
7
8 sub option_fields {
9   (
10     'feepart'  => { label     => 'Fee definition',
11                     type      => 'select-table', #select-part_fee XXX
12                     table     => 'part_fee',
13                     hashref   => { disabled => '' },
14                     name_col  => 'itemdesc',
15                     value_col => 'feepart',
16                     disable_empty => 1,
17                   },
18   );
19 }
20
21 sub default_weight { 10; }
22
23 sub do_action {
24   my( $self, $cust_object, $cust_event ) = @_;
25
26   die "no fee definition selected for event '".$self->event."'\n"
27     unless $self->option('feepart');
28
29   # mark the event so that the fee will be charged
30   # the logic for calculating the fee amount is in FS::part_fee
31   # the logic for attaching it to the base invoice/line items is in 
32   # FS::cust_bill_pkg
33   my $cust_event_fee = FS::cust_event_fee->new({
34       'eventnum'    => $cust_event->eventnum,
35       'feepart'     => $self->option('feepart'),
36       'billpkgnum'  => '',
37   });
38
39   my $error = $cust_event_fee->insert;
40   die $error if $error;
41
42   '';
43 }
44
45 1;