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