This commit was generated by cvs2svn to compensate for changes in r11022,
[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 price_info {
28     my $self = shift;
29     my $str = $self->SUPER::price_info;
30     my $rate = $self->option('base_rate');
31     $str .= " plus $rate/min" if $rate;
32     $str;
33 }
34
35 sub calc_setup {
36   my($self, $cust_pkg ) = @_;
37   $self->option('setup_fee');
38 }
39
40 sub calc_recur {
41   my $self = shift;
42   my($cust_pkg, $sdate, $details, $param ) = @_;
43
44   my $charges = 0;
45
46   $charges += $self->calc_usage(@_);
47   $charges += $self->calc_recur_Common(@_);
48
49   $charges;
50
51 }
52
53 sub can_discount { 0; }
54
55 sub calc_cancel {
56   my $self = shift;
57   my($cust_pkg, $sdate, $details, $param ) = @_;
58
59   $self->calc_usage(@_);
60 }
61
62 sub calc_usage {
63   my $self = shift;
64   my($cust_pkg, $sdate, $details, $param ) = @_;
65
66   my $last_bill = $cust_pkg->get('last_bill') || $cust_pkg->get('setup');
67   my @tickets = @{ FS::TicketSystem->comments_on_tickets( $cust_pkg->custnum, 100, $last_bill ) };
68
69   my $charges = 0;
70
71   my $rate = $self->option('base_rate');
72
73   foreach my $ding ( @tickets) {
74         $charges += sprintf('%.2f', $ding->{'timetaken'} * $rate);
75         push @$details, join( ", ", ("($ding->{timetaken}) Minutes", substr($ding->{'content'},0,255)));
76   }
77   cluck $rate, $charges, @$details if $DEBUG > 0;
78   return $charges;
79 }
80
81 1;