4 use vars qw( $opt_d $opt_u $opt_r );
6 use Date::Parse qw(str2time);
7 use FS::UID qw(adminsuidsetup dbh);
8 use FS::Record qw(qsearch qsearchs);
14 my $user = shift or &usage;
17 my $sdate = str2time($opt_d);
18 my $edate = $sdate + 86399;
20 my $oldAutoCommit = $FS::UID::AutoCommit;
21 local $FS::UID::AutoCommit = 0;
28 foreach my $h_cust_pkg (
29 qsearch({ table => 'h_cust_pkg',
30 hashref => { history_user => $opt_u,
31 history_action => 'replace_new',
33 extra_sql => ' AND history_date >= ? AND history_date <= ? ',
34 extra_param => [ [$sdate,'int'], [$edate,'int'] ],
35 #order_by => 'ORDER BY history_date asc',
38 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $h_cust_pkg->pkgnum } );
39 next if $cust_pkg->get('cancel');
41 my($s, $e) = ($h_cust_pkg->history_date-$fuzz, $h_cust_pkg->history_date+$fuzz);
44 table => 'h_cust_pkg',
45 hashref => { history_user => $opt_u,
46 history_action => 'replace_old',
47 pkgnum => $h_cust_pkg->pkgnum,
49 extra_sql => ' AND history_date >= ? AND history_date <= ? ',
50 extra_param => [ [$s,'int'], [$e,'int'] ],
53 my $diff = $h_cust_pkg->get('bill') - $old->get('bill');
55 warn "next bill date was decremented (not incremented) for pkgnum ". $cust_pkg->pkgnum. "; skipping\n";
57 } elsif ( $diff == 0 ) {
58 warn "next bill date was not changed for pkgnum ". $cust_pkg->pkgnum. "; skipping\n";
65 my $days = ($diff / 86400);
66 print "decrementing next bill for pkgnum ". $cust_pkg->pkgnum.
67 " (custnum ". $cust_pkg->custnum. ") by $days days\n";
70 $cust_pkg->set('bill', $cust_pkg->get('bill') - $diff );
71 my $error = $cust_pkg->replace;
77 $dbh->rollback or die $dbh->errstr; #if $oldAutoCommit;
79 $dbh->commit or die $dbh->errstr; #if $oldAutoCommit;
82 print "changed $changed packages\n";
85 die "usage: cust_pkg-revert -d date -u history_username [ -r ] employee_username\n";
94 cust_pkg-revert -d date -u history_username [ -r ] employee_username
98 Command-line tool to revert customer package changes from a specific day and user.
99 Currently only incrementing the next bill date (cust_pkg.bill) is reverted.
101 -d: Date of the changes to revert
103 -u: Username of the changes to revert