summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2010-03-30 02:53:10 +0000
committerivan <ivan>2010-03-30 02:53:10 +0000
commit548bde0209edab634e5b2ea919e4a2096607d2d0 (patch)
tree1282e186a9ea756c7faceadf3eee19b9f698aafb /FS
parent2848f5b5675c28051c3ddbc9b9fb302423a43ca4 (diff)
employee (otaker / access_user) commissioning, RT#6991
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/part_event/Action/Mixin/credit_pkg.pm63
-rw-r--r--FS/FS/part_event/Action/pkg_agent_credit.pm38
-rw-r--r--FS/FS/part_event/Action/pkg_agent_credit_pkg.pm9
-rw-r--r--FS/FS/part_event/Action/pkg_employee_credit_pkg.pm9
-rw-r--r--FS/FS/part_event/Action/pkg_referral_credit.pm7
-rw-r--r--FS/FS/part_event/Action/pkg_referral_credit_pkg.pm53
-rw-r--r--FS/FS/part_pkg.pm12
7 files changed, 137 insertions, 54 deletions
diff --git a/FS/FS/part_event/Action/Mixin/credit_pkg.pm b/FS/FS/part_event/Action/Mixin/credit_pkg.pm
new file mode 100644
index 000000000..aeda92f91
--- /dev/null
+++ b/FS/FS/part_event/Action/Mixin/credit_pkg.pm
@@ -0,0 +1,63 @@
+package FS::part_event::Action::Mixin::credit_pkg;
+
+use strict;
+
+sub eventtable_hashref {
+ { 'cust_pkg' => 1 };
+}
+
+sub option_fields {
+ (
+ 'reasonnum' => { 'label' => 'Credit reason',
+ 'type' => 'select-reason',
+ 'reason_class' => 'R',
+ },
+ 'percent' => { 'label' => 'Percent',
+ 'type' => 'input-percentage',
+ 'default' => '100',
+ },
+ 'what' => { 'label' => 'Of',
+ 'type' => 'select',
+ #add additional ways to specify in the package def
+ 'options' => [ qw( base_recur_permonth unit_setup recur_cost_permonth setup_cost ) ],
+ 'labels' => { 'base_recur_permonth' => 'Base monthly fee',
+ 'unit_setup' => 'Setup fee',
+ 'recur_cost_permonth' => 'Monthly cost',
+ 'setup_cost' => 'Setup cost',
+ },
+ },
+ );
+
+}
+
+#my %no_cust_pkg = ( 'setup_cost' => 1 );
+
+sub _calc_credit {
+ my( $self, $cust_pkg ) = @_;
+
+ my $cust_main = $self->cust_main($cust_pkg);
+
+ my $part_pkg = $cust_pkg->part_pkg;
+
+ my $what = $self->option('what');
+
+ #false laziness w/Condition/cust_payments_pkg.pm
+ if ( $what =~ /_permonth$/ ) { #huh. yuck.
+ if ( $part_pkg->freq !~ /^\d+$/ ) {
+ die 'WARNING: Not crediting for package '. $cust_pkg->pkgnum.
+ ' ( customer '. $cust_pkg->custnum. ')'.
+ ' - credits not (yet) available for '.
+ ' packages with '. $part_pkg->freq_pretty. ' frequency';
+ }
+ }
+
+ my $percent = $self->option('percent');
+
+ #my @arg = $no_cust_pkg{$what} ? () : ($cust_pkg);
+ my @arg = ($what eq 'setup_cost') ? () : ($cust_pkg);
+
+ sprintf('%.2f', $part_pkg->$what(@arg) * $percent / 100 );
+
+}
+
+1;
diff --git a/FS/FS/part_event/Action/pkg_agent_credit.pm b/FS/FS/part_event/Action/pkg_agent_credit.pm
new file mode 100644
index 000000000..250273846
--- /dev/null
+++ b/FS/FS/part_event/Action/pkg_agent_credit.pm
@@ -0,0 +1,38 @@
+package FS::part_event::Action::pkg_agent_credit;
+
+use strict;
+use base qw( FS::part_event::Action::pkg_referral_credit );
+
+sub description { 'Credit the agent a specific amount'; }
+
+#a little false laziness w/pkg_referral_credit
+sub do_action {
+ my( $self, $cust_pkg ) = @_;
+
+ my $cust_main = $self->cust_main($cust_pkg);
+
+ my $agent = $cust_main->agent;
+ return "No customer record for agent ". $agent->agent
+ unless $agent->agent_custnum;
+
+ my $agent_cust_main = $agent->agent_cust_main;
+ #? or return "No customer record for agent ". $agent->agent;
+
+ my $amount = $self->_calc_credit($cust_pkg);
+ return '' unless $amount > 0;
+
+ my $reasonnum = $self->option('reasonnum');
+
+ my $error = $agent_cust_main->credit(
+ $amount,
+ \$reasonnum,
+ 'addlinfo' =>
+ 'for customer #'. $cust_main->display_custnum. ': '.$cust_main->name,
+ );
+ die "Error crediting customer ". $agent_cust_main->custnum.
+ " for agent commission: $error"
+ if $error;
+
+}
+
+1;
diff --git a/FS/FS/part_event/Action/pkg_agent_credit_pkg.pm b/FS/FS/part_event/Action/pkg_agent_credit_pkg.pm
new file mode 100644
index 000000000..b3e11817d
--- /dev/null
+++ b/FS/FS/part_event/Action/pkg_agent_credit_pkg.pm
@@ -0,0 +1,9 @@
+package FS::part_event::Action::pkg_agent_credit_pkg;
+
+use strict;
+use base qw( FS::part_event::Action::Mixin::credit_pkg
+ FS::part_event::Action::pkg_agent_credit );
+
+sub description { 'Credit the agent an amount based on the referred package'; }
+
+1;
diff --git a/FS/FS/part_event/Action/pkg_employee_credit_pkg.pm b/FS/FS/part_event/Action/pkg_employee_credit_pkg.pm
new file mode 100644
index 000000000..e3b867fb2
--- /dev/null
+++ b/FS/FS/part_event/Action/pkg_employee_credit_pkg.pm
@@ -0,0 +1,9 @@
+package FS::part_event::Action::pkg_employee_credit_pkg;
+
+use strict;
+use base qw( FS::part_event::Action::Mixin::credit_pkg
+ FS::part_event::Action::pkg_employee_credit );
+
+sub description { 'Credit the ordering employee an amount based on the referred package'; }
+
+1;
diff --git a/FS/FS/part_event/Action/pkg_referral_credit.pm b/FS/FS/part_event/Action/pkg_referral_credit.pm
index 98d982066..da872e7ff 100644
--- a/FS/FS/part_event/Action/pkg_referral_credit.pm
+++ b/FS/FS/part_event/Action/pkg_referral_credit.pm
@@ -22,7 +22,6 @@ sub option_fields {
}
-#a little false laziness w/pkg_referral_credit_pkg
sub do_action {
my( $self, $cust_pkg ) = @_;
@@ -36,7 +35,9 @@ sub do_action {
return 'Referring customer is cancelled'
if $referring_cust_main->status eq 'cancelled';
- my $amount = $self->_calc_referral_credit($cust_pkg);
+ my $amount = $self->_calc_credit($cust_pkg);
+ return '' unless $amount > 0;
+
my $reasonnum = $self->option('reasonnum');
my $error = $referring_cust_main->credit(
@@ -51,7 +52,7 @@ sub do_action {
}
-sub _calc_referral_credit {
+sub _calc_credit {
my( $self, $cust_pkg ) = @_;
$self->option('amount');
diff --git a/FS/FS/part_event/Action/pkg_referral_credit_pkg.pm b/FS/FS/part_event/Action/pkg_referral_credit_pkg.pm
index eb9b5107c..667c4ce19 100644
--- a/FS/FS/part_event/Action/pkg_referral_credit_pkg.pm
+++ b/FS/FS/part_event/Action/pkg_referral_credit_pkg.pm
@@ -1,58 +1,9 @@
package FS::part_event::Action::pkg_referral_credit_pkg;
use strict;
-use base qw( FS::part_event::Action::pkg_referral_credit );
+use base qw( FS::part_event::Action::Mixin::credit_pkg
+ FS::part_event::Action::pkg_referral_credit );
sub description { 'Credit the referring customer an amount based on the referred package'; }
-#sub eventtable_hashref {
-# { 'cust_pkg' => 1 };
-#}
-
-sub option_fields {
- (
- 'reasonnum' => { 'label' => 'Credit reason',
- 'type' => 'select-reason',
- 'reason_class' => 'R',
- },
- 'percent' => { 'label' => 'Percent',
- 'type' => 'input-percentage',
- 'default' => '100',
- },
- 'what' => { 'label' => 'Of',
- 'type' => 'select',
- #also add some way to specify in the package def, no?
- 'options' => [ qw( base_recur_permonth ) ],
- 'labels' => { 'base_recur_permonth' => 'Base monthly fee', },
- },
- );
-
-}
-
-sub _calc_referral_credit {
- my( $self, $cust_pkg ) = @_;
-
- my $cust_main = $self->cust_main($cust_pkg);
-
- my $part_pkg = $cust_pkg->part_pkg;
-
- my $what = $self->option('what');
-
- #false laziness w/Condition/cust_payments_pkg.pm
- if ( $what eq 'base_recur_permonth' ) { #huh. yuck.
- if ( $part_pkg->freq !~ /^\d+$/ ) {
- die 'WARNING: Not crediting customer '. $cust_main->referral_custnum.
- ' for package '. $cust_pkg->pkgnum.
- ' ( customer '. $cust_pkg->custnum. ')'.
- ' - Referral credits not (yet) available for '.
- ' packages with '. $part_pkg->freq_pretty. ' frequency';
- }
- }
-
- my $percent = $self->option('percent');
-
- sprintf('%.2f', $part_pkg->$what($cust_pkg) * $percent / 100 );
-
-}
-
1;
diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm
index 08c9b87f9..d2f65967d 100644
--- a/FS/FS/part_pkg.pm
+++ b/FS/FS/part_pkg.pm
@@ -1209,6 +1209,18 @@ sub calc_units { 0; }
#fallback for everything except bulk.pm
sub hide_svc_detail { 0; }
+=item recur_cost_permonth CUST_PKG
+
+recur_cost divided by freq (only supported for monthly and longer frequencies)
+
+=cut
+
+sub recur_cost_permonth {
+ my($self, $cust_pkg) = @_;
+ return 0 unless $self->freq =~ /^\d+$/ && $self->freq > 0;
+ sprintf('%.2f', $self->recur_cost / $self->freq );
+}
+
=item format OPTION DATA
Returns data formatted according to the function 'format' described