summaryrefslogtreecommitdiff
path: root/FS/FS/part_pkg/rt_time.pm
blob: 03ed1cde769f93752598d061f8fd3446b7fd835b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package FS::part_pkg::rt_time;

use strict;
use FS::Conf;
use FS::Record qw(qsearchs qsearch);
use FS::part_pkg::recur_Common;
use Carp qw(cluck);

our @ISA = qw(FS::part_pkg::recur_Common);

our $DEBUG = 0;

our %info = (
  'name'      =>  'Bill from Time Worked on tickets in RT',
  'shortname' =>  'Project Billing (RT)',
  'weight'    => 55,
  'inherit_fields' => [ 'global_Mixin' ],
  'fields'    =>  {
    'base_rate' =>  {   'name'    =>  'Rate (per minute)',
                        'default' => 0,
                    },
    'recur_fee' => {'disabled' => 1},
  },
  'fieldorder' => [ 'base_rate' ],
);

sub calc_setup {
  my($self, $cust_pkg ) = @_;
  $self->option('setup_fee');
}

sub calc_recur {
  my $self = shift;
  my($cust_pkg, $sdate, $details, $param ) = @_;

  my $charges = 0;

  $charges += $self->calc_usage(@_);
  $charges += $self->calc_recur_Common(@_);

  $charges;

}

sub can_discount { 0; }

sub calc_cancel {
  my $self = shift;
  my($cust_pkg, $sdate, $details, $param ) = @_;

  $self->calc_usage(@_);
}

sub calc_usage {
  my $self = shift;
  my($cust_pkg, $sdate, $details, $param ) = @_;

  my $last_bill = $cust_pkg->get('last_bill') || $cust_pkg->get('setup');
  my @tickets = @{ FS::TicketSystem->comments_on_tickets( $cust_pkg->custnum, 100, $last_bill ) };

  my $charges = 0;

  my $rate = $self->option('base_rate');

  foreach my $ding ( @tickets) {
        $charges += sprintf('%.2f', $ding->{'timetaken'} * $rate);
        push @$details, join( ", ", ("($ding->{timetaken}) Minutes", substr($ding->{'content'},0,255)));
  }
  cluck $rate, $charges, @$details if $DEBUG > 0;
  return $charges;
}

1;