summaryrefslogtreecommitdiff
path: root/FS/FS
diff options
context:
space:
mode:
authorivan <ivan>2005-06-02 09:29:56 +0000
committerivan <ivan>2005-06-02 09:29:56 +0000
commit684a478c0f88e5bf6d1d3f32f4618089146b5709 (patch)
tree1f0c8e23048aa20e872ff10f07a134436968ac43 /FS/FS
parent14cc10e34e277f4761be76d67d621b5a5d10a87f (diff)
add ability to search on a date range of invoice events and then reprint or reemail (boy was that a bit more work than i expected), closes: Bug#946
Diffstat (limited to 'FS/FS')
-rw-r--r--FS/FS/UI/Web.pm13
-rw-r--r--FS/FS/cust_bill.pm149
-rw-r--r--FS/FS/cust_bill_event.pm96
-rw-r--r--FS/FS/part_bill_event.pm23
-rw-r--r--FS/FS/part_pkg.pm11
5 files changed, 244 insertions, 48 deletions
diff --git a/FS/FS/UI/Web.pm b/FS/FS/UI/Web.pm
index 46e904b..e701141 100644
--- a/FS/FS/UI/Web.pm
+++ b/FS/FS/UI/Web.pm
@@ -4,6 +4,19 @@ package FS::UI::Web;
#use FS::UI
#@ISA = qw( FS::UI );
+use Date::Parse;
+sub parse_beginning_ending {
+ my($cgi) = @_;
+
+ $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/;
+ my $beginning = str2time($1) || 0;
+
+ #need an option to turn off the + 86399 ???
+ $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/;
+ my $ending = ( $1 ? str2time($1) : 4294880896 ) + 86399;
+
+ ( $beginning, $ending );
+}
# begin JSRPC code...
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index 2c25c6f..888687e 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -20,6 +20,9 @@ use FS::cust_pkg;
use FS::cust_credit_bill;
use FS::cust_pay_batch;
use FS::cust_bill_event;
+use FS::part_pkg;
+use FS::cust_bill_pay;
+use FS::part_bill_event;
@ISA = qw( FS::Record );
@@ -557,63 +560,121 @@ sub send {
my $self = shift;
my $template = scalar(@_) ? shift : '';
return 'N/A' if scalar(@_) && $_[0] && $self->cust_main->agentnum != shift;
+
my $invoice_from =
scalar(@_)
? shift
: ( $self->_agent_invoice_from || $conf->config('invoice_from') );
- #my @print_text = $self->print_text('', $template);
my @invoicing_list = $self->cust_main->invoicing_list;
- if ( grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list or !@invoicing_list ) {
- #email
+ $self->send_email($template, $invoice_from)
+ if grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list or !@invoicing_list;
- #better to notify this person than silence
- @invoicing_list = ($invoice_from) unless @invoicing_list;
+ $self->send_print($template)
+ if grep { $_ eq 'POST' } @invoicing_list; #postal
- my $error = send_email(
- $self->generate_email(
- 'from' => $invoice_from,
- 'to' => [ grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list ],
- #'print_text' => [ @print_text ],
- 'template' => $template,
- )
- );
- die "can't email invoice: $error\n" if $error;
- #die "$error\n" if $error;
+ $self->send_fax($template)
+ if grep { $_ eq 'FAX' } @invoicing_list; #fax
- }
+ '';
- if ( grep { $_ =~ /^(POST|FAX)$/ } @invoicing_list ) {
- my $lpr_data;
- if ($conf->config('invoice_latex')) {
- $lpr_data = [ $self->print_ps('', $template) ];
- } else {
- $lpr_data = [ $self->print_text('', $template) ];
- }
+}
- if ( grep { $_ eq 'POST' } @invoicing_list ) { #postal
- my $lpr = $conf->config('lpr');
- open(LPR, "|$lpr")
- or die "Can't open pipe to $lpr: $!\n";
- print LPR @{$lpr_data};
- close LPR
- or die $! ? "Error closing $lpr: $!\n"
- : "Exit status $? from $lpr\n";
- }
+=item email [ TEMPLATENAME [ , INVOICE_FROM ] ]
- if ( grep { $_ eq 'FAX' } @invoicing_list ) { #fax
- die 'FAX invoice destination not supported with plain text invoices.'
- unless $conf->exists('invoice_latex');
- my $dialstring = $self->cust_main->getfield('fax');
- #Check $dialstring?
- my $error = send_fax(docdata => $lpr_data, dialstring => $dialstring);
- die $error if $error;
- }
+Emails this invoice.
- }
+TEMPLATENAME, if specified, is the name of a suffix for alternate invoices.
- '';
+INVOICE_FROM, if specified, overrides the default email invoice From: address.
+
+=cut
+
+sub email {
+ my $self = shift;
+ my $template = scalar(@_) ? shift : '';
+ my $invoice_from =
+ scalar(@_)
+ ? shift
+ : ( $self->_agent_invoice_from || $conf->config('invoice_from') );
+
+ my @invoicing_list = grep { $_ !~ /^(POST|FAX)$/ }
+ $self->cust_main->invoicing_list;
+
+ #better to notify this person than silence
+ @invoicing_list = ($invoice_from) unless @invoicing_list;
+
+ my $error = send_email(
+ $self->generate_email(
+ 'from' => $invoice_from,
+ 'to' => [ grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list ],
+ 'template' => $template,
+ )
+ );
+ die "can't email invoice: $error\n" if $error;
+ #die "$error\n" if $error;
+
+}
+
+=item lpr_data [ TEMPLATENAME ]
+
+Returns the postscript or plaintext for this invoice.
+
+TEMPLATENAME, if specified, is the name of a suffix for alternate invoices.
+
+=cut
+
+sub lpr_data {
+ my( $self, $template) = @_;
+ $conf->exists('invoice_latex')
+ ? [ $self->print_ps('', $template) ]
+ : [ $self->print_text('', $template) ];
+}
+
+=item print [ TEMPLATENAME ]
+
+Prints this invoice.
+
+TEMPLATENAME, if specified, is the name of a suffix for alternate invoices.
+
+=cut
+
+sub print {
+ my $self = shift;
+ my $template = scalar(@_) ? shift : '';
+
+ my $lpr = $conf->config('lpr');
+ open(LPR, "|$lpr")
+ or die "Can't open pipe to $lpr: $!\n";
+ print LPR @{ $self->lpr_data($template) };
+ close LPR
+ or die $! ? "Error closing $lpr: $!\n"
+ : "Exit status $? from $lpr\n";
+}
+
+=item fax [ TEMPLATENAME ]
+
+Faxes this invoice.
+
+TEMPLATENAME, if specified, is the name of a suffix for alternate invoices.
+
+=cut
+
+sub fax {
+ my $self = shift;
+ my $template = scalar(@_) ? shift : '';
+
+ die 'FAX invoice destination not (yet?) supported with plain text invoices.'
+ unless $conf->exists('invoice_latex');
+
+ my $dialstring = $self->cust_main->getfield('fax');
+ #Check $dialstring?
+
+ my $error = send_fax( 'docdata' => $self->lpr_data($template),
+ 'dialstring' => $dialstring,
+ );
+ die $error if $error;
}
@@ -1024,7 +1085,7 @@ sub print_text {
( grep { ! $_->pkgnum } $self->cust_bill_pkg ), #then taxes
) {
- if ( $cust_bill_pkg->pkgnum ) {
+ if ( $cust_bill_pkg->pkgnum > 0 ) {
my $cust_pkg = qsearchs('cust_pkg', { pkgnum =>$cust_bill_pkg->pkgnum } );
my $part_pkg = qsearchs('part_pkg', { pkgpart=>$cust_pkg->pkgpart } );
@@ -1919,7 +1980,7 @@ sub _items_cust_bill_pkg {
my @b = ();
foreach my $cust_bill_pkg ( @$cust_bill_pkg ) {
- if ( $cust_bill_pkg->pkgnum ) {
+ if ( $cust_bill_pkg->pkgnum > 0 ) {
my $cust_pkg = qsearchs('cust_pkg', { pkgnum =>$cust_bill_pkg->pkgnum } );
my $part_pkg = qsearchs('part_pkg', { pkgpart=>$cust_pkg->pkgpart } );
diff --git a/FS/FS/cust_bill_event.pm b/FS/FS/cust_bill_event.pm
index ddd6762..7b98139 100644
--- a/FS/FS/cust_bill_event.pm
+++ b/FS/FS/cust_bill_event.pm
@@ -1,13 +1,15 @@
package FS::cust_bill_event;
use strict;
-use vars qw( @ISA );
+use vars qw( @ISA $DEBUG );
use FS::Record qw( qsearch qsearchs );
use FS::cust_bill;
use FS::part_bill_event;
@ISA = qw(FS::Record);
+$DEBUG = 0;
+
=head1 NAME
FS::cust_bill_event - Object methods for cust_bill_event records
@@ -165,6 +167,98 @@ sub retry {
=back
+=head1 SUBROUTINES
+
+=over 4
+
+=item reprint
+
+=cut
+
+sub process_reprint {
+ process_re_X('print', @_);
+}
+
+=item reemail
+
+=cut
+
+sub process_reemail {
+ process_re_X('email', @_);
+}
+
+=item refax
+
+=cut
+
+sub process_refax {
+ process_re_X('fax', @_);
+}
+
+use Storable qw(thaw);
+use Data::Dumper;
+use MIME::Base64;
+sub process_re_X {
+ my( $method, $job ) = ( shift, shift );
+
+ my $param = thaw(decode_base64(shift));
+ warn Dumper($param) if $DEBUG;
+
+ re_X(
+ $method,
+ $param->{'beginning'},
+ $param->{'ending'},
+ $param->{'failed'},
+ $job,
+ );
+
+}
+
+sub re_X {
+ my($method, $beginning, $ending, $failed, $job) = @_;
+
+ my $where = " WHERE plan LIKE 'send%'".
+ " AND cust_bill_event._date >= $beginning".
+ " AND cust_bill_event._date <= $ending";
+ $where .= " AND statustext != '' AND statustext IS NOT NULL"
+ if $failed;
+
+ my $from = 'LEFT JOIN part_bill_event USING ( eventpart )';
+
+ my @cust_bill_event = qsearch( 'cust_bill_event', {}, '', $where, '', $from );
+
+ my( $num, $last, $min_sec ) = (0, time, 5); #progresbar foo
+ foreach my $cust_bill_event ( @cust_bill_event ) {
+
+ $cust_bill_event->cust_bill->$method(
+ $cust_bill_event->part_bill_event->templatename
+ );
+
+ if ( $job ) { #progressbar foo
+ $num++;
+ if ( time - $min_sec > $last ) {
+ my $error = $job->update_statustext(
+ int( 100 * $num / scalar(@cust_bill_event) )
+ );
+ die $error if $error;
+ $last = time;
+ }
+ }
+
+ }
+
+ #this doesn't work, but it would be nice
+ #if ( $job ) { #progressbar foo
+ # my $error = $job->update_statustext(
+ # scalar(@cust_bill_event). " invoices re-${method}ed"
+ # );
+ # die $error if $error;
+ #}
+
+}
+
+=back
+
=head1 BUGS
Far too early in the morning.
diff --git a/FS/FS/part_bill_event.pm b/FS/FS/part_bill_event.pm
index b7c8b6a..0d03ebf 100644
--- a/FS/FS/part_bill_event.pm
+++ b/FS/FS/part_bill_event.pm
@@ -171,11 +171,32 @@ sub check {
$self->SUPER::check;
}
+=item templatename
+
+Returns the alternate invoice template name, if any, or false if there is
+no alternate template for this invoice event.
+
+=cut
+
+sub templatename {
+ my $self = shift;
+ if ( $self->plan =~ /^send_(alternate|agent)$/
+ && $self->plandata =~ /^(agent_)?templatename (.*)$/m
+ )
+ {
+ $2;
+ } else {
+ '';
+ }
+}
+
+
=back
=head1 BUGS
-Alas.
+The whole "eventcode" idea is bunk. This should be refactored with subclasses
+like part_pkg/ and part_export/
=head1 SEE ALSO
diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm
index bf040c8..f9b36e2 100644
--- a/FS/FS/part_pkg.pm
+++ b/FS/FS/part_pkg.pm
@@ -2,7 +2,7 @@ package FS::part_pkg;
use strict;
use vars qw( @ISA %freq %plans $DEBUG );
-use Carp qw(carp cluck);
+use Carp qw(carp cluck confess);
use Tie::IxHash;
use FS::Conf;
use FS::Record qw( qsearch qsearchs dbh dbdef );
@@ -643,9 +643,15 @@ on how to create new price plans, but until then, see L</NEW PLAN CLASSES>.
sub _rebless {
my $self = shift;
my $plan = $self->plan;
+ unless ( $plan ) {
+ confess "no price plan found for pkgpart ". $self->pkgpart. "\n"
+ if $DEBUG;
+ return $self;
+ }
my $class = ref($self). "::$plan";
+ warn "reblessing $self into $class" if $DEBUG;
eval "use $class;";
- #die $@ if $@;
+ die $@ if $@;
bless($self, $class) unless $@;
$self;
}
@@ -697,6 +703,7 @@ sub calc_cancel { 0; }
my %info;
foreach my $INC ( @INC ) {
+ warn "globbing $INC/FS/part_pkg/*.pm\n" if $DEBUG;
foreach my $file ( glob("$INC/FS/part_pkg/*.pm") ) {
warn "attempting to load plan info from $file\n" if $DEBUG;
$file =~ /\/(\w+)\.pm$/ or do {