First version of RT Billing pkg. Basic concept is if a customer has this package...
authorjayce <jayce>
Tue, 26 Jan 2010 04:47:03 +0000 (04:47 +0000)
committerjayce <jayce>
Tue, 26 Jan 2010 04:47:03 +0000 (04:47 +0000)
This has not been used in production yet by anybody, it was just a proposal done for a customer.
 Modified Files:
  TicketSystem/RT_External.pm
 Added Files:
  part_pkg/rt_time.pm

FS/FS/TicketSystem/RT_External.pm
FS/FS/part_pkg/rt_time.pm [new file with mode: 0644]

index 8ccc937..5c51bdd 100644 (file)
@@ -9,6 +9,7 @@ use URI::Escape;
 use FS::UID qw(dbh);
 use FS::Record qw(qsearchs);
 use FS::cust_main;
+use Carp qw(cluck);
 
 $me = '[FS::TicketSystem::RT_External]';
 $DEBUG = 0;
@@ -96,6 +97,31 @@ sub customer_tickets {
 
 }
 
+sub comments_on_tickets {
+  my ($self, $custnum, $limit, $time ) = @_;
+  $limit ||= 0;
+
+  my( $from_sql, @param) = $self->_from_customer( $custnum );
+  my $sql = qq{
+    SELECT transactions.*, Attachments.content, Tickets.subject
+    FROM transactions
+      JOIN Attachments ON( Attachments.transactionid = transactions.id )
+      JOIN Tickets ON ( Tickets.id = transactions.objectid )
+      JOIN Links  ON ( Tickets.id    = Links.LocalBase
+                       AND Links.Base LIKE '%/ticket/' || Tickets.id )
+       
+
+    WHERE ( Status = 'new' OR Status = 'open' OR Status = 'stalled' )
+      AND Target = 'freeside://freeside/cust_main/$custnum'
+       AND transactions.type = 'Comment'
+       AND transactions.created >= (SELECT TIMESTAMP WITH TIME ZONE 'epoch' + $time * INTERVAL '1 second')
+     LIMIT $limit
+  };
+  cluck $sql if $DEBUG > 0;
+  #AND created > 
+  $dbh->selectall_arrayref( $sql, { Slice => {} } ) or die $dbh->errstr . " $sql";
+}
+
 sub _from_customer {
   my( $self, $custnum, $priority ) = @_;
 
diff --git a/FS/FS/part_pkg/rt_time.pm b/FS/FS/part_pkg/rt_time.pm
new file mode 100644 (file)
index 0000000..d179e75
--- /dev/null
@@ -0,0 +1,67 @@
+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)',
+  'fields'    =>  {
+    'base_rate' =>  {   'name'    =>  'Rate (per minute)',
+                        'default' => 0,
+                    },
+  }
+);
+
+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 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;