4 use FS::Daemon qw(daemonize1 drop_root logfile daemonize2 sigint sigterm);
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 );
26 'LEFT JOIN part_pkg USING ( pkgpart ) '.
27 "LEFT JOIN part_pkg_option
28 ON ( cust_pkg.pkgpart = part_pkg_option.pkgpart
29 AND part_pkg_option.optionname = 'bill_every_call' )";
31 #XXX should pay attention to disable_src for efficiency
34 "WHERE plan = 'voip_cdr' ".
35 " AND optionvalue = '1' ".
36 " AND ( susp IS NULL OR susp = 0)".
37 " AND ( cancel IS NULL OR cancel = 0)".
39 SELECT COUNT(*) FROM svc_phone LEFT JOIN cust_svc USING (svcnum)
40 WHERE cust_pkg.pkgnum = cust_svc.pkgnum
41 AND 0 < ( SELECT COUNT(*) FROM cdr
42 WHERE ( freesidestatus IS NULL OR freesidestatus = '' )
43 AND ( charged_party = svc_phone.phonenum
44 OR charged_party = svc_phone.countrycode
46 OR src = svc_phone.phonenum
47 OR src = svc_phone.countrycode
57 foreach my $cust_pkg (
59 'select' => 'cust_pkg.*, part_pkg.plan',
60 'table' => 'cust_pkg',
61 'addl_from' => $addl_from,
63 'extra_sql' => $extra_sql,
69 my $work_cust_pkg = $cust_pkg;
71 my $cust_main = $cust_pkg->cust_main;
74 $cust_main->bill_and_collect(
76 'invoice_time' => $time,
77 'actual_time' => $time,
78 'check_freq' => '1d', #well
84 die "exiting" if sigterm() || sigint();
85 sleep 5; # unless $found;
92 die "Usage:\n\n freeside-prepaidd user\n";
97 freeside-prepaidd - Real-time daemon for prepaid packages
105 Runs continuously and suspends or cancels any prepaid customer packages which
106 have passed their renewal date (next bill date).