[freeside-commits] branch master updated. 357211ff7f54864dbc04876db6e84580e02e807c
Ivan
ivan at 420.am
Sun Dec 28 15:03:22 PST 2014
The branch, master has been updated
via 357211ff7f54864dbc04876db6e84580e02e807c (commit)
from 1401eef8b37ea9ffc6a44819a0778697c775dac3 (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 357211ff7f54864dbc04876db6e84580e02e807c
Author: Ivan Kohler <ivan at freeside.biz>
Date: Sun Dec 28 15:03:21 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