referral credits overhaul, use billing events, agents can self-configure, limit to...
[freeside.git] / FS / FS / part_event / Condition / cust_payments.pm
diff --git a/FS/FS/part_event/Condition/cust_payments.pm b/FS/FS/part_event/Condition/cust_payments.pm
new file mode 100644 (file)
index 0000000..41ef6c7
--- /dev/null
@@ -0,0 +1,43 @@
+package FS::part_event::Condition::cust_payments;
+
+use strict;
+use base qw( FS::part_event::Condition );
+
+sub description { 'Customer total payments'; }
+
+sub option_fields {
+  (
+    'over' => { 'label'      => 'Customer total payments at least',
+                'type'       => 'money',
+                'value'      => '0.00', #default
+              },
+  );
+}
+
+sub condition {
+  my($self, $object) = @_;
+
+  my $cust_main = $self->cust_main($object);
+
+  my $over = $self->option('over');
+  $over = 0 unless length($over);
+
+  $cust_main->total_paid >= $over;
+
+}
+
+#XXX add for efficiency.  could use cust_main::total_paid_sql
+#use FS::cust_main;
+#sub condition_sql {
+#  my( $class, $table ) = @_;
+#
+#  my $over = $class->condition_sql_option('balance');
+#
+#  my $balance_sql = FS::cust_main->balance_sql;
+#
+#  "$balance_sql > $over";
+#
+#}
+
+1;
+