start of settlement CDR processing, RT#5495
[freeside.git] / FS / FS / part_pkg / cdr_termination.pm
1 package FS::part_pkg::cdr_termination;
2
3 use strict;
4 use base qw( FS::part_pkg::recur_Common );
5 use vars qw( $DEBUG %info );
6 use Tie::IxHash;
7
8 tie my %temporalities, 'Tie::IxHash',
9   'upcoming'  => "Upcoming (future)",
10   'preceding' => "Preceding (past)",
11 ;
12
13 %info = (
14   'name' => 'VoIP rating of CDR records for termination partners.',
15   'shortname' => 'VoIP/telco CDR termination',
16   'fields' => {
17
18     'setup_fee'     => { 'name' => 'Setup fee for this package',
19                          'default' => 0,
20                        },
21     'recur_fee'     => { 'name' => 'Base recurring fee for this package',
22                          'default' => 0,
23                        },
24
25     #false laziness w/flat.pm
26     'recur_temporality' => { 'name' => 'Charge recurring fee for period',
27                              'type' => 'select',
28                              'select_options' => \%temporalities,
29                            },
30
31     'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
32                                    ' of service at cancellation',
33                          'type' => 'checkbox',
34                        },
35
36     'cutoff_day'    => { 'name' => 'Billing Day (1 - 28) for prorating or '.
37                                    'subscription',
38                          'default' => '1',
39                        },
40
41     'recur_method'  => { 'name' => 'Recurring fee method',
42                          #'type' => 'radio',
43                          #'options' => \%recur_method,
44                          'type' => 'select',
45                          'select_options' => \%FS::part_pkg::recur_Common::recur_method,
46                        },
47   },
48
49   'fieldorder' => [qw(
50                        setup_fee recur_fee recur_temporality unused_credit
51                        recur_method cutoff_day
52                      )
53                   ],
54
55   'weight' => 48,
56
57 );
58
59 sub calc_setup {
60   my($self, $cust_pkg ) = @_;
61   $self->option('setup_fee');
62 }
63
64 sub calc_recur {
65   my $self = shift;
66   my($cust_pkg, $sdate, $details, $param ) = @_;
67
68   #my $last_bill = $cust_pkg->last_bill;
69   my $last_bill = $cust_pkg->get('last_bill'); #->last_bill falls back to setup
70
71   return 0
72     if $self->option('recur_temporality', 1) eq 'preceding'
73     && ( $last_bill eq '' || $last_bill == 0 );
74
75   my $charges = 0;
76
77   # termination calculations
78
79   # find CDRs with cdr_termination.status NULL
80   #  and matching our customer via svc_external.id/title?  (and via what field?)
81
82   #for each cdr, set status and rated price and add the charges, and add a line
83   #to the invoice
84
85   # eotermiation calculation
86
87   $charges += $self->calc_recur_Common(@_);
88
89   $charges;
90 }
91
92 sub is_free {
93   0;
94 }
95
96 1;