add more options to freeside-overdue
authorivan <ivan>
Fri, 28 Dec 2001 14:40:35 +0000 (14:40 +0000)
committerivan <ivan>
Fri, 28 Dec 2001 14:40:35 +0000 (14:40 +0000)
add charge method to FS::cust_main

one-off packages default to disabled

billing payname defaults to first and last, not "Accounts Payable"

FS/FS/cust_main.pm
FS/bin/freeside-bill
FS/bin/freeside-overdue
httemplate/edit/cust_main.cgi
httemplate/edit/part_pkg.cgi

index 3995e65..6c18f93 100644 (file)
@@ -28,6 +28,7 @@ use FS::cust_credit_bill;
 use FS::cust_bill_pay;
 use FS::prepay_credit;
 use FS::queue;
 use FS::cust_bill_pay;
 use FS::prepay_credit;
 use FS::queue;
+use FS::part_pkg;
 
 @ISA = qw( FS::Record );
 
 
 @ISA = qw( FS::Record );
 
@@ -1775,6 +1776,29 @@ sub credit {
   $cust_credit->insert;
 }
 
   $cust_credit->insert;
 }
 
+=item charge AMOUNT PKG COMMENT
+
+Creates a one-time charge for this customer.  If there is an error, returns
+the error, otherwise returns false.
+
+=cut
+
+sub charge {
+  my ( $self, $amount, $pkg, $comment ) = @_;
+
+  my $part_pkg = new FS::part_pkg ( {
+    'pkg'      => $pkg || 'One-time charge',
+    'comment'  => $comment,
+    'setup'    => $amount,
+    'freq'     => 0,
+    'recur'    => '0',
+    'disabled' => 'Y',
+  } );
+
+  $part_pkg->insert;
+
+}
+
 =back
 
 =head1 SUBROUTINES
 =back
 
 =head1 SUBROUTINES
