[freeside-commits] branch FREESIDE_4_BRANCH updated. 01ae8e0bf7047cde0b0b96e65a78514363bf4d1f
Ivan
ivan at 420.am
Mon Apr 25 09:51:22 PDT 2016
The branch, FREESIDE_4_BRANCH has been updated
via 01ae8e0bf7047cde0b0b96e65a78514363bf4d1f (commit)
from f805cf286bb990b4bc99cc8136ffbaeef00af805 (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 01ae8e0bf7047cde0b0b96e65a78514363bf4d1f
Author: Ivan Kohler <ivan at freeside.biz>
Date: Mon Apr 25 09:51:21 2016 -0700
add conditions for customer cancelled packages, RT#42043
diff --git a/FS/FS/cust_main/Packages.pm b/FS/FS/cust_main/Packages.pm
index efd3c6c..745d547 100644
--- a/FS/FS/cust_main/Packages.pm
+++ b/FS/FS/cust_main/Packages.pm
@@ -500,6 +500,26 @@ sub ncancelled_pkgs {
}
+=item cancelled_pkgs [ EXTRA_QSEARCH_PARAMS_HASHREF ]
+
+Returns all cancelled packages (see L<FS::cust_pkg>) for this customer.
+
+=cut
+
+sub cancelled_pkgs {
+ my $self = shift;
+ my $extra_qsearch = ref($_[0]) ? shift : { @_ };
+
+ return $self->num_cancelled_pkgs($extra_qsearch) unless wantarray;
+
+ $extra_qsearch->{'extra_sql'} .=
+ ' AND cust_pkg.cancel IS NOT NULL AND cust_pkg.cancel > 0 ';
+
+ local($skip_label_sort) = 1 if $extra_qsearch->{skip_label_sort};
+
+ sort sort_packages $self->_cust_pkg($extra_qsearch);
+}
+
sub _cust_pkg {
my $self = shift;
my $extra_qsearch = ref($_[0]) ? shift : {};
diff --git a/FS/FS/part_event/Condition/has_pkg_class_cancelled.pm b/FS/FS/part_event/Condition/has_pkg_class_cancelled.pm
new file mode 100644
index 0000000..214d445
--- /dev/null
+++ b/FS/FS/part_event/Condition/has_pkg_class_cancelled.pm
@@ -0,0 +1,43 @@
+package FS::part_event::Condition::has_pkg_class_cancelled;
+use base qw( FS::part_event::Condition );
+
+use strict;
+
+sub description {
+ 'Customer has cancelled package with class';
+}
+
+sub eventtable_hashref {
+ { 'cust_main' => 1,
+ 'cust_bill' => 1,
+ 'cust_pkg' => 1,
+ };
+}
+
+#something like this
+sub option_fields {
+ (
+ 'pkgclass' => { 'label' => 'Package Class',
+ 'type' => 'select-pkg_class',
+ 'multiple' => 1,
+ },
+ 'age' => { 'label' => 'Cacnellation in last',
+ 'type' => 'freq',
+ },
+ );
+}
+
+sub condition {
+ my( $self, $object, %opt ) = @_;
+
+ my $cust_main = $self->cust_main($object);
+
+ my $age = $self->option_age_from('age', $opt{'time'} );
+
+ #XXX test
+ my $hashref = $self->option('pkgclass') || {};
+ grep { $hashref->{ $_->part_pkg->classnum } && $_->get('cancel') > $age }
+ $cust_main->cancelled_pkgs;
+}
+
+1;
diff --git a/FS/FS/part_event/Condition/has_pkgpart_cancelled.pm b/FS/FS/part_event/Condition/has_pkgpart_cancelled.pm
new file mode 100644
index 0000000..992bfec
--- /dev/null
+++ b/FS/FS/part_event/Condition/has_pkgpart_cancelled.pm
@@ -0,0 +1,45 @@
+package FS::part_event::Condition::has_pkgpart_cancelled;
+use base qw( FS::part_event::Condition );
+
+use strict;
+
+sub description { 'Customer has cancelled specific package(s)'; }
+
+sub eventtable_hashref {
+ { 'cust_main' => 1,
+ 'cust_bill' => 1,
+ 'cust_pkg' => 1,
+ };
+}
+
+sub option_fields {
+ (
+ 'if_pkgpart' => { 'label' => 'Only packages: ',
+ 'type' => 'select-part_pkg',
+ 'multiple' => 1,
+ },
+ 'age' => { 'label' => 'Cancellation in last',
+ 'type' => 'freq',
+ },
+ );
+}
+
+sub condition {
+ my( $self, $object, %opt ) = @_;
+
+ my $cust_main = $self->cust_main($object);
+
+ my $age = $self->option_age_from('age', $opt{'time'} );
+
+ my $if_pkgpart = $self->option('if_pkgpart') || {};
+ grep { $if_pkgpart->{ $_->pkgpart } && $_->get('cancel') > $age }
+ $cust_main->cancelled_pkgs;
+
+}
+
+#XXX
+#sub condition_sql {
+#
+#}
+
+1;
-----------------------------------------------------------------------
Summary of changes:
FS/FS/cust_main/Packages.pm | 20 ++++++++++++++++++++
...has_pkg_class.pm => has_pkg_class_cancelled.pm} | 19 +++++++++++--------
.../{has_pkgpart.pm => has_pkgpart_cancelled.pm} | 17 +++++++++++------
3 files changed, 42 insertions(+), 14 deletions(-)
copy FS/FS/part_event/Condition/{has_pkg_class.pm => has_pkg_class_cancelled.pm} (55%)
copy FS/FS/part_event/Condition/{has_pkgpart.pm => has_pkgpart_cancelled.pm} (54%)
More information about the freeside-commits
mailing list