projects
/
freeside.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
91fd4ea
)
apply discount to setup fees, part 1 of 2, RT11512
author
levinse
<levinse>
Fri, 29 Apr 2011 12:12:45 +0000
(12:12 +0000)
committer
levinse
<levinse>
Fri, 29 Apr 2011 12:12:45 +0000
(12:12 +0000)
FS/FS/Schema.pm
patch
|
blob
|
history
FS/FS/cust_pkg.pm
patch
|
blob
|
history
FS/FS/cust_pkg_discount.pm
patch
|
blob
|
history
FS/FS/discount.pm
patch
|
blob
|
history
FS/FS/part_pkg/discount_Mixin.pm
patch
|
blob
|
history
FS/FS/part_pkg/flat.pm
patch
|
blob
|
history
httemplate/edit/discount.html
patch
|
blob
|
history
httemplate/edit/process/cust_pkg_discount.html
patch
|
blob
|
history
httemplate/edit/process/quick-cust_pkg.cgi
patch
|
blob
|
history
httemplate/elements/tr-select-discount.html
patch
|
blob
|
history
diff --git
a/FS/FS/Schema.pm
b/FS/FS/Schema.pm
index
5d453ac
..
3e2bb76
100644
(file)
--- a/
FS/FS/Schema.pm
+++ b/
FS/FS/Schema.pm
@@
-1534,6
+1534,7
@@
sub tables_hashref {
'percent', 'decimal', '', '', '', '',
'months', 'decimal', 'NULL', '', '', '',
'disabled', 'char', 'NULL', 1, '', '',
'percent', 'decimal', '', '', '', '',
'months', 'decimal', 'NULL', '', '', '',
'disabled', 'char', 'NULL', 1, '', '',
+ 'setup', 'char', 'NULL', 1, '', '',
],
'primary_key' => 'discountnum',
'unique' => [],
],
'primary_key' => 'discountnum',
'unique' => [],
diff --git
a/FS/FS/cust_pkg.pm
b/FS/FS/cust_pkg.pm
index
6c985cf
..
deb1cf1
100644
(file)
--- a/
FS/FS/cust_pkg.pm
+++ b/
FS/FS/cust_pkg.pm
@@
-30,6
+30,7
@@
use FS::reason;
use FS::cust_pkg_discount;
use FS::discount;
use FS::UI::Web;
use FS::cust_pkg_discount;
use FS::discount;
use FS::UI::Web;
+use Data::Dumper;
# need to 'use' these instead of 'require' in sub { cancel, suspend, unsuspend,
# setup }
# need to 'use' these instead of 'require' in sub { cancel, suspend, unsuspend,
# setup }
@@
-1416,7
+1417,6
@@
sub change {
}
}
-use Data::Dumper;
use Storable 'thaw';
use MIME::Base64;
sub process_bulk_cust_pkg {
use Storable 'thaw';
use MIME::Base64;
sub process_bulk_cust_pkg {
@@
-2608,6
+2608,7
@@
sub insert_discount {
'amount' => $self->discountnum_amount,
'percent' => $self->discountnum_percent,
'months' => $self->discountnum_months,
'amount' => $self->discountnum_amount,
'percent' => $self->discountnum_percent,
'months' => $self->discountnum_months,
+ 'setup' => $self->discountnum_setup,
#'disabled' => $self->discountnum_disabled,
};
#'disabled' => $self->discountnum_disabled,
};
diff --git
a/FS/FS/cust_pkg_discount.pm
b/FS/FS/cust_pkg_discount.pm
index
7b6b203
..
d41f497
100644
(file)
--- a/
FS/FS/cust_pkg_discount.pm
+++ b/
FS/FS/cust_pkg_discount.pm
@@
-106,6
+106,7
@@
sub insert {
'amount' => $self->amount,
'percent' => $self->percent,
'months' => $self->months,
'amount' => $self->amount,
'percent' => $self->percent,
'months' => $self->months,
+ 'setup' => $self->setup,
'disabled' => 'Y',
};
my $error = $discount->insert;
'disabled' => 'Y',
};
my $error = $discount->insert;
diff --git
a/FS/FS/discount.pm
b/FS/FS/discount.pm
index
4f42c5b
..
6fc3391
100644
(file)
--- a/
FS/FS/discount.pm
+++ b/
FS/FS/discount.pm
@@
-54,6
+54,11
@@
months
disabled
disabled
+=item setup - apply discount to setup fee (not just to recurring fee)
+
+If the discount is based on a percentage, then the % will be applied to the
+setup and recurring portions.
+
=back
=head1 METHODS
=back
=head1 METHODS
@@
-130,6
+135,7
@@
sub check {
|| $self->ut_float('percent') #actually decimal, but this will do
|| $self->ut_floatn('months') #actually decimal, but this will do
|| $self->ut_enum('disabled', [ '', 'Y' ])
|| $self->ut_float('percent') #actually decimal, but this will do
|| $self->ut_floatn('months') #actually decimal, but this will do
|| $self->ut_enum('disabled', [ '', 'Y' ])
+ || $self->ut_enum('setup', [ '', 'Y' ])
;
return $error if $error;
;
return $error if $error;
@@
-176,6
+182,7
@@
sub description {
my $self = shift;
my $desc = $self->description_short;
$desc .= ' for '. $self->months. ' months' if $self->months;
my $self = shift;
my $desc = $self->description_short;
$desc .= ' for '. $self->months. ' months' if $self->months;
+ $desc .= ', applies to setup' if $self->setup;
$desc;
}
$desc;
}
diff --git
a/FS/FS/part_pkg/discount_Mixin.pm
b/FS/FS/part_pkg/discount_Mixin.pm
index
83f1a77
..
8ce5ba8
100644
(file)
--- a/
FS/FS/part_pkg/discount_Mixin.pm
+++ b/
FS/FS/part_pkg/discount_Mixin.pm
@@
-43,6
+43,8
@@
sub calc_discount {
my $br = $self->base_recur($cust_pkg, $sdate);
$br += $param->{'override_charges'} if $param->{'override_charges'};
my $br = $self->base_recur($cust_pkg, $sdate);
$br += $param->{'override_charges'} if $param->{'override_charges'};
+
+ return 0 if defined $param->{'setup_charge'} && $param->{'setup_charge'} == 0;
my $tot_discount = 0;
#UI enforces just 1 for now, will need ordering when they can be stacked
my $tot_discount = 0;
#UI enforces just 1 for now, will need ordering when they can be stacked
@@
-90,9
+92,19
@@
sub calc_discount {
? min( $chg_months,
$discount->months - $cust_pkg_discount->months_used )
: $chg_months;
? min( $chg_months,
$discount->months - $cust_pkg_discount->months_used )
: $chg_months;
+
+ if(defined $param->{'setup_charge'}) {
+ next unless $discount->setup;
+
+ if ( $discount->percent ) {
+ $amount = sprintf('%.2f', $discount->percent * $param->{'setup_charge'} / 100 );
+ $months = 1;
+ }
+ }
my $error = $cust_pkg_discount->increment_months_used($months)
my $error = $cust_pkg_discount->increment_months_used($months)
- if $cust_pkg->pkgpart == $param->{real_pkgpart};
+ if ($cust_pkg->pkgpart == $param->{real_pkgpart}
+ && ! defined $param->{'setup_charge'});
die "error discounting: $error" if $error;
$amount *= $months;
die "error discounting: $error" if $error;
$amount *= $months;
@@
-114,9
+126,9
@@
sub calc_discount {
$months = sprintf('%.2f', $months) if $months =~ /\./;
my $d = 'Includes ';
$months = sprintf('%.2f', $months) if $months =~ /\./;
my $d = 'Includes ';
- $d .=
$discount->name. ' ' if $discount->name
;
+ $d .=
'setup ' if defined $param->{'setup_charge'}
;
$d .= 'discount of '. $discount->description_short;
$d .= 'discount of '. $discount->description_short;
- $d .= " for $months month". ( $months!=1 ? 's' : '' );
+ $d .= " for $months month". ( $months!=1 ? 's' : '' )
unless defined $param->{'setup_charge'}
;
$d .= ": $money_char$amount" if $months != 1 || $discount->percent;
push @$details, $d;
$d .= ": $money_char$amount" if $months != 1 || $discount->percent;
push @$details, $d;
diff --git
a/FS/FS/part_pkg/flat.pm
b/FS/FS/part_pkg/flat.pm
index
04f4951
..
78c5764
100644
(file)
--- a/
FS/FS/part_pkg/flat.pm
+++ b/
FS/FS/part_pkg/flat.pm
@@
-106,7
+106,11
@@
sub calc_setup {
my $quantity = $cust_pkg->quantity || 1;
my $charge = $quantity * $self->unit_setup($cust_pkg, $sdate, $details);
my $quantity = $cust_pkg->quantity || 1;
my $charge = $quantity * $self->unit_setup($cust_pkg, $sdate, $details);
- sprintf('%.2f', $charge);
+
+ my $param = { 'setup_charge' => $charge };
+ my $discount = $self->calc_discount($cust_pkg, $sdate, $details, $param);
+
+ sprintf('%.2f', $charge - $discount);
}
sub unit_setup {
}
sub unit_setup {
diff --git
a/httemplate/edit/discount.html
b/httemplate/edit/discount.html
index
6e0d8e1
..
b195eb3
100644
(file)
--- a/
httemplate/edit/discount.html
+++ b/
httemplate/edit/discount.html
@@
-21,6
+21,7
@@
{ field => 'months', type => 'text', size => 2,
postfix => '<BR><FONT SIZE="-1"><I>(blank for non-expiring discount)</I></FONT>',
},
{ field => 'months', type => 'text', size => 2,
postfix => '<BR><FONT SIZE="-1"><I>(blank for non-expiring discount)</I></FONT>',
},
+ { field => 'setup', type => 'checkbox', value=>'Y', },
],
'labels' => {
'discountnum' => 'Discount #',
],
'labels' => {
'discountnum' => 'Discount #',
@@
-30,6
+31,7
@@
'amount' => 'Amount ',
'percent' => 'Percentage ',
'months' => 'Duration (months)',
'amount' => 'Amount ',
'percent' => 'Percentage ',
'months' => 'Duration (months)',
+ 'setup' => 'Apply to setup fees',
},
'viewall_dir' => 'browse',
'new_callback' => $new_callback,
},
'viewall_dir' => 'browse',
'new_callback' => $new_callback,
diff --git
a/httemplate/edit/process/cust_pkg_discount.html
b/httemplate/edit/process/cust_pkg_discount.html
index
ad9842a
..
6f97a79
100644
(file)
--- a/
httemplate/edit/process/cust_pkg_discount.html
+++ b/
httemplate/edit/process/cust_pkg_discount.html
@@
-39,6
+39,7
@@
my $cust_pkg_discount = new FS::cust_pkg_discount {
'amount' => scalar($cgi->param('discountnum_amount')),
'percent' => scalar($cgi->param('discountnum_percent')),
'months' => scalar($cgi->param('discountnum_months')),
'amount' => scalar($cgi->param('discountnum_amount')),
'percent' => scalar($cgi->param('discountnum_percent')),
'months' => scalar($cgi->param('discountnum_months')),
+ 'setup' => scalar($cgi->param('discountnum_setup')),
#'disabled' => $self->discountnum_disabled,
};
my $error = $cust_pkg_discount->insert;
#'disabled' => $self->discountnum_disabled,
};
my $error = $cust_pkg_discount->insert;
diff --git
a/httemplate/edit/process/quick-cust_pkg.cgi
b/httemplate/edit/process/quick-cust_pkg.cgi
index
bf5087c
..
4ab56e1
100644
(file)
--- a/
httemplate/edit/process/quick-cust_pkg.cgi
+++ b/
httemplate/edit/process/quick-cust_pkg.cgi
@@
-91,6
+91,7
@@
my $cust_pkg = new FS::cust_pkg {
'discountnum_amount' => scalar($cgi->param('discountnum_amount')),
'discountnum_percent' => scalar($cgi->param('discountnum_percent')),
'discountnum_months' => scalar($cgi->param('discountnum_months')),
'discountnum_amount' => scalar($cgi->param('discountnum_amount')),
'discountnum_percent' => scalar($cgi->param('discountnum_percent')),
'discountnum_months' => scalar($cgi->param('discountnum_months')),
+ 'discountnum_setup' => scalar($cgi->param('discountnum_setup')),
'contract_end' => ( scalar($cgi->param('contract_end'))
? parse_datetime($cgi->param('contract_end'))
: ''
'contract_end' => ( scalar($cgi->param('contract_end'))
? parse_datetime($cgi->param('contract_end'))
: ''
diff --git
a/httemplate/elements/tr-select-discount.html
b/httemplate/elements/tr-select-discount.html
index
258eeb3
..
e8be393
100644
(file)
--- a/
httemplate/elements/tr-select-discount.html
+++ b/
httemplate/elements/tr-select-discount.html
@@
-64,6
+64,16
@@
)
%>
)
%>
+ <% include( '/elements/tr-checkbox.html',
+ 'label' => '<B>Apply discount to setup fee</B>',
+ 'field' => $name.'_setup',
+ 'id' => $name.'_setup',
+ 'curr_value' => scalar($cgi->param($name.'_setup')),
+ 'value' => 'Y',
+ 'colspan' => $opt{'colspan'},
+ )
+ %>
+
<SCRIPT TYPE="text/javascript">
% my $ge = 'document.getElementById';
<SCRIPT TYPE="text/javascript">
% my $ge = 'document.getElementById';
@@
-83,6
+93,10
@@
<% $ge %>('<% $name %>_months').style.visibility = '';
<% $ge %>('<% $name %>_months_postfix').style.display = '';
<% $ge %>('<% $name %>_months_postfix').style.visibility = '';
<% $ge %>('<% $name %>_months').style.visibility = '';
<% $ge %>('<% $name %>_months_postfix').style.display = '';
<% $ge %>('<% $name %>_months_postfix').style.visibility = '';
+ <% $ge %>('<% $name %>_setup_label0').style.display = '';
+ <% $ge %>('<% $name %>_setup_label0').style.visibility = '';
+ <% $ge %>('<% $name %>_setup').style.display = '';
+ <% $ge %>('<% $name %>_setup').style.visibility = '';
} else {
<% $ge %>('<% $name %>__type_label0').style.display = 'none';
} else {
<% $ge %>('<% $name %>__type_label0').style.display = 'none';
@@
-110,6
+124,11
@@
<% $ge %>('<% $name %>_months').style.visibility = 'hidden';
<% $ge %>('<% $name %>_months_postfix').style.display = 'none';
<% $ge %>('<% $name %>_months_postfix').style.visibility = 'hidden';
<% $ge %>('<% $name %>_months').style.visibility = 'hidden';
<% $ge %>('<% $name %>_months_postfix').style.display = 'none';
<% $ge %>('<% $name %>_months_postfix').style.visibility = 'hidden';
+
+ <% $ge %>('<% $name %>_setup_label0').style.display = 'none';
+ <% $ge %>('<% $name %>_setup_label0').style.visibility = 'hidden';
+ <% $ge %>('<% $name %>_setup').style.display = 'none';
+ <% $ge %>('<% $name %>_setup').style.visibility = 'hidden';
}
}