@@ -1916,7 +1940,7 @@ sub append_fuzzyfiles {
 
 =head1 VERSION
 
 
 =head1 VERSION
 
-$Id: cust_main.pm,v 1.51 2001-12-26 11:17:49 ivan Exp $
+$Id: cust_main.pm,v 1.52 2001-12-28 14:40:35 ivan Exp $
 
 =head1 BUGS
 
 
 =head1 BUGS
 
index 7898936..49ec43c 100755 (executable)
@@ -59,14 +59,14 @@ foreach $cust_main (
 
   if ($opt_p) {
     $cust_main->apply_payments;
 
   if ($opt_p) {
     $cust_main->apply_payments;
-    $error=$cust_main->apply_credits;
+    $cust_main->apply_credits;
   }
 
   if ($opt_c) {
     $error=$cust_main->collect('invoice_time'=>$time,
                                'batch_card' => $opt_i ? 'no' : 'yes',
                               );
   }
 
   if ($opt_c) {
     $error=$cust_main->collect('invoice_time'=>$time,
                                'batch_card' => $opt_i ? 'no' : 'yes',
                               );
-    warn "Error collecting from customer #" . $cust_main->gcustnum.  ":$error"
+    warn "Error collecting from customer #" . $cust_main->custnum.  ":$error"
       if $error;
 
     #sleep 1;
       if $error;
 
     #sleep 1;
@@ -123,7 +123,7 @@ customers.  Otherwise, bills all customers.
 
 =head1 VERSION
 
 
 =head1 VERSION
 
-$Id: freeside-bill,v 1.10 2001-11-05 14:04:56 ivan Exp $
+$Id: freeside-bill,v 1.11 2001-12-28 14:40:35 ivan Exp $
 
 =head1 BUGS
 
 
 =head1 BUGS
 
index 0c62b99..8f7f872 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/perl -w
 
 use strict;
 use vars qw( $days_to_pay $cust_main $cust_pkg 
 
 use strict;
 use vars qw( $days_to_pay $cust_main $cust_pkg 
@@ -13,12 +13,12 @@ use FS::UID qw(adminsuidsetup);
 
 &untaint_argv;
 my %opt;
 
 &untaint_argv;
 my %opt;
-getopts('ed:qplsc', \%opt);
+getopts('ed:qplscbyoi', \%opt);
 my $user = shift or die &usage;
 
 adminsuidsetup $user;
 
 my $user = shift or die &usage;
 
 adminsuidsetup $user;
 
-my $now = time;
+my $now = time; #eventually take a time option like freeside-bill
 my ($sec,$min,$hour,$mday,$mon,$year) =
   (localtime($now) )[0,1,2,3,4,5];
 $mon++;
 my ($sec,$min,$hour,$mday,$mon,$year) =
   (localtime($now) )[0,1,2,3,4,5];
 $mon++;
@@ -48,21 +48,23 @@ foreach $cust_main ( qsearch('cust_main',{} ) ) {
             $cust_main->balance_date(time-$opt{d} * 86400);
     }
 
             $cust_main->balance_date(time-$opt{d} * 86400);
     }
 
-#    if ( $opt{l} ) {
-#      print "\n\tCharging late fee of \$$opt{l}" unless $opt{q};
-#
-#    }
+    if ( $opt{p} && ! grep { $_ eq 'POST' } $cust_main->invoicing_list ) {
+      print "\n\tAdding postal invoicing" unless $opt{q};
+      my @invoicing_list = $cust_main->invoicing_list;
+      push @invoicing_list, 'POST';
+      $cust_main->invoicing_list(\@invoicing_list);
+    }
+
+    if ( $opt{l} ) {
+      print "\n\tCharging late fee of \$$opt{l}" unless $opt{q};
+      my $error = $cust_main->charge($opt{l}, 'Late fee');
+      # comment or plandata with info so we don't redo the same late fee every
+      # day
+    }
 
     foreach $cust_pkg ( qsearch( 'cust_pkg', 
                                  { 'custnum' => $cust_main->custnum } ) ) {
 
 
     foreach $cust_pkg ( qsearch( 'cust_pkg', 
                                  { 'custnum' => $cust_main->custnum } ) ) {
 
-      if ( $opt{p} && ! grep { $_ eq 'POST' } $cust_main->invoicing_list ) {
-        print "\n\tAdding postal invoicing" unless $opt{q};
-        my @invoicing_list = $cust_main->invoicing_list;
-        push @invoicing_list, 'POST';
-        $cust_main->invoicing_list(\@invoicing_list);
-      }
-
       if ($opt{s}) {
         print "\n\tSuspending pkgnum " . $cust_pkg->pkgnum unless $opt{q};
         $cust_pkg->suspend;
       if ($opt{s}) {
         print "\n\tSuspending pkgnum " . $cust_pkg->pkgnum unless $opt{q};
         $cust_pkg->suspend;
@@ -72,7 +74,29 @@ foreach $cust_main ( qsearch('cust_main',{} ) ) {
         print "\n\tCancelling pkgnum " . $cust_pkg->pkgnum unless $opt{q};
         $cust_pkg->cancel;
       }
         print "\n\tCancelling pkgnum " . $cust_pkg->pkgnum unless $opt{q};
         $cust_pkg->cancel;
       }
+      
+    }
+
+    if ( $opt{b} ) {
+      print "\n\tBilling" unless $opt{q};
+      my $error = $cust_main->bill('time'=>$now);
+      warn "Error billing,  customer #" . $cust_main->custnum . 
+        ":" . $error if $error;
+    }
 
 
+    if ( $opt{y} ) {
+      print "\n\tApplying outstanding payments and credits" unless $opt{q};
+      $cust_main->apply_payments;
+      $cust_main->apply_credits;
+    }
+
+    if ( $opt{o} ) {
+      print "\n\tCollecting" unless $opt{q};
+      my $error = $cust_main->collect( 'invoice_time'=>$now,
+                                       'batch_card' => $opt{i} ? 'no' : 'yes',
+                                     );
+      warn "Error collecting from customer #" . $cust_main->custnum.  ":$error"
+        if $error;
     }
 
     print "\n" unless $opt{q};
     }
 
     print "\n" unless $opt{q};
@@ -99,7 +123,7 @@ freeside-overdue - Perform actions on overdue and/or expired accounts.
 
 =head1 SYNOPSIS
 
 
 =head1 SYNOPSIS
 
-  freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -l amount ] [ -s ] [ -c ] user
+  freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -l amount ] [ -s ] [ -c ] [ -b ] [ -y ] [ -o [ -i ] ] user
 
 =head1 DESCRIPTION
 
 
 =head1 DESCRIPTION
 
@@ -107,22 +131,31 @@ Performs actions on overdue and/or expired accounts.
 
 Selection options (at least one selection option is required):
 
 
 Selection options (at least one selection option is required):
 
-  -d:  Customers with a balance due on invoices older than the supplied number
-        of days.  Requires an integer argument.
+  -d:  Customers with a balance due on invoices older than the supplied number
+       of days.  Requires an integer argument.
 
 
-  -e:   Customers with a billing expiration date in the past.
+  -e:  Customers with a billing expiration date in the past.
 
 Action options: 
 
 
 Action options: 
 
-  -q:   Be quiet (by default, selected accounts are printed).
+  -q:  Be quiet (by default, selected accounts are printed).
+
+  -p:  Add postal invoicing to the relevant customers.
+
+  -l:  Add a charge of the given amount to the relevant customers.
+
+  -s:  Suspend accounts.
 
 
-  -p:   Add postal invoicing to the relevant customers.
+  -c:  Cancel accounts.
 
 
-  -l:   Add a charge of the given amount to the relevant customers.
+  -b:  Bill customers (create invoices)
 
 
-  -s:  Suspend accounts.
+  -y:  Apply unapplied payments and credits
 
 
-  -c:   Cancel accounts.
+  -o:  Collect from customers (charge cards, print invoices)
+
+    -i:  real-time billing (as opposed to batch billing).  only relevant
+         for credit cards.
 
   user: From the mapsecrets file - see config.html from the base documentation
 
 
   user: From the mapsecrets file - see config.html from the base documentation
 
@@ -146,6 +179,12 @@ Example crontab entries:
 
 Original disable-overdue version by mw/kwh: Mark W.? and Kristian Hoffmann ?
 
 
 Original disable-overdue version by mw/kwh: Mark W.? and Kristian Hoffmann ?
 
+Ivan seems to be turning it into the "do-everything" CLI.
+
+=head1 BUGS
+
+Hell now that this is the do-everything CLI it should have --longoptions
+
 =cut
 
 1;
 =cut
 
 1;
index 9588dcb..d3251c2 100755 (executable)
@@ -1,5 +1,5 @@
 <%
 <%
-#<!-- $Id: cust_main.cgi,v 1.17 2001-12-27 09:26:14 ivan Exp $ -->
+#<!-- $Id: cust_main.cgi,v 1.18 2001-12-28 14:40:35 ivan Exp $ -->
 
 use vars qw( $cgi $custnum $action $cust_main $p1 @agents $agentnum 
              $last $first $ss $company $address1 $address2 $city $zip 
 
 use vars qw( $cgi $custnum $action $cust_main $p1 @agents $agentnum 
              $last $first $ss $company $address1 $address2 $city $zip 
@@ -364,12 +364,12 @@ print "<TR><TD>Billing type</TD></TR>",
 
 %payby = (
   'CARD' => qq!Credit card<BR>${r}<INPUT TYPE="text" NAME="CARD_payinfo" VALUE="" MAXLENGTH=19><BR>${r}Exp !. expselect("CARD"). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="CARD_payname" VALUE="">!,
 
 %payby = (
   'CARD' => qq!Credit card<BR>${r}<INPUT TYPE="text" NAME="CARD_payinfo" VALUE="" MAXLENGTH=19><BR>${r}Exp !. expselect("CARD"). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="CARD_payname" VALUE="">!,
-  'BILL' => qq!Billing<BR>P.O. <INPUT TYPE="text" NAME="BILL_payinfo" VALUE=""><BR>${r}Exp !. expselect("BILL", "12-2037"). qq!<BR>${r}Attention<BR><INPUT TYPE="text" NAME="BILL_payname" VALUE="Accounts Payable">!,
+  'BILL' => qq!Billing<BR>P.O. <INPUT TYPE="text" NAME="BILL_payinfo" VALUE=""><BR>${r}Exp !. expselect("BILL", "12-2037"). qq!<BR>Attention<BR><INPUT TYPE="text" NAME="BILL_payname" VALUE="">!,
   'COMP' => qq!Complimentary<BR>${r}Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE=""><BR>${r}Exp !. expselect("COMP"),
 );
 %paybychecked = (
   'CARD' => qq!Credit card<BR>${r}<INPUT TYPE="text" NAME="CARD_payinfo" VALUE="$payinfo" MAXLENGTH=19><BR>${r}Exp !. expselect("CARD", $cust_main->paydate). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="CARD_payname" VALUE="$payname">!,
   'COMP' => qq!Complimentary<BR>${r}Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE=""><BR>${r}Exp !. expselect("COMP"),
 );
 %paybychecked = (
   'CARD' => qq!Credit card<BR>${r}<INPUT TYPE="text" NAME="CARD_payinfo" VALUE="$payinfo" MAXLENGTH=19><BR>${r}Exp !. expselect("CARD", $cust_main->paydate). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="CARD_payname" VALUE="$payname">!,
-  'BILL' => qq!Billing<BR>P.O. <INPUT TYPE="text" NAME="BILL_payinfo" VALUE="$payinfo"><BR>${r}Exp !. expselect("BILL", $cust_main->paydate). qq!<BR>${r}Attention<BR><INPUT TYPE="text" NAME="BILL_payname" VALUE="$payname">!,
+  'BILL' => qq!Billing<BR>P.O. <INPUT TYPE="text" NAME="BILL_payinfo" VALUE="$payinfo"><BR>${r}Exp !. expselect("BILL", $cust_main->paydate). qq!<BR>Attention<BR><INPUT TYPE="text" NAME="BILL_payname" VALUE="$payname">!,
   'COMP' => qq!Complimentary<BR>${r}Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE="$payinfo"><BR>${r}Exp !. expselect("COMP", $cust_main->paydate),
 );
 for (qw(CARD BILL COMP)) {
   'COMP' => qq!Complimentary<BR>${r}Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE="$payinfo"><BR>${r}Exp !. expselect("COMP", $cust_main->paydate),
 );
 for (qw(CARD BILL COMP)) {
index 1618c5a..735f4f2 100755 (executable)
@@ -1,4 +1,4 @@
-<!-- $Id: part_pkg.cgi,v 1.7 2001-12-27 09:26:14 ivan Exp $ -->
+<!-- $Id: part_pkg.cgi,v 1.8 2001-12-28 14:40:35 ivan Exp $ -->
 
 <%
 
 
 <%
 
@@ -26,6 +26,7 @@ if ( $cgi->param('clone') ) {
   my $old_part_pkg =
     qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
   $part_pkg ||= $old_part_pkg->clone;
   my $old_part_pkg =
     qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
   $part_pkg ||= $old_part_pkg->clone;
+  $part_pkg->disabled('Y');
 } elsif ( $query && $query =~ /^(\d+)$/ ) {
   $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
 } else {
 } elsif ( $query && $query =~ /^(\d+)$/ ) {
   $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
 } else {