communigate provisioning phase 2: add svc_domain.trailer -> communigate TrailerText...
[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 can_discount { 0; }
43
44 sub calc_cancel {
45   my $self = shift;
46   my($cust_pkg, $sdate, $details, $param ) = @_;
47
48   $self->calc_usage(@_);
49 }
50
51 sub calc_usage {
52   my $self = shift;
53   my($cust_pkg, $sdate, $details, $param ) = @_;
54
55   my $last_bill = $cust_pkg->get('last_bill') || $cust_pkg->get('setup');
56   my @tickets = @{ FS::TicketSystem->comments_on_tickets( $cust_pkg->custnum, 100, $last_bill ) };
57
58   my $charges = 0;
59
60   my $rate = $self->option('base_rate');
61
62   foreach my $ding ( @tickets) {
63         $charges += sprintf('%.2f', $ding->{'timetaken'} * $rate);
64         push @$details, join( ", ", ("($ding->{timetaken}) Minutes", substr($ding->{'content'},0,255)));
65   }
66   cluck $rate, $charges, @$details if $DEBUG > 0;
67   return $charges;
68 }
69
70 1;