From 5e25b996982d42eb2587ec54db0d5b39508aa730 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 28 Dec 2001 14:40:35 +0000 Subject: [PATCH] add more options to freeside-overdue 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 | 26 ++++++++++++- FS/bin/freeside-bill | 6 +-- FS/bin/freeside-overdue | 85 +++++++++++++++++++++++++++++++------------ httemplate/edit/cust_main.cgi | 6 +-- httemplate/edit/part_pkg.cgi | 3 +- 5 files changed, 95 insertions(+), 31 deletions(-) diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 3995e6561..6c18f93a1 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -28,6 +28,7 @@ use FS::cust_credit_bill; use FS::cust_bill_pay; use FS::prepay_credit; use FS::queue; +use FS::part_pkg; @ISA = qw( FS::Record ); @@ -1775,6 +1776,29 @@ sub credit { $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 @@ -1916,7 +1940,7 @@ sub append_fuzzyfiles { =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 diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 7898936c5..49ec43c82 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -59,14 +59,14 @@ foreach $cust_main ( 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', ); - warn "Error collecting from customer #" . $cust_main->gcustnum. ":$error" + warn "Error collecting from customer #" . $cust_main->custnum. ":$error" if $error; #sleep 1; @@ -123,7 +123,7 @@ customers. Otherwise, bills all customers. =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 diff --git a/FS/bin/freeside-overdue b/FS/bin/freeside-overdue index 0c62b99c1..8f7f872c8 100755 --- a/FS/bin/freeside-overdue +++ b/FS/bin/freeside-overdue @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w 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; -getopts('ed:qplsc', \%opt); +getopts('ed:qplscbyoi', \%opt); 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++; @@ -48,21 +48,23 @@ foreach $cust_main ( qsearch('cust_main',{} ) ) { $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 } ) ) { - 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; @@ -72,7 +74,29 @@ foreach $cust_main ( qsearch('cust_main',{} ) ) { 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}; @@ -99,7 +123,7 @@ freeside-overdue - Perform actions on overdue and/or expired accounts. =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 @@ -107,22 +131,31 @@ Performs actions on overdue and/or expired accounts. 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: - -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 @@ -146,6 +179,12 @@ Example crontab entries: 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; diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index 9588dcb3a..d3251c2b9 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -1,5 +1,5 @@ <% -# +# use vars qw( $cgi $custnum $action $cust_main $p1 @agents $agentnum $last $first $ss $company $address1 $address2 $city $zip @@ -364,12 +364,12 @@ print "Billing type", %payby = ( 'CARD' => qq!Credit card
${r}
${r}Exp !. expselect("CARD"). qq!
${r}Name on card
!, - 'BILL' => qq!Billing
P.O.
${r}Exp !. expselect("BILL", "12-2037"). qq!
${r}Attention
!, + 'BILL' => qq!Billing
P.O.
${r}Exp !. expselect("BILL", "12-2037"). qq!
Attention
!, 'COMP' => qq!Complimentary
${r}Approved by
${r}Exp !. expselect("COMP"), ); %paybychecked = ( 'CARD' => qq!Credit card
${r}
${r}Exp !. expselect("CARD", $cust_main->paydate). qq!
${r}Name on card
!, - 'BILL' => qq!Billing
P.O.
${r}Exp !. expselect("BILL", $cust_main->paydate). qq!
${r}Attention
!, + 'BILL' => qq!Billing
P.O.
${r}Exp !. expselect("BILL", $cust_main->paydate). qq!
Attention
!, 'COMP' => qq!Complimentary
${r}Approved by
${r}Exp !. expselect("COMP", $cust_main->paydate), ); for (qw(CARD BILL COMP)) { diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi index 1618c5a99..735f4f269 100755 --- a/httemplate/edit/part_pkg.cgi +++ b/httemplate/edit/part_pkg.cgi @@ -1,4 +1,4 @@ - + <% @@ -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; + $part_pkg->disabled('Y'); } elsif ( $query && $query =~ /^(\d+)$/ ) { $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1}); } else { -- 2.11.0