add prepaid support which sets RADIUS Expiration attribute, update customer view...
[freeside.git] / FS / bin / freeside-prepaidd
1 #!/usr/bin/perl -w
2
3 use strict;
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);
7 use FS::cust_pkg;
8
9 my $user = shift or die &usage;
10
11 #daemonize1('freeside-sprepaidd', $user); #keep unique pid files w/multi installs
12 daemonize1('freeside-prepaidd');
13
14 drop_root();
15
16 adminsuidsetup($user);
17
18 logfile( "/usr/local/etc/freeside/prepaidd-log.". $FS::UID::datasrc );
19
20 daemonize2();
21
22 #--
23
24 while (1) {
25
26   foreach my $cust_pkg ( 
27     qsearch( {
28       'select'    => 'cust_pkg.*, part_pkg.plan',
29       'table'     => 'cust_pkg',
30       'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )',
31       #'hashref'   => { 'plan' => 'prepaid' },#should check part_pkg::is_prepaid
32       #'extra_sql' => "AND bill < ". time.
33       'hashref'   => {},
34       'extra_sql' => "WHERE plan = 'prepaid' AND bill < ". time.
35                      " AND bill IS NOT NULL".
36                      " AND ( susp   IS NULL OR susp   = 0)".
37                      " AND ( cancel IS NULL OR cancel = 0)"
38     } )
39   ) {
40     my $error = $cust_pkg->suspend;
41     warn "Error suspended package ". $cust_pkg->pkgnum.
42          " for custnum ". $cust_pkg->custnum.
43          ": $error\n"
44       if $error;
45   }
46
47   die "exiting" if sigterm() || sigint();
48   sleep 5;
49
50 }
51
52 #--
53
54 sub usage { 
55   die "Usage:\n\n  freeside-prepaidd user\n";
56 }
57
58 =head1 NAME
59
60 freeside-prepaidd - Real-time daemon for prepaid packages
61
62 =head1 SYNOPSIS
63
64   freeside-prepaidd
65
66 =head1 DESCRIPTION
67
68 Runs continuously and suspendes any prepaid customer packages which have
69 passed their renewal date (next bill date).
70
71 =head1 SEE ALSO
72
73 =cut
74
75 1;