doc: return fields for customer_info, RT#84796
[freeside.git] / bin / cust_main-email_and_rebill
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Date::Parse;
6 use FS::UID qw( adminsuidsetup );
7 use FS::Record qw( qsearchs );
8 use FS::cust_pkg;
9 use FS::msg_template;
10
11 adminsuidsetup shift or die 'Usage: cust_main-email_and_rebill username\n';
12
13 my $DRY_RUN = 1;
14 my $msgnum = 17;
15
16 my $sep1 = str2time('9/1/2017');
17 my $aug15 = str2time('8/15/2017') + 1802;
18
19 my $msg_template = qsearchs('msg_template', { 'msgnum' => $msgnum } )
20   or die "unknown msg_template $msgnum\n";
21
22 while (<>) {
23   chomp;
24   my $pkgnum = $_;
25
26   #find the package
27   my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum'=>$pkgnum } )
28     or die "pkgnum $pkgnum not found\n";
29
30   #reset its next bill date back to sep 1
31   $cust_pkg->set('bill', $sep1);
32   unless ( $DRY_RUN ) {
33     warn "updating cust_pkg $pkgnum bill to $sep1\n";
34     my $error = $cust_pkg->replace;
35     die $error if $error;
36   } else {
37     warn "DRY RUN: would update cust_pkg $pkgnum bill to $sep1\n";
38   }
39
40   #customer
41   my $cust_main = $cust_pkg->cust_main;
42   my $custnum = $cust_main->custnum;
43
44   #send the custoemr a notice
45   unless ( $DRY_RUN ) {
46     warn "emailing msg_template $msgnum to customer $custnum\n";
47     $msg_template->send( 'cust_main' => $cust_main,
48                          'object'    => $cust_main,
49                        );
50   } else {
51     warn "DRY RUN: emailing msg_template $msgnum to customer $custnum\n";
52   }
53
54   #bill the package
55   unless ( $DRY_RUN ) {
56     warn "billing customer $custnum for package $pkgnum as of $sep1\n";
57     $cust_main->bill( 'time'         => $sep1,
58                       'invoice_time' => $aug15,
59                       'pkg_list'     => [ $cust_pkg ],
60                     );
61   } else {
62     warn "DRY RUN: billing customer $custnum for package $pkgnum as of $sep1\n";
63   }
64
65   #something about removing their pending batch payment??
66   #hmm, there doesn't appear to be anything in a batch
67   #dating the invoices aug 15th will ensure payments for them are batched
68
69   #events will take care of the rest...
70
71 }
72
73 1;