combine ticket notification scrips, #15353
[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 ###
30 # specifics
31 ###
32
33 my @conditions = $part_event->part_event_condition;
34 foreach my $condition ( @conditions ) {
35   my $sat = $condition->condition( $object, 'cust_event' => $cust_event );
36   print $condition->conditionname. '.pm: '.
37         ( $sat ? "satisfied\n" : "NOT SATISFIED\n" );
38
39 }
40
41 ###
42 # random shit to test pkg_balance_under.pm
43 ###
44
45 #my $cust_main = $object->cust_main;
46 #my $pkg_balance = $cust_main->balance_pkgnum($tablenum);
47 #print "\nbalance for cust_pkg $tablenum: $pkg_balance\n";
48
49 ###
50 # overall
51 ###
52
53 print "\n";
54
55 my $run = $cust_event->test_conditions;
56
57 print "\n". $part_event->eventpart.': '. $part_event->event.
58       " for $table $tablenum: ".  ( $run ? "RUN\n" : "DON'T RUN\n" );
59
60 sub usage {
61   die "Usage:\n  test-event user eventpart table tablenum\n";
62 }
63
64