[freeside-commits] branch FREESIDE_3_BRANCH updated. af9b59cca47d3b7757ba71a7c8bbafabc505381b
Ivan
ivan at 420.am
Sun Dec 28 15:03:26 PST 2014
The branch, FREESIDE_3_BRANCH has been updated
via af9b59cca47d3b7757ba71a7c8bbafabc505381b (commit)
from 8c6df81f77cf069afbf8d84eb62e7dcebb6f935f (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 af9b59cca47d3b7757ba71a7c8bbafabc505381b
Author: Ivan Kohler <ivan at freeside.biz>
Date: Sun Dec 28 15:03:25 2014 -0800
add condition on "Invoice is newer than last payment type change", RT#31185
diff --git a/FS/FS/part_event/Condition/cust_bill_age_before_payby.pm b/FS/FS/part_event/Condition/cust_bill_age_before_payby.pm
new file mode 100644
index 0000000..273f508
--- /dev/null
+++ b/FS/FS/part_event/Condition/cust_bill_age_before_payby.pm
@@ -0,0 +1,57 @@
+package FS::part_event::Condition::cust_bill_age_before_payby;
+use base qw( FS::part_event::Condition );
+
+use strict;
+use FS::Record qw( qsearchs );
+use FS::h_cust_main;
+
+sub description { 'Invoice is newer than last payment type change'; }
+
+sub eventtable_hashref {
+ { 'cust_main' => 0,
+ 'cust_bill' => 1,
+ 'cust_pkg' => 0,
+ };
+}
+
+sub condition {
+ my( $self, $cust_bill, %opt ) = @_;
+
+ #my $cust_main = $cust_bill->cust_main;
+
+ my $change_date = 0;
+ my $newest = 4294967295; #2^32-1
+
+ #this is pretty expensive, it would be way more efficient to check for
+ # changed payby in SQL
+ # (it would also help if a replace_new had a real FK ref to its replace_old)
+ while ( my $replace_new = qsearchs({
+ 'table' => 'h_cust_main',
+ 'hashref' => { 'custnum' => $cust_bill->custnum,
+ 'history_action' => 'replace_new',
+ 'history_date' => { op=>'<', value=>$newest },
+ },
+ 'order_by' => 'ORDER BY history_date DESC LIMIT 1',
+ }))
+ {
+ my $newest = $replace_new->history_date;
+ my $replace_old = qsearchs({
+ 'table' => 'h_cust_main',
+ 'hashref' => { 'custnum' => $replace_new->custnum,
+ 'history_action' => 'replace_old',
+ 'history_date' => $replace_new->history_date,
+ }
+ }) or next; #no replace_old? ignore and continue on i guess
+
+ if ( $replace_new->payby ne $replace_old->payby ) {
+ $change_date = $replace_new->history_date;
+ last;
+ }
+
+ }
+
+ ( $cust_bill->_date ) > $change_date;
+
+}
+
+1;
-----------------------------------------------------------------------
Summary of changes:
.../Condition/cust_bill_age_before_payby.pm | 57 ++++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 FS/FS/part_event/Condition/cust_bill_age_before_payby.pm
More information about the freeside-commits
mailing list