4 use FS::Daemon ':all'; #daemonize1 drop_root daemonize2 myexit logfile sig*
5 use FS::UID qw(adminsuidsetup);
6 use FS::Record qw(qsearch ); #qsearchs);
10 my $user = shift or die &usage;
12 #daemonize1('freeside-sprepaidd', $user); #keep unique pid files w/multi installs
13 daemonize1('freeside-cdrd');
17 adminsuidsetup($user);
19 logfile( "%%%FREESIDE_LOG%%%/cdrd-log.". $FS::UID::datasrc );
23 die "not running; no voip_cdr package defs w/ bill_every_call and customer pkgs"
29 'LEFT JOIN part_pkg USING ( pkgpart ) '.
30 "LEFT JOIN part_pkg_option
31 ON ( cust_pkg.pkgpart = part_pkg_option.pkgpart
32 AND part_pkg_option.optionname = 'bill_every_call' )";
34 #XXX should pay attention to disable_src for efficiency
37 "WHERE plan = 'voip_cdr' ".
38 " AND optionvalue = '1' ".
39 " AND ( susp IS NULL OR susp = 0)".
40 " AND ( cancel IS NULL OR cancel = 0)".
42 SELECT COUNT(*) FROM svc_phone LEFT JOIN cust_svc USING (svcnum)
43 WHERE cust_pkg.pkgnum = cust_svc.pkgnum
44 AND 0 < ( SELECT COUNT(*) FROM cdr
45 WHERE ( freesidestatus IS NULL OR freesidestatus = '' )
46 AND ( charged_party = svc_phone.phonenum
47 OR charged_party = svc_phone.countrycode
49 OR src = svc_phone.phonenum
50 OR src = svc_phone.countrycode
60 foreach my $cust_pkg (
62 'select' => 'cust_pkg.*, part_pkg.plan',
63 'table' => 'cust_pkg',
64 'addl_from' => $addl_from,
66 'extra_sql' => $extra_sql,
72 #my $work_cust_pkg = $cust_pkg;
74 my $cust_main = $cust_pkg->cust_main;
77 $cust_main->bill_and_collect(
79 'invoice_time' => $time,
80 'actual_time' => $time,
81 'check_freq' => '1d', #well
87 myexit() if sigterm() || sigint();
88 sleep 5; # unless $found;
97 ' AND 0 < ( SELECT COUNT(*) FROM cust_pkg
98 WHERE cust_pkg.pkgpart = part_pkg.pkgpart
99 AND ( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )
104 grep $_->option('bill_every_call', 'hush'),
106 'table' => 'part_pkg',
107 'hashref' => { 'plan' => 'voip_cdr' },
108 'extra_sql' => $extra_sql,
117 die "Usage:\n\n freeside-prepaidd user\n";
122 freeside-prepaidd - Real-time daemon for prepaid packages
130 Runs continuously and suspends or cancels any prepaid customer packages which
131 have passed their renewal date (next bill date).