summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2013-08-25 01:40:28 -0700
committerIvan Kohler <ivan@freeside.biz>2013-08-25 01:40:28 -0700
commitd29b455cf176358089f98e2970beaab88195bc62 (patch)
treebd076935c628774c3297f68da9acafe80ca35e94
parent60724f233fbeb9388f4b2cbb68a4e6297c2b2118 (diff)
continue sales person work: customer and package selection, commissions, reporting. RT#23402
-rw-r--r--FS/FS/part_event.pm1
-rw-r--r--FS/FS/part_event/Action/Mixin/credit_sales_pkg_class.pm1
-rw-r--r--FS/FS/part_event/Condition/pkg_age_Common.pm9
-rw-r--r--FS/FS/part_event/Condition/pkg_age_before_sales.pm58
-rw-r--r--FS/FS/part_event_condition.pm3
5 files changed, 69 insertions, 3 deletions
diff --git a/FS/FS/part_event.pm b/FS/FS/part_event.pm
index b7371c9..a740bb8 100644
--- a/FS/FS/part_event.pm
+++ b/FS/FS/part_event.pm
@@ -583,6 +583,7 @@ sub actions {
(
map { $_ => $actions{$_} }
sort { $actions{$a}->{'default_weight'}<=>$actions{$b}->{'default_weight'} }
+ # || $actions{$a}->{'description'} cmp $actions{$b}->{'description'} }
$class->all_actions( $eventtable )
);
diff --git a/FS/FS/part_event/Action/Mixin/credit_sales_pkg_class.pm b/FS/FS/part_event/Action/Mixin/credit_sales_pkg_class.pm
index 666de13..fc7a3e3 100644
--- a/FS/FS/part_event/Action/Mixin/credit_sales_pkg_class.pm
+++ b/FS/FS/part_event/Action/Mixin/credit_sales_pkg_class.pm
@@ -3,6 +3,7 @@ use base qw( FS::part_event::Action::Mixin::credit_pkg );
use strict;
use FS::Record qw(qsearchs);
+use FS::sales_pkg_class;
sub option_fields {
my $class = shift;
diff --git a/FS/FS/part_event/Condition/pkg_age_Common.pm b/FS/FS/part_event/Condition/pkg_age_Common.pm
index 0f3b9ef..726b01d 100644
--- a/FS/FS/part_event/Condition/pkg_age_Common.pm
+++ b/FS/FS/part_event/Condition/pkg_age_Common.pm
@@ -40,7 +40,7 @@ sub option_fields {
sub condition {
my( $self, $cust_pkg, %opt ) = @_;
- my $age = $self->option_age_from('age', $opt{'time'} );
+ my $age = $self->pkg_age_age( $cust_pkg, %opt );
my $pkg_date = $cust_pkg->get( $self->option('field') );
@@ -48,6 +48,13 @@ sub condition {
}
+sub pkg_age_age {
+ my( $self, $cust_pkg, %opt );
+ $self->option_age_from('age', $opt{'time'} );
+}
+
+#doesn't work if you override pkg_age_age,
+# so if you do, override this with at least a stub that returns 'true'
sub condition_sql {
my( $class, $table, %opt ) = @_;
my $age = $class->condition_sql_option_age_from('age', $opt{'time'});
diff --git a/FS/FS/part_event/Condition/pkg_age_before_sales.pm b/FS/FS/part_event/Condition/pkg_age_before_sales.pm
new file mode 100644
index 0000000..4ad56fa
--- /dev/null
+++ b/FS/FS/part_event/Condition/pkg_age_before_sales.pm
@@ -0,0 +1,58 @@
+package FS::part_event::Condition::pkg_age_before_sales;
+use base qw( FS::part_event::Condition::pkg_age_before );
+
+use strict;
+use Time::Local qw( timelocal_nocheck );
+use FS::Record qw( qsearchs );
+use FS::sales_pkg_class;
+
+sub description { 'Package age younger than sales person commission duration'; }
+
+sub option_fields {
+ my $class = shift;
+ my %option_fields = $class->SUPER::option_fields();
+
+ delete $option_fields{'age'};
+
+ $option_fields{'cust_main_sales'} = {
+ 'label' => "Compare to the customer sales person if there is no package sales person",
+ 'type' => 'checkbox',
+ 'value' => 'Y',
+ };
+
+ %option_fields;
+}
+
+sub pkg_age_age {
+ my( $self, $cust_pkg, %opt );
+
+ my $salesnum = $cust_pkg->salesnum;
+ $salesnum ||= $self->cust_main($cust_pkg)->salesnum
+ if $self->option('cust_main_sales');
+
+ return 0 unless $salesnum;
+
+ my $sales_pkg_class = qsearchs( 'sales_pkg_class', {
+ 'salesnum' => $salesnum,
+ 'classnum' => $cust_pkg->part_pkg->classnum,
+ });
+
+ my $commission_duration = $sales_pkg_class->commission_duration;
+ return 0 unless $commission_duration =~ /^\s*(\d+)\s*$/;
+
+ #false laziness w/Condition::option_age_from, but just months
+
+ my $time = $opt{'time'};
+ my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($time) )[0,1,2,3,4,5];
+ $mon -= $commission_duration;
+ until ( $mon >= 0 ) { $mon += 12; $year--; }
+
+ timelocal_nocheck($sec,$min,$hour,$mday,$mon,$year);
+}
+
+#no working condition_sql for this comparison yet, don't want pkg_age_Common's
+sub condition_sql {
+ 'true';
+}
+
+1;
diff --git a/FS/FS/part_event_condition.pm b/FS/FS/part_event_condition.pm
index d550680..78aa3b1 100644
--- a/FS/FS/part_event_condition.pm
+++ b/FS/FS/part_event_condition.pm
@@ -224,8 +224,7 @@ sub conditions {
my( $class, $eventtable ) = @_;
(
map { $_ => $conditions{$_} }
-# sort { $conditions{$a}->{'default_weight'}<=>$conditions{$b}->{'default_weight'} }
-# sort by ?
+ sort {$conditions{$a}->{'description'} cmp $conditions{$b}->{'description'}}
$class->all_conditionnames( $eventtable )
);