Merge branch 'master' of git.freeside.biz:/home/git/freeside
[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, 'cust_event' => $cust_event );
38
39   my $sql = $condition->condition_sql();
40   
41
42   print $condition->conditionname. '.pm: '.
43         ( $sat ? "satisfied\n" : "NOT SATISFIED\n" );
44
45 }
46
47 ###
48 # random shit to test pkg_balance_under.pm
49 ###
50
51 #my $cust_main = $object->cust_main;
52 #my $pkg_balance = $cust_main->balance_pkgnum($tablenum);
53 #print "\nbalance for cust_pkg $tablenum: $pkg_balance\n";
54
55 ###
56 # overall
57 ###
58
59 my $run = $cust_event->test_conditions;
60
61 print "\n". $part_event->eventpart.': '. $part_event->event.
62       " for $table $tablenum: ".  ( $run ? "RUN\n" : "DON'T RUN\n" );
63
64 sub usage {
65   die "Usage:\n  test-event user eventpart table tablenum\n";
66 }
67
68