add discount capability to sql_external, RT10481
authorlevinse <levinse>
Tue, 18 Jan 2011 05:21:08 +0000 (05:21 +0000)
committerlevinse <levinse>
Tue, 18 Jan 2011 05:21:08 +0000 (05:21 +0000)
FS/FS/part_pkg/discount_Mixin.pm
FS/FS/part_pkg/recur_Common.pm
FS/FS/part_pkg/sql_external.pm

index df65e97..a0bdcee 100644 (file)
@@ -42,6 +42,7 @@ sub calc_discount {
   my($self, $cust_pkg, $sdate, $details, $param ) = @_;
 
   my $br = $self->base_recur($cust_pkg);
+  $br += $param->{'override_charges'} if $param->{'override_charges'};
 
   my $tot_discount = 0;
   #UI enforces just 1 for now, will need ordering when they can be stacked
index 7614d7a..95ae0d0 100644 (file)
@@ -32,6 +32,7 @@ sub calc_recur_Common {
     my $recur_method = $self->option('recur_method', 1) || 'anniversary';
     
     $charges = $self->base_recur;
+    $charges += $param->{'override_charges'} if $param->{'override_charges'};
 
     if ( $recur_method eq 'prorate' ) {
       my $cutoff_day = $self->option('cutoff_day') || 1;
index 8d43086..7185487 100644 (file)
@@ -1,7 +1,7 @@
 package FS::part_pkg::sql_external;
 
 use strict;
-use base qw( FS::part_pkg::recur_Common );
+use base qw( FS::part_pkg::recur_Common FS::part_pkg::discount_Mixin );
 use vars qw( %info );
 use DBI;
 #use FS::Record qw(qsearch qsearchs);
@@ -47,9 +47,8 @@ use DBI;
 
 sub calc_recur {
   my $self = shift;
-  my($cust_pkg) = @_; #, $sdate, $details, $param ) = @_;
-
-  my $price = $self->calc_recur_Common(@_);
+  my($cust_pkg, $sdate, $details, $param ) = @_;
+  my $price = 0;
 
   my $dbh = DBI->connect( map { $self->option($_) }
                               qw( datasrc db_username db_password )
@@ -67,10 +66,11 @@ sub calc_recur {
     $price += $sth->fetchrow_arrayref->[0];
   }
 
-  $price;
+  $param->{'override_charges'} = $price;
+  $self->calc_recur_Common($cust_pkg,$sdate,$details,$param);
 }
 
-sub can_discount { 0; }
+sub can_discount { 1; }
 
 sub is_free { 0; }