add option to limit automatic unsuspensions to a specific suspension reason type...
[freeside.git] / bin / test-event
1 #!/usr/bin/perl -w
2
3 use strict;
4 use FS::UID qw( adminsuidsetup );
5 use FS::Schema qw( dbdef );
6 use FS::Record qw(qsearchs);
7 use FS::part_event;
8 #XXX all event tables
9 use FS::cust_main;
10 use FS::cust_bill;
11
12 my $user = shift or die &usage;
13 adminsuidsetup($user);
14
15 my $eventpart = shift or die &usage;
16 my $table     = shift or die &usage;
17 my $tablenum  = shift or die &usage;
18
19 my $part_event = qsearchs('part_event', { 'eventpart' => $eventpart } )
20   or die "unknown eventpart $eventpart";
21
22 my $pkey = dbdef->table($table)->primary_key;
23
24 my $object = qsearchs($table, { $pkey => $tablenum } )
25   or die "can't find $pkey $tablenum in $table";
26
27 my $cust_event = $part_event->new_cust_event($object);
28
29 print "\n";
30
31 ###
32 # specifics
33 ###
34
35 my @conditions = $part_event->part_event_condition;
36 foreach my $condition ( @conditions ) {
37   my $sat = $condition->condition( $object,
38                                    'cust_event' => $cust_event,
39                                    'time' => time,
40                                  );
41
42   my $sql = $condition->condition_sql();
43   
44
45   print $condition->conditionname. '.pm: '.
46         ( $sat ? "satisfied\n" : "NOT SATISFIED\n" );
47
48 }
49
50 ###
51 # random shit to test pkg_balance_under.pm
52 ###
53
54 #my $cust_main = $object->cust_main;
55 #my $pkg_balance = $cust_main->balance_pkgnum($tablenum);
56 #print "\nbalance for cust_pkg $tablenum: $pkg_balance\n";
57
58 ###
59 # overall
60 ###
61
62 my $run = $cust_event->test_conditions;
63
64 print "\n". $part_event->eventpart.': '. $part_event->event.
65       " for $table $tablenum: ".  ( $run ? "RUN\n" : "DON'T RUN\n" );
66
67 sub usage {
68   die "Usage:\n  test-event user eventpart table tablenum\n";
69 }
70
71