summaryrefslogtreecommitdiff
path: root/bin/test-event
blob: 73c9d31ec0eddebb1d09c1c7e3cd0ec551dc88b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl -w

use strict;
use FS::UID qw( adminsuidsetup );
use FS::Schema qw( dbdef );
use FS::Record qw(qsearchs);
use FS::part_event;
#XXX all event tables
use FS::cust_main;
use FS::cust_bill;

my $user = shift or die &usage;
adminsuidsetup($user);

my $eventpart = shift or die &usage;
my $table     = shift or die &usage;
my $tablenum  = shift or die &usage;

my $part_event = qsearchs('part_event', { 'eventpart' => $eventpart } )
  or die "unknown eventpart $eventpart";

my $pkey = dbdef->table($table)->primary_key;

my $object = qsearchs($table, { $pkey => $tablenum } )
  or die "can't find $pkey $tablenum in $table";

my $cust_event = $part_event->new_cust_event($object);

print "\n";

###
# specifics
###

my @conditions = $part_event->part_event_condition;
foreach my $condition ( @conditions ) {
  my $sat = $condition->condition( $object,
                                   'cust_event' => $cust_event,
                                   'time' => time,
                                 );

  my $sql = $condition->condition_sql();
  

  print $condition->conditionname. '.pm: '.
        ( $sat ? "satisfied\n" : "NOT SATISFIED\n" );

}

###
# random shit to test pkg_balance_under.pm
###

#my $cust_main = $object->cust_main;
#my $pkg_balance = $cust_main->balance_pkgnum($tablenum);
#print "\nbalance for cust_pkg $tablenum: $pkg_balance\n";

###
# overall
###

my $run = $cust_event->test_conditions;

print "\n". $part_event->eventpart.': '. $part_event->event.
      " for $table $tablenum: ".  ( $run ? "RUN\n" : "DON'T RUN\n" );

sub usage {
  die "Usage:\n  test-event user eventpart table tablenum\n";
}