giving it a weight avoids weight use of uninitialized value in sort messages in part_...
[freeside.git] / FS / FS / part_pkg / rt_time.pm
1 package FS::part_pkg::rt_time;
2
3 use strict;
4 use FS::Conf;
5 use FS::Record qw(qsearchs qsearch);
6 use FS::part_pkg::recur_Common;
7 use Carp qw(cluck);
8
9 our @ISA = qw(FS::part_pkg::recur_Common);
10
11 our $DEBUG = 0;
12
13 our %info = (
14   'name'      =>  'Bill from Time Worked on tickets in RT',
15   'shortname' =>  'Project Billing (RT)',
16   'weight'    => 55,
17   'fields'    =>  {
18     'base_rate' =>  {   'name'    =>  'Rate (per minute)',
19                         'default' => 0,
20                     },
21   }
22 );
23
24 sub calc_setup {
25   my($self, $cust_pkg ) = @_;
26   $self->option('setup_fee');
27 }
28
29 sub calc_recur {
30   my $self = shift;
31   my($cust_pkg, $sdate, $details, $param ) = @_;
32
33   my $charges = 0;
34
35   $charges += $self->calc_usage(@_);
36   $charges += $self->calc_recur_Common(@_);
37
38   $charges;
39
40 }
41
42 sub calc_cancel {
43   my $self = shift;
44   my($cust_pkg, $sdate, $details, $param ) = @_;
45
46   $self->calc_usage(@_);
47 }
48
49 sub calc_usage {
50   my $self = shift;
51   my($cust_pkg, $sdate, $details, $param ) = @_;
52
53   my $last_bill = $cust_pkg->get('last_bill') || $cust_pkg->get('setup');
54   my @tickets = @{ FS::TicketSystem->comments_on_tickets( $cust_pkg->custnum, 100, $last_bill ) };
55
56   my $charges = 0;
57
58   my $rate = $self->option('base_rate');
59
60   foreach my $ding ( @tickets) {
61         $charges += sprintf('%.2f', $ding->{'timetaken'} * $rate);
62         push @$details, join( ", ", ("($ding->{timetaken}) Minutes", substr($ding->{'content'},0,255)));
63   }
64   cluck $rate, $charges, @$details if $DEBUG > 0;
65   return $charges;
66 }
67
68 1;