fix quotations, RT#21103
[freeside.git] / bin / event-search
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Data::Dumper;
5 use FS::UID qw(adminsuidsetup);
6 use FS::Record qw(qsearch);
7 use FS::part_event;
8 use FS::part_event_condition;
9
10 my $fs_user = shift or die "usage: event-search username";
11 adminsuidsetup( $fs_user );
12
13 my $eventtable = 'cust_bill';
14 my $pkey = 'invnum';
15 #my $pkey_value = 33623;
16 my $pkey_value = 34333;
17
18     my $cross = "CROSS JOIN $eventtable";
19     $cross .= ' LEFT JOIN cust_main USING ( custnum )'
20       unless $eventtable eq 'cust_main';
21
22 my $cross_where = "$eventtable.$pkey = $pkey_value";
23
24       my $join = FS::part_event_condition->join_conditions_sql( $eventtable );
25
26       @FS::part_event_condition::SKIP_CONDITION_SQL = ( 'once' );
27
28       my $extra_sql =
29         FS::part_event_condition->where_conditions_sql( $eventtable,
30                                                         #'time'=>$opt{'time'}
31                                                         'time'=>time,
32                                                       );
33
34       my $order = FS::part_event_condition->order_conditions_sql( $eventtable );
35
36       $extra_sql = "AND $extra_sql" if $extra_sql;
37
38       #here is the agent virtualization
39       $extra_sql .= " AND (    part_event.agentnum IS NULL
40                             OR part_event.agentnum = 5 )";
41
42       $extra_sql .= " $order";
43
44
45       my @part_event = qsearch( {
46         #'debug'     => ( $opt{'debug'} > 3 ? 1 : 0 ),
47         'select'    => 'part_event.*',
48         'table'     => 'part_event',
49         'addl_from' => "$cross $join",
50         'hashref'   => { 'check_freq' => '1d', #( $opt{'check_freq'} || '1d' ),
51                          'eventtable' => $eventtable,
52                          'disabled'   => '',
53                        },
54         'extra_sql' => "AND $cross_where $extra_sql",
55       } );
56
57 warn scalar(@part_event). " found\n";
58 warn Dumper(@part_event);