import torrus 1.0.9
[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   'inherit_fields' => [ 'global_Mixin' ],
18   'fields'    =>  {
19     'base_rate' =>  {   'name'    =>  'Rate (per minute)',
20                         'default' => 0,
21                     },
22     'recur_fee' => {'disabled' => 1},
23   },
24   'fieldorder' => [ 'base_rate' ],
25 );
26
27 sub calc_setup {
28   my($self, $cust_pkg ) = @_;
29   $self->option('setup_fee');
30 }
31
32 sub calc_recur {
33   my $self = shift;
34   my($cust_pkg, $sdate, $details, $param ) = @_;
35
36   my $charges = 0;
37
38   $charges += $self->calc_usage(@_);
39   $charges += $self->calc_recur_Common(@_);
40
41   $charges;
42
43 }
44
45 sub can_discount { 0; }
46
47 sub calc_cancel {
48   my $self = shift;
49   my($cust_pkg, $sdate, $details, $param ) = @_;
50
51   $self->calc_usage(@_);
52 }
53
54 sub calc_usage {
55   my $self = shift;
56   my($cust_pkg, $sdate, $details, $param ) = @_;
57
58   my $last_bill = $cust_pkg->get('last_bill') || $cust_pkg->get('setup');
59   my @tickets = @{ FS::TicketSystem->comments_on_tickets( $cust_pkg->custnum, 100, $last_bill ) };
60
61   my $charges = 0;
62
63   my $rate = $self->option('base_rate');
64
65   foreach my $ding ( @tickets) {
66         $charges += sprintf('%.2f', $ding->{'timetaken'} * $rate);
67         push @$details, join( ", ", ("($ding->{timetaken}) Minutes", substr($ding->{'content'},0,255)));
68   }
69   cluck $rate, $charges, @$details if $DEBUG > 0;
70   return $charges;
71 }
72
73 1;