summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2005-06-15 00:44:28 +0000
committerivan <ivan>2005-06-15 00:44:28 +0000
commit34d94b50332bcb2196ced634a27b596287600a8c (patch)
tree48598844fec10ee957a588ee8de8d1dfd3681820
parent0402f78ff052d950bc9fd4e4845b7d81d2196c47 (diff)
add reprint/fax/email links to invoice search results
-rw-r--r--FS/FS/cust_bill.pm74
-rwxr-xr-xhttemplate/search/cust_bill.html3
2 files changed, 51 insertions, 26 deletions
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index 0a00de701..dfebba63c 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -2153,39 +2153,71 @@ sub process_re_X {
re_X(
$method,
- $param->{'beginning'},
- $param->{'ending'},
- $param->{'failed'},
$job,
+ %$param,
);
}
sub re_X {
- my($method, $beginning, $ending, $failed, $job) = @_;
+ my($method, $job, %param ) = @_;
+# [ 'begin', 'end', 'agentnum', 'open', 'days', 'newest_percust' ],
- 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;
+ #some false laziness w/search/cust_bill.html
+ my $distinct = '';
+ my $orderby = 'ORDER BY cust_bill._date';
- my $from = 'LEFT JOIN part_bill_event USING ( eventpart )';
+ my @where;
- my @cust_bill_event = qsearch( 'cust_bill_event', {}, '', $where, '', $from );
+ if ( $param{'begin'} =~ /^(\d+)$/ ) {
+ push @where, "cust_bill._date >= $1";
+ }
+ if ( $param{'end'} =~ /^(\d+)$/ ) {
+ push @where, "cust_bill._date < $1";
+ }
+ if ( $param{'agentnum'} =~ /^(\d+)$/ ) {
+ push @where, "cust_main.agentnum = $1";
+ }
- my( $num, $last, $min_sec ) = (0, time, 5); #progresbar foo
- foreach my $cust_bill_event ( @cust_bill_event ) {
+ my $owed =
+ "charged - ( SELECT COALESCE(SUM(amount),0) FROM cust_bill_pay
+ WHERE cust_bill_pay.invnum = cust_bill.invnum )
+ - ( SELECT COALESCE(SUM(amount),0) FROM cust_credit_bill
+ WHERE cust_credit_bill.invnum = cust_bill.invnum )";
- $cust_bill_event->cust_bill->$method(
- $cust_bill_event->part_bill_event->templatename
- );
+ push @where, "0 != $owed"
+ if $param{'open'};
+
+ push @where, "cust_bill._date < ". (time-86400*$param{'days'})
+ if $param{'days'};
+
+ my $extra_sql = scalar(@where) ? 'WHERE '. join(' AND ', @where) : '';
+
+ my $addl_from = 'left join cust_main using ( custnum )';
+
+ if ( $param{'newest_percust'} ) {
+ $distinct = 'DISTINCT ON ( cust_bill.custnum )';
+ $orderby = 'ORDER BY cust_bill.custnum ASC, cust_bill._date DESC';
+ #$count_query = "SELECT COUNT(DISTINCT cust_bill.custnum), 'N/A', 'N/A'";
+ }
+
+ my @cust_bill = qsearch( 'cust_bill',
+ {},
+ "$distinct cust_bill.*",
+ $extra_sql,
+ '',
+ $addl_from
+ );
+
+ my( $num, $last, $min_sec ) = (0, time, 5); #progresbar foo
+ foreach my $cust_bill ( @cust_bill ) {
+ $cust_bill->$method();
if ( $job ) { #progressbar foo
$num++;
if ( time - $min_sec > $last ) {
my $error = $job->update_statustext(
- int( 100 * $num / scalar(@cust_bill_event) )
+ int( 100 * $num / scalar(@cust_bill) )
);
die $error if $error;
$last = time;
@@ -2194,14 +2226,6 @@ sub re_X {
}
- #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
diff --git a/httemplate/search/cust_bill.html b/httemplate/search/cust_bill.html
index 33967e935..5e904e114 100755
--- a/httemplate/search/cust_bill.html
+++ b/httemplate/search/cust_bill.html
@@ -19,6 +19,7 @@
# )
#{
+ #some false laziness w/cust_bill::re_X
my @where;
my $orderby = 'ORDER BY cust_bill._date';
@@ -118,7 +119,7 @@
( my $action = $_ ) =~ s/_$//;
include('/elements/progress-init.html',
$_.'form',
- [ 'begin', 'end', 'agentnum', 'open', 'days' ],
+ [ 'begin', 'end', 'agentnum', 'open', 'days', 'newest_percust' ],
"../misc/${_}invoices.cgi",
{ 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
$_, #key