[freeside-commits] branch FREESIDE_3_BRANCH updated. 21d544fe7cef15876114a380ba90190373ca519f
Mark Wells
mark at 420.am
Tue Dec 30 23:29:21 PST 2014
The branch, FREESIDE_3_BRANCH has been updated
via 21d544fe7cef15876114a380ba90190373ca519f (commit)
from 41c91051e8bfd4266b6fee72fcd2f07138a676d6 (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 21d544fe7cef15876114a380ba90190373ca519f
Author: Mark Wells <mark at freeside.biz>
Date: Tue Dec 30 23:28:26 2014 -0800
sales commission on invoices: allow commission based on cost, #25847
diff --git a/FS/FS/part_event/Action/Mixin/credit_bill.pm b/FS/FS/part_event/Action/Mixin/credit_bill.pm
index 4930e35..82b215d 100644
--- a/FS/FS/part_event/Action/Mixin/credit_bill.pm
+++ b/FS/FS/part_event/Action/Mixin/credit_bill.pm
@@ -24,14 +24,15 @@ sub option_fields {
'label' => 'Of',
'type' => 'select',
#add additional ways to specify in the package def
- 'options' => [qw( setuprecur setup recur setuprecur_margin setup_margin recur_margin )],
+ 'options' => [qw( setuprecur setup recur setup_cost recur_cost setup_margin recur_margin_permonth )],
'labels' => {
- 'setuprecur' => 'Amount charged',
- 'setup' => 'Setup fee',
- 'recur' => 'Recurring fee',
- 'setuprecur_margin' => 'Amount charged minus total cost',
- 'setup_margin' => 'Setup fee minus setup cost',
- 'recur_margin' => 'Recurring fee minus recurring cost',
+ 'setuprecur' => 'Amount charged on this invoice',
+ 'setup' => 'Setup fee charged on this invoice',
+ 'recur' => 'Recurring fee charged on this invoice',
+ 'setup_cost' => 'Setup cost',
+ 'recur_cost' => 'Recurring cost',
+ 'setup_margin' => 'Package setup fee minus setup cost',
+ 'recur_margin_permonth' => 'Monthly recurring fee minus recurring cost',
},
},
);
@@ -55,7 +56,8 @@ sub _calc_credit {
my $cust_bill_pkg = shift;
my $what = $self->option('what');
- my $margin = 1 if $what =~ s/_margin$//;
+ my $cost = ($what =~ /_cost/ ? 1 : 0);
+ my $margin = ($what =~ /_margin/ ? 1 : 0);
my $pkgnum = $cust_bill_pkg->pkgnum;
my $cust_pkg = $cust_bill_pkg->cust_pkg;
@@ -68,24 +70,31 @@ sub _calc_credit {
}
my $charge = 0;
- if ( $what eq 'setup' ) {
- $charge = $cust_bill_pkg->get('setup');
- } elsif ( $what eq 'recur' ) {
- $charge = $cust_bill_pkg->get('recur');
- } elsif ( $what eq 'setuprecur' ) {
- $charge = $cust_bill_pkg->get('setup') + $cust_bill_pkg->get('recur');
- }
- if ( $margin ) {
+ if ( $margin or $cost ) {
+ # look up package costs only if we need them
my $pkgpart = $cust_bill_pkg->pkgpart_override || $cust_pkg->pkgpart;
my $part_pkg = $part_pkg_cache{$pkgpart}
||= FS::part_pkg->by_key($pkgpart);
+
+ if ( $cost ) {
+ $charge = $part_pkg->get($what);
+ } else { # $margin
+ $charge = $part_pkg->$what($cust_pkg);
+ }
+
+ $charge = ($charge || 0) * ($cust_pkg->quantity || 1);
+
+ } else { # setup, recur, or setuprecur
+
if ( $what eq 'setup' ) {
- $charge -= $part_pkg->get('setup_cost');
+ $charge = $cust_bill_pkg->get('setup');
} elsif ( $what eq 'recur' ) {
- $charge -= $part_pkg->get('recur_cost');
+ $charge = $cust_bill_pkg->get('recur');
} elsif ( $what eq 'setuprecur' ) {
- $charge -= $part_pkg->get('setup_cost') + $part_pkg->get('recur_cost');
+ $charge = $cust_bill_pkg->get('setup') + $cust_bill_pkg->get('recur');
}
+
+ # don't multiply by quantity here; it's already included
}
$charge = 0 if $charge < 0; # e.g. prorate
diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm
index b7b9be5..bac4b8b 100644
--- a/FS/FS/part_pkg.pm
+++ b/FS/FS/part_pkg.pm
@@ -1590,7 +1590,7 @@ recur_cost divided by freq (only supported for monthly and longer frequencies)
sub recur_cost_permonth {
my($self, $cust_pkg) = @_;
return 0 unless $self->freq =~ /^\d+$/ && $self->freq > 0;
- sprintf('%.2f', $self->recur_cost / $self->freq );
+ sprintf('%.2f', ($self->recur_cost || 0) / $self->freq );
}
=item cust_bill_pkg_recur CUST_PKG
@@ -1635,7 +1635,7 @@ unit_setup minus setup_cost
sub setup_margin {
my $self = shift;
- $self->unit_setup(@_) - $self->setup_cost;
+ $self->unit_setup(@_) - ($self->setup_cost || 0);
}
=item recur_margin_permonth
-----------------------------------------------------------------------
Summary of changes:
FS/FS/part_event/Action/Mixin/credit_bill.pm | 47 +++++++++++++++-----------
FS/FS/part_pkg.pm | 4 +--
2 files changed, 30 insertions(+), 21 deletions(-)
More information about the freeside-commits
mailing list