5 use FS::UID qw(adminsuidsetup);
6 use FS::Record qw(qsearch);
8 use FS::part_event_condition;
10 my $fs_user = shift or die "usage: event-search username";
11 adminsuidsetup( $fs_user );
13 my $eventtable = 'cust_bill';
15 #my $pkey_value = 33623;
16 my $pkey_value = 34333;
18 my $cross = "CROSS JOIN $eventtable";
19 $cross .= ' LEFT JOIN cust_main USING ( custnum )'
20 unless $eventtable eq 'cust_main';
22 my $cross_where = "$eventtable.$pkey = $pkey_value";
24 my $join = FS::part_event_condition->join_conditions_sql( $eventtable );
26 @FS::part_event_condition::SKIP_CONDITION_SQL = ( 'once' );
29 FS::part_event_condition->where_conditions_sql( $eventtable,
34 my $order = FS::part_event_condition->order_conditions_sql( $eventtable );
36 $extra_sql = "AND $extra_sql" if $extra_sql;
38 #here is the agent virtualization
39 $extra_sql .= " AND ( part_event.agentnum IS NULL
40 OR part_event.agentnum = 5 )";
42 $extra_sql .= " $order";
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,
54 'extra_sql' => "AND $cross_where $extra_sql",
57 warn scalar(@part_event). " found\n";
58 warn Dumper(@part_event);