[freeside-commits] branch master updated. 87a59b1bdf236765177c27ab18390ef1317cc34c

Ivan ivan at 420.am
Thu Jan 9 15:29:54 PST 2014


The branch, master has been updated
       via  87a59b1bdf236765177c27ab18390ef1317cc34c (commit)
       via  8a7eec7b683294a15aab0b2bf1710e10fa80b4c5 (commit)
      from  b1cd043555e332d70d686f3011f3f8a64c30a779 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 87a59b1bdf236765177c27ab18390ef1317cc34c
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Thu Jan 9 15:29:50 2014 -0800

    time/data/etc. unit pricing add-ons, RT#24392

diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index f530947..fa09640 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -336,13 +336,6 @@ sub insert {
   # set order date unless it was specified as part of an import
   $self->order_date(time) unless $import && $self->order_date;
 
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE';
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE';
-  local $SIG{PIPE} = 'IGNORE';
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -444,13 +437,6 @@ hide cancelled packages.
 sub delete {
   my $self = shift;
 
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE';
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE';
-  local $SIG{PIPE} = 'IGNORE';
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -561,13 +547,6 @@ sub replace {
 
   local($disable_agentcheck) = 1 if $old->pkgpart == $new->pkgpart;
 
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE';
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE';
-  local $SIG{PIPE} = 'IGNORE';
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -801,13 +780,6 @@ sub cancel {
        join(', ', map { "$_: $options{$_}" } keys %options ). "\n"
     if $DEBUG;
 
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE';
-  local $SIG{QUIT} = 'IGNORE'; 
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE';
-  local $SIG{PIPE} = 'IGNORE';
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -1004,13 +976,6 @@ sub uncancel {
   # Transaction-alize
   ##
 
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE'; 
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE'; 
-  local $SIG{PIPE} = 'IGNORE'; 
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -1165,13 +1130,6 @@ sub unexpire {
   my( $self, %options ) = @_;
   my $error;
 
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE';
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE';
-  local $SIG{PIPE} = 'IGNORE';
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -1248,13 +1206,6 @@ sub suspend {
     return $self->main_pkg->suspend(%options);
   }
 
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE';
-  local $SIG{QUIT} = 'IGNORE'; 
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE';
-  local $SIG{PIPE} = 'IGNORE';
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -1491,13 +1442,6 @@ sub unsuspend {
     return $self->main_pkg->unsuspend(%opt);
   }
 
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE';
-  local $SIG{QUIT} = 'IGNORE'; 
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE';
-  local $SIG{PIPE} = 'IGNORE';
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -1674,13 +1618,6 @@ sub unadjourn {
   my( $self, %options ) = @_;
   my $error;
 
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE';
-  local $SIG{QUIT} = 'IGNORE'; 
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE';
-  local $SIG{PIPE} = 'IGNORE';
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -1798,13 +1735,6 @@ sub change {
   my $conf = new FS::Conf;
 
   # Transactionize this whole mess
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE'; 
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE'; 
-  local $SIG{PIPE} = 'IGNORE'; 
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -2431,13 +2361,6 @@ sub process_bulk_cust_pkg {
   #my $keep_dates = $param->{'keep_dates'} || 0;
   my $keep_dates = 1; # there is no good reason to turn this off
 
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE';
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE';
-  local $SIG{PIPE} = 'IGNORE';
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -2674,13 +2597,6 @@ If there is an error, returns the error, otherwise returns false.
 sub set_cust_pkg_detail {
   my( $self, $detailtype, @details ) = @_;
 
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE';
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE';
-  local $SIG{PIPE} = 'IGNORE';
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -3168,7 +3084,7 @@ Returns a label for this package.  (Currently "pkgnum: pkg - comment" or
 
 sub pkg_label {
   my $self = shift;
-  my $label = $self->part_pkg->pkg_comment( 'nopkgpart' => 1 );
+  my $label = $self->part_pkg->pkg_comment( cust_pkg=>$self, nopkgpart=>1 );
   $label = $self->pkgnum. ": $label"
     if $FS::CurrentUser::CurrentUser->option('show_pkgnum');
   $label;
@@ -3634,13 +3550,6 @@ sub grab_svcnums {
   my $self = shift;
   my @svcnum = @_;
 
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE';
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE';
-  local $SIG{PIPE} = 'IGNORE';
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -3675,13 +3584,6 @@ order_pkgs methods in FS::cust_main for a better way to defer provisioning.
 sub reexport {
   my $self = shift;
 
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE';
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE';
-  local $SIG{PIPE} = 'IGNORE';
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -3712,13 +3614,6 @@ Calls the "pkg_change" export action for all services attached to this package.
 sub export_pkg_change {
   my( $self, $old )  = ( shift, shift );
 
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE';
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE';
-  local $SIG{PIPE} = 'IGNORE';
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -3890,6 +3785,34 @@ sub recharge {
   }
 }
 
+=item apply_usageprice 
+
+=cut
+
+sub apply_usageprice {
+  my $self = shift;
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  my $error = '';
+
+  foreach my $cust_pkg_usageprice ( $self->cust_pkg_usageprice ) {
+    $error ||= $cust_pkg_usageprice->apply;
+  }
+
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    die "error applying part_pkg_usageprice add-ons, pkgnum ". $self->pkgnum.
+        ": $error\n";
+  } else {
+    $dbh->commit if $oldAutoCommit;
+  }
+
+
+}
+
 =item cust_pkg_discount
 
 =item cust_pkg_discount_active
@@ -3930,16 +3853,10 @@ sub apply_usage {
   my $pkgnum = $self->pkgnum;
   my $custnum = $self->custnum;
 
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE'; 
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE'; 
-  local $SIG{PIPE} = 'IGNORE'; 
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
+
   my $order = FS::Conf->new->config('cdr-minutes_priority');
 
   my $is_classnum;
@@ -4921,13 +4838,6 @@ sub order {
   my $conf = new FS::Conf;
 
   # Transactionize this whole mess
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE'; 
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE'; 
-  local $SIG{PIPE} = 'IGNORE'; 
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
@@ -5067,13 +4977,6 @@ sub bulk_change {
   my ($pkgparts, $remove_pkgnum, $return_cust_pkg) = @_;
 
   # Transactionize this whole mess
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE'; 
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE'; 
-  local $SIG{PIPE} = 'IGNORE'; 
-
   my $oldAutoCommit = $FS::UID::AutoCommit;
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
diff --git a/FS/FS/cust_pkg_usageprice.pm b/FS/FS/cust_pkg_usageprice.pm
index 5380081..394ba0b 100644
--- a/FS/FS/cust_pkg_usageprice.pm
+++ b/FS/FS/cust_pkg_usageprice.pm
@@ -103,13 +103,84 @@ sub check {
   $self->SUPER::check;
 }
 
+=item price
+
+Returns the price for this customer usage pricing add-on (quantity of this
+record multiplied by price of the associated FS::part_pkg_usageprice record)
+
+=cut
+
+sub price {
+  my $self = shift;
+  sprintf('%.2f', $self->quantity * $self->part_pkg_usageprice->price);
+}
+
+=item apply
+
+Applies this customer usage pricing add-on.  (Mulitplies quantity of this record
+by part_pkg_usageprice.amount, and applies to to any services of this package
+matching part_pkg_usageprice.target)
+
+If there is an error, returns the error, otherwise returns false.
+
+=cut
+
+sub apply {
+  my $self = shift;
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  my $error = '';
+
+  my $part_pkg_usageprice = $self->part_pkg_usageprice;
+
+  my $amount = $self->quantity * $part_pkg_usageprice->amount;
+
+  my $target = $part_pkg_usageprice->target;
+
+  #these are ongoing counters that count down, so increment them
+  if ( $target =~ /^svc_acct.(\w+)$/ ) {
+
+    my $method = "increment_$1";
+
+    foreach my $cust_svc ( $self->cust_pkg->cust_svc(svcdb=>'svc_acct') ) {
+      $error ||= $cust_svc->svc_x->$method( $amount );
+    }
+
+  #this is a maximum number, not a counter, so we want to take our number
+  # and add it to the default for the service
+  } elsif ( $target eq 'svc_conferencing.participants' ) {
+
+    foreach my $cust_svc ($self->cust_pkg->cust_svc(svcdb=>'svc_conferencing')){
+      my $svc_conferencing = $cust_svc->svc_x;
+      my $base_amount = $cust_svc->part_svc->part_svc_column('participants')->columnvalue || 0; #assuming.. D?  F would get overridden  :/
+      $svc_acct->participants( $base_amount + $amount );
+      $error ||= $svc_acct->replace;
+    }
+
+  #this has no multiplication involved, its just a set only
+  #} elsif ( $target eq 'svc_conferencing.confqualitynum' ) {
+
+  }
+
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+  } else {
+    $dbh->commit if $oldAutoCommit;
+  }
+  return $error;
+
+}
+
 =back
 
 =head1 BUGS
 
 =head1 SEE ALSO
 
-L<FS::Record>
+L<FS::part_pkg_usageprice>, L<FS::cust_pkg>, L<FS::Record>
 
 =cut
 
diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm
index 3c4c127..8e65c50 100644
--- a/FS/FS/part_pkg.pm
+++ b/FS/FS/part_pkg.pm
@@ -837,8 +837,8 @@ sub custom_comment {
   my $price_info = $self->price_info(@_);
   ( $self->custom ? '(CUSTOM) ' : '' ).
     $self->comment.
-    ( ( ($self->custom || $self->comment) && $price_info ) ? ' - ' : '' ).
-    $price_info;
+    ( ($self->custom || $self->comment) ? ' - ' : '' ).
+    ($price_info || 'No charge');
 }
 
 =item pkg_class
@@ -1068,6 +1068,10 @@ sub can_discount { 0; }
  
 # whether the plan allows changing the start date
 sub can_start_date { 1; }
+
+# whether the plan supports part_pkg_usageprice add-ons (a specific kind of
+#  pre-selectable usage pricing, there's others this doesn't refer to)
+sub can_usageprice { 0; }
   
 # the delay start date if present
 sub delay_start_date {
diff --git a/FS/FS/part_pkg/agent.pm b/FS/FS/part_pkg/agent.pm
index 6ab21d6..4a87728 100644
--- a/FS/FS/part_pkg/agent.pm
+++ b/FS/FS/part_pkg/agent.pm
@@ -1,17 +1,14 @@
 package FS::part_pkg::agent;
+#use base qw(FS::part_pkg::recur_Common);
+use base qw(FS::part_pkg::prorate);
 
 use strict;
-use vars qw(@ISA $DEBUG $me %info);
+use vars qw($DEBUG $me %info);
 use Date::Format;
 use FS::Record qw( qsearch );
 use FS::agent;
 use FS::cust_main;
 
-#use FS::part_pkg::recur_Common;;
-#@ISA = qw(FS::part_pkg::recur_Common);
-use FS::part_pkg::prorate;
- at ISA = qw(FS::part_pkg::prorate);
-
 $DEBUG = 0;
 
 $me = '[FS::part_pkg::agent]';
@@ -160,13 +157,11 @@ sub calc_recur {
 
 sub can_discount { 0; }
 
-sub hide_svc_detail {
-  1;
-}
+sub hide_svc_detail { 1; }
 
-sub is_free {
-  0;
-}
+sub is_free { 0; }
+
+sub can_usageprice { 0; }
 
 1;
 
diff --git a/FS/FS/part_pkg/bulk_Common.pm b/FS/FS/part_pkg/bulk_Common.pm
index 4e8850e..3477c44 100644
--- a/FS/FS/part_pkg/bulk_Common.pm
+++ b/FS/FS/part_pkg/bulk_Common.pm
@@ -31,12 +31,12 @@ $me = '[FS::part_pkg::bulk_Common]';
 
 sub price_info {
     my $self = shift;
-    my $str = $self->SUPER::price_info;
+    my $str = $self->SUPER::price_info(@_);
     my $svc_setup_fee = $self->option('svc_setup_fee');
     my $svc_recur_fee = $self->option('svc_recur_fee');
     my $conf = new FS::Conf;
     my $money_char = $conf->config('money_char') || '$';
-    $str .= " , bulk" if $str;
+    $str .= ", bulk " if $str;
     $str .= ": $money_char" . $svc_setup_fee . " one-time per service" 
 	if $svc_setup_fee;
     $str .= ", " if ($svc_setup_fee && $svc_recur_fee);
@@ -120,5 +120,7 @@ sub is_free_options {
   qw( setup_fee recur_fee svc_setup_fee svc_recur_fee );
 }
 
+sub can_usageprice { 0; }
+
 1;
 
diff --git a/FS/FS/part_pkg/cdr_termination.pm b/FS/FS/part_pkg/cdr_termination.pm
index 54bce2c..9011846 100644
--- a/FS/FS/part_pkg/cdr_termination.pm
+++ b/FS/FS/part_pkg/cdr_termination.pm
@@ -1,7 +1,7 @@
 package FS::part_pkg::cdr_termination;
+use base qw( FS::part_pkg::recur_Common );
 
 use strict;
-use base qw( FS::part_pkg::recur_Common );
 use vars qw( $DEBUG %info );
 use Tie::IxHash;
 use FS::Record qw( qsearch ); #qsearchs );
@@ -187,8 +187,8 @@ sub calc_recur {
   $charges;
 }
 
-sub is_free {
-  0;
-}
+sub is_free { 0; }
+
+sub can_usageprice { 0; }
 
 1;
diff --git a/FS/FS/part_pkg/currency_fixed.pm b/FS/FS/part_pkg/currency_fixed.pm
index c64fb78..bbd95e8 100644
--- a/FS/FS/part_pkg/currency_fixed.pm
+++ b/FS/FS/part_pkg/currency_fixed.pm
@@ -33,7 +33,7 @@ use FS::currency_exchange;
 
 sub price_info {
     my $self = shift;
-    my $str = $self->SUPER::price_info;
+    my $str = $self->SUPER::price_info(@_);
     $str .= " (or local currency pricing)" if $str;
     $str;
 }
@@ -93,4 +93,6 @@ sub is_free { 0; }
 
 sub can_currency_exchange { 1; }
 
+sub can_usageprice { 0; }
+
 1;
diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm
index 6118fd2..7bc44e1 100644
--- a/FS/FS/part_pkg/flat.pm
+++ b/FS/FS/part_pkg/flat.pm
@@ -98,12 +98,16 @@ tie my %contract_years, 'Tie::IxHash', (
 
 sub price_info {
     my $self = shift;
+    my %opt = @_;
     my $conf = new FS::Conf;
     my $money_char = $conf->config('money_char') || '$';
-    my $setup = $self->option('setup_fee') || 0;
-    my $recur = $self->option('recur_fee', 1) || 0;
+    my $setup = $opt{cust_pkg} ? $self->base_setup( $opt{cust_pkg} )
+                               : ($self->option('setup_fee') || 0);
+    my $recur = $opt{cust_pkg} ? $self->base_recur( $opt{cust_pkg} )
+                               : ($self->option('recur_fee', 1) || 0);
+    $recur += $self->usageprice_recur( $opt{cust_pkg} ) if $opt{cust_pkg};
     my $str = '';
-    $str = $money_char . $setup . ($recur ? ' setup ' : ' one-time') if $setup;
+    $str = $money_char . $setup . ($recur ? ' setup' : ' one-time') if $setup;
     $str .= ', ' if ($setup && $recur);
     $str .= $money_char. $recur. '/'. $self->freq_pretty if $recur;
     $str;
@@ -160,6 +164,9 @@ sub calc_recur {
     $charge *= $param->{freq_override} if $param->{freq_override};
   }
 
+  $charge += $self->usageprice_recur($cust_pkg, $sdate);
+  $cust_pkg->apply_usageprice(); #$sdate for prorating?
+
   my $discount = $self->calc_discount($cust_pkg, $sdate, $details, $param);
 
   sprintf( '%.2f', ($cust_pkg->quantity || 1) * ($charge - $discount) );
@@ -190,6 +197,15 @@ sub base_recur_permonth {
   sprintf('%.2f', $self->base_recur($cust_pkg) / $self->freq );
 }
 
+sub usageprice_recur {
+  my($self, $cust_pkg, $sdate) = @_;
+
+  my $recur = 0;
+  $recur += $_->price foreach $cust_pkg->cust_pkg_usageprice;
+
+  sprintf('%.2f', $recur);
+}
+
 sub calc_cancel {
   my $self = shift;
   my $conf = new FS::Conf;
@@ -257,6 +273,8 @@ sub can_start_date { ! shift->option('start_1st', 1) }
 
 sub can_discount { 1; }
 
+sub can_usageprice { 1; }
+
 sub recur_temporality {
   my $self = shift;
   $self->option('recur_temporality', 1);
diff --git a/FS/FS/part_pkg/prorate.pm b/FS/FS/part_pkg/prorate.pm
index a5f9ef6..a81bfda 100644
--- a/FS/FS/part_pkg/prorate.pm
+++ b/FS/FS/part_pkg/prorate.pm
@@ -1,12 +1,10 @@
 package FS::part_pkg::prorate;
+use base qw( FS::part_pkg::flat );
 
 use strict;
-use vars qw(@ISA %info);
+use vars qw(%info);
 use Time::Local qw(timelocal);
 #use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg::flat;
-
- at ISA = qw(FS::part_pkg::flat);
 
 %info = (
   'name' => 'First partial month pro-rated, then flat-rate (selectable billing day)',
@@ -44,9 +42,14 @@ use FS::part_pkg::flat;
 
 sub calc_recur {
   my $self = shift;
+  #my($cust_pkg, $sdate, $details, $param ) = @_;
   my $cust_pkg = $_[0];
 
   my $charge = $self->calc_prorate(@_, $self->cutoff_day($cust_pkg));
+
+  $charge += $self->usageprice_recur(@_);
+  $cust_pkg->apply_usageprice(); #$sdate for prorating?
+
   my $discount = $self->calc_discount(@_);
 
   sprintf( '%.2f', ($cust_pkg->quantity || 1) * ($charge - $discount) );
diff --git a/FS/FS/part_pkg/sql_external.pm b/FS/FS/part_pkg/sql_external.pm
index 813e808..be36c11 100644
--- a/FS/FS/part_pkg/sql_external.pm
+++ b/FS/FS/part_pkg/sql_external.pm
@@ -44,7 +44,7 @@ use DBI;
 
 sub price_info {
     my $self = shift;
-    my $str = $self->SUPER::price_info;
+    my $str = $self->SUPER::price_info(@_);
     $str .= " plus per-service charges" if $str;
     $str;
 }
diff --git a/FS/FS/part_pkg/sql_generic.pm b/FS/FS/part_pkg/sql_generic.pm
index e323d8b..0a875b0 100644
--- a/FS/FS/part_pkg/sql_generic.pm
+++ b/FS/FS/part_pkg/sql_generic.pm
@@ -42,7 +42,7 @@ use FS::part_pkg::flat;
 
 sub price_info {
     my $self = shift;
-    my $str = $self->SUPER::price_info;
+    my $str = $self->SUPER::price_info(@_);
     $str .= " plus per-service charges" if $str;
     $str;
 }
diff --git a/FS/FS/part_pkg/sqlradacct_daily.pm b/FS/FS/part_pkg/sqlradacct_daily.pm
index 1a0bafe..ab1afd7 100644
--- a/FS/FS/part_pkg/sqlradacct_daily.pm
+++ b/FS/FS/part_pkg/sqlradacct_daily.pm
@@ -78,7 +78,7 @@ use Date::Format;
 
 sub price_info {
     my $self = shift;
-    my $str = $self->SUPER::price_info;
+    my $str = $self->SUPER::price_info(@_);
     $str .= " plus usage" if $str;
     $str;
 }
diff --git a/FS/FS/part_pkg/sqlradacct_hour.pm b/FS/FS/part_pkg/sqlradacct_hour.pm
index c9fdb36..e929735 100644
--- a/FS/FS/part_pkg/sqlradacct_hour.pm
+++ b/FS/FS/part_pkg/sqlradacct_hour.pm
@@ -73,7 +73,7 @@ use FS::part_pkg::flat;
 
 sub price_info {
     my $self = shift;
-    my $str = $self->SUPER::price_info;
+    my $str = $self->SUPER::price_info(@_);
     $str .= " plus usage" if $str;
     $str;
 }
diff --git a/FS/FS/part_pkg/torrus_Common.pm b/FS/FS/part_pkg/torrus_Common.pm
index d0dc9d1..b32deab 100644
--- a/FS/FS/part_pkg/torrus_Common.pm
+++ b/FS/FS/part_pkg/torrus_Common.pm
@@ -11,7 +11,7 @@ sub recur_temporality { 'preceding'; }
 
 sub price_info {
     my $self = shift;
-    my $str = $self->SUPER::price_info;
+    my $str = $self->SUPER::price_info(@_);
     $str .= " plus usage" if $str;
     $str;
 }
diff --git a/FS/FS/part_pkg/voip_cdr.pm b/FS/FS/part_pkg/voip_cdr.pm
index 1a99bd7..db0b9e7 100644
--- a/FS/FS/part_pkg/voip_cdr.pm
+++ b/FS/FS/part_pkg/voip_cdr.pm
@@ -361,7 +361,7 @@ tie my %accountcode_tollfree_field, 'Tie::IxHash',
 
 sub price_info {
     my $self = shift;
-    my $str = $self->SUPER::price_info;
+    my $str = $self->SUPER::price_info(@_);
     $str .= " plus usage" if $str;
     $str;
 }
diff --git a/FS/FS/part_pkg/voip_inbound.pm b/FS/FS/part_pkg/voip_inbound.pm
index ec95c90..1566c18 100644
--- a/FS/FS/part_pkg/voip_inbound.pm
+++ b/FS/FS/part_pkg/voip_inbound.pm
@@ -167,7 +167,7 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
 
 sub price_info {
     my $self = shift;
-    my $str = $self->SUPER::price_info;
+    my $str = $self->SUPER::price_info(@_);
     $str .= " plus usage" if $str;
     $str;
 }
diff --git a/FS/FS/part_pkg/voip_sqlradacct.pm b/FS/FS/part_pkg/voip_sqlradacct.pm
index b856b5c..f58194f 100644
--- a/FS/FS/part_pkg/voip_sqlradacct.pm
+++ b/FS/FS/part_pkg/voip_sqlradacct.pm
@@ -31,7 +31,7 @@ $DEBUG = 1;
 
 sub price_info {
     my $self = shift;
-    my $str = $self->SUPER::price_info;
+    my $str = $self->SUPER::price_info(@_);
     $str .= " plus usage" if $str;
     $str;
 }
diff --git a/httemplate/misc/cancel_pkg.html b/httemplate/misc/cancel_pkg.html
index f9a46a8..2003207 100755
--- a/httemplate/misc/cancel_pkg.html
+++ b/httemplate/misc/cancel_pkg.html
@@ -7,7 +7,7 @@
 <INPUT TYPE="hidden" NAME="method" VALUE="<% $method %>">
 
 <BR><BR>
-<% emt(ucfirst($method)." [_1]", $part_pkg->pkg_comment) %>
+<% emt(ucfirst($method)." [_1]", $part_pkg->pkg_comment(cust_pkg=>$cust_pkg) %>
 <% ntable("#cccccc", 2) %>
 
 % my $date_init = 0;
diff --git a/httemplate/misc/delay_susp_pkg.html b/httemplate/misc/delay_susp_pkg.html
index e5f1d8c..02f8824 100755
--- a/httemplate/misc/delay_susp_pkg.html
+++ b/httemplate/misc/delay_susp_pkg.html
@@ -12,7 +12,9 @@
 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
 
 <BR><BR>
-<% "Delay automatic suspension of " .$part_pkg->pkg_comment %>
+<% "Delay automatic suspension of ".
+     $part_pkg->pkg_comment( cust_pkg=>$cust_pkg )
+%>
 <% ntable("#cccccc", 2) %>
 
 <TR>
diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi
index 69f04f5..ee1dd85 100755
--- a/httemplate/search/cust_main.cgi
+++ b/httemplate/search/cust_main.cgi
@@ -233,7 +233,7 @@
 %      my $pkgnum = $_->pkgnum;
 %      my $part_pkg = $_->part_pkg;
 %
-%      my $pkg_comment = $part_pkg->pkg_comment(nopkgpart => 1);
+%      my $pkg_comment = $part_pkg->pkg_comment( cust_pkg=>$_, nopkgpart=>1 );
 %      my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
 %                   ? ''
 %                   : ';show=packages';
diff --git a/httemplate/view/cust_main/packages/package.html b/httemplate/view/cust_main/packages/package.html
index 7a1e9a5..06eb50d 100644
--- a/httemplate/view/cust_main/packages/package.html
+++ b/httemplate/view/cust_main/packages/package.html
@@ -11,7 +11,7 @@
         <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"
            ID  ="cust_pkg<% $cust_pkg->pkgnum %>"
         ><% $curuser->option('show_pkgnum') ? $cust_pkg->pkgnum.': ' : '' %><B><% $part_pkg->pkg |h %></B></A>
-%       my $custom_comment = $part_pkg->custom_comment();
+%       my $custom_comment = $part_pkg->custom_comment('cust_pkg'=>$cust_pkg);
         <% $custom_comment ? ' - ' : '' %>
         <% $custom_comment |h %>
       </TD>
diff --git a/httemplate/view/cust_main/packages/status.html b/httemplate/view/cust_main/packages/status.html
index 70b623c..3ebdf22 100644
--- a/httemplate/view/cust_main/packages/status.html
+++ b/httemplate/view/cust_main/packages/status.html
@@ -416,14 +416,16 @@ sub pkg_status_row_changed {
   my $old = $cust_pkg->old_cust_pkg;
   if ( $old ) {
     my $part_pkg = $old->part_pkg;
-    $html .= pkg_status_row_colspan( $cust_pkg, 
-                                     emt("Changed from [_1]: [_2]",
-                                            $cust_pkg->change_pkgnum,
-                                            $part_pkg->pkg_comment(nopartpkg => 1) ),
-                                     '',
-                                     'size'    => '-1',
-                                     'align'   => 'right',
-                                   );
+    $html .= pkg_status_row_colspan(
+      $cust_pkg, 
+      emt("Changed from [_1]: [_2]",
+             $cust_pkg->change_pkgnum,
+             $part_pkg->pkg_comment(cust_pkg=>$old, nopartpkg=>1)
+         ),
+      '',
+      'size'    => '-1',
+      'align'   => 'right',
+    );
   }
 
   $html;

commit 8a7eec7b683294a15aab0b2bf1710e10fa80b4c5
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Thu Jan 9 14:13:33 2014 -0800

    removing obsolete price plans

diff --git a/FS/FS/part_pkg/flat_comission.pm b/FS/FS/part_pkg/flat_comission.pm
deleted file mode 100644
index 0bc1e7c..0000000
--- a/FS/FS/part_pkg/flat_comission.pm
+++ /dev/null
@@ -1,68 +0,0 @@
-package FS::part_pkg::flat_comission;
-
-use strict;
-use vars qw(@ISA %info);
-#use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg::flat;
-
- at ISA = qw(FS::part_pkg::flat);
-
-%info = (
-  'name' => 'Flat rate with recurring commission per (any) active package',
-  'shortname' => 'Commission per (any) active package',
-  'inherit_fields' => [ 'global_Mixin' ],
-  'fields' => {
-    'comission_amount' => { 'name' => 'Commission amount per month (per active package)',
-                            'default' => 0,
-                          },
-    'comission_depth'  => { 'name' => 'Number of layers',
-                            'default' => 1,
-                          },
-    'reason_type'      => { 'name' => 'Reason type for commission credits',
-                            'type' => 'select',
-                            'select_table' => 'reason_type',
-                            'select_hash'  => { 'class' => 'R' },
-                            'select_key'   => 'typenum',
-                            'select_label' => 'type',
-                          },
-  },
-  'fieldorder' => [ 'comission_depth', 'comission_amount', 'reason_type' ],
-  #'setup' => 'what.setup_fee.value',
-  #'recur' => '\'my $error = $cust_pkg->cust_main->credit( \' + what.comission_amount.value + \' * scalar($cust_pkg->cust_main->referral_cust_pkg(\' + what.comission_depth.value+ \')), "commission" ); die $error if $error; \' + what.recur_fee.value + \';\'',
-  'weight' => 62,
-);
-
-sub price_info {
-    my $self = shift;
-    my $str = $self->SUPER::price_info;
-    my $com = $self->option('comission_amount');
-    $str .= ", $com commission" if $com;
-    $str;
-}
-
-sub calc_recur {
-  my($self, $cust_pkg ) = @_;
-
-  my $amount = $self->option('comission_amount');
-  my $num_active = scalar(
-    $cust_pkg->cust_main->referral_cust_pkg( $self->option('comission_depth') )
-  );
-
-  my $commission = sprintf('%.2f', $amount*$num_active);
-
-  if ( $commission > 0 ) {
-
-    my $error =
-      $cust_pkg->cust_main->credit( $commission, "commission",
-                                    'reason_type'=>$self->option('reason_type'),
-                                  );
-    die $error if $error;
-
-  }
-
-  $self->option('recur_fee');
-}
-
-sub can_discount { 0; }
-
-1;
diff --git a/FS/FS/part_pkg/flat_comission_cust.pm b/FS/FS/part_pkg/flat_comission_cust.pm
deleted file mode 100644
index 5acf73d..0000000
--- a/FS/FS/part_pkg/flat_comission_cust.pm
+++ /dev/null
@@ -1,44 +0,0 @@
-package FS::part_pkg::flat_comission_cust;
-
-use strict;
-use vars qw(@ISA %info);
-#use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg::flat;
-
- at ISA = qw(FS::part_pkg::flat);
-
-%info = (
-  'name' => 'Flat rate with recurring commission per active customer',
-  'shortname' => 'Commission per active customer',
-  'inherit_fields' => [ 'flat_comission', 'global_Mixin' ],
-  'fields' => { },
-  'fieldorder' => [ ],
-  #'setup' => 'what.setup_fee.value',
-  #'recur' => '\'my $error = $cust_pkg->cust_main->credit( \' + what.comission_amount.value + \' * scalar($cust_pkg->cust_main->referral_cust_main_ncancelled(\' + what.comission_depth.value+ \')), "commission" ); die $error if $error; \' + what.recur_fee.value + \';\'',
-  'weight' => '60',
-);
-
-sub calc_recur {
-  my($self, $cust_pkg ) = @_;
-
-  my $amount = $self->option('comission_amount');
-  my $num_active = scalar(
-    $cust_pkg->cust_main->referral_cust_main_ncancelled(
-      $self->option('comission_depth')
-    )
-  );
-
-  if ( $amount && $num_active ) {
-    my $error =
-      $cust_pkg->cust_main->credit( $amount*$num_active, "commission",
-                                    'reason_type'=>$self->option('reason_type'),
-                                  );
-    die $error if $error;
-  }
-
-  $self->option('recur_fee');
-}
-
-sub can_discount { 0; }
-
-1;
diff --git a/FS/FS/part_pkg/flat_comission_pkg.pm b/FS/FS/part_pkg/flat_comission_pkg.pm
deleted file mode 100644
index 26dd4d2..0000000
--- a/FS/FS/part_pkg/flat_comission_pkg.pm
+++ /dev/null
@@ -1,38 +0,0 @@
-package FS::part_pkg::flat_comission_pkg;
-
-use strict;
-use vars qw(@ISA %info);
-#use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg::flat;
-
- at ISA = qw(FS::part_pkg::flat);
-
-%info = (
-  'name' => 'Flat rate with recurring commission per (selected) active package',
-  'shortname' => 'Commission per (selected) active package',
-  'inherit_fields' => [ 'flat_comission', 'global_Mixin' ],
-  'fields' => {
-    'comission_pkgpart' => { 'name' => 'Applicable packages<BR><FONT SIZE="-1">(hold <b>ctrl</b> to select multiple packages)</FONT>',
-                             'type' => 'select_multiple',
-                             'select_table' => 'part_pkg',
-                             'select_hash'  => { 'disabled' => '' } ,
-                             'select_key'   => 'pkgpart',
-                             'select_label' => 'pkg',
-                           },
-  },
-  'fieldorder' => [ 'comission_depth', 'comission_amount', 'comission_pkgpart', 'reason_type' ],
-  #'setup' => 'what.setup_fee.value',
-  #'recur' => '""; var pkgparts = ""; for ( var c=0; c < document.flat_comission_pkg.comission_pkgpart.options.length; c++ ) { if (document.flat_comission_pkg.comission_pkgpart.options[c].selected) { pkgparts = pkgparts + document.flat_comission_pkg.comission_pkgpart.options[c].value + \', \'; } } what.recur.value = \'my $error = $cust_pkg->cust_main->credit( \' + what.comission_amount.value + \' * scalar( grep { my $pkgpart = $_->pkgpart; grep { $_ == $pkgpart } ( \' + pkgparts + \'  ) } $cust_pkg->cust_main->referral_cust_pkg(\' + what.comission_depth.value+ \')), "commission" ); die $error if $error; \' + what.recur_fee.value + \';\'',
-  #'disabled' => 1,
-  'weight' => '64',
-);
-
-# XXX this needs to be fixed!!!
-sub calc_recur {
-  my($self, $cust_pkg ) = @_;
-  $self->option('recur_fee');
-}
-
-sub can_discount { 0; }
-
-1;
diff --git a/FS/FS/part_pkg/sesmon_hour.pm b/FS/FS/part_pkg/sesmon_hour.pm
deleted file mode 100644
index 8d019c3..0000000
--- a/FS/FS/part_pkg/sesmon_hour.pm
+++ /dev/null
@@ -1,58 +0,0 @@
-package FS::part_pkg::sesmon_hour;
-
-use strict;
-use vars qw(@ISA %info);
-#use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg::flat;
-
- at ISA = qw(FS::part_pkg::flat);
-
-%info = (
-  'disabled' => 1, #internal session db deprecated (or at least on hold)
-  'name' => 'Base charge plus charge per-hour from the session monitor',
-  'shortname' => 'Session monitor (per-hour)',
-  'inherit_fields' => [ 'global_Mixin' ],
-  'fields' => {
-    'recur_included_hours' => { 'name' => 'Hours included',
-                                'default' => 0,
-                              },
-    'recur_hourly_charge' => { 'name' => 'Additional charge per hour',
-                               'default' => 0,
-                             },
-  },
-  'fieldorder' => [ 'recur_included_hours', 'recur_hourly_charge' ],
-  #'setup' => 'what.setup_fee.value',
-  #'recur' => '\'my $hours = $cust_pkg->seconds_since($cust_pkg->bill || 0) / 3600 - \' + what.recur_included_hours.value + \'; $hours = 0 if $hours < 0; \' + what.recur_fee.value + \' + \' + what.recur_hourly_charge.value + \' * $hours;\'',
-  'weight' => 80,
-);
-
-sub price_info {
-    my $self = shift;
-    my $str = $self->SUPER::price_info;
-    $str .= " plus usage" if $str;
-    $str;
-}
-
-sub calc_recur {
-  my($self, $cust_pkg ) = @_;
-
-  my $hours = $cust_pkg->seconds_since($cust_pkg->bill || 0) / 3600;
-  $hours -= $self->option('recur_included_hours');
-  $hours = 0 if $hours < 0;
-
-  $self->option('recur_fee') + $hours * $self->option('recur_hourly_charge');
-
-}
-
-sub can_discount { 0; }
-
-sub is_free_options {
-  qw( setup_fee recur_fee recur_hourly_charge );
-}
-
-sub base_recur {
-  my($self, $cust_pkg) = @_;
-  $self->option('recur_fee');
-}
-
-1;
diff --git a/FS/FS/part_pkg/sesmon_minute.pm b/FS/FS/part_pkg/sesmon_minute.pm
deleted file mode 100644
index b86cffd..0000000
--- a/FS/FS/part_pkg/sesmon_minute.pm
+++ /dev/null
@@ -1,56 +0,0 @@
-package FS::part_pkg::sesmon_minute;
-
-use strict;
-use vars qw(@ISA %info);
-#use FS::Record qw(qsearch qsearchs);
-use FS::part_pkg::flat;
-
- at ISA = qw(FS::part_pkg::flat);
-
-%info = (
-  'disabled' => 1, #internal session db deprecated (or at least on hold)
-  'name' => 'Base charge plus charge per-minute from the session monitor',
-  'shortname' => 'Session monitor (per-minute)',
-  'inherit_fields' => [ 'global_Mixin' ],
-  'fields' => {
-    'recur_included_min' => { 'name' => 'Minutes included',
-                              'default' => 0,
-                              },
-    'recur_minly_charge' => { 'name' => 'Additional charge per minute',
-                              'default' => 0,
-                            },
-  },
-  'fieldorder' => [ 'recur_included_min', 'recur_minly_charge' ],
-  #'setup' => 'what.setup_fee.value',
-  #'recur' => '\'my $min = $cust_pkg->seconds_since($cust_pkg->bill || 0) / 60 - \' + what.recur_included_min.value + \'; $min = 0 if $min < 0; \' + what.recur_fee.value + \' + \' + what.recur_minly_charge.value + \' * $min;\'',
-  'weight' => 80,
-);
-
-sub price_info {
-    my $self = shift;
-    my $str = $self->SUPER::price_info;
-    $str .= " plus usage" if $str;
-    $str;
-}
-
-sub calc_recur {
-  my( $self, $cust_pkg ) = @);
-  my $min = $cust_pkg->seconds_since($cust_pkg->bill || 0) / 60;
-  $min -= $self->option('recur_included_min');
-  $min = 0 if $min < 0;
-
-  $self->option('recur_fee') + $min * $self->option('recur_minly_charge');
-}
-
-sub can_discount { 0; }
-
-sub is_free_options {
-  qw( setup_fee recur_fee recur_minly_charge );
-}
-
-sub base_recur {
-  my($self, $cust_pkg) = @_;
-  $self->option('recur_fee');
-}
-
-1;

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/cust_pkg.pm                               |  157 +++++------------------
 FS/FS/cust_pkg_usageprice.pm                    |   73 +++++++++++-
 FS/FS/part_pkg.pm                               |    8 +-
 FS/FS/part_pkg/agent.pm                         |   19 +--
 FS/FS/part_pkg/bulk_Common.pm                   |    6 +-
 FS/FS/part_pkg/cdr_termination.pm               |    8 +-
 FS/FS/part_pkg/currency_fixed.pm                |    4 +-
 FS/FS/part_pkg/flat.pm                          |   24 +++-
 FS/FS/part_pkg/flat_comission.pm                |   68 ----------
 FS/FS/part_pkg/flat_comission_cust.pm           |   44 -------
 FS/FS/part_pkg/flat_comission_pkg.pm            |   38 ------
 FS/FS/part_pkg/prorate.pm                       |   11 +-
 FS/FS/part_pkg/sesmon_hour.pm                   |   58 ---------
 FS/FS/part_pkg/sesmon_minute.pm                 |   56 --------
 FS/FS/part_pkg/sql_external.pm                  |    2 +-
 FS/FS/part_pkg/sql_generic.pm                   |    2 +-
 FS/FS/part_pkg/sqlradacct_daily.pm              |    2 +-
 FS/FS/part_pkg/sqlradacct_hour.pm               |    2 +-
 FS/FS/part_pkg/torrus_Common.pm                 |    2 +-
 FS/FS/part_pkg/voip_cdr.pm                      |    2 +-
 FS/FS/part_pkg/voip_inbound.pm                  |    2 +-
 FS/FS/part_pkg/voip_sqlradacct.pm               |    2 +-
 httemplate/misc/cancel_pkg.html                 |    2 +-
 httemplate/misc/delay_susp_pkg.html             |    4 +-
 httemplate/search/cust_main.cgi                 |    2 +-
 httemplate/view/cust_main/packages/package.html |    2 +-
 httemplate/view/cust_main/packages/status.html  |   18 ++-
 27 files changed, 178 insertions(+), 440 deletions(-)
 delete mode 100644 FS/FS/part_pkg/flat_comission.pm
 delete mode 100644 FS/FS/part_pkg/flat_comission_cust.pm
 delete mode 100644 FS/FS/part_pkg/flat_comission_pkg.pm
 delete mode 100644 FS/FS/part_pkg/sesmon_hour.pm
 delete mode 100644 FS/FS/part_pkg/sesmon_minute.pm




More information about the freeside-commits mailing list