4 use vars qw($opt_s $opt_u $opt_p $opt_k);
6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearch qsearchs);
13 my($svc_acct, $cust_pkg) = @_;
14 $svc_acct->seconds_since_sqlradacct( $cust_pkg->last_bill, time );
17 my($svc_acct, $cust_pkg) = @_;
18 $svc_acct->attribute_since_sqlradacct(
19 $cust_pkg->last_bill, time, 'AcctInputOctets' );
22 my($svc_acct, $cust_pkg) = @_;
23 $svc_acct->attribute_since_sqlradacct(
24 $cust_pkg->last_bill, time, 'AcctOutputOctets' );
27 my($svc_acct, $cust_pkg) = @_;
28 $svc_acct->attribute_since_sqlradacct(
29 $cust_pkg->last_bill, time, 'AcctInputOctets' )
31 $svc_acct->attribute_since_sqlradacct(
32 $cust_pkg->last_bill, time, 'AcctOutputOctets' )
37 my $user = shift or die &usage;
41 die "can only reset seconds, upbytes, downbytes or totalbytes"
42 unless $field2sub{$field};
46 #false laziness w/freeside-reexport
51 my $cust_svc = qsearchs('cust_svc', { svcnum=>$opt_s } )
52 or die "svcnum $opt_s not found\n";
53 push @svc_x, $cust_svc->svc_x;
55 my $svc_x = qsearchs('svc_acct', { username=>$opt_u } )
56 or die "username $opt_u not found\n";
59 push @svc_x, map { $_->svc_x } qsearch('cust_svc', { svcpart=>$opt_p } );
60 die "no services with svcpart $opt_p found\n" unless @svc_x;
66 addl_from => 'LEFT JOIN cust_pkg USING ( pkgnum )',
67 extra_sql => "WHERE pkgpart = $opt_k",
69 die "no services with pkgpart $opt_k found\n" unless @svc_x;
72 warn "setting $field to $value before usage\n";
73 foreach my $svc_x ( @svc_x ) {
74 my $cust_pkg = $svc_x->cust_svc->cust_pkg;
75 my $cust_usage = $value - &{ $field2sub{$field} }( $svc_x, $cust_pkg );
76 # warn "resetting ". $svc_x->svcnum.':'.$svc_x->username. " to $cust_usage\n";
77 warn "$field for ". $svc_x->svcnum.':'.$svc_x->username. " reached limit\n"
79 $svc_x->$field($cust_usage);
81 my $error = $svc_x->replace;
86 die "Usage:\n\n svc_acct-recalculate_usage user [ -s svcnum | -u username | -p svcpart ]\n";
91 svc-acct-recalculate_usage - Command line tool to recalculate usage for existing services
95 svc_acct-recalculate_usage user usagefield initialvalue [ -s svcnum | -u username | -p svcpart ]
97 #recalculate a 1gb totalbytes limit for pkgpart 2
98 svc_acct-recalculate_usage ivan totalbytes 1073741824 -k 2
102 Re-calculates the specified usage field for the specified service(s) (selected
103 by svcnum, username or svcpart).
107 L<FS::svc_acct>, L<freeside-reexport>, L<FS::part_export>