From 96cfdeaacaf990b16f6accb23b75607a5c188335 Mon Sep 17 00:00:00 2001 From: levinse Date: Tue, 18 Jan 2011 05:21:08 +0000 Subject: [PATCH] add discount capability to sql_external, RT10481 --- FS/FS/part_pkg/discount_Mixin.pm | 1 + FS/FS/part_pkg/recur_Common.pm | 1 + FS/FS/part_pkg/sql_external.pm | 12 ++++++------ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/FS/FS/part_pkg/discount_Mixin.pm b/FS/FS/part_pkg/discount_Mixin.pm index df65e9708..a0bdcee0a 100644 --- a/FS/FS/part_pkg/discount_Mixin.pm +++ b/FS/FS/part_pkg/discount_Mixin.pm @@ -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 diff --git a/FS/FS/part_pkg/recur_Common.pm b/FS/FS/part_pkg/recur_Common.pm index 7614d7abc..95ae0d077 100644 --- a/FS/FS/part_pkg/recur_Common.pm +++ b/FS/FS/part_pkg/recur_Common.pm @@ -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; diff --git a/FS/FS/part_pkg/sql_external.pm b/FS/FS/part_pkg/sql_external.pm index 8d4308676..718548771 100644 --- a/FS/FS/part_pkg/sql_external.pm +++ b/FS/FS/part_pkg/sql_external.pm @@ -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; } -- 2.11.0