summaryrefslogtreecommitdiff
path: root/FS/FS
diff options
context:
space:
mode:
authormark <mark>2011-11-27 00:46:11 +0000
committermark <mark>2011-11-27 00:46:11 +0000
commit552969c19c3c00367315e861f0d86f14d2ed4427 (patch)
tree77ddc2847dc34ae6ab8eb1afc4e02d70ab6002ae /FS/FS
parent99d1d8e1d4230097dbe5f00ca10241e74941d6e3 (diff)
correct display of prepay discount info with non-monthly packages, #15040
Diffstat (limited to 'FS/FS')
-rw-r--r--FS/FS/cust_bill.pm66
-rw-r--r--FS/FS/cust_main/Billing.pm9
-rw-r--r--FS/FS/cust_pay.pm9
3 files changed, 53 insertions, 31 deletions
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index 77c571b..d9a5e42 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -5203,44 +5203,52 @@ sub _items_discounts_avail {
foreach my $cust_bill_pkg ( $self->cust_bill_pkg ) {
my $cust_pkg = $cust_bill_pkg->cust_pkg or next;
my $part_pkg = $cust_pkg->part_pkg or next;
-
- next if $part_pkg->freq ne '1';
+ my $freq = $part_pkg->freq;
my $setup = $cust_bill_pkg->setup || 0;
my $recur = $cust_bill_pkg->recur || 0;
- my $permonth = $part_pkg->base_recur_permonth || 0;
- my ($discount) = grep { $_->months == $months }
- map { $_->discount } $part_pkg->part_pkg_discount;
+ if ( $freq eq '1' ) { #monthly
+ my $permonth = $part_pkg->base_recur_permonth || 0;
- $hash->{base} += $setup + $recur + ($months - 1) * $permonth;
- if ($discount) {
+ my ($discount) = grep { $_->months == $months }
+ map { $_->discount } $part_pkg->part_pkg_discount;
- my $discountable;
- if ( $discount->setup ) {
- $discountable += $setup;
- }
- else {
- $hash->{discounted} += $setup;
- }
+ $hash->{base} += $setup + $recur + ($months - 1) * $permonth;
+
+ if ( $discount ) {
+
+ my $discountable;
+ if ( $discount->setup ) {
+ $discountable += $setup;
+ }
+ else {
+ $hash->{discounted} += $setup;
+ }
+
+ if ( $discount->percent ) {
+ $discountable += $months * $permonth;
+ $discountable -= ($discountable * $discount->percent / 100);
+ $discountable -= ($permonth - $recur); # correct for prorate
+ $hash->{discounted} += $discountable;
+ }
+ else {
+ $discountable += $recur;
+ $discountable -= $discount->amount * $recur/$permonth;
+
+ $discountable += ($months - 1) * max($permonth - $discount->amount,0);
+ }
- if ( $discount->percent ) {
- $discountable += $months * $permonth;
- $discountable -= ($discountable * $discount->percent / 100);
- $discountable -= ($permonth - $recur); # correct for prorate
$hash->{discounted} += $discountable;
+ push @{ $hash->{pkgnums} }, $cust_pkg->pkgnum;
}
- else {
- $discountable += $recur;
- $discountable -= $discount->amount * $recur/$permonth;
-
- $discountable += ($months - 1) * max($permonth - $discount->amount,0);
+ else { #no discount
+ $hash->{discounted} += $setup + $recur + ($months - 1) * $permonth;
+ $hash->{list_pkgnums} = 1;
}
-
- $hash->{discounted} += $discountable;
- push @{ $hash->{pkgnums} }, $cust_pkg->pkgnum;
- }
- else { #no discount
- $hash->{discounted} += $setup + $recur + ($months - 1) * $permonth;
+ } #if $freq eq '1'
+ else { # all non-monthly packages: include current charges only
+ $hash->{discounted} += $setup + $recur;
+ $hash->{base} += $setup + $recur;
$hash->{list_pkgnums} = 1;
}
} #foreach $cust_bill_pkg
diff --git a/FS/FS/cust_main/Billing.pm b/FS/FS/cust_main/Billing.pm
index abcf8dc..0595618 100644
--- a/FS/FS/cust_main/Billing.pm
+++ b/FS/FS/cust_main/Billing.pm
@@ -253,7 +253,8 @@ charges, etc.
=item freq_override
If set, then override the normal frequency and look for a part_pkg_discount
-to take at that frequency.
+to take at that frequency. This will exclude any packages that aren't billed
+on a monthly cycle.
=item time
@@ -846,6 +847,12 @@ sub _make_lines {
my $time = $params{'time'} or die "no time specified";
my (%options) = %{$params{options}};
+ if ( $part_pkg->freq ne '1' and ($options{'freq_override'} || 0) > 0 ) {
+ # this should never happen
+ die 'freq_override billing attempted on non-monthly package '.
+ $cust_pkg->pkgnum;
+ }
+
my $dbh = dbh;
my $real_pkgpart = $params{real_pkgpart};
my %hash = $cust_pkg->hash;
diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm
index 60c437a..d98d11e 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -194,7 +194,14 @@ sub insert {
my ($cust_bill) = ($cust_main->cust_bill)[-1]; # most recent invoice
return "can't accept prepayment for an unbilled customer" if !$cust_bill;
- my %billing_pkgs = map { $_->pkgnum => $_ } $cust_main->billing_pkgs;
+ # %billing_pkgs contains this customer's active monthly packages.
+ # Recurring fees for those packages will be credited and then rebilled
+ # for the full discount term. Other packages on the last invoice
+ # (canceled, non-monthly recurring, or one-time charges) will be
+ # left as they are.
+ my %billing_pkgs = map { $_->pkgnum => $_ }
+ grep { $_->part_pkg->freq eq '1' }
+ $cust_main->billing_pkgs;
my $credit = 0; # sum of recurring charges from that invoice
my $last_bill_date = 0; # the real bill date
foreach my $item ( $cust_bill->cust_bill_pkg ) {